Esempio n. 1
0
void mainLoop(void)		/*this is our primary loop*/
{
	calcNextStep();	/*calculate the next step*/

	renderMain();	/*render the window and subwindows*/
	renderSub1();
	renderSub2();
	renderSub3();

	frame++;		/*calculate fps*/
	timepassed = glutGet(GLUT_ELAPSED_TIME);
	if(timepassed - timebase > 1000)
	{
		fps = frame*1000.0/(timepassed-timebase);
		printf("%5.3f fps\n", fps);
		timebase = timepassed;
		frame = 0;
	}
}
Esempio n. 2
0
/*********************************************
		SDL event loop
**********************************************/
void App::utilEventLoop(){

	SDL_Event event;

    while ( !done ){
	   
	    while ( SDL_PollEvent( &event ) ){
	    
	    	//Hand the event off to the GUI first. If the GUI handles it, it's
	    	//done. 
#ifdef ENABLE_GUI
	    	if(processGUIEvent(event)){
	    		continue;
	    	}
#endif
	    
		    switch( event.type ){
						      
			case SDL_VIDEORESIZE:
			    //handle resize event
			    surface = SDL_SetVideoMode( event.resize.w, event.resize.h, 
			    							16, videoFlags );
			    if ( !surface ){
				    ERR( "Could not get a surface after resize: %s\n", 
				    	SDL_GetError( ) );
				    notifyShutdown();
				}
			    resizeWindow( event.resize.w, event.resize.h );
#ifdef ENABLE_GUI
			    resizeGUI( event.resize.w, event.resize.h );
#endif
			    break;
			
			case SDL_QUIT:
			    //handle quit requests
			    notifyShutdown();
			    break;
			
			case SDL_MOUSEBUTTONDOWN:
								
				if(mFlowMgr->onClick(event.button.button, 
									fMouseX, fMouseY, fMouseZ)){
					break;
				}			
				
				onMouseEvent(event.button.button, SDL_MOUSEBUTTONDOWN); 
				beginDrag();
												
				break;	
				
			case SDL_MOUSEBUTTONUP:
				onMouseEvent(event.button.button, SDL_MOUSEBUTTONUP); 
				endDrag();
				break;	
				
			case SDL_KEYDOWN:
				handleKeyEvent(&event.key.keysym, event.type);
				break;
			
			case SDL_KEYUP:
				handleKeyEvent(&event.key.keysym, event.type);
				break;
			
			default:
			    break;
			}
		}
		
	    if (!done){
	    
	    	//Do one frames worth of work and figure out the length of time
	    	uint32_t startTime = SDL_GetTicks();
			renderMain();
			updateMain();
			uint32_t endTime = SDL_GetTicks();
			
			//Figure out the scaling factor for FPS-independent movement
			uint32_t diff = endTime - startTime;
			
			if (iMaxFrameRate > 0 && diff < 1000 / iMaxFrameRate) {
				SDL_Delay((1000 / iMaxFrameRate) - diff);
				diff = 1000 / iMaxFrameRate;
			}
			
			fTimeScale = (float)diff * fTimeScaleScale;
			
			//Every hour, do a cleanup
			if(fCleanupTimer < 0.0f){
				ps()->doPeriodicCleanup();				
				fCleanupTimer = CLEANUP_TIMER;
			}
			
			//Update our various timers
			fCleanupTimer -= fTimeScale;
			fUptime += fTimeScale;
			fParticleFPS = fTimeScale;
		}
	}
	
}