diff --git a/src/application/application.cpp b/src/application/application.cpp index 0dde87df..222ba11e 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -70,14 +70,19 @@ Application::Application(char const *name, ivec2 resolution, float framerate) data = new ApplicationData(name, resolution, framerate); } -void Application::ShowPointer(bool show) +bool Application::MustTick() { - data->app.ShowPointer(show); + return !Ticker::Finished(); } -void Application::Run() +void Application::Tick() { - data->app.Run(); + data->app.Tick(); +} + +void Application::ShowPointer(bool show) +{ + data->app.ShowPointer(show); } Application::~Application() diff --git a/src/application/application.h b/src/application/application.h index 94af770f..428efb3c 100644 --- a/src/application/application.h +++ b/src/application/application.h @@ -27,8 +27,12 @@ public: Application(char const *name, ivec2 resolution, float framerate); ~Application(); + bool MustTick(); + void Tick(); + + void Run() { while(MustTick()) Tick(); } + void ShowPointer(bool show); - void Run(); private: ApplicationData *data; diff --git a/src/eglapp.cpp b/src/eglapp.cpp index 2347115f..5cddbdb6 100644 --- a/src/eglapp.cpp +++ b/src/eglapp.cpp @@ -267,16 +267,13 @@ void EglApp::ShowPointer(bool show) (void)show; } -void EglApp::Run() +void EglApp::Tick() { - while (!Ticker::Finished()) - { - /* Tick the renderer, show the frame and clamp to desired framerate. */ - Ticker::TickDraw(); + /* Tick the renderer, show the frame and clamp to desired framerate. */ + Ticker::TickDraw(); #if defined USE_EGL && !defined __ANDROID__ - eglSwapBuffers(data->egl_dpy, data->egl_surf); + eglSwapBuffers(data->egl_dpy, data->egl_surf); #endif - } } EglApp::~EglApp() diff --git a/src/eglapp.h b/src/eglapp.h index d24d153f..d6b33c6a 100644 --- a/src/eglapp.h +++ b/src/eglapp.h @@ -30,7 +30,7 @@ public: virtual ~EglApp(); void ShowPointer(bool show); - void Run(); + void Tick(); private: EglAppData *data; diff --git a/src/platform/android/androidapp.cpp b/src/platform/android/androidapp.cpp index e1d54822..0f94d9ff 100644 --- a/src/platform/android/androidapp.cpp +++ b/src/platform/android/androidapp.cpp @@ -46,22 +46,24 @@ void AndroidApp::ShowPointer(bool show) { } -/* This is a fake Run() method. We just wait until we're called and +/* This is a fake Tick() method. We just wait until we're called and * signal nativeInit() that all the user's initialisation code was * called. Then we sit here forever, the Java layer is in charge of * calling TickDraw(). */ -void AndroidApp::Run() +void AndroidApp::Tick() { - g_main_queue.Push(1); - g_main_queue.Push(1); - - while (!Ticker::Finished()) + static int init = 0; + if (!init) { - /* Do nothing while the real render thread does the job. The - * real stuff happens in nativeRender() */ - Timer t; - t.Wait(0.5f); + init = 1; + g_main_queue.Push(1); + g_main_queue.Push(1); } + + /* Do nothing while the real render thread does the job. The + * real stuff happens in nativeRender() */ + Timer t; + t.Wait(0.5f); } void *AndroidApp::MainRun(void *data) diff --git a/src/platform/android/androidapp.h b/src/platform/android/androidapp.h index 7d373d04..92750f4f 100644 --- a/src/platform/android/androidapp.h +++ b/src/platform/android/androidapp.h @@ -30,7 +30,7 @@ public: virtual ~AndroidApp(); void ShowPointer(bool show); - void Run(); + void Tick(); static void *MainRun(void *data); diff --git a/src/platform/nacl/nacl-app.cpp b/src/platform/nacl/nacl-app.cpp index d1037f27..9c4d08f1 100644 --- a/src/platform/nacl/nacl-app.cpp +++ b/src/platform/nacl/nacl-app.cpp @@ -50,15 +50,17 @@ void NaClApp::ShowPointer(bool show) ; } -void NaClApp::Run() +void NaClApp::Tick() { + /* The caller should run forever */ #if defined __native_client__ - NaClInstance::MainSignal(); + static int init = 0; + if (!init) + { + NaClInstance::MainSignal(); + init = 1; + } #endif - - /* Wait forever */ - Queue q; - q.Pop(); } NaClApp::~NaClApp() diff --git a/src/platform/nacl/nacl-app.h b/src/platform/nacl/nacl-app.h index 623d77d2..d6053e38 100644 --- a/src/platform/nacl/nacl-app.h +++ b/src/platform/nacl/nacl-app.h @@ -30,7 +30,7 @@ public: virtual ~NaClApp(); void ShowPointer(bool show); - void Run(); + void Tick(); private: NaClAppData *data; diff --git a/src/platform/ps3/ps3app.cpp b/src/platform/ps3/ps3app.cpp index bbb04029..da7047a2 100644 --- a/src/platform/ps3/ps3app.cpp +++ b/src/platform/ps3/ps3app.cpp @@ -114,20 +114,17 @@ void Ps3App::ShowPointer(bool show) ; } -void Ps3App::Run() +void Ps3App::Tick() { - while (!Ticker::Finished()) - { - /* Tick the renderer, show the frame and clamp to desired framerate. */ - Ticker::TickDraw(); + /* Tick the renderer, show the frame and clamp to desired framerate. */ + Ticker::TickDraw(); #if defined __CELLOS_LV2__ - psglSwap(); + psglSwap(); - /* Check if exit callback was called */ - cellSysutilCheckCallback(); + /* Check if exit callback was called */ + cellSysutilCheckCallback(); #endif - } } Ps3App::~Ps3App() diff --git a/src/platform/ps3/ps3app.h b/src/platform/ps3/ps3app.h index d1c22cda..9b4a222f 100644 --- a/src/platform/ps3/ps3app.h +++ b/src/platform/ps3/ps3app.h @@ -30,7 +30,7 @@ public: virtual ~Ps3App(); void ShowPointer(bool show); - void Run(); + void Tick(); private: Ps3AppData *data; diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 99ba367d..83d8a095 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -109,31 +109,28 @@ void SdlApp::ShowPointer(bool show) #endif } -void SdlApp::Run() +void SdlApp::Tick() { - while (!Ticker::Finished()) - { #if defined USE_SDL && defined USE_D3D9 - HRESULT hr; - hr = g_d3ddevice->BeginScene(); - if (FAILED(hr)) - Abort(); + HRESULT hr; + hr = g_d3ddevice->BeginScene(); + if (FAILED(hr)) + Abort(); #endif - /* Tick the renderer, show the frame and clamp to desired framerate. */ - Ticker::TickDraw(); + /* Tick the renderer, show the frame and clamp to desired framerate. */ + Ticker::TickDraw(); #if defined USE_SDL # if defined USE_D3D9 - hr = g_d3ddevice->EndScene(); - if (FAILED(hr)) - Abort(); - hr = g_d3ddevice->Present(NULL, NULL, NULL, NULL); - if (FAILED(hr)) - Abort(); + hr = g_d3ddevice->EndScene(); + if (FAILED(hr)) + Abort(); + hr = g_d3ddevice->Present(NULL, NULL, NULL, NULL); + if (FAILED(hr)) + Abort(); # else - SDL_GL_SwapBuffers(); + SDL_GL_SwapBuffers(); # endif #endif - } } SdlApp::~SdlApp() diff --git a/src/platform/sdl/sdlapp.h b/src/platform/sdl/sdlapp.h index 4ec54c7d..4953934c 100644 --- a/src/platform/sdl/sdlapp.h +++ b/src/platform/sdl/sdlapp.h @@ -30,7 +30,7 @@ public: virtual ~SdlApp(); void ShowPointer(bool show); - void Run(); + void Tick(); private: SdlAppData *data; diff --git a/src/platform/xbox/xboxapp.cpp b/src/platform/xbox/xboxapp.cpp index e63cb78f..a45d875f 100644 --- a/src/platform/xbox/xboxapp.cpp +++ b/src/platform/xbox/xboxapp.cpp @@ -61,17 +61,14 @@ void XboxApp::ShowPointer(bool show) ; } -void XboxApp::Run() +void XboxApp::Tick() { - while (!Ticker::Finished()) - { - /* Tick the renderer, show the frame and clamp to desired framerate. */ - Ticker::TickDraw(); + /* Tick the renderer, show the frame and clamp to desired framerate. */ + Ticker::TickDraw(); #if defined _XBOX - g_d3ddevice->Present(NULL, NULL, NULL, NULL); + g_d3ddevice->Present(NULL, NULL, NULL, NULL); #endif - } } XboxApp::~XboxApp() diff --git a/src/platform/xbox/xboxapp.h b/src/platform/xbox/xboxapp.h index 5c88ef89..684ca87c 100644 --- a/src/platform/xbox/xboxapp.h +++ b/src/platform/xbox/xboxapp.h @@ -30,7 +30,7 @@ public: virtual ~XboxApp(); void ShowPointer(bool show); - void Run(); + void Tick(); private: XboxAppData *data;