void PlatformDesktop::SingleLoop() { if( mEventRecorder ) mEventRecorder->StartOfFrame( GetTime() ); HandleEvents(); poro_assert( GetApplication() ); poro_assert( mGraphics ); types::Double32 dt = mOneFrameShouldLast; if( mFixedTimeStep == false ) { static types::Double32 last_time_update_called = 0; dt = (types::Double32)( GetUpTime() - last_time_update_called ); last_time_update_called = GetUpTime(); } GetApplication()->Update( (types::Float32)(dt) ); mGraphics->BeginRendering(); GetApplication()->Draw(mGraphics); mGraphics->EndRendering(); if( mEventRecorder ) mEventRecorder->EndOfFrame( GetTime() ); }
void * CaptureUserInput(void * arg) { int i; GetMyDeviceType(); ReadDeviceKeyDB(); printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event)); maxEventPlusOne = -1; for (i=0; i<=MAX_INPUT_FILE_ID; i++) { if (nKeyEntries[i] == 0) { inputEvents[i] = -1; } else { inputEvents[i] = OpenInputDevice(i); if (inputEvents[i] > maxEventPlusOne) maxEventPlusOne = inputEvents[i]; } } maxEventPlusOne++; while (1) { if (!HandleEvents()) break; } printf("Thread CaptureUserInput() exit.\n"); for (i=0; i<=MAX_INPUT_FILE_ID; i++) { CloseInputDevice(i); } return 0; }
void GameStateManager::Run(void) { Initialise(); while (m_running) { // If a new state is set to begin, set it now if (m_preparedState) InitialisePreparedState(); // Update static key states KeyTools::UpdateStates(); // State's key press responses m_currentState->OnKeys(SDL_GetKeyboardState(nullptr)); // Update State m_currentState->OnUpdate(delta); // Render State m_currentState->OnRender(); HandleEvents(); delta = RegulateFrameRate(); } delete this; }
void Game::Run() { const float TargetFps = 60.0f; const float DelayTime = 1000.0f / TargetFps; gameState = RUNNING; while(gameState == RUNNING) { frameStart = SDL_GetTicks(); HandleEvents(); Update(); Render(); frameCount += 1; frameTime = SDL_GetTicks() - frameStart; if(frameStart < DelayTime) { SDL_Delay((int)(DelayTime - frameTime)); } } Clean(); }
void Displayer::RenderLoop() { InitWindow(); while (win->IsOpened() && !closed) { HandleEvents(); // Don't draw if disabled/minimised if (!Displayer::drawingEnabled) continue; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, win->GetWidth(), win->GetHeight(), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); // Draw panels controlPanel->Draw(*win, defaultFont); DrawWorldPanel(); // Display and sleep win->Display(); sf::Sleep(1.0f / refreshRate); } }
void GameEngine::Start() { int ticksPerFrame = (int)(1000.0 / FPS_TARGET + 0.5); Uint32 nextSecond = SDL_GetTicks() + 1000; int frames = 0; Mix_Chunk *track = NULL; int channel = 0; _isRunning = true; while (_isRunning) { _frameTimer.Mark(); HandleEvents(); Update(); Draw(); // If there is no music playing if(Mix_Playing(channel) == 0) // Play music channel = Music(track); if (_frameTimer.GetTicks() < ticksPerFrame) SDL_Delay(ticksPerFrame - _frameTimer.GetTicks()); if (SDL_GetTicks() >= nextSecond) { nextSecond += 1000; _currentFps = frames; frames = 0; } ++frames; } }
Word NewGameWindow(Word NewVidSize) { XSizeHints sizehints; if (NewVidSize == VidSize) return VidSize; if (NewVidSize < 4) { w = VidXs[NewVidSize]; h = VidYs[NewVidSize]; v = VidVs[NewVidSize]; } else { fprintf(stderr, "Invalid Vid size: %d\n", NewVidSize); exit(EXIT_FAILURE); } sizehints.min_width = w; sizehints.min_height = h; sizehints.flags = PMinSize; XSetWMNormalHints(dpy, win, &sizehints); XResizeWindow(dpy, win, w, h); SetAPalette(rBlackPal); ClearTheScreen(BLACK); BlastScreen(); VidSize = NewVidSize; XSync(dpy, False); glXWaitGL(); glXWaitX(); HandleEvents(); return VidSize; }
void GameEngine::Run() { HandleWindowEvents(); HandleEvents(); Update(); Draw(); }
int main( int argc, char **argv ) { /* Save our program name - for error messages */ set_DeadPipe_handler(DeadPipe); InitMyApp (CLASS_IDENT, argc, argv, NULL, NULL, 0 ); LinkAfterStepConfig(); set_signal_handler( SIGSEGV ); ConnectX( ASDefaultScr, 0 ); ConnectAfterStep (WINDOW_CONFIG_MASK | WINDOW_NAME_MASK | M_END_WINDOWLIST, 0); Config = CreateIdentConfig (); /* Request a list of all windows, while we load our config */ SendInfo ("Send_WindowList", 0); LoadBaseConfig ( GetBaseOptions); LoadColorScheme(); LoadConfig ("ident", GetOptions); CheckConfigSanity(); ReloadASDatabase(); ReloadCategories(True); if (MyArgs.src_window == 0) MyArgs.src_window = get_target_window(); /* And at long last our main loop : */ HandleEvents(); return 0 ; }
void Application::Run() { Initialize(); double tickCounter = 0; int frames = 0; clock_t t1 = clock(); clock_t t2; while(!HandleEvents()) { Update(); BeginDraw(); Draw(); EndDraw(); frames++; t2 = clock(); clock_t diff = t2 - t1; //Guarantee a maximum fps rate double sleepInteval = (double)CLOCKS_PER_SEC / fps - diff; if(sleepInteval > 0) { usleep(1000000 * sleepInteval / CLOCKS_PER_SEC); tickCounter += sleepInteval; } //Display FPS rate tickCounter += diff; if(tickCounter > CLOCKS_PER_SEC) { _frameRate = frames; tickCounter = 0; frames = 0; } t1 = clock(); } }
void Sys_SendKeyEvents (void) { // XEvent event; // bk001204 - unused if (!screen) return; HandleEvents(); }
void Map::Update() { for (std::vector<Entity*>::iterator it = entities.begin(); it != entities.end();) { if ((*it)->active) ++it; else { delete *it; it = entities.erase(it); } } HandleCollision(); HandleEvents(); Entity* entity; for (std::vector<Entity*>::iterator it = entities.begin(); it != entities.end(); ++it) { entity = (*it); if (entity->OnScreen == false) continue; if (entity->GetLight() > 0 && ((int) entity->shape->GetCenterX() != (int) (entity->prevPos.x + entity->GetSize().x / 2.0) || (int) entity->shape->GetCenterY() != (int) (entity->prevPos.y + entity->GetSize().y / 2.0))) lightDirty = true; } skyManager->Update(); }
int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_EVERYTHING); atexit(SDL_Quit); debugLogFile = fopen("stderr.txt", "wb"); { char buffer[128]; const time_t raw(time(NULL)); const struct tm* local(localtime(&raw)); strftime(buffer, sizeof(buffer)-1, "%c\n", local); LOG("%s", buffer); } if (!Initialise()) { exit(EXIT_FAILURE); } unsigned int lastUpdate = 0; while (!quit) { HandleEvents(); unsigned int now = SDL_GetTicks(); unsigned int elapsedMS = now - lastUpdate; lastUpdate = now; UpdateGame(elapsedMS); RenderFrame(); Device::SwapBuffers(); } return 0; }
void Game::Run(){ while (running) { //trap mouse curser in window HWND hwnd; hwnd = FindWindow(0,LPCWSTR("Pew")); RECT r; //top left coords r.left = window.getPosition().x; r.top = window.getPosition().y; //bottom right coords r.right = window.getPosition().x + window.getSize().x; r.bottom = window.getPosition().y + window.getSize().y; //clip mouse to window GetWindowRect(hwnd, &r); ClipCursor(&r); //do the game stuff Update(); HandleEvents(); Render(); Quit(); } }
int main(int argc, char *argv[]) { initialize(); srand(time(NULL)); SDL_Surface *screen; screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError()); exit(1); } //Main game loop while(1) { //Check for end game conditions if (!player.alive) { RenderFinal(screen, FALSE); } else if (g_monsters == NULL) { RenderFinal(screen, TRUE); } UpdateState(); RenderState(screen); HandleEvents(); usleep(50000); } }
void * CaptureUserInput(void * arg) { int i; __android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "pre_getMyDeviceType"); GetMyDeviceType(); __android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "pre_ReadDeviceKeyDB"); ReadDeviceKeyDB(); __android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() ", "post_ReadDeviceKeyDB"); printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event)); maxEventPlusOne = -1; char aLine[256]; for (i=0; i<=MAX_INPUT_FILE_ID; i++) { sprintf(aLine, "i = %d", i); if (nKeyEntries[i] == 0) { inputEvents[i] = -1; } else { inputEvents[i] = OpenInputDevice(i); if (inputEvents[i] > maxEventPlusOne) { maxEventPlusOne = inputEvents[i]; sprintf(aLine, "NOT_EXPECTED: i = %d, inputEvents[i] (%d) > maxEventPlusOne = %d", i, inputEvents[i], maxEventPlusOne); #ifdef TEST_INPUT WriteUserInputLog("libpcap: b CaptureUserInput() nKeyEntries[i] != 0 ", aLine); #endif } } } maxEventPlusOne++; while (1) { if (!HandleEvents()) { #ifdef TEST_INPUT WriteUserInputLog("libpcap: After HandleEvents returns 0 in CaptureUserInput() ", "setting exitFlag = 3 and breaking from loop"); #endif exitFlag = 3; break; } if (exitFlag == 4) { #ifdef TEST_INPUT WriteUserInputLog("libpcap: After HandleEvents exitFlag is 4 ", "setting exitFlag = 3 and breaking from loop"); #endif exitFlag = 3; break; } } printf("Thread CaptureUserInput() exit.\n"); __android_log_print(ANDROID_LOG_DEBUG, "Thread CaptureUserInput() exit", "EXIT"); printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event)); for (i=0; i<=MAX_INPUT_FILE_ID; i++) { CloseInputDevice(i); } CloseUserInputLog(); return 0; }
void BaseScene::RunFrame() { FrameStart(); HandleEvents(); Update(); Render(screen); SDL_Flip(screen); FrameEnd(); }
void Sys_SendKeyEvents( void ) { // XEvent event; // bk001204 - unused if ( !dpy ) { return; } HandleEvents(); }
// internal routines, run by the posting thread void LinuxaioQueue::PostRequests() { RequestPtr req; io_event* events = new io_event[max_events_]; for ( ; ; ) // as long as thread is running { // might block until next request or message comes in size_t num_currently_waiting_requests = num_waiting_requests_.wait(); // terminate if termination has been requested if (post_thread_state_() == TERMINATING && num_currently_waiting_requests == 0) break; std::unique_lock<std::mutex> lock(waiting_mtx_); if (!waiting_requests_.empty()) { req = waiting_requests_.front(); waiting_requests_.pop_front(); lock.unlock(); // might block because too many requests are posted num_free_events_.wait(); // polymorphic_downcast while (!dynamic_cast<LinuxaioRequest*>(req.get())->post()) { // post failed, so first handle events to make queues (more) // empty, then try again. // wait for at least one event to complete, no time limit long num_events = syscall(SYS_io_getevents, context_, 1, max_events_, events, nullptr); if (num_events < 0) { THRILL_THROW_ERRNO(IoError, "linuxaio_queue::post_requests" " io_getevents() nr_events=" << num_events); } HandleEvents(events, num_events, false); } // request is finally posted { std::unique_lock<std::mutex> lock(posted_mtx_); posted_requests_.push_back(req); num_posted_requests_.signal(); } } else { lock.unlock(); // num_waiting_requests-- was premature, compensate for that num_waiting_requests_.signal(); } } delete[] events; }
int CSDL_ApplicationBase::Main(int argc, char *argv[]) { while(m_bIsRunning) { m_pKeystate = ::SDL_GetKeyState(NULL); m_Modstate = ::SDL_GetModState(); HandleEvents(); } return EXIT_SUCCESS; }
void Game::RunGameLoop() { while (window->isOpen()) { HandleEvents(); Update(); Draw(); } }
void Sys_SendKeyEvents (void) { #ifndef DEDICATED_ONLY HandleEvents(); #endif // grab frame time sys_frame_time = Sys_Milliseconds(); }
void VID_Finish (void) { vid_usevsync = vid_vsync.integer && !cls.timedemo && qglXSwapIntervalSGI; switch(vid.renderpath) { case RENDERPATH_SOFT: if(vidx11_shmevent >= 0) { vidx11_ximage_pos = !vidx11_ximage_pos; vid.softpixels = (unsigned int *) vidx11_ximage[vidx11_ximage_pos]->data; DPSOFTRAST_SetRenderTargets(vid.width, vid.height, vid.softdepthpixels, vid.softpixels, NULL, NULL, NULL); // save mouse motion so we can deal with it later in_mouse_x = 0; in_mouse_y = 0; while(vidx11_shmwait) HandleEvents(); in_mouse_x_save += in_mouse_x; in_mouse_y_save += in_mouse_y; in_mouse_x = 0; in_mouse_y = 0; ++vidx11_shmwait; XShmPutImage(vidx11_display, win, vidx11_gc, vidx11_ximage[!vidx11_ximage_pos], 0, 0, 0, 0, vid.width, vid.height, True); } else { // no buffer switching here, we just flush the renderer DPSOFTRAST_Finish(); XPutImage(vidx11_display, win, vidx11_gc, vidx11_ximage[vidx11_ximage_pos], 0, 0, 0, 0, vid.width, vid.height); } break; case RENDERPATH_GL11: case RENDERPATH_GL13: case RENDERPATH_GL20: case RENDERPATH_GLES1: case RENDERPATH_GLES2: if (vid_usingvsync != vid_usevsync) { vid_usingvsync = vid_usevsync; if (qglXSwapIntervalSGI && qglXSwapIntervalSGI (vid_usevsync)) Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n"); } if (!vid_hidden) { CHECKGLERROR if (r_speeds.integer == 2 || gl_finish.integer) GL_Finish(); qglXSwapBuffers(vidx11_display, win);CHECKGLERROR } break; case RENDERPATH_D3D9: case RENDERPATH_D3D10: case RENDERPATH_D3D11: break; }
void InitGraphics(int argc, char *argv[]) { Dimension width, height; XEvent event; static String fallback_resources[] = { "*xcheck*background: #e0e0e0", "*xcheck*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*", "*xcheck*font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*", "*xcheck*XmText.background: #b0e0c0", NULL, }; XtSetLanguageProc(NULL,NULL,NULL); toplevel = XtVaAppInitialize( &app,"App-Class", NULL,0, &argc,argv, fallback_resources, NULL); mainWidget = XtVaCreateManagedWidget("mw", xmMainWindowWidgetClass, toplevel, NULL); dpy = XtDisplay(mainWidget); gc = XCreateGC(dpy,DefaultRootWindow(dpy),(int)NULL,NULL); XSetLineAttributes(dpy,gc,2,LineSolid,CapButt,JoinMiter); colormap = CreateColorMap(mainWidget); menubar = CreateMenuBar(mainWidget); workwin = CreateWorkWin(mainWidget); message = CreateMessage(mainWidget); XtVaSetValues(mainWidget, XmNcolormap,colormap, XmNmenuBar,menubar, XmNworkWindow,workwin, XmNmessageWindow,message, NULL); XtRealizeWidget(toplevel); do { XtAppNextEvent(app,&event); XtDispatchEvent(&event); } while(event.type != Expose); XtVaGetValues(toplevel,XmNheight,&height,XmNwidth,&width,NULL); XtVaSetValues(toplevel, XmNwidth, width, XmNheight, height, XmNmaxWidth, width, XmNmaxHeight, height, XmNminWidth, width, XmNminHeight, height, XmNallowShellResize, False, NULL); HandleEvents(); strcpy(xval[0],"human"); strcpy(xval[1],"computer"); strcpy(xval[2],"10.0"); }
int main(void){ const unsigned int serverPort = 0xC001; DiagnosticsServerPtr server = createServer(serverPort); if(NULL == server) { error("Failed to create the server"); } /* Enter the eternal reactive event loop. */ for(;;){ HandleEvents(); } }
void UpdateInputState(u32 port) { static char key = 0; kcode[port]=0xFFFF; rt[port]=0; lt[port]=0; HandleEvents(port); }
MainGame::MainGame() { ConfigurationManager configManager(resourcePath() + "configuration.txt"); //if SDL fails, close program if (SDL_Init(SDL_INIT_VIDEO)) throw std::logic_error("Failed to initialize SDL! " + std::string(SDL_GetError())); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); if (configManager.GetItem<bool>("Multisampling")) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configManager.GetItem<int>("MultisampleBuffers")); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configManager.GetItem<int>("MultisampleSamples")); } SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(0, &mode); Uint32 windowFlags = SDL_WINDOW_OPENGL; size_t width = configManager.GetItem<float>("WindowWidth"), height = configManager.GetItem<float>("WindowHeight"); if (configManager.GetItem<bool>("Fullscreen")) { // width = mode.w; height = mode.h; windowFlags|=SDL_WINDOW_FULLSCREEN_DESKTOP; } window = SDL_CreateWindow("Genetic Algorithm", 0, 0, width, height, windowFlags); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetSwapInterval(1); SDL_SetRelativeMouseMode(SDL_TRUE); if (window==nullptr) throw std::logic_error("Window failed to be initialized"); SDL_GLContext context = SDL_GL_CreateContext(window); if (context==nullptr) throw std::logic_error("SDL_GL could not be initialized!"); int cpuCount = SDL_GetCPUCount(); GLManager glManager(resourcePath() + "fragmentShader.glsl", resourcePath() + "vertexShader.glsl", configManager); std::string fileLoc =resourcePath() + "performance.csv"; EvolutionSystem evolutionSystem(fileLoc, configManager, cpuCount); Camera camera(configManager.GetItem<float>("WindowWidth"), configManager.GetItem<float>("WindowHeight"), configManager); while (GameState!=GameState::EXIT) { Update(evolutionSystem); camera.Update(); glManager.Programs[0].SetMatrix4("transformMatrix", glm::value_ptr(camera.GetTransformMatrix())); Draw(evolutionSystem); SDL_GL_SwapWindow(window); HandleEvents(evolutionSystem,camera); } }
void GameEngine::Update(MasterControl* Control){ Timer::Update(); HandleEvents(Control); UpdateObjects(); if (CollisionTimer.IsTime()){ CollisionDetection(); } if (RenderTimer.IsTime()){ Draw(); } }
int DoEvents() { RSJ = 0; if (HandleEvents()) { if (keys[SC_B]) { /* Special */ return 'B'; } return 1; } return 0; }
void Sys_SendKeyEvents (void) { XEvent event; if (!dpy) return; HandleEvents(); // while (XCheckMaskEvent(dpy,KEY_MASK|MOUSE_MASK,&event)) // HandleEvent(&event); }