home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / includes / gs_application.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-11  |  4.0 KB  |  183 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    gsCApplication
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    12/03/00
  8. //
  9. // Base:    None
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #ifndef _INCLUDE_GS_APPLICATION_H
  16. #define _INCLUDE_GS_APPLICATION_H
  17.  
  18. #include "gs_object.h"
  19. #include "gs_rect.h"
  20. #include "gs_screen.h"
  21. #include "gs_image.h"
  22. #include "gs_tiledimage.h"
  23. #include "gs_colour.h"
  24. #include "gs_framecounter.h"
  25. #include "gs_timer.h"
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. const float gsFRAME_RATE = 60.f;
  30.  
  31. //-------------------------------------------------------------
  32.  
  33. class gsCApplication : public gsCObject
  34. {
  35.     friend class gsCScreen;
  36.     
  37.     private:
  38.         static const char *m_app_name;
  39.  
  40.         static HINSTANCE m_instance;
  41.         static HWND m_window;
  42.         static bool m_isActive;
  43.         static bool m_isReady;
  44.         static bool m_running;
  45.         static bool m_isWindowed;
  46.         static bool m_isPaused;
  47.         static gsCPoint m_default_size;
  48.  
  49.         static LRESULT CALLBACK windowProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
  50.  
  51.         static gsCFrameCounter m_frame_counter;
  52.         static float m_last_time_stamp;
  53.  
  54.         static gsCApplication *m_app;
  55.  
  56.         static bool m_restarting;
  57.  
  58.     protected:
  59.         
  60.         static gsCScreen *m_screen;                // currently active screen object
  61.         
  62.     public:
  63.  
  64.         gsCApplication(const char *app_name = 0);
  65.         virtual ~gsCApplication();
  66.  
  67.         static HINSTANCE _cdecl getInstance();
  68.         static HWND _cdecl getWindow();
  69.  
  70.         static bool isActive();
  71.         static bool isReady();
  72.         static bool isWindowed();
  73.         static bool isPaused();
  74.  
  75.         static gsCApplication *getApp();
  76.         static gsCScreen *getScreen();
  77.         
  78.         int run(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow);
  79.  
  80.         virtual bool initialize();
  81.         virtual bool mainloop();
  82.         virtual bool shutdown();
  83.  
  84.         float getFrameRate();
  85.  
  86.         static void requestRestart();
  87.  
  88.         static void setPaused(bool state);
  89. };
  90.  
  91. //-------------------------------------------------------------
  92. // Get application instance handle
  93.  
  94. inline HINSTANCE _cdecl gsCApplication::getInstance()
  95. {
  96.     return m_instance;
  97. }
  98.  
  99. //-------------------------------------------------------------
  100. // Get window handle
  101.  
  102. inline HWND _cdecl gsCApplication::getWindow()
  103. {
  104.     return m_window;
  105. }
  106.  
  107. //-------------------------------------------------------------
  108. // Get currently active application
  109.  
  110. inline gsCApplication *gsCApplication::getApp()
  111. {
  112.     return m_app;
  113. }
  114.  
  115. //-------------------------------------------------------------
  116. // Get currently active screen
  117.  
  118. inline gsCScreen *gsCApplication::getScreen()
  119. {
  120.     return m_screen;
  121. }
  122.  
  123. //-------------------------------------------------------------
  124. // Test if application is active
  125.  
  126. inline bool gsCApplication::isActive()
  127. {
  128.     return m_isActive;
  129. }
  130.  
  131. //-------------------------------------------------------------
  132. // Test if application is ready
  133.  
  134. inline bool gsCApplication::isReady()
  135. {
  136.     return m_isReady;
  137. }
  138.  
  139. //-------------------------------------------------------------
  140. // Test if application is running in a window
  141.  
  142. inline bool gsCApplication::isWindowed()
  143. {
  144.     return m_isWindowed;
  145. }
  146.  
  147. //-------------------------------------------------------------
  148. // Get current frame rate
  149.  
  150. inline float gsCApplication::getFrameRate()
  151. {
  152.     return m_frame_counter.getFrameRate();
  153. }
  154.  
  155. //-------------------------------------------------------------
  156. // Request a complete restart of the application
  157. //
  158. // Note: required e.g. if changing screen mode / colour depth etc
  159.  
  160. inline void gsCApplication::requestRestart()
  161. {
  162.     m_restarting = true;
  163. }
  164.  
  165. //-------------------------------------------------------------
  166.  
  167. inline bool gsCApplication::isPaused()
  168. {
  169.     return m_isPaused;
  170. }
  171.  
  172. //-------------------------------------------------------------
  173.  
  174. inline void gsCApplication::setPaused(bool state)
  175. {
  176.     m_isPaused = state;
  177. }
  178.  
  179. //-------------------------------------------------------------
  180.  
  181. #endif
  182.  
  183.