BsCoreSceneManager.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsGameObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Manages all objects in the scene and provides various query methods
  9. * for finding objects. This is just the base class with basic query
  10. * functionality. You should override it with your own version.
  11. */
  12. class BS_CORE_EXPORT CoreSceneManager : public Module<CoreSceneManager>
  13. {
  14. public:
  15. CoreSceneManager();
  16. virtual ~CoreSceneManager();
  17. /**
  18. * @brief Returns the root scene object.
  19. */
  20. HSceneObject getRootNode() const { return mRootNode; }
  21. /**
  22. * @brief Destroys all scene objects in the scene.
  23. *
  24. * @param forceAll If true, then even the persistent objects will be unloaded.
  25. */
  26. void clearScene(bool forceAll = false);
  27. /**
  28. * @brief Changes the root scene object. Any persistent objects will remain in the scene, now parented
  29. * to the new root.
  30. *
  31. * @note Internal method.
  32. */
  33. void _setRootNode(const HSceneObject& root);
  34. /**
  35. * @brief Called every frame. Calls update methods on all
  36. * scene objects and their components.
  37. *
  38. * @note Internal method.
  39. */
  40. virtual void _update();
  41. /**
  42. * @brief Updates dirty transforms on any core objects that may be tied with
  43. * scene objects.
  44. */
  45. virtual void _updateCoreObjectTransforms() { }
  46. protected:
  47. friend class SceneObject;
  48. /**
  49. * @brief Register a new node in the scene manager, on the top-most level of the hierarchy.
  50. *
  51. * @note After you add a node in the scene manager, it takes ownership of its memory and is responsible for releasing it.
  52. * Do NOT add nodes that have already been added (i.e. if you just want to change their parent). Normally this method will only be called by SceneObject.
  53. *
  54. * @param [in] node Node you wish to add. It's your responsibility not to add duplicate or null nodes. This method won't check.
  55. */
  56. void registerNewSO(const HSceneObject& node);
  57. protected:
  58. HSceneObject mRootNode;
  59. };
  60. /**
  61. * @brief Handles creation of a scene manager.
  62. *
  63. * @note Since scene manager implementations may vary it is expected that a concrete implementation
  64. * of a scene manager will register its creation method using "setFactoryMethod" which will then
  65. * later be used for creating the scene manager during application start up.
  66. */
  67. class BS_CORE_EXPORT SceneManagerFactory
  68. {
  69. public:
  70. /**
  71. * @brief Creates a concrete scene manager, depending on the currently set factory method.
  72. */
  73. static void create();
  74. /**
  75. * @brief Sets method that will be used for creating the scene manager when "create" gets called.
  76. */
  77. static void setFactoryMethod(const std::function<void()>& method)
  78. {
  79. mFactoryMethod = method;
  80. }
  81. private:
  82. static std::function<void()> mFactoryMethod;
  83. };
  84. /**
  85. * @brief Provides easy access to the scene manager.
  86. */
  87. BS_CORE_EXPORT CoreSceneManager& gCoreSceneManager();
  88. }