App.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef APP_H
  2. #define APP_H
  3. #include <SDL/SDL.h>
  4. #include <boost/filesystem.hpp>
  5. #include "Object.h"
  6. #include "StdTypes.h"
  7. #include "Properties.h"
  8. #include "Exception.h"
  9. class StdinListener;
  10. class Scene;
  11. class MainRenderer;
  12. class Camera;
  13. class Input;
  14. /// The one and only global variable
  15. extern class App* app;
  16. /// This class holds all the global objects of the application and its also responsible for some of the SDL stuff.
  17. /// It should be singleton
  18. class App: public Object
  19. {
  20. PROPERTY_R(uint, windowW, getWindowWidth) ///< The main window width
  21. PROPERTY_R(uint, windowH, getWindowHeight) ///< The main window height
  22. PROPERTY_R(boost::filesystem::path, settingsPath, getSettingsPath)
  23. PROPERTY_R(boost::filesystem::path, cachePath, getCachePath)
  24. public:
  25. uint timerTick;
  26. App(int argc, char* argv[], Object* parent = NULL);
  27. ~App() {}
  28. void initWindow();
  29. void quit(int code);
  30. void waitForNextFrame();
  31. void togleFullScreen();
  32. void swapBuffers();
  33. /// The func pools the stdinListener for string in the console, if there are any it executes them with
  34. /// scriptingEngine
  35. void execStdinScpripts();
  36. static void printAppInfo();
  37. uint getDesktopWidth() const;
  38. uint getDesktopHeight() const;
  39. /// @name Accessors
  40. /// @{
  41. bool isTerminalColoringEnabled() const;
  42. Scene& getScene();
  43. StdinListener& getStdinLintener();
  44. MainRenderer& getMainRenderer();
  45. Camera* getActiveCam() {return activeCam;}
  46. void setActiveCam(Camera* cam) {activeCam = cam;}
  47. /// @}
  48. /// @return Returns the number of milliseconds since SDL library initialization
  49. static uint getTicks();
  50. private:
  51. static bool isCreated; ///< A flag to ensure one @ref App instance
  52. bool terminalColoringEnabled; ///< Terminal coloring for Unix terminals. Default on
  53. uint time;
  54. SDL_WindowID windowId;
  55. SDL_GLContext glContext;
  56. SDL_Surface* iconImage;
  57. bool fullScreenFlag;
  58. Camera* activeCam; ///< Pointer to the current camera
  59. /// @name Pointers to serious subsystems
  60. /// @{
  61. Scene* scene;
  62. MainRenderer* mainRenderer;
  63. StdinListener* stdinListener;
  64. /// @}
  65. void parseCommandLineArgs(int argc, char* argv[]);
  66. /// A slot to handle the messageHandler's signal
  67. void handleMessageHanlderMsgs(const char* file, int line, const char* func, const char* msg);
  68. };
  69. inline bool App::isTerminalColoringEnabled() const
  70. {
  71. return terminalColoringEnabled;
  72. }
  73. inline Scene& App::getScene()
  74. {
  75. RASSERT_THROW_EXCEPTION(scene == NULL);
  76. return *scene;
  77. }
  78. inline StdinListener& App::getStdinLintener()
  79. {
  80. RASSERT_THROW_EXCEPTION(stdinListener == NULL);
  81. return *stdinListener;
  82. }
  83. inline MainRenderer& App::getMainRenderer()
  84. {
  85. RASSERT_THROW_EXCEPTION(mainRenderer == NULL);
  86. return *mainRenderer;
  87. }
  88. #endif