Quote:Original post by ToohrVyk
It's one way to do it, and it is acceptable for very small projects where you only have a small number of possible game states, and (very important) the game states do not need to store internal data exclusively.
For any non-trivial project (i.e. anything past Pong, Tetris or Breakout), it's better to drop the switch altogether, and use a stack of polymorphic game state objects instead, as these can encapsulate game behaviour much better.
My typical game loop looks like this:let loop () = (* Prepare a new frame *) let scheduler = schedulers # top in let time = timer # now in (* Read input *) input # poll time; (* Update state *) while scheduler # next < time do scheduler # pop # execute time done; (* Render scene *) renderer # frame time; (* Repeat *) loop ();;
Anyone have any good beginner articles/tutorials on this subject? I'm interested in what Toohr said but having a hard time grasping the concept because of the language he uses.