Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

cgame.h

Go to the documentation of this file.
00001 #ifndef CGAME_H
00002 #define CGAME_H
00003 
00014 #include "globals.h"
00015 
00016 #include "cevent.h"
00017 #include "ccomponent.h"
00018 #include "cfont.h"
00019 #include "cvideo.h"
00020 #include "ctimer.h"
00021 
00022 #include <string>
00023 #include <list>
00024 
00025 #include <assert.h>
00026 
00034 struct CSystemFactorySet {
00036   CTimerSystemFactory *timerFactory;
00038   CEventSystemFactory *eventFactory;
00040   CVideoSystemFactory *videoFactory;
00041 };
00042 
00065 namespace TempGameConstants {
00066   const char* const GAME_FONT_BIG_FILENAME = "gfw_font02.bmp";
00067   const char* const GAME_FONT_SMALL_FILENAME = "gfw_font01.bmp";
00068   /* Maximum time (in ms) between each frame.  Note that
00069      the actual time per frame can be more than this, but the
00070      pman game module "pretends" that only this much time has
00071      passed. */
00072   const unsigned int GAME_MAX_FRAME_TIME = 200;
00073 
00074   /* Information about the game's default "big size" font. */
00075   const int GAME_FONT_BIG_CHAR_WIDTH = 6*2;
00076   const int GAME_FONT_BIG_CHAR_HEIGHT = 8*2;
00077   const int GAME_FONT_BIG_CHARS_PER_LINE = 16;
00078 
00079   /* Information about the game's default "small size" font. */
00080   const int GAME_FONT_SMALL_CHAR_WIDTH = 6;
00081   const int GAME_FONT_SMALL_CHAR_HEIGHT = 8;
00082   const int GAME_FONT_SMALL_CHARS_PER_LINE = 16;
00083 }
00084 
00088 class CGame : public CPanel {
00089 private:
00090   /* The list of rectangles that need to be updated on the
00091      screen. */
00092   CRectList dirty_rects;
00093 
00094   /* Flag tells us whether we should quit after processing the
00095      current frame. */
00096   int quit_flag;
00097 
00098   /* Singleton instance. */
00099   static CGame *unique_instance;
00100 
00101   /* The "big" game font.
00102      \todo Should be moved to some kind of
00103      resource manager flyweight pool if/when I implement one. */
00104   CFont *font_large;
00105 
00106   /* The "small" game font. */
00107   CFont *font_small;
00108 
00109   /* Draw the current frame. */
00110   void draw_frame();
00111 
00112   /* Handle the given event. */
00113   virtual int do_handle_event(CEvent &event);
00114   
00115   /* Return whether the game's quit flag is true or not. */
00116   int is_game_quit();
00117 
00118   /* Outlaw constructing, copying, destruction, etc. of this singleton class. */
00119   CGame(CSystemFactorySet *driver);
00120   CGame(CGame &copy);
00121   CGame &operator=(CGame &);
00122   virtual ~CGame();
00123 
00124 protected:
00125   virtual void do_draw(CSurface &surface, CRect &rect);
00126 
00128   virtual void add_dirty_rect(const CRect &r) { dirty_rects.push_back(r); }
00129 
00130 public:
00133   std::list<ITickable *> tickables;
00134 
00137   CFPSTimer timer;
00138   
00140   void run();
00141 
00143   void quit();
00144 
00148   CFont *get_font_large() { return font_large; }
00149 
00151   CFont *get_font_small() { return font_small; }
00152 
00155   static void init(CSystemFactorySet *driver);
00156 
00159   static void deinit();
00160 
00162   static CGame &get_instance() { assert(unique_instance); return *unique_instance; }
00163 };
00164 
00165 #endif

Generated on Wed Aug 27 11:58:41 2003 for GFW by doxygen 1.3.3