void engineHandleCommand(struct android_app* app, int32_t cmd) { ARUserData * data = (ARUserData*) app->userData; Engine* engine = data->engine; LOGD(LOGTAG_INPUT,"Handling OS cmd: %d",cmd); switch (cmd) { case APP_CMD_INIT_WINDOW: LOGI(LOGTAG_MAIN,"OS Has Initialized Window"); initializeEngine(app, engine); initializeWindow(app, engine); break; case APP_CMD_TERM_WINDOW: LOGI(LOGTAG_MAIN,"Terminated Window"); shutdownEngine(engine); break; case APP_CMD_GAINED_FOCUS: LOGI(LOGTAG_MAIN,"Gained focus"); engine->animating = 1; break; case APP_CMD_LOST_FOCUS: LOGI(LOGTAG_MAIN,"Lost focus, pausing animation"); engine->animating = 0; break; } }
void TriV::Engine::Core::TriVEngine::initiateEngineLoop() { std::cout << "ENGINE: Initiating Engine Loop..." << std::endl; while (!exitRequested) { frameDelta = engineClock.GetFrameDeltaSeconds(); frameAccumulator += frameDelta; if(frameAccumulator >= 1.0f) { framesPerSecond = engineClock.GetFrameCount() / frameAccumulator; std::cout << " FPS: " << framesPerSecond << " | Frame: " << frameDelta << "s | Render: " << engineClock.RenderAverage() << "ms | Update: " << engineClock.UpdateAverage() << "ms | Physics: " << engineClock.PhysicsAverage() << "ms" << std::endl; frameAccumulator = 0.0f; engineClock.Reset(); } engineClock.StartPhysicsTimer(); tickPhysics(); engineClock.StopPhysicsTimer(); engineClock.StartUpdateTimer(); tick(); engineClock.StopUpdateTimer(); engineClock.StartRenderTimer(); render(); engineClock.StopRenderTimer(); } shutdownEngine(); }
void MyGame::onKeyUp(KeyEvent *e) { if( e->button == SDLK_ESCAPE ) { shutdownEngine(); } }
void __AtracShutdown() { for (auto it = atracMap.begin(), end = atracMap.end(); it != end; ++it) { delete it->second; } atracMap.clear(); #ifdef _USE_DSHOW_ shutdownEngine(); #endif // _USE_DSHOW_ }
void android_main(struct android_app* state) { LOG_INTRO(); if (!envInitialized) { LOGE("ERROR! JAVA DID NOT INITIALIZE FIRST. Exiting!"); return; } pthread_mutex_init(&incomingMutex,NULL); jniDataVector.clear(); Engine mainEngine = Engine(); AmplifyRunner myRunner = AmplifyRunner(&mainEngine); struct ARUserData myData; memset(&myData,0,sizeof(ARUserData)); myData.engine = &mainEngine; myData.runner = &myRunner; state->userData = &myData; initializeEngine(state, &mainEngine); bool running = true; while (running) { // Read all pending events. int ident; int events; struct android_poll_source* source; // If not animating, we will block forever waiting for events. // If animating, we loop until all events are read, then continue to draw the next frame of animation. while ((ident = ALooper_pollAll(mainEngine.animating ? 0 : -1, NULL, &events, (void**) &source)) >= 0) { // Process this event. if (source != NULL) { source->process(state, source); } //Process sensor events if (ident == LOOPER_ID_USER) { mainEngine.sensorCollector->ProcessSensorEvents(); } // Check if we are exiting. if (state->destroyRequested != 0) { LOGI(LOGTAG_MAIN,"Engine thread destroy requested!"); shutdownEngine(&mainEngine); return; } } if (mainEngine.animating == 1) { mainEngine.communicator->Update(javaVM); //Check for messages in JNI queue if ( pthread_mutex_trylock(&incomingMutex) == 0) { int count = 0; while (!jniDataVector.empty()) { count++; mainEngine.communicator->AddIncomingMessage(jniDataVector.back()); jniDataVector.pop_back(); } if (count > 0) LOGD(LOGTAG_NETWORKING,"Got %d messages from JNI queue",count); pthread_mutex_unlock(&incomingMutex); } try { myRunner.DoFrame(&mainEngine); } catch (exception & e) { LOGE("Exiting due to caught exception. Message=%s",e.what()); myRunner.Teardown(&mainEngine); shutdownEngine(&mainEngine); } } //Check if state has changed during animation loop if (mainEngine.animating == 0) { LOGW(LOGTAG_MAIN,"Exiting due to internal user command."); ANativeActivity_finish(state->activity); } } myRunner.~AmplifyRunner(); shutdownEngine(&mainEngine); //ANativeActivity_finish(state->activity); }