mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into iss1583-update-js
This commit is contained in:
commit
bb6e03bd3f
|
@ -116,9 +116,10 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
final float tmp = x;
|
||||
x = y;
|
||||
y = -tmp;
|
||||
}
|
||||
|
||||
Cocos2dxAccelerometer.onSensorChanged(x, y, z, pSensorEvent.timestamp);
|
||||
}
|
||||
|
||||
Cocos2dxGLSurfaceView.queueAccelerometer(x,y,z,pSensorEvent.timestamp);
|
||||
|
||||
/*
|
||||
if(BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "x = " + pSensorEvent.values[0] + " y = " + pSensorEvent.values[1] + " z = " + pSensorEvent.values[2]);
|
||||
|
@ -132,9 +133,10 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// Native method called from Cocos2dxGLSurfaceView (To be in the same thread)
|
||||
// ===========================================================
|
||||
|
||||
private static native void onSensorChanged(final float pX, final float pY, final float pZ, final long pTimestamp);
|
||||
|
||||
public static native void onSensorChanged(final float pX, final float pY, final float pZ, final long pTimestamp);
|
||||
|
||||
// ===========================================================
|
||||
// Inner and Anonymous Classes
|
||||
|
|
|
@ -117,6 +117,16 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
|
|||
// Getter & Setter
|
||||
// ===========================================================
|
||||
|
||||
|
||||
public static void queueAccelerometer(final float x, final float y, final float z, final long timestamp) {
|
||||
mCocos2dxGLSurfaceView.queueEvent(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Cocos2dxAccelerometer.onSensorChanged(x, y, z, timestamp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setCocos2dxRenderer(final Cocos2dxRenderer renderer) {
|
||||
this.mCocos2dxRenderer = renderer;
|
||||
this.setRenderer(this.mCocos2dxRenderer);
|
||||
|
|
|
@ -79,23 +79,32 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
|
|||
|
||||
@Override
|
||||
public void onDrawFrame(final GL10 gl) {
|
||||
/*
|
||||
* FPS controlling algorithm is not accurate, and it will slow down FPS
|
||||
* on some devices. So comment FPS controlling code.
|
||||
*/
|
||||
|
||||
/*
|
||||
final long nowInNanoSeconds = System.nanoTime();
|
||||
final long interval = nowInNanoSeconds - this.mLastTickInNanoSeconds;
|
||||
*/
|
||||
|
||||
// should render a frame when onDrawFrame() is called or there is a
|
||||
// "ghost"
|
||||
Cocos2dxRenderer.nativeRender();
|
||||
|
||||
/*
|
||||
// fps controlling
|
||||
if (interval < Cocos2dxRenderer.sAnimationInterval) {
|
||||
try {
|
||||
// because we render it before, so we should sleep twice time interval
|
||||
Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) * 2 / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
|
||||
Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
this.mLastTickInNanoSeconds = nowInNanoSeconds;
|
||||
*/
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
|
|
|
@ -790,7 +790,9 @@ void JSScheduleWrapper::scheduleFunc(float dt) const
|
|||
return;
|
||||
}
|
||||
|
||||
if(!JSVAL_IS_VOID(jsCallback) && !JSVAL_IS_VOID(jsThisObj)) {
|
||||
if(!jsCallback.isNullOrUndefined() || !jsThisObj.isNullOrUndefined()) {
|
||||
JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(jsThisObj));
|
||||
|
||||
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(jsThisObj), jsCallback, 1, &data, &retval);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue