| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "Utility/BsModule.h"
- #include "Scene/BsGameObject.h"
- namespace bs
- {
- class LightProbeVolume;
- /** @addtogroup Scene-Internal
- * @{
- */
- /** Contains information about a camera managed by the scene manager. */
- struct SceneCameraData
- {
- SceneCameraData() { }
- SceneCameraData(const SPtr<Camera>& camera, const HSceneObject& sceneObject)
- :camera(camera), sceneObject(sceneObject)
- { }
- SPtr<Camera> camera;
- HSceneObject sceneObject;
- };
- /** Contains information about a renderable managed by the scene manager. */
- struct SceneRenderableData
- {
- SceneRenderableData() { }
- SceneRenderableData(const SPtr<Renderable>& renderable, const HSceneObject& sceneObject)
- :renderable(renderable), sceneObject(sceneObject)
- { }
- SPtr<Renderable> renderable;
- HSceneObject sceneObject;
- };
- /** Contains information about a light managed by the scene manager. */
- struct SceneLightData
- {
- SceneLightData() { }
- SceneLightData(const SPtr<Light>& light, const HSceneObject& sceneObject)
- :light(light), sceneObject(sceneObject)
- { }
- SPtr<Light> light;
- HSceneObject sceneObject;
- };
- /** Contains information about a reflection probe managed by the scene manager. */
- struct SceneReflectionProbeData
- {
- SceneReflectionProbeData() { }
- SceneReflectionProbeData(const SPtr<ReflectionProbe>& probe, const HSceneObject& sceneObject)
- :probe(probe), sceneObject(sceneObject)
- { }
- SPtr<ReflectionProbe> probe;
- HSceneObject sceneObject;
- };
- /** Contains information about a light probe volume managed by the scene manager. */
- struct SceneLightProbeVolumeData
- {
- SceneLightProbeVolumeData() { }
- SceneLightProbeVolumeData(const SPtr<LightProbeVolume>& volume, const HSceneObject& sceneObject)
- :volume(volume), sceneObject(sceneObject)
- { }
- SPtr<LightProbeVolume> volume;
- HSceneObject sceneObject;
- };
- /** Possible states components can be in. Controls which component callbacks are triggered. */
- enum class ComponentState
- {
- Running, /**< All components callbacks are being triggered normally. */
- Paused, /**< All component callbacks except update are being triggered normally. */
- Stopped /**< No component callbacks are being triggered. */
- };
- /** Manages active SceneObjects and provides ways for querying and updating them or their components. */
- class BS_CORE_EXPORT SceneManager : public Module<SceneManager>
- {
- public:
- SceneManager();
- ~SceneManager();
- /** Returns the root scene object. */
- HSceneObject getRootNode() const { return mRootNode; }
- /**
- * Destroys all scene objects in the scene.
- *
- * @param[in] forceAll If true, then even the persistent objects will be unloaded.
- */
- void clearScene(bool forceAll = false);
- /**
- * Changes the component state that globally determines which component callbacks are activated. Only affects
- * components that don't have the ComponentFlag::AlwaysRun flag set.
- */
- void setComponentState(ComponentState state);
- /** Checks are the components currently in the Running state. */
- bool isRunning() const { return mComponentState == ComponentState::Running; }
- /** Returns all cameras in the scene. */
- const Map<Camera*, SceneCameraData>& getAllCameras() const { return mCameras; }
- /**
- * Returns the camera in the scene marked as main. Main camera controls the final render surface that is displayed
- * to the user. If there are multiple main cameras, the first one found returned.
- */
- SceneCameraData getMainCamera() const;
- /**
- * Sets the render target that the main camera in the scene (if any) will render its view to. This generally means
- * the main game window when running standalone, or the Game viewport when running in editor.
- */
- void setMainRenderTarget(const SPtr<RenderTarget>& rt);
- /** Returns all renderables in the scene. */
- const Map<Renderable*, SceneRenderableData>& getAllRenderables() const { return mRenderables; }
- /** Notifies the scene manager that a new renderable was created. */
- void _registerRenderable(const SPtr<Renderable>& renderable, const HSceneObject& so);
- /** Notifies the scene manager that a renderable was removed. */
- void _unregisterRenderable(const SPtr<Renderable>& renderable);
- /** Notifies the scene manager that a new light was created. */
- void _registerLight(const SPtr<Light>& light, const HSceneObject& so);
- /** Notifies the scene manager that a light was removed. */
- void _unregisterLight(const SPtr<Light>& light);
- /** Notifies the scene manager that a new camera was created. */
- void _registerCamera(const SPtr<Camera>& camera, const HSceneObject& so);
- /** Notifies the scene manager that a camera was removed. */
- void _unregisterCamera(const SPtr<Camera>& camera);
- /** Notifies the scene manager that a new reflection probe was created. */
- void _registerReflectionProbe(const SPtr<ReflectionProbe>& probe, const HSceneObject& so);
- /** Notifies the scene manager that a reflection probe was removed. */
- void _unregisterReflectionProbe(const SPtr<ReflectionProbe>& probe);
- /** Notifies the scene manager that a new light probe volume was created. */
- void _registerLightProbeVolume(const SPtr<LightProbeVolume>& volume, const HSceneObject& so);
- /** Notifies the scene manager that a light proble volume was removed. */
- void _unregisterLightProbeVolume(const SPtr<LightProbeVolume>& volume);
- /** Notifies the scene manager that a camera either became the main camera, or has stopped being main camera. */
- void _notifyMainCameraStateChanged(const SPtr<Camera>& camera);
- /** Changes the root scene object. Any persistent objects will remain in the scene, now parented to the new root. */
- void _setRootNode(const HSceneObject& root);
- /** Called every frame. Calls update methods on all scene objects and their components. */
- void _update();
- /** Updates dirty transforms on any core objects that may be tied with scene objects. */
- void _updateCoreObjectTransforms();
- /** Notifies the manager that a new component has just been created. The manager triggers necessary callbacks. */
- void _notifyComponentCreated(const HComponent& component, bool parentActive);
- /**
- * Notifies the manager that a scene object the component belongs to was activated. The manager triggers necessary
- * callbacks.
- */
- void _notifyComponentActivated(const HComponent& component, bool triggerEvent);
- /**
- * Notifies the manager that a scene object the component belongs to was deactivated. The manager triggers necessary
- * callbacks.
- */
- void _notifyComponentDeactivated(const HComponent& component, bool triggerEvent);
- /** Notifies the manager that a component is about to be destroyed. The manager triggers necessary callbacks. */
- void _notifyComponentDestroyed(const HComponent& component);
- protected:
- friend class SceneObject;
- /**
- * Register a new node in the scene manager, on the top-most level of the hierarchy.
- *
- * @param[in] node Node you wish to add. It's your responsibility not to add duplicate or null nodes. This
- * method won't check.
- *
- * @note
- * After you add a node in the scene manager, it takes ownership of its memory and is responsible for releasing it.
- * Do NOT add nodes that have already been added (if you just want to change their parent). Normally this
- * method will only be called by SceneObject.
- */
- void registerNewSO(const HSceneObject& node);
- /** Callback that is triggered when the main render target size is changed. */
- void onMainRenderTargetResized();
- /** Removes a component from the active component list. */
- void removeFromActiveList(const HComponent& component);
- /** Removes a component from the inactive component list. */
- void removeFromInactiveList(const HComponent& component);
- /** Removes a component from the uninitialized component list. */
- void removeFromUninitializedList(const HComponent& component);
- /**
- * Encodes an index and a type into a single 32-bit integer. Top 2 bits represent the type, while the rest represent
- * the index.
- */
- UINT32 encodeComponentId(UINT32 idx, UINT32 type);
- /** Decodes an id encoded with encodeComponentId(). */
- void decodeComponentId(UINT32 id, UINT32& idx, UINT32& type);
- protected:
- HSceneObject mRootNode;
- Map<Camera*, SceneCameraData> mCameras;
- Vector<SceneCameraData> mMainCameras;
- Map<Renderable*, SceneRenderableData> mRenderables;
- Map<Light*, SceneLightData> mLights;
- Map<ReflectionProbe*, SceneReflectionProbeData> mReflectionProbes;
- Map<LightProbeVolume*, SceneLightProbeVolumeData> mLightProbeVolumes;
- Vector<HComponent> mActiveComponents;
- Vector<HComponent> mInactiveComponents;
- Vector<HComponent> mUnintializedComponents;
- SPtr<RenderTarget> mMainRT;
- HEvent mMainRTResizedConn;
- ComponentState mComponentState = ComponentState::Running;
- };
- /** Provides easy access to the SceneManager. */
- BS_CORE_EXPORT SceneManager& gSceneManager();
- /** @} */
- }
|