void MainLoop() { double deltaT; double time = glfwGetTime(); double lastTime = time; bool running = true; Game* game = new Game; game->Init(); while (running) { double time = glfwGetTime(); deltaT = time - lastTime; lastTime = time; running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); game->Update(deltaT); game->Render(); glFlush(); glfwSwapBuffers(); Util::CheckGlError(); } game->Cleanup(); glfwTerminate(); }
int main(int argc, char*argv[]) { Game game; game.Init("Space Shooter",Settings::ScreenWidth,Settings::ScreenHeight,32,false); game.ChangeState(LogoState::Instance()); while(game.Running()) { game.HandleEvents(); game.Update(); game.Draw(); } printf("about to call cleanup\n"); game.Cleanup(); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd){ Game mygame; if (FAILED(mygame.Init(hInstance))){ MessageBox(NULL, L"Failed to initialize game", NULL, MB_OK); return 1; } //Get the time in milliseconds DWORD startTime = GetTickCount(); float deltaTime = 0; MSG msg; memset(&msg, 0, sizeof(MSG)); while (msg.message != WM_QUIT){ if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ //Put the message in a recognizable form TranslateMessage(&msg); //Send the message to the window procedure DispatchMessage(&msg); } else{ //Update the game DWORD t = GetTickCount(); deltaTime = float(t - startTime)*0.001f; //Pass time in seconds mygame.Update(deltaTime); //Render the world mygame.Render(); startTime = t; } } mygame.Cleanup(); return (int)msg.wParam; }