BsCoreSceneManager.h 2.3 KB

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