/** * @brief Called on keypresses, clicks, etc. * * @param[in] event Describes the event that occurred. */ void MazeSolverApp::OnEvent(SDL_Event* event) { if(event->type == SDL_QUIT) { running = false; } else if (event->type == SDL_KEYDOWN) { if (event->key.keysym.unicode == 'd') { /* Solve the maze with a depth-first search. */ if (solver) { delete solver; solver = NULL; } solver = (MazeSolverBase *) new DepthFirstSolver(this); solver->solve(maze); OnRender(); } else if (event->key.keysym.unicode == 'b') { /* Solve the maze with a breadth-first search. */ if (solver) { delete solver; solver = NULL; } solver = (MazeSolverBase *) new BreadthFirstSolver(this); solver->solve(maze); OnRender(); } else if (event->key.keysym.unicode == 'r') { /* Reset the maze. */ if (solver) { delete solver; solver = NULL; } rb->create_maze(); OnRender(); } else if (event->key.keysym.unicode == 'q') { running = false; } } }
//------------------------------------------------------------------------------ int CApp::OnExecute() { if(OnInit() == false) { return -1; } SDL_Event Event; while(Running) { if(AIenabled && CurrentPlayer && GameState == GAME_STATE_RUNNING) { GameClick(AIMove()); } while(SDL_PollEvent(&Event)) { OnEvent(&Event); } OnLoop(); OnRender(); } OnCleanup(); return 0; }
int SampleApp::MainLoop() { MSG msg = { 0 }; while (WM_QUIT != msg.message) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { LARGE_INTEGER pc; QueryPerformanceCounter(&pc); if (pc.QuadPart - prevCounter.QuadPart >= counterPerFrame) { LONGLONG elapsed = pc.QuadPart - prevCounter.QuadPart; prevCounter = pc; OnUpdate(elapsed); OnRender(); } } } return (int)msg.wParam; }
int main(int argc,char ** argv) { // start GL context and O/S window using the GLFW helper library appDelegate.AppWillStart(); FPS_Helper fpsHelper; fpsHelper.SetFixedFPS(30); InitOpenGL(); appDelegate.AppDidStart(); while (!glfwWindowShouldClose (mainWnd.window)) { // wipe the drawing surface clear static double timer_last = 0; double curr_time = glfwGetTime(); if(curr_time - timer_last > 0.2) { timer_last = timer_last + 0.02; OnTimer(); } if(fpsHelper.Tick()) { OnRender(); // update other events like input handling glfwPollEvents (); // put the stuff we've been drawing onto the display glfwSwapBuffers (mainWnd.window); } } // close GL context and any other GLFW resources appDelegate.AppWillTerminate(); glfwTerminate(); return 0; }
//Holds game logic together int Game::OnStart() { //Initialize the game if (OnInit() == false) { return -1; } SDL_Event Event; //While game is running while (running) { while (gameType == 0 && running) { while (SDL_PollEvent(&Event)) { OnEvent(&Event); } //meanwhile show menu showMenu(); } while (SDL_PollEvent(&Event)) { //Handle user input OnEvent(&Event); } OnLoop(); OnRender(); } OnCleanUp(); return 0; };
void ConvexHullApp::add_to_hull(Tuple *p) { hull.push_back(p); SDL_Delay(ANIMATION_DELAY); OnRender(); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if ((message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) || (message >= WM_KEYFIRST && message <= WM_KEYLAST) || (message >= WM_TOUCH && message <= WM_POINTERWHEEL)) { GetCurrentInputMessageSource(&g_inputSource); InvalidateRect(g_hwnd, NULL, FALSE); } switch (message) { case WM_PAINT: case WM_DISPLAYCHANGE: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); OnRender(hdc, ps.rcPaint); EndPaint(hwnd, &ps); } return 0; case WM_DESTROY: { PostQuitMessage(0); } return 1; } return DefWindowProc(hwnd, message, wParam, lParam); }
int Main::OnExecute(CL_ParamList* pCL_Params) { if(!OnInit(pCL_Params)) return -1; SDL_Event Event; Uint32 t1,t2; float fTime = 0.0f; while(Running) { t1 = SDL_GetTicks(); while(SDL_PollEvent(&Event)) { if(Event.type == SDL_QUIT) Running = false; else OnEvent(&Event); } OnMove(fTime); OnRender(); t2 = SDL_GetTicks(); fTime = (float)(t2-t1)/1000.0f; } OnExit(); return 1; }
void Game::OnExecute() { if (m_state != GameState::INIT_SUCCESSFUL) { std::cerr << "Game INIT was not successful." << std::endl; return; } m_state = GameState::RUNNING; CreateAsteroid(Asteroids::Asteroid::AsteroidSize::BIG, 1); SDL_Event event; while (m_state == GameState::RUNNING) { // Input polling // while (SDL_PollEvent(&event)) { OnEvent(&event); } // OnUpdate(); OnRender(); } }
// Called whenever the client area needs to be drawn HRESULT FirstTry::OnPaint() { // Update the animation manager with the current time UI_ANIMATION_SECONDS secondsNow; HRESULT hr = m_pAnimationTimer->GetTime(&secondsNow); if (SUCCEEDED(hr)) { hr = m_pAnimationManager->Update(secondsNow); // Read the values of the animation variables and draw the client area hr = OnRender(); if (SUCCEEDED(hr)) { // Continue redrawing the client area as long as there are animations scheduled. UI_ANIMATION_MANAGER_STATUS status; hr = m_pAnimationManager->GetStatus(&status); if (SUCCEEDED(hr)) { if (status == UI_ANIMATION_MANAGER_BUSY) { InvalidateRect(m_hwnd, NULL, FALSE); } } } } return hr; }
/** * @brief Called on keypresses, clicks, etc. * * @param[in] event Describes the event that occurred. */ void LineApp::OnEvent(SDL_Event* event) { if(event->type == SDL_QUIT) { running = false; } else if (event->type == SDL_KEYDOWN) { if (event->key.keysym.unicode == 'q') { running = false; } else if (event->key.keysym.unicode == 'l') { DoLineAlg(); } else if (event->key.keysym.unicode == 'c') { delete_all(); } } else if (event->type == SDL_MOUSEBUTTONDOWN) { if (event->button.state == SDL_PRESSED) { int x = event->button.x; int y = event->button.y; points.push_back(new Tuple(x, y)); } OnRender(); } }
void MainGameLoop::Run() { FrameCounter fc; // main game loop while (!m_bExitLoop) { OnTick(); ProcessEvents(); if (m_bExitLoop) break; if (!m_bAppActive) { // as we're not visible, just wait for next event SDL_WaitEvent(NULL); continue; } // render the scene { OpenGL::ResetPolycount(); OnRender(); fc.OnNextFrame(); } // count ticks for fps double dFramesPerSecond; if (m_bUpdateFrameCount && fc.GetUpdatedCount(dFramesPerSecond)) UpdateCaption(dFramesPerSecond); } }
void CApplication::MainLoop() { SDL_Event event; Uint32 startTime, elapsedTime; while( !m_Quit ) { // Le temps avant l'éxécution startTime = SDL_GetTicks(); // Tant qu'il y a des messages, les traiter while( SDL_PollEvent(&event) ) { OnEvent(event); } // Mise à jour de la scène OnUpdate(); // Démarrer le rendu m_Renderer.BeginScene(); OnRender(); m_Renderer.EndScene(); // Si on a mis moins de temps que le nombre de FPS demandé, on attend // permet de limiter les fps et de gagner du temps de process CPU if( (elapsedTime = SDL_GetTicks()-startTime) < m_FPSLimit ) { SDL_Delay(m_FPSLimit - elapsedTime); } } }
int App::OnExecute() { if(OnInit() == false) { return -1; } controller->Initialize(); SDL_Event Event; while(running) { Scene* scene = controller->GetCurrentScene(); if (scene == NULL) { break; } if(SDL_PollEvent(&Event)) { OnEvent(scene, &Event); } OnLoop(scene); OnRender(scene); } OnCleanup(); return 0; }
int CApp::OnExecute(){ if (OnInit() == false){ return -1; } SDL_Event Event; while(Running){ while(SDL_PollEvent(&Event)){ OnEvent(&Event); } OnLoop(); OnRender(); } OnCleanup(); return 0; }
int cLayer::Render() { int Result = OnRender(); return Result; }
int CInstance_Menu_MJ::OnExecute() { if(!Init()) { cerr << ERROR_STR_INIT << " MENU_MJ" << endl; return ERROR_CODE_GENERAL; } int frame = 0; CTemporizador fps; int salida = I_SALIDA; while(i_running) { fps.empezar(); while(SDL_PollEvent(&event)) { OnEvent(salida); } OnLoop(salida); OnRender(); frame++; if((fps.getTicks() < (1000 / FRAMES_PER_SECOND))) SDL_Delay((1000 / FRAMES_PER_SECOND ) - fps.getTicks()); } Close(); return salida; }
int CApp::OnExecute() { // Initialize application. int state = OnInit(); if (state != APP_OK) { return state; } // Enter the SDL event loop. SDL_Event event; running = true; while (running) { while (SDL_PollEvent(&event)) { OnEvent(&event); } OnUpdate(); OnRender(); } return state; }
/** * Handle all events that come from SDL. * These are timer or keyboard events. */ void SFApp::OnEvent(SFEvent& event) { SFEVENT the_event = event.GetCode(); switch (the_event) { case SFEVENT_QUIT: is_running = false; break; case SFEVENT_UPDATE: OnUpdateWorld(); OnRender(); break; case SFEVENT_PLAYER_UP: player->GoNorth(); break; case SFEVENT_PLAYER_DOWN: player->GoSouth(); break; case SFEVENT_PLAYER_LEFT: player->GoWest(); break; case SFEVENT_PLAYER_RIGHT: player->GoEast(); break; case SFEVENT_FIRE: fire ++; FireProjectile(); break; } }
int cFX::Render() { return OnRender(); }
void WavingGrass::RunLoop() { glEnable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); n = 20; m = 10; w = 20, h = 50; mUp = glm::vec3(0, 1, 0); mRight = glm::vec3(1, 0, 0); std::vector<glm::vec3> grass(n*m); int Z = -50, X = -100; for (int i = 0; i < n; ++i, Z+=5) { int offset = (i%2==0)?X:(X+10); for (int j = 0; j < m; ++j, offset+=w) { float x = (2*offset+w)/2;//(offsetX+offsetX+w)/2 float y = h/2; grass[m*i+j] = glm::vec3(x, y, Z); //Quads的中心点 } } std::vector<GLushort> indices(n*m); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { indices[m*i+j] = j; } } glGenBuffers(1, &mVBO); glBindBuffer(GL_ARRAY_BUFFER, mVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3)*grass.size(), &grass[0], GL_STATIC_DRAW); glGenBuffers(1, &mIBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*indices.size(), &indices[0], GL_STATIC_DRAW); glGenVertexArrays(1, &mVAO); glBindVertexArray(mVAO); glEnableVertexAttribArray(0); //glEnableVertexAttribArray(1); //glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, mVBO); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), NULL); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIBO); glBindVertexArray(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glfwSetTime(0.2); while ( !glfwWindowShouldClose(mpWindow) ) { OnRender(); glfwSwapBuffers(mpWindow); glfwPollEvents(); } glfwTerminate(); }
LRESULT MetroWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { PAINTSTRUCT ps; ::BeginPaint(m_hWnd, &ps); OnRender(); ::EndPaint(m_hWnd, &ps); return 0; }
void IActor::Render() const { OnRender(); for (auto&& child : m_children) { child->Render(); } }
void HKeyPixelFrame::OnPaint() { CPaintDC dc(this); CRect rect; GetClientRect(&rect); HMemDC memDC(&dc,rect); m_Image.Draw(memDC.GetSafeHdc(),0,0); OnRender(memDC); }
LRESULT MainWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandle) { LRESULT hr = S_OK; PAINTSTRUCT ps; BeginPaint(&ps); /// if auto return OnRender(),CPU usage is too high hr = OnRender(); EndPaint(&ps); return hr; }
void Engine::Run() { OnInit(); m_isRunning = true; while (m_isRunning) { OnRender(); OnUpdate(1.0f); } OnCleanUp(); }
void Gameplay::Execute(CApp* app) { SDL_Event event; while(SDL_PollEvent(&event)) { app->OnEvent(&event); } app->OnLoop(); OnRender(app); }
int D3D11App::Run() { MSG msg; msg.wParam = 0; if (Create()) { if (Load()) { // Initialize high-res timer LARGE_INTEGER freq, lCnt, cnt; QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&cnt); do { while (true) { //if (activeWindow && !minimized){ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) <= 0) break; /*} else { if (GetMessage(&msg, NULL, 0, 0) <= 0) break; }*/ TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) break; // Keep track of time lCnt = cnt; QueryPerformanceCounter(&cnt); m_frameTime = float(cnt.QuadPart - lCnt.QuadPart) / freq.QuadPart; // On some systems this appears to be the only "solution" to random glitches in the timer m_frameTime = clamp(m_frameTime, 0.0001f, 1.0f); m_time += m_frameTime; OnRender(); } while (true); // Clear state first to get rid of "currently bound" warnings m_context->GetDeviceContext()->ClearState(); Unload(); } } Destroy(); return (int) msg.wParam; }
/** * Handle all events that come from SDL. * These are timer or keyboard events. */ void SFApp::OnEvent(SFEvent& event) { SFEVENT the_event = event.GetCode(); switch (the_event) { case SFEVENT_QUIT: is_running = false; break; case SFEVENT_UPDATE: OnUpdateWorld(); OnRender(); break; } }
void Window::Render(const boost::shared_ptr<Surface>& target) { if (IsDone()) { return; } target->PushState(); target->SetViewportRelative(GetBounds()); OnRender(target); target->PopState(); }