// // get frames per second // void GetFramesPerSecond(void) { clock_t now; float delta; GameTick(); // add to global counter CheckRespawn(); if (frames++ >= FRAME_RATE_SAMPLES) { now = clock(); delta = (now - last_time) / (float)CLOCKS_PER_SEC; AddTime((float)(now - last_time)); AddSeconds(delta); // tabulate data last_time = now; framerate = FRAME_RATE_SAMPLES / delta; frames = 0; } // end of the if } // end of the functino
void Level::Tick(double deltaTime) { // Check whether the reload button has been pressed if (GAME_ENGINE->IsKeyboardKeyPressed('R')) { StreetJustice911* game = Singleton<StreetJustice911>::GetInstance(); game->LoadLevel(m_StandardConfigPath); return; } // Check whether physics rendering should be enabled or not if (GAME_ENGINE->IsKeyboardKeyPressed('P')) { m_PhysicsRendering = !m_PhysicsRendering; GAME_ENGINE->EnablePhysicsDebugRendering(m_PhysicsRendering); } // Tick depending on the state of the level switch (m_LevelState) { case LevelState::PLAYING: // Show the pause menu when pressing escape if (GAME_ENGINE->IsKeyboardKeyPressed(VK_ESCAPE) && (m_LevelState != LevelState::PAUSED)) { // Check whether the game should be paused or not SetActive(false); m_LevelState = LevelState::PAUSED; m_GameMenu = new GameMenu(); return; } GameTick(deltaTime); m_CameraPtr->Tick(deltaTime); break; case LevelState::OBJECTIVE: ObjectiveTick(deltaTime); break; case LevelState::COMPLETED: CompletedTick(deltaTime); break; case LevelState::FAILED: FailedTick(deltaTime); break; case LevelState::PAUSED: MenuTick(deltaTime); break; } }
void onTick(int value) { printf("onTick: value = %d\n", value); if (Window != value) { printf("Current window (%d) != tick id!\n", Window); return; } if (Window == W_GAME) { GameTick(); } else if (Window == W_CHAMPION) { ChampionTick(); } else { printf("Unknown window value\n"); } glutPostRedisplay(); }
void Engine::MainLoop() { CDEBUG("mainloop"); // static int numframes, t = 0, fps = 0; // frame counter stuff (Why do these need to be static?) ScopedPtr<Ika::Font> font; try { font = new Ika::Font("system.fnt", video); } catch (Ika::FontException) { font = 0; _showFramerate = false; } int now = GetTime(); SyncTime(); for (;;) { CheckMessages(); int skipcount = 0; while ( (_oldTime < now) && (skipcount <= _frameSkip)) { GameTick(); _oldTime++; skipcount++; } _oldTime = now; now = GetTime(); Render(); if (_showFramerate) { font->PrintString(0, 0, va("Fps: %i", video->GetFrameRate())); } video->ShowPage(); } }