PolyCoreServices.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "PolyGlobals.h"
  21. #include "PolyString.h"
  22. #include "PolyEventDispatcher.h"
  23. #include <map>
  24. namespace Polycode {
  25. class PolycodeModule;
  26. class Renderer;
  27. class Config;
  28. class FontManager;
  29. class MaterialManager;
  30. class SceneManager;
  31. class ScreenManager;
  32. class TimerManager;
  33. class TweenManager;
  34. class ResourceManager;
  35. class SoundManager;
  36. class Core;
  37. class CoreMutex;
  38. /**
  39. * 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.
  40. */
  41. class _PolyExport CoreServices : public EventDispatcher {
  42. public:
  43. /**
  44. * 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.
  45. */
  46. static CoreServices *getInstance();
  47. static void setInstance(CoreServices *_instance);
  48. static CoreMutex *getRenderMutex();
  49. void setRenderer(Renderer *renderer);
  50. /**
  51. * Returns the main renderer.
  52. * @return The main renderer.
  53. * @see Renderer
  54. */
  55. Renderer *getRenderer();
  56. void Update(int elapsed);
  57. void setCore(Core *core);
  58. /**
  59. * Returns the core.
  60. * @return The core.
  61. * @see Core
  62. */
  63. Core *getCore();
  64. void handleEvent(Event *event);
  65. /**
  66. * Installs a plugin module at runtime.
  67. * @param module Plugin module to install. See PolygonModule for more details on modules.
  68. @see PolycodeModule
  69. */
  70. void installModule(PolycodeModule *module);
  71. /**
  72. * Returns the material manager. The material manager is responsible for loading and managing textures, shaders and materials.
  73. * @return Material manager.
  74. * @see MaterialManager
  75. */
  76. MaterialManager *getMaterialManager();
  77. /**
  78. * Returns the screen manager. The screen manager is responsible for maintaining and rendering 2D screens.
  79. * @return Screen Manager
  80. * @see ScreenManager
  81. */
  82. ScreenManager *getScreenManager();
  83. /**
  84. * Returns the scene manager. The screen manager is responsible for maintaining and rendering 3D scenes.
  85. * @return Scene Manager
  86. * @see SceneManager
  87. */
  88. SceneManager *getSceneManager();
  89. /**
  90. * Returns the timer manager. The timer manager is responsible for updating timers in the framework.
  91. * @return Timer Manager
  92. * @see TimerManager
  93. */
  94. TimerManager *getTimerManager();
  95. /**
  96. * Returns the tween manager. The tween manager is responsible for updating animated tweens in the framework.
  97. * @return Tween Manager
  98. * @see TweenManager
  99. */
  100. TweenManager *getTweenManager();
  101. /**
  102. * Returns the resource manager. The resource manager is responsible for loading and unloading resources.
  103. * @return Resource Manager
  104. * @see ResourceManager
  105. */
  106. ResourceManager *getResourceManager();
  107. /**
  108. * Returns the sound manager. The sound manager is responsible for loading and playing sounds.
  109. * @return Sound Manager
  110. * @see SoundManager
  111. */
  112. SoundManager *getSoundManager();
  113. /**
  114. * Returns the font manager. The font manager is responsible for loading and managing fonts.
  115. * @return Font Manager
  116. * @see FontManager
  117. */
  118. FontManager *getFontManager();
  119. /**
  120. * Returns the config. The config loads and saves data to disk.
  121. * @return Config manager.
  122. * @see Config
  123. */
  124. Config *getConfig();
  125. ~CoreServices();
  126. protected:
  127. CoreServices();
  128. private:
  129. static CoreServices* overrideInstance;
  130. static std::map <long, CoreServices*> instanceMap;
  131. static CoreMutex *renderMutex;
  132. std::vector<PolycodeModule*> modules;
  133. Core *core;
  134. Config *config;
  135. MaterialManager *materialManager;
  136. ScreenManager *screenManager;
  137. SceneManager *sceneManager;
  138. TimerManager *timerManager;
  139. TweenManager *tweenManager;
  140. ResourceManager *resourceManager;
  141. SoundManager *soundManager;
  142. FontManager *fontManager;
  143. Renderer *renderer;
  144. };
  145. }