Changeset 1944


Ignore:
Timestamp:
Sep 23, 2012, 5:35:24 PM (5 years ago)
Author:
sam
Message:

android: fix a synchronisation issue between Java and the game thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/platform/android/androidapp.cpp

    r1684 r1944  
    3636JavaVM *g_vm;
    3737jobject g_activity;
     38Queue<int> g_main_queue;
    3839Thread *g_main_thread;
    3940
    40 AndroidApp::AndroidApp(char const *title, ivec2 res, float fps) :
    41     data(0)
     41AndroidApp::AndroidApp(char const *title, ivec2 res, float fps)
     42  : data(0)
    4243{
    4344}
     
    4748}
    4849
     50/* This is a fake Run() method. We just wait until we're called and
     51 * signal nativeInit() that all the user's initialisation code was
     52 * called. Then we sit here forever, the Java layer is in charge of
     53 * calling TickDraw(). */
    4954void AndroidApp::Run()
    5055{
     56    g_main_queue.Push(1);
     57
    5158    while (!Ticker::Finished())
    5259    {
    53         /* Tick the renderer, show the frame and clamp to desired framerate. */
    54         Ticker::TickDraw();
     60        /* Do nothing while the real render thread does the job. The
     61         * real stuff happens in nativeRender() */
     62        Timer t;
     63        t.Wait(0.5f);
    5564    }
    5665}
     
    8695Java_org_zoy_LolEngine_LolActivity_nativeInit(JNIEnv* env, jobject thiz)
    8796{
     97    Log::Info("Java layer initialising activity");
    8898    env->NewGlobalRef(thiz); /* FIXME: never released! */
    8999    g_activity = thiz;
     
    93103Java_org_zoy_LolEngine_LolRenderer_nativeInit(JNIEnv* env)
    94104{
    95     Log::Info("initialising renderer");
     105    Log::Info("Java layer initialising renderer");
    96106    Ticker::Setup(30.0f);
    97107    Video::Setup(ivec2(320, 200));
    98108
    99109    g_main_thread = new Thread(lol::AndroidApp::MainRun, NULL);;
     110    g_main_queue.Pop();
    100111}
    101112
     
    104115                                                jint w, jint h)
    105116{
    106     Log::Info("resizing to %i x %i", w, h);
     117    Log::Info("Java layer resizing to %i x %i", w, h);
    107118    Video::Setup(ivec2(w, h));
    108119}
Note: See TracChangeset for help on using the changeset viewer.