[AD] generic game loop

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I was wondering if Allegro could benefit from having a generic game loop function that users can use to run their games. I hope its not to ridiculous..

Something like
int game_loop( int (*logic)( void * data ), int (*draw)( void * data), int time, void * data );

Where logic is a function pointer to the function that performs all the game logic, draw is a function that draws everything, time is how much time to wait between loops and data is passed to logic() and draw() when they are called.

I havent attached game_loop because I didnt want to spend the energy to formalize the function unless people cared although it would just be some of my own code with minor modifications anyway, but it would look something like:
while ( !quit ){
    int dodraw = 0;
   while ( counter < 0 )
      counter--;
      logic( data );
      dodraw = 1;
   }
   if ( dodraw ) draw( data );
}

The reason I think this could be in Allegro is a) the question of how to do correct timing loops comes up again and again b) im sure many users get the timing loop suboptimal even if they know what it is and c) it reminds them of the "correct" way to structure games by seperating drawing and logic code.

I can see a critiscm be "This is a basic part of games that people should know how to do and doesnt belong in a graphics library." but this is exactly the point, its so common( or should be ) that it might as well go in a game library, which Allegro is supposed to be.

Just an idea, I wont be to upset if it gets shot down.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/