2
0

BsCoreSceneManager.h 2.4 KB

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