BsCoreSceneManager.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 Called every frame. Calls update methods on all
  29. * scene objects and their components.
  30. *
  31. * @note Internal method.
  32. */
  33. virtual void _update();
  34. /**
  35. * @brief Updates dirty transforms on any core objects that may be tied with
  36. * scene objects.
  37. */
  38. virtual void _updateCoreObjectTransforms() { }
  39. protected:
  40. friend class SceneObject;
  41. /**
  42. * @brief Register a new node in the scene manager, on the top-most level of the hierarchy.
  43. *
  44. * @note After you add a node in the scene manager, it takes ownership of its memory and is responsible for releasing it.
  45. * 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.
  46. *
  47. * @param [in] node Node you wish to add. It's your responsibility not to add duplicate or null nodes. This method won't check.
  48. */
  49. void registerNewSO(const HSceneObject& node);
  50. protected:
  51. HSceneObject mRootNode;
  52. };
  53. /**
  54. * @brief Handles creation of a scene manager.
  55. *
  56. * @note Since scene manager implementations may vary it is expected that a concrete implementation
  57. * of a scene manager will register its creation method using "setFactoryMethod" which will then
  58. * later be used for creating the scene manager during application start up.
  59. */
  60. class BS_CORE_EXPORT SceneManagerFactory
  61. {
  62. public:
  63. /**
  64. * @brief Creates a concrete scene manager, depending on the currently set factory method.
  65. */
  66. static void create();
  67. /**
  68. * @brief Sets method that will be used for creating the scene manager when "create" gets called.
  69. */
  70. static void setFactoryMethod(const std::function<void()>& method)
  71. {
  72. mFactoryMethod = method;
  73. }
  74. private:
  75. static std::function<void()> mFactoryMethod;
  76. };
  77. /**
  78. * @brief Provides easy access to the scene manager.
  79. */
  80. BS_CORE_EXPORT CoreSceneManager& gCoreSceneManager();
  81. }