daily pastebin goal
55%
SHARE
TWEET

game.cpp

Archon Jan 6th, 2011 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // (C) 2009-2011 Tim Gurto
  2.  
  3. #include <cassert>
  4. #include <map>
  5. #include <string>
  6. #include <fstream>
  7.  
  8. #include "SDL.h"
  9. #include "SDL_mixer.h"
  10.  
  11. #include "game.h"
  12. #include "globals.h"
  13. #include "update.h"
  14. #include "render.h"
  15. #include "util.h"
  16. #include "misc.h"
  17. #include "Debug.h"
  18. #include "Point.h"
  19. #include "MessageBox.h"
  20. #include "Surface.h"
  21. #include "Screen.h"
  22. #include "GameState.h"
  23. #include "Sound.h"
  24.  
  25. extern Debug debug;
  26. extern bool gameLoop;
  27. extern GameOutcome gameOutcome;
  28.  
  29. unsigned gameMode(Screen &/*screen*/, const void * /*data*/){
  30.  
  31.    GameState state;
  32.  
  33.  
  34.    Surface blankBack(SUR_UNINIT, 1, 1, BLUE);
  35.    MessageBox fpsDisplay(WHITE,
  36.                          Screen::getScreenRes().x / 2 - 40, 2,
  37.                          1,
  38.                          blankBack,
  39.                          FONT_DEBUG, 0,
  40.                          false, DEBUG);
  41.  
  42.    SDL_ShowCursor(SDL_DISABLE);
  43.  
  44.    //flush event queue before accepting game controls,
  45.    //specifically the mouse up event from clicking "Play Game"
  46.    SDL_Event event;
  47.    while(SDL_PollEvent(&event))
  48.       debug("Unhandled event: ", int(event.type));
  49.  
  50.    timer_t oldTicks = SDL_GetTicks();
  51.    while (state.loop){
  52.  
  53.       //time stuff
  54.       timer_t newTicks = SDL_GetTicks();
  55.       timer_t delta = newTicks - oldTicks;
  56.       oldTicks = newTicks;
  57.  
  58.       double deltaMod = 1.0 * delta / DELTA_MODIFIER;
  59.      
  60.       double fps = delta == 0 ? 0 : 1000 / delta;
  61.       fpsDisplay(format3(fps), "fps  |  ", delta, "ms ");
  62.  
  63.       //force interface refresh
  64.       pushMouseMove();
  65.  
  66.       //update state
  67.       updateState(deltaMod, state, fpsDisplay);
  68.  
  69.       //render
  70.       render(state, fpsDisplay);
  71.    }
  72.  
  73.    //Clean up
  74.    SDL_ShowCursor(SDL_ENABLE);
  75.  
  76.    GameOutcome outcome = state.outcome;
  77.    return outcome; //return something more meaningful
  78. }
RAW Paste Data
Top