int main(int argc, char* argv[]) { gpMemoryTracker = new MemoryTracker(); PerformanceTracker* pPerformanceTracker = New PerformanceTracker; pPerformanceTracker->startTracking("init"); gpEventSystem = New EventSystem(); gpGame = New Game(); if(!gpGame->init(DISPLAY_WIDTH, DISPLAY_HEIGHT)) { cout << "\nFailed to init Game\n"; system("PAUSE"); return 0; } gpGame->runLoop(); delete gpUnitManager; delete pPerformanceTracker; delete gpGame; delete gpEventSystem; delete mpTimer; if (gpMemoryTracker->getNumAllocations() > 0) { gpMemoryTracker->reportAllocations(std::cout); system("PAUSE"); } delete gpMemoryTracker; return 0; }
void ClientGameSession::gameLoop() { Timer* pTimer = new Timer(); PerformanceTracker* pPerformanceTracker = new PerformanceTracker(); mpTimer->start(); double deltaTime = 0.0f; while( mGameIsRunning ) { pPerformanceTracker->startTracking( "FPS" ); double start = mpTimer->getElapsedTime(); mpNetworkPeer->ProcessPackets(); mpNetworkPeer->CheckChatInput(); input(); update( deltaTime ); draw(); double sleepAmount = ( start + msSkipTime ) - mpTimer->getElapsedTime(); if( sleepAmount > 0.0f ) { pTimer->start(); pTimer->sleepUntilElapsed( sleepAmount ); } pPerformanceTracker->stopTracking( "FPS" ); deltaTime = pPerformanceTracker->getElapsedTime( "FPS" ); pPerformanceTracker->clearTracker( "FPS" ); } pTimer->sleepUntilElapsed( 100 ); delete pTimer; delete pPerformanceTracker; }