GLBox() { sf::err().rdbuf(NULL); //hide errors #ifdef __APPLE__ int nullFD = open("/dev/null", O_WRONLY); int oldFD = dup(2); // Duplicate the old file descriptor, so it can be restored dup2(nullFD, 2); // Redirect #endif sf::VideoMode mode(RESOLUTION, RESOLUTION, 32); #ifdef __linux__ sf::ContextSettings settings(32, 0, 0, 3, 3); #else sf::ContextSettings settings(0, 0, 0, 3, 3, sf::ContextSettings::Core); #endif sf::Window window(mode, "glver", sf::Style::Default, settings); #ifdef __APPLE__ dup2(oldFD, 2); // Redirect back close(oldFD); // Not needed anymore #endif renderLoop(window); }
/* The main game loop */ GAMECODE gameLoop() { static uint32_t lastFlushTime = 0; static int renderBudget = 0; // Scaled time spent rendering minus scaled time spent updating. static bool previousUpdateWasRender = false; const Rational renderFraction(2, 5); // Minimum fraction of time spent rendering. const Rational updateFraction = Rational(1) - renderFraction; countUpdate(false); // kick off with correct counts while (true) { // Receive NET_BLAH messages. // Receive GAME_BLAH messages, and if it's time, process exactly as many GAME_BLAH messages as required to be able to tick the gameTime. recvMessage(); // Update gameTime and graphicsTime, and corresponding deltas. Note that gameTime and graphicsTime pause, if we aren't getting our GAME_GAME_TIME messages. gameTimeUpdate(renderBudget > 0 || previousUpdateWasRender); if (deltaGameTime == 0) { break; // Not doing a game state update. } ASSERT(!paused && !gameUpdatePaused(), "Nonsensical pause values."); unsigned before = wzGetTicks(); syncDebug("Begin game state update, gameTime = %d", gameTime); gameStateUpdate(); syncDebug("End game state update, gameTime = %d", gameTime); unsigned after = wzGetTicks(); renderBudget -= (after - before) * renderFraction.n; renderBudget = std::max(renderBudget, (-updateFraction * 500).floor()); previousUpdateWasRender = false; ASSERT(deltaGraphicsTime == 0, "Shouldn't update graphics and game state at once."); } if (realTime - lastFlushTime >= 400u) { lastFlushTime = realTime; NETflush(); // Make sure that we aren't waiting too long to send data. } unsigned before = wzGetTicks(); GAMECODE renderReturn = renderLoop(); unsigned after = wzGetTicks(); renderBudget += (after - before) * updateFraction.n; renderBudget = std::min(renderBudget, (renderFraction * 500).floor()); previousUpdateWasRender = true; return renderReturn; }
Renderer::Renderer() { assert(!mRenderer); // singleton, only one instance mRenderer = this; mDone = false; mRenderThreadState = stopped; mLevel = NULL; mCurrent = NULL; renderLoop(); }
int main(void) { init(); while (!glfwWindowShouldClose(window)) { NOW=glfwGetTime(); logicLoop(); renderLoop(); } shutdown(); }
int main() { if (!glfwInit()) return -1; window = glfwCreateWindow(1280, 720, "FluidSim", NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwMakeContextCurrent(window); if (glewInit() != GLEW_OK) return -1; demoInit(); int num_steps = 0; int max_steps = 300; while (!glfwWindowShouldClose(window) && num_steps < max_steps) { renderLoop(); num_steps++; } std::cout << "grouptime: " << grouptime / max_steps << std::endl; std::cout << "sorttime: " << sorttime / max_steps << std::endl; std::cout << "offsettime: " << offsettime / max_steps << std::endl; std::cout << "denstime: " << denstime / max_steps << std::endl; std::cout << "accel time: " << simtime / max_steps << std::endl; std::cout << "update time: " << rendertime / max_steps << std::endl; std::cout << "rendertime: " << rendertime / max_steps << std::endl; std::cout << "swaptime: " << swaptime / max_steps << std::endl; glfwTerminate(); return 0; }
int main(int argc, char **argv) { // fix `fullscreen quit kills mouse` issue. atexit(SDL_Quit); std::string config_filename = getConfigFilename(); ConfigFile config(config_filename); // window dimensions from configfile wvw = config.read<int>("Window Width", 512); wvh = config.read<int>("Window Height", 512); fullscreen = config.read("Fullscreen", true); init_display(wvw, wvh, &fvw, &fvh, fullscreen); SDL_WM_SetCaption(PROJECTM_TITLE, NULL); // memleak test while (doMemleakTest) { static int k = 0; std::cerr << "[iter " << k++ << "]" << std::endl; globalPM = new projectM(config_filename); assert(globalPM); delete (globalPM); if (k >= memLeakIterations) break; } globalPM = new projectM(config_filename); // if started fullscreen, give PM new viewport dimensions if (fullscreen) globalPM->projectM_resetGL(fvw, fvh); renderLoop(); // not reached return 1; }
int main() { srand(time(NULL)); if(!initCamera()) { fprintf(stderr, "Camera initialization failed.\n"); return EXIT_FAILURE; } pthread_t cameraThread; if(pthread_create(&cameraThread, NULL, cameraLoop, NULL)) { fprintf(stderr, "pthread_create failed.\n"); return EXIT_FAILURE; } usleep(30); /* We wait two frames for the camera to initialize itself. */ for(int i = 0; i < 2; i++) { pthread_mutex_lock(&kinectMutex); while(!colorUpdate || !depthUpdate) { pthread_cond_wait(&kinectSignal, &kinectMutex); } pthread_mutex_unlock(&kinectMutex); swapColorBuffers(); swapDepthBuffers(); } createModel(); pthread_t runThread; if(pthread_create(&runThread, NULL, runLoop, NULL)) { fprintf(stderr, "pthread_create failed.\n"); return EXIT_FAILURE; } renderLoop(); return EXIT_SUCCESS; }
Renderer::Renderer(int32_t windowWidth, int32_t windowHeight) :mRenderThreadState(stopped) ,mLevel(NULL) ,mDone(false) ,mCurrent(NULL) ,mRocketContext(NULL) { assert(!mRenderer); // singleton, only one instance // Render initialization. { Render::RenderSettings settings; settings.windowWidth = windowWidth; settings.windowHeight = windowHeight; Render::init(settings); mRocketContext = Render::initGui(boost::bind(&Renderer::loadGuiTextureFunc, this, _1, _2, _3), boost::bind(&Renderer::generateGuiTextureFunc, this, _1, _2, _3), boost::bind(&Renderer::releaseGuiTextureFunc, this, _1)); mRenderer = this; } renderLoop(); }
/* The main game loop */ GAMECODE gameLoop(void) { static uint32_t lastFlushTime = 0; bool didTick = false; while (true) { // Receive NET_BLAH messages. // Receive GAME_BLAH messages, and if it's time, process exactly as many GAME_BLAH messages as required to be able to tick the gameTime. recvMessage(); // Update gameTime and graphicsTime, and corresponding deltas. Note that gameTime and graphicsTime pause, if we aren't getting our GAME_GAME_TIME messages. gameTimeUpdate(); if (deltaGameTime == 0) { break; // Not doing a game state update. } didTick = true; ASSERT(!paused && !gameUpdatePaused() && !editPaused(), "Nonsensical pause values."); syncDebug("Begin game state update, gameTime = %d", gameTime); gameStateUpdate(); syncDebug("End game state update, gameTime = %d", gameTime); ASSERT(deltaGraphicsTime == 0, "Shouldn't update graphics and game state at once."); } if (didTick || realTime - lastFlushTime < 400u) { lastFlushTime = realTime; NETflush(); // Make sure the game time tick message is really sent over the network, and that we aren't waiting too long to send data. } return renderLoop(); }
int main( int argc, char **argv ) { const char **ports; const char *client_name; const char *server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; int i; char projectM_data[1024]; std::string config_file; config_file = read_config(); ConfigFile config(config_file); wvw = config.read<int>( "Window Width", 512 ); wvh = config.read<int>( "Window Height", 512 ); int fullscreen = 0; if (config.read("Fullscreen", true)) fullscreen = 1; else fullscreen = 0; #ifdef DEBUG int value; int rgb_size[3]; #endif const SDL_VideoInfo* info = NULL; int bpp = 0; /* Flags we will pass into SDL_SetVideoMode. */ int flags = 0; //JACK INIT //---------------------------------------------- if (argc >= 2) { /* client name specified? */ client_name = argv[1]; if (argc >= 3) { /* server name specified? */ server_name = argv[2]; // options |= JackServerName; } } else { /* use basename of argv[0] */ client_name = strrchr(argv[0], '/'); if (client_name == 0) { client_name = argv[0]; } else { client_name++; } } /* open a client connection to the JACK server */ client = jack_client_open (client_name, options, &status, server_name); if (client == NULL) { fprintf (stderr, "jack_client_open() failed, " "status = 0x%2.0x\n", status); if (status & JackServerFailed) { fprintf (stderr, "Unable to connect to JACK server\n"); } exit (1); } if (status & JackServerStarted) { fprintf (stderr, "JACK server started\n"); } if (status & JackNameNotUnique) { client_name = jack_get_client_name(client); fprintf (stderr, "unique name `%s' assigned\n", client_name); } /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback (client, process, 0); /* tell the JACK server to call `jack_shutdown()' if it ever shuts down, either entirely, or if it just decides to stop calling us. */ jack_on_shutdown (client, jack_shutdown, 0); /* display the current sample rate. */ printf ("engine sample rate: %d\n", jack_get_sample_rate (client)); /* create two ports */ input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); if (input_port == NULL) { fprintf(stderr, "no more JACK ports available\n"); exit (1); } /* Tell the JACK server that we are ready to roll. Our * process() callback will start running now. */ //END JACK INIT ---------------------------------- init_display(wvw,wvh,&fvw,&fvh,fullscreen); /** Setup some window stuff */ SDL_WM_SetCaption( PROJECTM_TITLE, NULL ); globalPM = new projectM(config_file); /** Initialise projectM */ //JACK BEGIN----------------------------- if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); exit (1); } /* Connect the ports. You can't do this before the client is * activated, because we can't make connections to clients * that aren't running. Note the confusing (but necessary) * orientation of the driver backend ports: playback ports are * "input" to the backend, and capture ports are "output" from * it. */ ports = jack_get_ports (client, NULL, NULL, JackPortIsOutput); if (ports == NULL) { fprintf(stderr, "no physical capture ports\n"); exit (1); } i=0; while (ports[i]!=NULL) { printf("Connecting to Jack port %s\n",ports[i]); if (jack_connect (client, ports[i], jack_port_name (input_port))) { fprintf (stderr, "cannot connect input ports\n"); } i++; } free (ports); //----------------------------------END /** Initialise the thread */ renderLoop(); return 1; }
void CCEngine::updateEngineThread() { // Update our system time updateTime(); time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { #if !defined WP8 && !defined WIN8 const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); #endif loggedUpdates = 0; loggedDelta = 0.0f; } #endif if( backButtonPressed ) { backButtonPressed = false; handleBackButton(); } // Run callbacks if( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); while( engineThreadCallbacks.length > 0 ) { CCLambdaCallback *callback = engineThreadCallbacks.pop(); if( callback != NULL ) { callback->safeRun(); delete callback; } } CCNativeThreadUnlock(); CCJobsThreadUnlock(); } finishJobs(); updateLoop(); if( paused == false && pauseRendering == false ) { CCAppManager::UpdateOrientation( time.delta ); renderLoop(); } #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }
void CCEngine::updateEngineThread() { // Update our system time updateTime(); time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { #if !defined WP8 && !defined WIN8 const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); #endif loggedUpdates = 0; loggedDelta = 0.0f; } #endif if( backButtonActionPending ) { backButtonActionPending = false; handleBackButton(); } // Run callbacks if( engineThreadCallbacks.length > 0 ) { int jobsProcessed = 0; const double startTime = CCEngine::GetSystemTime(); const double finishTime = startTime + 0.002f; // Spend a max of 2ms on this task double currentTime = startTime; while( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); CCLambdaCallback *callback = engineThreadCallbacks.pop(); if( callback != NULL ) { callback->safeRun(); } CCNativeThreadUnlock(); CCJobsThreadUnlock(); if( callback != NULL ) { delete callback; } jobsProcessed++; if( textureManager != NULL && textureManager->isReady() ) { currentTime = CCEngine::GetSystemTime(); if( currentTime > finishTime ) { DEBUGLOG( "Max engineThreadCallbacks processed in time %i, %i\n", jobsProcessed, engineThreadCallbacks.length ); break; } } } } finishJobs(); updateLoop(); if( paused == false ) { CCAppManager::UpdateOrientation( time.delta ); } renderLoop(); #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }
void CCEngine::updateEngineThread() { // Update our system time if( updateTime() == false ) { #ifdef ANDROID // FIXME: Android needs to always redraw the scene // We currently never return false, so perhaps remove this.. renderer->clear(); renderLoop(); #endif return; } time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); loggedUpdates = 0; loggedDelta = 0.0f; } #endif // Run callbacks if( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); CCLambdaCallback *callback = engineThreadCallbacks.pop(); CCNativeThreadUnlock(); CCJobsThreadUnlock(); callback->run(); delete callback; // for( int i=0; i<engineThreadCallbacks.length; ++i ) // { // engineThreadCallbacks.list[i]->run(); // delete engineThreadCallbacks.list[i]; // } // engineThreadCallbacks.length = 0; } finishJobs(); updateLoop(); CCViewManager::UpdateOrientation( time.delta ); renderer->clear(); renderLoop(); renderer->resolve(); #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }