   Can I see your main game loop
  I'm trying to figure out how to structure my main game loop and I'm wondering how other people have done theirs.  If you have one that you are willing to share, could you post your code (or pseudo code) here so that I can see it.   
  while(!Global_Input_Handler.did_exit){   //update the timer   game_time = SDL_GetTicks();   game_time = game_time/10;   game_time = game_time%5000;   //update the world   Global_Arena_Manager.update(game_time);   //check input   Global_Input_Handler.check_input();   //draw   Global_Graphics_Manager.clear_screen(0); // a stand in for draw background   Global_Map.draw(Global_Input_Handler.get_player()->get_pos()[0],    Global_Input_Handler.get_player()->get_pos()[1]);   Global_Arena_Manager.draw_objects();   Global_Graphics_Manager.swap();    }   ;voidKernel::tick( void ){++m_iFrame;std::list<Task*>::iterator i;std::list<PostProcess*>::iterator j;float dTime = (float)m_loopTimer.getTime();m_loopTimer.reset();m_pInput->tick();for ( i = m_Tasks.begin(); i != m_Tasks.end(); i++ )if ( !m_bPaused || (*i)->getPriority() == TP_KERNEL )(*i)->tick( dTime );m_pGraphics->beginScene();for ( i = m_Tasks.begin(); i != m_Tasks.end(); i++ ){m_pGraphics->resetView();(*i)->render3d( m_pGraphics );}m_pGraphics->begin2DScene();for ( i = m_Tasks.begin(); i != m_Tasks.end(); i++ ){(*i)->render2d( m_pGraphics );}m_pGraphics->end2DScene();m_pGraphics->endScene();};  It's approximately this (pseudo-code):update_time = 1/60 # update at 60 Hzexec_time = 0last_time = GetTime()this_time = 0frame_id = 0while not done:    this_time = GetTime()    dT = last_time - this_time    last_time = this_time    exec_time += dT    while exec_time > update_time:   Update(frame_id * update_time)   exec_time = exec_time - update   frame_id += 1    Render(exec_time / update_time)John B   ; //if(m_MaxRenderFPS!=-1){//if( (float)(timeGetTime()-LRTime)>(float)(1000/m_MaxRenderFPS))//LRTime=timeGetTime();//else return;}if(CheckDevice()){   ProcessKeyboard();ProcessMouse();ProcessGame();g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(RR,GG, BB), 1.0f, 0);g_D3DDevice->BeginScene();switch (GameState){case _1:Render_1();break;case _2:Render_2();break;case Menu:RenderMenu();break;} g_D3DDevice->EndScene();g_D3DDevice->Present(NULL, NULL, NULL, NULL);}   ;Quote:Original post by JohnBSmallIt's approximately this (pseudo-code):*** Source Snippet Removed ***John BI tried implementing something very similar to this but I found that my physics loop would eat up a lot of time thus slowing down my rendering.  I'm not trying to merge the two together, so that the physics and graphics get updated at the same time.   ;  Essentially, it looks like:let rec loop ( ) =  let now = timer # now in  input # poll;  scheduler # advance now;  video # render;  loop( )timer # now returns the number of milliseconds since the game started. I then call input # poll to check for SDL input events and add them (if any) to the scheduler. Then, scheduler # advance runs all events that were scheduled before now in the order in which they are meant to occur. Finally, video # render displays everything.And I repeat the process through a recursive call.   ;Quote:Original post by ToohrVykEssentially, it looks like:let rec loop ( ) =  let now = timer # now in  input # poll;  scheduler # advance now;  video # render;  loop( )OCaml? I'd be really interested to know about whatever you're working on. Any links or pointers   ;Quote:Original post by Muhammad HaggagOCaml? I'd be really interested to know about whatever you're working on. Any links or pointersYes, it is indeed OCaml.I did some quick game engine prototypes (including a collision detection system) a few weeks ago. I'm currently laying down the design of a very simple 2D game engine, using SDL and OpenGL. I hope to have it implemented by the end of the month.I definitely intend to make it publically available, and maybe even write one or two GDNet articles on the subject. Once it is done, of course. If you're interested, I can PM you (or post on the forums) the source code to one of the collision detection prototypes. EDIT: the code is in this thread.   ;  Sth like this:  void App::run (void)  {    MSG  msg;    // Init times to avoid large first-frame time    TimerCycle lastStartTime, lastEndTime;    PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );    while( mMessageLoop ){ PROFILE ("Root::run()"); while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) {   TranslateMessage( &msg );   DispatchMessage( &msg ); } if (mBehave) { // sth like this to be nice for other programs & not steal cpu%if( mHadFocus && !hasFocus )    SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL );else if( hasFocus && !mHadFocus )    SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL );if( !hasFocus ) Sleep(mBehaveSleep); } // Do frame started event TimerCycle fTime = timer->getTime(); float deltaT = MATH_CLAMP ((float)((fTime - lastStartTime).  getSeconds()), mClampMin, mClampMax); // abstract base class with 3 functions, client apps should derive // and implement their own behaviour // returns false in frameStarted/Ended if you wants to end the  // message loop, additionally can set "mMessageLoop" to false // over seperate function eg App::instance().endMessageLoop() {...} if (!_frameStarted (deltaT))   return; _frameRender(); // Do frame ended event fTime = timer->getTime(); deltaT = MATH_CLAMP((float)((fTime - lastEndTime).getSeconds()), mClampMin, mClampMax); if (!_frameEnded(deltaT))   return; // and prepare time for next update lastEndTime = fTime;  }}