mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3767 from michaelcontento/android-add-runOnGLThread-back-again
[ci skip]re-introduce Cocos2dxHelper.runOnGLThread(Runnable)
This commit is contained in:
commit
0c5e5cbf0c
|
@ -23,8 +23,10 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Locale;
|
||||
import java.lang.Runnable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
|
@ -44,6 +46,7 @@ public class Cocos2dxHelper {
|
|||
// Constants
|
||||
// ===========================================================
|
||||
private static final String PREFS_NAME = "Cocos2dxPrefsFile";
|
||||
private static final int RUNNABLES_PER_FRAME = 5;
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
|
@ -57,6 +60,7 @@ public class Cocos2dxHelper {
|
|||
private static String sFileDirectory;
|
||||
private static Activity sActivity = null;
|
||||
private static Cocos2dxHelperListener sCocos2dxHelperListener;
|
||||
private static ConcurrentLinkedQueue<Runnable> jobs = new ConcurrentLinkedQueue<Runnable>();
|
||||
|
||||
/**
|
||||
* Optional meta-that can be in the manifest for this component, specifying
|
||||
|
@ -70,6 +74,20 @@ public class Cocos2dxHelper {
|
|||
// Constructors
|
||||
// ===========================================================
|
||||
|
||||
public static void dispatchPendingRunnables() {
|
||||
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
|
||||
Runnable job = jobs.poll();
|
||||
if (job == null) {
|
||||
return;
|
||||
}
|
||||
job.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runOnGLThread(final Runnable r) {
|
||||
jobs.add(r);
|
||||
}
|
||||
|
||||
public static void init(final Activity activity) {
|
||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||
|
||||
|
|
|
@ -211,6 +211,30 @@ static cocos_dimensions engine_init_display(struct engine* engine) {
|
|||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the dispatching of the next bunch of Runnables in the Java-Land
|
||||
*/
|
||||
static void dispatch_pending_runnables() {
|
||||
static cocos2d::JniMethodInfo info;
|
||||
static bool initialized = false;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = cocos2d::JniHelper::getStaticMethodInfo(
|
||||
info,
|
||||
"org/cocos2dx/lib/Cocos2dxHelper",
|
||||
"dispatchPendingRunnables",
|
||||
"()V"
|
||||
);
|
||||
|
||||
if (!initialized) {
|
||||
LOGW("Unable to dispatch pending Runnables!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
info.env->CallStaticVoidMethod(info.classID, info.methodID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just the current frame in the display.
|
||||
*/
|
||||
|
@ -225,6 +249,7 @@ static void engine_draw_frame(struct engine* engine) {
|
|||
return;
|
||||
}
|
||||
|
||||
dispatch_pending_runnables();
|
||||
cocos2d::Director::getInstance()->mainLoop();
|
||||
LOG_RENDER_DEBUG("engine_draw_frame : just called cocos' mainLoop()");
|
||||
|
||||
|
|
Loading…
Reference in New Issue