States.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /******************************************************************************
  2. Use 'States' to handle different application states, for which you can specify custom functions for:
  3. -Initialize
  4. -Shut Down
  5. -Update
  6. -Draw
  7. /******************************************************************************/
  8. struct State // Application State
  9. {
  10. void (*draw)();
  11. // set
  12. void set( ); // set as active state (this sets current State to the StateNext, and in the next frame it will be set also as StateActive)
  13. void set(Flt fade_time, Bool fade_previous_frame=false); // set as active state and use screen fade effect between states, that lasts 'fade_time' number of seconds, 'fade_previous_frame'=if use result of previous frame instead of the next frame for fading
  14. State(Bool (*update)(), void (*draw)(), Bool (*init)()=null, void (*shut)()=null); // 'init' and 'shut' may be set to null
  15. #if EE_PRIVATE
  16. void shutDo() { if(shut) shut();}
  17. Bool initDo() {return !init || init();}
  18. #endif
  19. #if !EE_PRIVATE
  20. private:
  21. #endif
  22. Bool (*update)();
  23. Bool (*init )();
  24. void (*shut )();
  25. }extern
  26. StateExit , // state which always exits application ( null, null, null, null)
  27. StateMain , // main state (Update, Draw, null, null)
  28. *StateActive, // active state
  29. *StateNext ; // next state that will be activated in the next frame, default=&StateMain
  30. /******************************************************************************/
  31. #if EE_PRIVATE
  32. void InitState();
  33. void ShutState();
  34. Bool UpdateState();
  35. Bool DrawState();
  36. #endif
  37. /******************************************************************************/