BsCoreSceneManager.h 2.9 KB

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