PolyCoreServices.h 5.7 KB

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