BsCoreSceneManager.h 3.1 KB

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