PolyCoreServices.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyString.h"
  21. #include "PolyLogger.h"
  22. #include "PolyGlobals.h"
  23. #include "PolyRenderer.h"
  24. #include "PolyMaterialManager.h"
  25. #include "PolyScreenManager.h"
  26. #include "PolySceneManager.h"
  27. #include "PolyTimerManager.h"
  28. #include "PolyFontManager.h"
  29. #include "PolyTweenManager.h"
  30. #include "PolySoundManager.h"
  31. #include "PolyResourceManager.h"
  32. #include "PolyCore.h"
  33. #include "PolyConfig.h"
  34. #include "PolyModule.h"
  35. #include "PolyBasics.h"
  36. #include <map>
  37. namespace Polycode {
  38. class Renderer;
  39. class MaterialManager;
  40. class SceneManager;
  41. class ScreenManager;
  42. class TimerManager;
  43. class TweenManager;
  44. class ResourceManager;
  45. class SoundManager;
  46. class Core;
  47. class CoreMutex;
  48. /**
  49. * Global services singleton. CoreServices instantiates and provides global Singleton access to all of the main manager classes in Polycode as well as the Renderer and Config classes.
  50. */
  51. class _PolyExport CoreServices : public EventDispatcher {
  52. public:
  53. /**
  54. * Returns the singleton instance. NOTE: The singleton instance is unique to each thread and currently Polycode does not support multithreaded access to the core services. The reason for this is being able to run multiple cores in the same application and still have global singleton access to these services.
  55. */
  56. static CoreServices *getInstance();
  57. static CoreMutex *getRenderMutex();
  58. void setRenderer(Renderer *renderer);
  59. /**
  60. * Returns the main renderer.
  61. * @return The main renderer.
  62. * @see Renderer
  63. */
  64. Renderer *getRenderer();
  65. void Update(int elapsed);
  66. void setCore(Core *core);
  67. /**
  68. * Returns the core.
  69. * @return The core.
  70. * @see Core
  71. */
  72. Core *getCore();
  73. void handleEvent(Event *event);
  74. /**
  75. * Installs a plugin module at runtime.
  76. * @param module Plugin module to install. See PolygonModule for more details on modules.
  77. @see PolycodeModule
  78. */
  79. void installModule(PolycodeModule *module);
  80. /**
  81. * Returns the material manager. The material manager is responsible for loading and managing textures, shaders and materials.
  82. * @return Material manager.
  83. * @see MaterialManager
  84. */
  85. MaterialManager *getMaterialManager();
  86. /**
  87. * Returns the screen manager. The screen manager is responsible for maintaining and rendering 2D screens.
  88. * @return Screen Manager
  89. * @see ScreenManager
  90. */
  91. ScreenManager *getScreenManager();
  92. /**
  93. * Returns the scene manager. The screen manager is responsible for maintaining and rendering 3D scenes.
  94. * @return Scene Manager
  95. * @see SceneManager
  96. */
  97. SceneManager *getSceneManager();
  98. /**
  99. * Returns the timer manager. The timer manager is responsible for updating timers in the framework.
  100. * @return Timer Manager
  101. * @see TimerManager
  102. */
  103. TimerManager *getTimerManager();
  104. /**
  105. * Returns the tween manager. The tween manager is responsible for updating animated tweens in the framework.
  106. * @return Tween Manager
  107. * @see TweenManager
  108. */
  109. TweenManager *getTweenManager();
  110. /**
  111. * Returns the resource manager. The resource manager is responsible for loading and unloading resources.
  112. * @return Resource Manager
  113. * @see ResourceManager
  114. */
  115. ResourceManager *getResourceManager();
  116. /**
  117. * Returns the sound manager. The sound manager is responsible for loading and playing sounds.
  118. * @return Sound Manager
  119. * @see SoundManager
  120. */
  121. SoundManager *getSoundManager();
  122. /**
  123. * Returns the font manager. The font manager is responsible for loading and managing fonts.
  124. * @return Font Manager
  125. * @see FontManager
  126. */
  127. FontManager *getFontManager();
  128. /**
  129. * Returns the config. The config loads and saves data to disk.
  130. * @return Config manager.
  131. * @see Config
  132. */
  133. Config *getConfig();
  134. ~CoreServices();
  135. protected:
  136. CoreServices();
  137. private:
  138. static std::map <long, CoreServices*> instanceMap;
  139. static CoreMutex *renderMutex;
  140. vector<PolycodeModule*> modules;
  141. Core *core;
  142. Config *config;
  143. MaterialManager *materialManager;
  144. ScreenManager *screenManager;
  145. SceneManager *sceneManager;
  146. TimerManager *timerManager;
  147. TweenManager *tweenManager;
  148. ResourceManager *resourceManager;
  149. SoundManager *soundManager;
  150. FontManager *fontManager;
  151. Renderer *renderer;
  152. };
  153. }