``` while(true) {Event*Event=waitforevent (); Dispatchevent (Event);} while(true) {processinput (); Update (); Render ();} The game loop is executed during the game run, each cycle will process user input, update the game state, render the scene, etc. Record the cycle time to control the rhythm (rate) of the game. "\ \ Lock Frame rates while(true){ DoubleStart =GetCurrentTime (); ProcessInput (); Update (); Render (); Sleep (Start+ Ms_per_frame-getcurrenttime ());} \ elapsed, the frame rate is not fixed, but the game uses the time difference to update \ \ Different frame rate, the physical motion results are the sameDoubleLasttime =getcurrenttime (); while(true){ DoubleCurrent =GetCurrentTime (); DoubleElapsed = current-Lasttime; ProcessInput (); Update (elapsed); Render (); Lasttime=Current ;} "' \ \ \ \ \ \ \ \ \ \ \" \ \ \ \ ""DoublePrevious =getcurrenttime ();Doublelag =0.0; while(true){ DoubleCurrent =GetCurrentTime (); DoubleElapsed = current-previous; Previous=Current ; Lag+=elapsed; ProcessInput (); while(Lag >=ms_per_update) {update (); Lag-=ms_per_update; } render (); //prevent the object from beatingRender (lag/ms_per_update);} "' # # Power consumption1the frame rate is as high as possible. will bring a better experience, will also be with electricity, heat more2Limit the frame rate. Bring a good enough experience and reduce power consumption
8_ Game Loops