void runMe() { SDL_Event event; //uint last = SDL_GetTicks(); //float frames = 0, tenths = 0; while (running) { /*frames++; if (SDL_GetTicks() - last > 10) { char buff[128]; rotation += 1; last = SDL_GetTicks(); tenths++; float seconds = tenths/100.0f; sprintf(buff, "%i fps for %i seconds and %i frames", (int)(frames/seconds), (int)seconds, (int)frames); fps->setText(buff); }*/ tickBSGUI(); while (SDL_PollEvent(&event)) { if (!handleSDLEvent(&event)) switch (event.type) { case SDL_QUIT: running = false; break; } } render(); } }
void App::loop() { looping = true; while(looping) { float frameStartTime = SDL_GetTicks() / 1000.f; //// Handle events //controllers::startFrame(); SDL_Event sdlEvent; while(SDL_PollEvent(&sdlEvent)) { handleSDLEvent(sdlEvent); } //for(int i = 0; i < controllers::getNumControllers(); i++) //{ // std::vector<std::pair<int, float>> controllerAxisEvents = controllers::getAxesChangedSinceLastFrame(i); // for(auto controllerAxisEvent : controllerAxisEvents) // { // ControllerAxisEvent event{Ptr<Window>()}; // event.controller = i; // event.axis = controllerAxisEvent.first; // event.value = controllerAxisEvent.second; // handleEvent(event); // } //} // Update float dt = 1.f / targetFrameRate; for(auto & window : windows) { window->update(dt); } for(auto & scene : scenes) { scene->update(dt); } // PreRender Update for(auto & window : windows) { window->preRenderUpdate(); } for(auto scene : scenes) { scene->preRenderUpdate(); } // Render (Scene render happens in each Viewport) for(auto const & window : windows) { window->render(glContext); } // FIX THIS: Introduce better loop timing float delayTime = (1.f / targetFrameRate) - (SDL_GetTicks() / 1000.f - frameStartTime); if(delayTime > 0) { SDL_Delay((unsigned int)(delayTime * 1000)); } } }
int main(int argc,char** argv) { rfbClient* cl; int i, j; SDL_Event e; for (i = 1, j = 1; i < argc; i++) if (!strcmp(argv[i], "-viewonly")) viewOnly = 1; else if (!strcmp(argv[i], "-listen")) { listenLoop = 1; argv[i] = const_cast<char*>("-listennofork"); ++j; } else if (!strcmp(argv[i], "-joystick")) { drcInputFeeder = TRUE; } else { if (i != j) argv[j] = argv[i]; j++; } argc = j; Init_DRC(); drc::InputData drc_input_data; if (drcInputFeeder) { printf("Started in Joystick mode, toggle Mouse mode with POWER button\n"); g_streamer->EnableSystemInputFeeder(); drcJoystickMode = 1; } else { printf("Started in Mouse-only mode\n"); drcJoystickMode = 0; } SDL_Init(SDL_INIT_VIDEO); SDL_StartTextInput(); atexit(SDL_Quit); signal(SIGINT, exit); do { /* 16-bit: cl=rfbGetClient(5,3,2); */ cl=rfbGetClient(8,3,4); SDL_PixelFormat *fmt = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888); cl->format.bitsPerPixel = fmt->BitsPerPixel; cl->format.redShift = fmt->Rshift; cl->format.greenShift = fmt->Gshift; cl->format.blueShift = fmt->Bshift; cl->format.redMax = fmt->Rmask>>cl->format.redShift; cl->format.greenMax = fmt->Gmask>>cl->format.greenShift; cl->format.blueMax = fmt->Bmask>>cl->format.blueShift; cl->MallocFrameBuffer=resize; cl->canHandleNewFBSize = TRUE; cl->GotFrameBufferUpdate=update; cl->HandleKeyboardLedState=kbd_leds; cl->listenPort = LISTEN_PORT_OFFSET; cl->listen6Port = LISTEN_PORT_OFFSET; if(!rfbInitClient(cl,&argc,argv)) { cl = NULL; /* rfbInitClient has already freed the client struct */ cleanup(cl); break; } while(1) { g_streamer->PollInput(&drc_input_data); if (drc_input_data.valid) { Process_DRC_Input(cl, drc_input_data); } if(SDL_PollEvent(&e)) { /* handleSDLEvent() return 0 if user requested window close. In this case, handleSDLEvent() will have called cleanup(). */ if(!handleSDLEvent(cl, &e)) break; } else { i=WaitForMessage(cl,500); if(i<0) { cleanup(cl); break; } if(i) { if(!HandleRFBServerMessage(cl)) { cleanup(cl); break; } } } if (vncUpdate) { SDL_UpdateTexture(sdlTexture, NULL, cl->frameBuffer, drc::kScreenWidth * 4); SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); SDL_RenderPresent(sdlRenderer); Push_DRC_Frame(cl); vncUpdate = FALSE; } } } while(listenLoop); return 0; }