src/core/android/SDL_android.cpp
changeset 6212 78d854de3a66
parent 6191 2c0d35b1af4e
child 6284 1893d507ba42
     1.1 --- a/src/core/android/SDL_android.cpp	Thu Jan 12 22:54:09 2012 -0500
     1.2 +++ b/src/core/android/SDL_android.cpp	Fri Jan 13 20:57:35 2012 -0500
     1.3 @@ -70,7 +70,7 @@
     1.4  
     1.5  // Accelerometer data storage
     1.6  static float fLastAccelerometer[3];
     1.7 -
     1.8 +static bool bHasNewData;
     1.9  
    1.10  /*******************************************************************************
    1.11                   Functions called by JNI
    1.12 @@ -111,6 +111,8 @@
    1.13      midAudioQuit = mEnv->GetStaticMethodID(mActivityClass,
    1.14                                  "audioQuit", "()V");
    1.15  
    1.16 +    bHasNewData = false;
    1.17 +
    1.18      if(!midCreateGLContext || !midFlipBuffers || !midAudioInit ||
    1.19         !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
    1.20          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    1.21 @@ -156,7 +158,8 @@
    1.22  {
    1.23      fLastAccelerometer[0] = x;
    1.24      fLastAccelerometer[1] = y;
    1.25 -    fLastAccelerometer[2] = z;   
    1.26 +    fLastAccelerometer[2] = z;
    1.27 +    bHasNewData = true;
    1.28  }
    1.29  
    1.30  // Quit
    1.31 @@ -224,12 +227,20 @@
    1.32      }
    1.33  }
    1.34  
    1.35 -extern "C" void Android_JNI_GetAccelerometerValues(float values[3])
    1.36 +extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
    1.37  {
    1.38      int i;
    1.39 -    for (i = 0; i < 3; ++i) {
    1.40 -        values[i] = fLastAccelerometer[i];
    1.41 +    SDL_bool retval = SDL_FALSE;
    1.42 +
    1.43 +    if (bHasNewData) {
    1.44 +        for (i = 0; i < 3; ++i) {
    1.45 +            values[i] = fLastAccelerometer[i];
    1.46 +        }
    1.47 +        bHasNewData = false;
    1.48 +        retval = SDL_TRUE;
    1.49      }
    1.50 +
    1.51 +    return retval;
    1.52  }
    1.53  
    1.54  //