BsCoreSceneManager.h 3.1 KB

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