PolyCoreServices.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "polycode/core/PolyGlobals.h"
  21. #include "polycode/core/PolyString.h"
  22. #include "polycode/core/PolyRectangle.h"
  23. #include "polycode/core/PolyEventDispatcher.h"
  24. #include <map>
  25. namespace Polycode {
  26. class PolycodeModule;
  27. class Renderer;
  28. class Config;
  29. class TimerManager;
  30. class TweenManager;
  31. class ResourceManager;
  32. class SoundManager;
  33. class Core;
  34. class CoreInput;
  35. class CoreMutex;
  36. class Logger;
  37. /**
  38. * 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.
  39. */
  40. class _PolyExport CoreServices : public EventDispatcher {
  41. public:
  42. /**
  43. * 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.
  44. */
  45. static CoreServices *getInstance();
  46. static void setInstance(CoreServices *_instance);
  47. static CoreMutex *getRenderMutex();
  48. static void createInstance();
  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 fixedUpdate();
  58. void setCore(Core *core);
  59. /**
  60. * Returns the core.
  61. * @return The core.
  62. * @see Core
  63. */
  64. Core *getCore();
  65. /**
  66. * Returns the core input.
  67. * @return Core input.
  68. * @see CoreInput
  69. */
  70. CoreInput *getInput();
  71. void handleEvent(Event *event);
  72. /**
  73. * Returns the timer manager. The timer manager is responsible for updating timers in the framework.
  74. * @return Timer Manager
  75. * @see TimerManager
  76. */
  77. TimerManager *getTimerManager();
  78. /**
  79. * Returns the tween manager. The tween manager is responsible for updating animated tweens in the framework.
  80. * @return Tween Manager
  81. * @see TweenManager
  82. */
  83. TweenManager *getTweenManager();
  84. /**
  85. * Returns the resource manager. The resource manager is responsible for loading and unloading resources.
  86. * @return Resource Manager
  87. * @see ResourceManager
  88. */
  89. ResourceManager *getResourceManager();
  90. /**
  91. * Returns the sound manager. The sound manager is responsible for loading and playing sounds.
  92. * @return Sound Manager
  93. * @see SoundManager
  94. */
  95. SoundManager *getSoundManager();
  96. /**
  97. * Returns the logger. It can log messages and broadcast them to listeners.
  98. */
  99. Logger *getLogger();
  100. /**
  101. * Returns the config. The config loads and saves data to disk.
  102. * @return Config manager.
  103. * @see Config
  104. */
  105. Config *getConfig();
  106. ~CoreServices();
  107. protected:
  108. CoreServices();
  109. private:
  110. static CoreServices* overrideInstance;
  111. static std::map <long, CoreServices*> instanceMap;
  112. static CoreMutex *renderMutex;
  113. Core *core;
  114. Config *config;
  115. Logger *logger;
  116. TimerManager *timerManager;
  117. TweenManager *tweenManager;
  118. ResourceManager *resourceManager;
  119. SoundManager *soundManager;
  120. Renderer *renderer;
  121. };
  122. _PolyExport CoreServices *Services();
  123. }