17#ifndef TOYMAKERENGINE_SCENESYSTEM_H
18#define TOYMAKERENGINE_SCENESYSTEM_H
22#include <unordered_map>
26#include <glm/gtc/quaternion.hpp>
60 {RelativeTo::PARENT,
"parent"},
85 class SceneNodeCore:
public std::enable_shared_from_this<SceneNodeCore> {
111 template <
typename TComponent>
112 void addComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
120 void addComponent(
const nlohmann::json& jsonComponent,
const bool bypassSceneActivityCheck=
false);
130 template <
typename TComponent>
131 TComponent
getComponent(
const float simulationProgress=1.f)
const;
140 template <
typename TComponent>
158 template <
typename TComponent>
175 template <
typename TComponent>
176 void addOrUpdateComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
184 void addOrUpdateComponent(
const nlohmann::json& component,
const bool bypassSceneActivityCheck=
false);
191 template <
typename TComponent>
202 template <
typename TSystem>
212 template <
typename TSystem>
241 std::weak_ptr<ECSWorld>
getWorld()
const;
272 bool isAncestorOf(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
282 bool hasNode(
const std::string& pathToChild)
const;
290 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
297 std::vector<std::shared_ptr<SceneNodeCore>>
getChildren();
304 std::vector<std::shared_ptr<const SceneNodeCore>>
getChildren()
const;
320 template <
typename TObject=std::shared_ptr<SceneNode>>
321 TObject
getByPath(
const std::string& where);
330 template <
typename TSceneNode=SceneNode>
361 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
383 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
404 void setName(
const std::string& name);
442 static std::shared_ptr<SceneNodeCore>
copy(
const std::shared_ptr<const SceneNodeCore> other);
452 template<
typename ...TComponents>
527 template<
typename ...TComponents>
545 template <
typename TObject,
typename Enable=
void>
547 static TObject get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where);
548 static constexpr bool s_valid {
false };
556 virtual std::shared_ptr<SceneNodeCore>
clone()
const;
574 static void setParentViewport(std::shared_ptr<SceneNodeCore> node, std::shared_ptr<ViewportNode> newViewport);
582 static std::shared_ptr<SceneNodeCore>
disconnectNode(std::shared_ptr<SceneNodeCore> node);
591 static bool detectCycle(std::shared_ptr<SceneNodeCore> node);
602 static std::tuple<std::string, std::string>
nextInPath(
const std::string& where);
667 std::vector<std::shared_ptr<SceneNodeCore>>
mChildren {};
684 template<
typename TSceneNode>
696 template <
typename TSceneNode>
712 template <
typename ...TComponents>
713 static std::shared_ptr<TSceneNode>
create(
const Key&,
const Placement& placement,
const std::string& name, TComponents...components);
726 template <
typename ...TComponents>
727 static std::shared_ptr<TSceneNode>
create(
const Placement& placement,
const std::string& name, TComponents...components);
737 static std::shared_ptr<TSceneNode>
create(
const nlohmann::json& sceneNodeDescription);
749 static std::shared_ptr<TSceneNode>
copy(
const std::shared_ptr<const TSceneNode> sceneNode);
750 template <
typename...TComponents>
761 SceneNodeCore{ key, placement, name, components... }
772 template<
typename ...TComponents>
774 SceneNodeCore{ placement, name, components... }
782 BaseSceneNode(
const nlohmann::json& nodeDescription) : SceneNodeCore { nodeDescription } {}
803 template <
typename ...TComponents>
804 static std::shared_ptr<SceneNode> create(
const Placement& placement,
const std::string& name, TComponents...components);
805 static std::shared_ptr<SceneNode> create(
const nlohmann::json& sceneNodeDescription);
806 static std::shared_ptr<SceneNode> copy(
const std::shared_ptr<const SceneNode> other);
808 static inline std::string getResourceTypeName() {
return "SceneNode"; }
811 template<
typename ...TComponents>
812 SceneNode(
const Placement& placement,
const std::string& name, TComponents...components):
817 SceneNode(
const nlohmann::json& jsonSceneNode):
822 SceneNode(
const SceneNode& sceneObject):
960 static std::shared_ptr<ViewportNode>
create(
const std::string& name,
bool inheritsWorld,
bool allowActionFlowThrough,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
973 static std::shared_ptr<ViewportNode>
create(
const nlohmann::json& sceneNodeDescription);
981 static std::shared_ptr<ViewportNode>
copy(
const std::shared_ptr<const ViewportNode> other);
1042 virtual std::shared_ptr<const ViewportNode>
getLocalViewport()
const override;
1096 void setSkybox(std::shared_ptr<Texture> skybox);
1156 bool handleAction(std::pair<ActionDefinition, ActionData> pendingAction);
1184 Resource<ViewportNode>{0},
1187 ViewportNode(
const nlohmann::json& jsonSceneNode):
1188 BaseSceneNode<ViewportNode>{jsonSceneNode},
1192 ViewportNode(
const ViewportNode& sceneObject):
1193 BaseSceneNode<ViewportNode>{sceneObject},
1234 static std::shared_ptr<ViewportNode>
create(
const Key& key,
const std::string& name,
bool inheritsWorld,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
1253 std::shared_ptr<SceneNodeCore>
clone()
const override;
1274 std::shared_ptr<SceneNodeCore> findFallbackCamera();
1299 uint32_t
render(
float simulationProgress, uint32_t variableStep);
1307 void render_(
float simulationProgress);
1327 bool operator() (
const std::shared_ptr<ViewportNode>& one,
const std::shared_ptr<ViewportNode>& two)
const {
1328 return one->getViewportLoadOrdinal() < two->getViewportLoadOrdinal();
1378 std::set<std::shared_ptr<SceneNodeCore>, std::owner_less<std::shared_ptr<SceneNodeCore>>>
mDomainCameras {};
1418 class SceneSystem:
public System<SceneSystem, std::tuple<>, std::tuple<Placement, SceneHierarchyData, Transform>> {
1453 template<
typename TObject=std::shared_ptr<SceneNode>>
1454 TObject
getByPath(
const std::string& where);
1463 template <
typename TSceneNode>
1472 std::vector<std::shared_ptr<SceneNodeCore>>
getNodesByID(
const std::vector<UniversalEntityID>& universalEntityIDs);
1480 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
1488 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
1496 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
1538 void simulationStep(uint32_t simStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1551 void variableStep(
float simulationProgress, uint32_t simulationLagMillis, uint32_t variableStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1584 class PlacementUpdateReporter:
public System<PlacementUpdateReporter, std::tuple<Placement>, std::tuple<Transform, SceneHierarchyData>> {
1586 explicit PlacementUpdateReporter(std::weak_ptr<ECSWorld> world):
1589 static std::string
getSystemTypeName() {
return "SceneSystem::PlacementUpdateReporter"; }
1624 class TransformUpdateReporter:
public System<TransformUpdateReporter, std::tuple<Transform>, std::tuple<Placement, SceneHierarchyData>> {
1626 explicit TransformUpdateReporter(std::weak_ptr<ECSWorld> world):
1629 static std::string
getSystemTypeName() {
return "SceneSystem::TransformUpdateReporter"; }
1662 template <
typename TSceneNode,
typename Enable=
void>
1674 bool isActive(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1692 bool inScene(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1790 void nodeAdded(std::shared_ptr<SceneNodeCore> sceneNode);
1797 void nodeRemoved(std::shared_ptr<SceneNodeCore> sceneNode);
1855 std::map<UniversalEntityID, std::weak_ptr<SceneNodeCore>, std::less<UniversalEntityID>>
mEntityToNode {};
1881 template <
typename TSceneNode>
1882 template <
typename ...TComponents>
1884 std::shared_ptr<SceneNodeCore> newNode (
new TSceneNode(placement, name, components...), &
SceneNodeCore_del_);
1885 newNode->onCreated();
1886 return std::static_pointer_cast<TSceneNode>(newNode);
1889 template <
typename TSceneNode>
1890 template <
typename ...TComponents>
1892 std::shared_ptr<SceneNodeCore> newNode(
new TSceneNode(key, placement, name, components...), &
SceneNodeCore_del_);
1893 newNode->onCreated();
1894 return std::static_pointer_cast<TSceneNode>(newNode);
1897 template <
typename TSceneNode>
1899 std::shared_ptr<SceneNodeCore> newNode{
new TSceneNode{ sceneNodeDescription }, &
SceneNodeCore_del_};
1900 newNode->onCreated();
1901 return std::static_pointer_cast<TSceneNode>(newNode);
1904 template <
typename TSceneNode>
1907 newNode->onCreated();
1908 return std::static_pointer_cast<TSceneNode>(newNode);
1911 template<
typename ...TComponents>
1912 std::shared_ptr<SceneNode> SceneNode::create(
const Placement& placement,
const std::string& name, TComponents...components) {
1916 template <
typename TObject>
1918 return getByPath_Helper<TObject>::get(shared_from_this(), where);
1921 template <
typename TObject>
1923 return mRootNode->getByPath<TObject>(where);
1926 template <
typename TSceneNode>
1933 template <
typename TObject,
typename Enable>
1934 TObject SceneNodeCore::getByPath_Helper<TObject, Enable>::get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1935 static_assert(
false &&
"No Object-by-Path method for this type exists");
1939 template <
typename TSceneNode,
typename Enable>
1940 std::shared_ptr<TSceneNode> SceneSystem::getNodeByID_Helper<TSceneNode, Enable>::get(
const UniversalEntityID& universalEntityID,
SceneSystem& sceneSystem) {
1941 static_assert(
false &&
"No scene node of this type exists");
1942 return std::shared_ptr<TSceneNode>{};
1945 template <
typename TSceneNode>
1948 return std::static_pointer_cast<TSceneNode>(sceneSystem.
getNodeByID(universalEntityID));
1952 template <
typename TObject>
1954 static std::shared_ptr<TObject> get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1955 return std::static_pointer_cast<TObject>(rootNode->getNode(where));
1957 static constexpr bool s_valid {
true };
1960 template <
typename ...TComponents>
1964 mEntity = std::make_shared<Entity>(
1969 .mModelMatrix { glm::mat4{1.f} },
1982 template <
typename ...TComponents>
1985 mEntity = std::make_shared<Entity>(
1990 .mModelMatrix { glm::mat4{1.f} },
2003 template <
typename TComponent>
2005 mEntity->addComponent<TComponent>(component);
2010 if(!bypassSceneActivityCheck &&
isActive()) {
2018 template <
typename TComponent>
2020 return mEntity->getComponent<TComponent>(simulationProgress);
2023 template <
typename TComponent>
2025 return mEntity->hasComponent<TComponent>();
2028 template <
typename TComponent>
2030 mEntity->updateComponent<TComponent>(component);
2033 template <
typename TComponent>
2042 template <
typename TComponent>
2044 mEntity->removeComponent<TComponent>();
2047 template <
typename TSystem>
2049 return mEntity->isEnabled<TSystem>();
2052 template <
typename TSystem>
2054 const SystemType systemType {
mEntity->getWorld().lock()->getSystemType<TSystem>() };
2076 mEntity->getWorld().lock()->getSystem<SceneSystem>()->nodeActivationChanged(
2085 assert(
false &&
"Cannot remove a scene node's Placement component");
2090 assert(
false &&
"Cannot remove a scene node's Transform component");
2093 template <
typename TSceneNode>
2100 {ViewportNode::RenderConfiguration::ResizeType::OFF,
"off"},
2101 {ViewportNode::RenderConfiguration::ResizeType::VIEWPORT_DIMENSIONS,
"viewport-dimensions"},
2102 {ViewportNode::RenderConfiguration::ResizeType::TEXTURE_DIMENSIONS,
"texture-dimensions"},
2107 {ViewportNode::RenderConfiguration::ResizeMode::FIXED_ASPECT,
"fixed-aspect"},
2108 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_VERTICALLY,
"expand-vertically"},
2109 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_HORIZONTALLY,
"expand-horizontally"},
2110 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_FILL,
"expand-fill"},
2115 {ViewportNode::RenderConfiguration::UpdateMode::NEVER,
"never"},
2116 {ViewportNode::RenderConfiguration::UpdateMode::ONCE,
"once"},
2117 {ViewportNode::RenderConfiguration::UpdateMode::ON_FETCH,
"on-fetch"},
2118 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER,
"on-render"},
2119 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER_CAP_FPS,
"on-render-cap-fps"},
2124 {ViewportNode::RenderConfiguration::RenderType::BASIC_3D,
"basic-3d"},
2125 {ViewportNode::RenderConfiguration::RenderType::ADDITION,
"addition"},
2131 {
"base_dimensions", nlohmann::json::array({renderConfiguration.mBaseDimensions.x, renderConfiguration.mBaseDimensions.y})},
2132 {
"update_mode", renderConfiguration.mUpdateMode},
2133 {
"resize_type", renderConfiguration.mResizeType},
2134 {
"resize_mode", renderConfiguration.mResizeMode},
2135 {
"render_scale", renderConfiguration.mRenderScale},
2136 {
"render_type", renderConfiguration.mRenderType},
2137 {
"fps_cap", renderConfiguration.mFPSCap},
2143 assert(json.find(
"base_dimensions") != json.end() &&
"Viewport descriptions must contain the \"base_dimensions\" size 2 array of Numbers attribute");
2144 json.at(
"base_dimensions")[0].get_to(renderConfiguration.mBaseDimensions.x);
2145 json.at(
"base_dimensions")[1].get_to(renderConfiguration.mBaseDimensions.y);
2146 json.at(
"render_type").get_to(renderConfiguration.mRenderType);
2147 renderConfiguration.mRequestedDimensions = renderConfiguration.mBaseDimensions;
2148 renderConfiguration.mComputedDimensions = renderConfiguration.mBaseDimensions;
2149 assert(renderConfiguration.mBaseDimensions.x > 0 && renderConfiguration.mBaseDimensions.y > 0 &&
"Base dimensions cannot include a 0 in either dimension");
2151 assert(json.find(
"update_mode") != json.end() &&
"Viewport render configuration must include the \"update_mode\" enum attribute");
2152 json.at(
"update_mode").get_to(renderConfiguration.mUpdateMode);
2154 assert(json.find(
"resize_type") != json.end() &&
"Viewport render configuration must include the \"resize_type\" enum attribute");
2155 json.at(
"resize_type").get_to(renderConfiguration.mResizeType);
2157 assert(json.find(
"resize_mode") != json.end() &&
"Viewport render configuration must include the \"resize_mode\" enum attribute");
2158 json.at(
"resize_mode").get_to(renderConfiguration.mResizeMode);
2160 assert(json.find(
"render_scale") != json.end() &&
"Viewport render configuration must include the \"render_scale\" float attribute");
2161 json.at(
"render_scale").get_to(renderConfiguration.mRenderScale);
2162 assert(renderConfiguration.mRenderScale > 0.f &&
"Render scale must be a positive non-zero decimal number");
2164 assert(json.find(
"fps_cap") != json.end() &&
"Viewport must include the \"fps_cap\" float attribute");
2165 json.at(
"fps_cap").get_to(renderConfiguration.mFPSCap);
2166 assert(renderConfiguration.mFPSCap > 0.f &&
"FPS cap must be a positive non-zero decimal number");
An object responsible for tracking action listeners for a given project.
Definition input_system.hpp:586
An object containing a coarse simplified representation, AABB, of spatially queryable objects.
Definition types.hpp:1322
A CRTP template for all the scene node types present in the project.
Definition scene_system.hpp:697
BaseSceneNode(const Key &key, const Placement &placement, const std::string &name, TComponents...components)
Constructor for a single node of a subclass.
Definition scene_system.hpp:760
static std::shared_ptr< TSceneNode > copy(const std::shared_ptr< const TSceneNode > sceneNode)
Creates a scene node of a specific type based on another node of that type.
Definition scene_system.hpp:1905
BaseSceneNode(const SceneNodeCore &other)
Constructs a new node of a certain type as a copy of another node.
Definition scene_system.hpp:789
BaseSceneNode(const nlohmann::json &nodeDescription)
Constructs a new node of a certain type based on its json description.
Definition scene_system.hpp:782
static std::shared_ptr< TSceneNode > create(const Key &, const Placement &placement, const std::string &name, TComponents...components)
A (private) method for the creation of a new scene node for a particular type.
Definition scene_system.hpp:1891
BaseSceneNode(const Placement &placement, const std::string &name, TComponents...components)
General constructor for a single node of a subclass.
Definition scene_system.hpp:773
A class that represents a set of systems, entities, and components, that are all interrelated,...
Definition ecs_world.hpp:1464
static Entity createEntityPrototype(TComponents...components)
Create a prototype entity object.
Definition ecs_world.hpp:2807
The base class for any type whose creation and storage should be managed by the ResourceDatabase.
Definition resource_database.hpp:369
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:386
The core of a node in the SceneSystem, a set of components and methods overridable or usable by all t...
Definition scene_system.hpp:85
virtual void onCreated()
Scene node lifecycle hook for when a node is created.
Definition scene_system.cpp:21
std::shared_ptr< SceneNodeCore > removeNode(const std::string &where)
Removes a node from the tree present at the path specified.
Definition scene_system.cpp:350
virtual std::shared_ptr< SceneNodeCore > clone() const
Virtual method which each type of scene node with special members should implement (in lieu of copy c...
Definition scene_system.cpp:42
std::unordered_map< std::string, std::size_t > mChildNameToNode
A mapping of names of this node's child nodes to the indices of the nodes themselves.
Definition scene_system.hpp:661
void addComponent(const TComponent &component, const bool bypassSceneActivityCheck=false)
Adds a component of type TComponent to the node.
Definition scene_system.hpp:2004
std::shared_ptr< TSceneNode > getNodeByID(EntityID entityID)
Gets a pointer to a node by its EntityID, assuming that node and this one belong to the same ECSWorld...
Definition scene_system.hpp:2094
bool isAncestorOf(std::shared_ptr< const SceneNodeCore > sceneNode) const
Tests whether a particular scene node is the ancestor of this one.
Definition scene_system.cpp:169
RelativeTo mRelativeTo
A marker indicating how this node's transform component should be computed.
Definition scene_system.hpp:635
std::weak_ptr< ECSWorld > getWorld() const
Gets a reference to the ECSWorld this node belongs to.
Definition scene_system.cpp:407
virtual std::shared_ptr< ViewportNode > getLocalViewport()
Returns the viewport node which is in the same ECSWorld as and is the closest ancestor of (or the sam...
Definition scene_system.cpp:311
SceneNodeCore(const Placement &placement, const std::string &name, TComponents...components)
Constructs a scene node object from essential and extra components.
Definition scene_system.hpp:1961
static std::shared_ptr< SceneNodeCore > disconnectNode(std::shared_ptr< SceneNodeCore > node)
Disconnects this node from its parent node if it has one.
Definition scene_system.cpp:334
void recomputeChildNameIndexMapping()
Utility function for updating SceneHierarchyData components belonging to a single ECSWorld in the Sce...
Definition scene_system.cpp:82
void setPrototype_(std::shared_ptr< SceneNodeCore > prototype)
A reference to the node which was used in order to construct this one.
Definition scene_system.hpp:424
std::string mName
The name of this scene node.
Definition scene_system.hpp:621
std::string getPathFromAncestor(std::shared_ptr< const SceneNodeCore > ancestor) const
Gets the path from a node (assumed to be an ancestor) to this node.
Definition scene_system.cpp:385
std::vector< std::shared_ptr< SceneNodeCore > > getChildren()
Returns a list of all of this node's immediate children scene nodes.
Definition scene_system.cpp:248
virtual void onDeactivated()
Scene node lifecycle hook for when a node is deactivated on the SceneSystem.
Definition scene_system.cpp:23
virtual ~SceneNodeCore()=default
Destroys SceneNodeCore.
static std::tuple< std::string, std::string > nextInPath(const std::string &where)
Strips the root-most part of the path to a node.
Definition scene_system.cpp:192
std::vector< std::shared_ptr< SceneNodeCore > > mChildren
A list of this node's child nodes.
Definition scene_system.hpp:667
virtual void joinWorld(ECSWorld &world)
Removes this node's entity from its current ECSWorld and adds it to a new ECSWorld.
Definition scene_system.cpp:410
static void setParentViewport(std::shared_ptr< SceneNodeCore > node, std::shared_ptr< ViewportNode > newViewport)
Sets a node as the parent viewport of another one.
Definition scene_system.cpp:273
std::shared_ptr< SceneNodeCore > getNode(const std::string &where)
Gets a reference to a scene node (of any valid type) based on its path relative to this node.
Definition scene_system.cpp:259
void addOrUpdateComponent(const TComponent &component, const bool bypassSceneActivityCheck=false)
A method for adding a component or updating a component if that component is already present on this ...
Definition scene_system.hpp:2034
std::string getName() const
Returns the name string for this node.
Definition scene_system.cpp:184
std::string getViewportLocalPath() const
Gets the path of this node relative to its local viewport node.
Definition scene_system.cpp:188
static void validateName(const std::string &nodeName)
Tests whether a given name is actually valid, throwing an error when it is not.
Definition scene_system.cpp:425
bool isActive() const
Returns whether this node is present as part of the SceneSystem's scene tree, AND is active there as ...
Definition scene_system.cpp:165
static void SceneNodeCore_del_(SceneNodeCore *sceneNode)
Deleter for a managed pointer to a scene node which ensures its onDestroyed virtual function gets cal...
Definition scene_system.cpp:15
void copyDescendants(const SceneNodeCore &other)
Copies descendant nodes belonging to another node, attaches the copies to this node.
Definition scene_system.cpp:105
virtual void onActivated()
Scene node lifecycle hook for when a node is made an active part of the SceneSystem.
Definition scene_system.cpp:22
void updateComponent(const TComponent &component)
Updates the value of a component of this node (to what it should be at the start of the next simulati...
Definition scene_system.hpp:2029
std::shared_ptr< Entity > mEntity
The ECSWorld entity which this node is a wrapper over.
Definition scene_system.hpp:641
TComponent getComponent(const float simulationProgress=1.f) const
Retrieves a component belonging to this node.
Definition scene_system.hpp:2019
std::shared_ptr< SceneNodeCore > getParentNode()
Gets the parent node of this node, if one is present.
Definition scene_system.cpp:318
void copyAndReplaceAttributes(const SceneNodeCore &other)
Copies component values from another node and replaces the values on node's components with them.
Definition scene_system.cpp:89
bool hasComponent() const
Tests whether this node has a component of a specific type.
Definition scene_system.hpp:2024
std::vector< std::shared_ptr< SceneNodeCore > > getDescendants()
Gets all of the descendant nodes belonging to this scene node.
Definition scene_system.cpp:375
virtual void onDestroyed()
Scene node lifecycle hook for when a node (and possibly its descendants) are about to be destroyed.
Definition scene_system.cpp:24
void addNode(std::shared_ptr< SceneNodeCore > node, const std::string &where)
Adds a node (or a tree of them) as a child of the node specified by the path in the argument.
Definition scene_system.cpp:225
uint8_t mStateFlags
Flags indicating the state of this scene node in the scene system.
Definition scene_system.hpp:629
Signature mSystemMask
A bitset, each position of which indicates whether a system should influence this node when it is par...
Definition scene_system.hpp:681
void setName(const std::string &name)
Sets the name of this node.
Definition scene_system.cpp:179
std::vector< std::shared_ptr< SceneNodeCore > > removeChildren()
Disconnects and removes all the child nodes attached to this node.
Definition scene_system.cpp:365
std::weak_ptr< ViewportNode > mParentViewport
A reference to this node's parent viewport (whose meaning changes depending on whether this node is a...
Definition scene_system.hpp:653
UniversalEntityID getUniversalEntityID() const
Gets the UniversalEntityID aka the world-entity-id pair associated with this node.
Definition scene_system.cpp:404
TObject getByPath(const std::string &where)
Gets a reference to a node or related object by its path.
Definition scene_system.hpp:1917
std::shared_ptr< SceneNodeCore > mPrototype
Allows a prototype scene node to be retained as a resource so long as this node is present in memory ...
Definition scene_system.hpp:673
bool hasNode(const std::string &pathToChild) const
Tests whether a node specified by some path relative to this node is a real descendant of this node.
Definition scene_system.cpp:208
void setEnabled(bool state)
Sets whether or not a given system should be able to influence this scene object.
Definition scene_system.hpp:2053
std::weak_ptr< SceneNodeCore > mParent
A reference to this node's parent scene node.
Definition scene_system.hpp:647
static std::shared_ptr< SceneNodeCore > copy(const std::shared_ptr< const SceneNodeCore > other)
Creates a new scene tree by copying another scene node and its descendants.
Definition scene_system.cpp:26
EntityID getEntityID() const
Returns the entity id associated with these scene node.
Definition scene_system.cpp:398
static bool detectCycle(std::shared_ptr< SceneNodeCore > node)
Tests whether there are any cycles in the path up to the node's oldest ancestor.
Definition scene_system.cpp:147
WorldID getWorldID() const
Returns the ID of the ECSWorld this node belongs to.
Definition scene_system.cpp:401
void removeComponent()
Removes a component present on this node.
Definition scene_system.hpp:2043
StateFlags
Flags that indicate whether this node is enabled and active for the SceneSystem.
Definition scene_system.hpp:534
bool inScene() const
Returns whether this node is present as part of the SceneSystem's scene tree.
Definition scene_system.cpp:161
bool getEnabled() const
Returns whether a particular system has been enabled for this node.
Definition scene_system.hpp:2048
The most basic vanilla flavour of scene node comprised of no more than a name and some components.
Definition scene_system.hpp:801
void onEntityUpdated(EntityID entityID, ComponentType updatedComponent) override
Notifies scene system that a placement component in its world has been updated.
Definition scene_system.cpp:1522
void clearReportList()
Called at the end of the transform update to clear report list in preparation for the next time step'...
Definition scene_system.hpp:1609
std::set< EntityID > mReportedEntities
Entities whose placement updates this system has reported.
Definition scene_system.hpp:1596
The SceneSystem, a singleton System, responsible for tracking all objects in the scene,...
Definition scene_system.hpp:1418
bool isSingleton() const override
Informs this System's ECSWorld that the SceneSystem is a singleton, i.e., there should not be more th...
Definition scene_system.hpp:1444
bool inScene(std::shared_ptr< const SceneNodeCore > sceneNode) const
Returns whether a particular scene node is in the SceneSystem's scene tree, even if it is inactive.
Definition scene_system.cpp:1110
std::set< UniversalEntityID, std::less< UniversalEntityID > > mComputePlacementQueue
Nodes whose transforms were updated this variable or simulation step should have their placements rec...
Definition scene_system.hpp:1875
std::vector< std::weak_ptr< ECSWorld > > getActiveWorlds()
Returns the ECSWorlds owned by ViewportNodes active in the scene tree.
Definition scene_system.cpp:1142
std::weak_ptr< ECSWorld > getRootWorld() const
Gets the world associated with the root ViewportNode of the scene system.
Definition scene_system.cpp:1134
ViewportNode & getRootViewport() const
Gets a reference to the root viewport of the SceneSystem, usually used to adjust its rendering config...
Definition scene_system.cpp:1155
std::vector< std::shared_ptr< SceneNodeCore > > getNodesByID(const std::vector< UniversalEntityID > &universalEntityIDs)
Gets nodes by their world-entity ID pair.
Definition scene_system.cpp:1550
std::set< UniversalEntityID, std::less< UniversalEntityID > > mActiveEntities
A list of world-entity IDs associated with all the active nodes known by the SceneSystem.
Definition scene_system.hpp:1861
void markDirtyPlacement(UniversalEntityID universalEntityID)
Marks a node as in need of a placement update based on its universal entity id.
Definition scene_system.cpp:1495
uint32_t render(float simulationProgress, uint32_t variableStep)
Runs the render step for the SceneSystem's root viewport and its descendants.
Definition scene_system.cpp:1086
void deactivateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Deactivates this node and its descendants.
Definition scene_system.cpp:1327
void activateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Activates this node and its descendants.
Definition scene_system.cpp:1311
std::set< UniversalEntityID, std::less< UniversalEntityID > > mComputeTransformQueue
Nodes which were updated during this variable or simulation step scheduled for a Transform update.
Definition scene_system.hpp:1867
void simulationStep(uint32_t simStepMillis, std::vector< std::pair< ActionDefinition, ActionData > > triggeredActions={})
Runs a single step for the root viewport and its descendants, propagating any actions generated by th...
Definition scene_system.cpp:990
void nodeRemoved(std::shared_ptr< SceneNodeCore > sceneNode)
Plays any side effects related to a node being removed from the SceneSystem's scene tree.
Definition scene_system.cpp:1279
std::shared_ptr< TSceneNode > getNodeByID(const UniversalEntityID &universalEntityID)
Gets a scene node by its world-entity ID pair.
Definition scene_system.hpp:1927
void updateHierarchyDataInsertion(std::shared_ptr< SceneNodeCore > insertedNode)
Updates a node's scene hierarchy data per its location in the scene tree.
Definition scene_system.cpp:1163
void onApplicationInitialize(const ViewportNode::RenderConfiguration &rootViewportRenderConfiguration)
A method intended to be used at the start of the application to configure the SceneSystem's root view...
Definition scene_system.cpp:1508
std::shared_ptr< SceneNodeCore > removeNode(const std::string &where)
Removes a node present at the path specified in the call.
Definition scene_system.cpp:1129
Transform getCachedWorldTransform(std::shared_ptr< const SceneNodeCore > sceneNode) const
Returns the Transform of a node based on both its local Placement and its hierarchical transforms.
Definition scene_system.cpp:1434
void onApplicationEnd()
Clean up tasks the SceneSystem should perform before the application is terminated.
Definition scene_system.cpp:1105
void variableStep(float simulationProgress, uint32_t simulationLagMillis, uint32_t variableStepMillis, std::vector< std::pair< ActionDefinition, ActionData > > triggeredActions={})
Runs the variable step for the SceneSystem's root viewport and its descendants.
Definition scene_system.cpp:1045
static std::string getSystemTypeName()
The system type string associated with the SceneSystem.
Definition scene_system.hpp:1434
void nodeAdded(std::shared_ptr< SceneNodeCore > sceneNode)
Plays any side effects associated with a node being added to the SceneSystem's scene tree.
Definition scene_system.cpp:1240
void onWorldPlacementUpdate(UniversalEntityID UniversalEntityID)
A callback used by this system's subsystem to notify the SceneSystem that an entity's placement has b...
Definition scene_system.cpp:1500
std::weak_ptr< ECSWorld > getWorld(WorldID world)
Returns a reference to the world with a particular ID.
Definition scene_system.cpp:1146
void updateHierarchyDataRemoval(std::shared_ptr< SceneNodeCore > removedNode)
Removes a node's scene hierarchy data before it's removed from the hierarchy.
Definition scene_system.cpp:1204
void updateTransformsPlacements()
Updates transforms of objects in the scene per changes in those object's Placement component.
Definition scene_system.cpp:1343
SceneSystem(std::weak_ptr< ECSWorld > world)
Constructs a new SceneSystem object.
Definition scene_system.hpp:1425
std::vector< std::shared_ptr< ViewportNode > > getActiveViewports()
Returns a list of active viewports including the root viewport of the scene tree.
Definition scene_system.cpp:1138
void nodeActivationChanged(std::shared_ptr< SceneNodeCore > sceneNode, bool state)
"Activates" or deactivates a node and its descendants on various ECS systems, per the node's system m...
Definition scene_system.cpp:1295
void transformStep(uint32_t timestepMillis)
Updates transforms and placements as needed after a system update step.
Definition scene_system.cpp:1066
void onWorldTransformUpdate(UniversalEntityID universalEntityID)
A callback used by this system's subsystem to notify it that an entity's Transform has been updated.
Definition scene_system.cpp:1504
void addNode(std::shared_ptr< SceneNodeCore > node, const std::string &where)
Adds a node to the SceneSystem's scene tree as a child of the node specified by its path.
Definition scene_system.cpp:1159
Transform getInheritedTransform(std::shared_ptr< const SceneNodeCore > sceneNode) const
Gets the transform premultiplied with this object's local transform based on its transform settings.
Definition scene_system.cpp:1440
Transform getLocalTransform(std::shared_ptr< const SceneNodeCore > sceneNode) const
Gets the transform of a node solely based on its Placement component and independent of its position ...
Definition scene_system.cpp:1421
std::shared_ptr< SceneNodeCore > getNode(const std::string &where)
Gets a node by its scene node path.
Definition scene_system.cpp:1124
TObject getByPath(const std::string &where)
Gets an object of a specific type based on a valid path to that object belonging to the scene system ...
Definition scene_system.hpp:1922
void markDirtyTransform(UniversalEntityID universalEntityID)
Marks a node as in need of a transform update based on its universal entity id.
Definition scene_system.cpp:1489
void onApplicationStart()
Method to be called by main to initialize the SceneSystem as a whole.
Definition scene_system.cpp:1517
std::shared_ptr< ViewportNode > mRootNode
The root node of the SceneSystem, alive and active throughout the lifetime of the application.
Definition scene_system.hpp:1849
std::map< UniversalEntityID, std::weak_ptr< SceneNodeCore >, std::less< UniversalEntityID > > mEntityToNode
A mapping from the world-entity IDs of active nodes in the SceneSystem to the nodes themselves.
Definition scene_system.hpp:1855
bool isActive(std::shared_ptr< const SceneNodeCore > sceneNode) const
Returns whether a particular scene node is an active member of the SceneSystem's scene tree.
Definition scene_system.cpp:1117
A system template that disables systems with this form of declaration.
Definition ecs_world.hpp:1087
A type of node capable of and responsible for interacting sensibly with the engine's RenderSystem and...
Definition scene_system.hpp:842
std::set< std::shared_ptr< SceneNodeCore >, std::owner_less< std::shared_ptr< SceneNodeCore > > > mDomainCameras
The set of all active cameras that belong to the domain owned by this viewport.
Definition scene_system.hpp:1378
ActionDispatch & getActionDispatch()
Gets the action dispatch object for this viewport, which is the central location from which all actio...
Definition scene_system.cpp:949
bool mActionFlowthrough
Whether or not handled actions are propagated to this viewport's descendant viewports.
Definition scene_system.hpp:1354
void unregisterDomainCamera(std::shared_ptr< SceneNodeCore > cameraNode)
Removes a camera from this viewport's domain.
Definition scene_system.cpp:777
std::shared_ptr< Texture > fetchRenderResult(float simulationProgress)
Fetches the render result for the most recently computed render frame.
Definition scene_system.cpp:797
void requestDimensions(glm::u16vec2 requestedDimensions)
Target dimensions that another part of the program specifies for this viewport.
Definition scene_system.cpp:644
void updateExposure(float newExposure)
Updates the exposure of this viewport's RenderSet.
Definition scene_system.cpp:596
uint64_t mViewportLoadOrdinal
Number dictating when this viewport should be computed relative to other viewports,...
Definition scene_system.hpp:1336
std::shared_ptr< const SceneNodeCore > getActiveCamera() const
Gets the active camera for this viewport.
Definition scene_system.cpp:640
void createAndJoinWorld()
Creates and joins its own ECSWorld.
Definition scene_system.cpp:559
uint32_t mNLifetimeChildrenAdded
A number that is incremented whenever a child viewport is added to this viewport, guaranteeing unique...
Definition scene_system.hpp:1342
std::shared_ptr< ViewportNode > getLocalViewport() override
Returns this viewport instead of base class return value.
Definition scene_system.cpp:953
static std::shared_ptr< ViewportNode > copy(const std::shared_ptr< const ViewportNode > other)
Copies the properties and components of another viewport and uses them to construct a new one.
Definition scene_system.cpp:530
std::set< std::shared_ptr< ViewportNode >, ViewportChildComp_ > mChildViewports
This viewports children viewport, in the order they were added to this viewport.
Definition scene_system.hpp:1366
uint32_t render(float simulationProgress, uint32_t variableStep)
Requests execution of the render pipeline.
Definition scene_system.cpp:830
bool handleAction(std::pair< ActionDefinition, ActionData > pendingAction)
Handles an action received by this viewport, generally by dispatching it to subscribed listeners and ...
Definition scene_system.cpp:909
void joinWorld(ECSWorld &world) override
Joins this node's entity to a world (either its own or its parent viewport's).
Definition scene_system.cpp:413
void setFPSCap(float fpsCap)
If an FPS capped update mode is selected, sets what that cap actually is.
Definition scene_system.cpp:761
RenderConfiguration mRenderConfiguration
The render configuration associated with this viewport.
Definition scene_system.hpp:1398
bool disallowsHandledActionPropagation() const
Returns whether an action handled by one of this viewport's (high precedence) child viewports,...
Definition scene_system.hpp:1164
~ViewportNode() override
Destroys this viewport object.
Definition scene_system.cpp:437
static std::string getResourceTypeName()
Gets the resource type string associated with the ViewportNode.
Definition scene_system.hpp:988
uint32_t getViewportLoadOrdinal() const
(When this viewport is the immediate descendant of a RenderSet::RenderType::ADDITION viewport) The pr...
Definition scene_system.hpp:1179
void setActiveCamera(const std::string &cameraPath)
Sets the active camera for this viewport's RenderSet via path to the camera node.
Definition scene_system.cpp:619
void setRenderConfiguration(const RenderConfiguration &renderConfiguration)
Sets the render configuration for this viewport.
Definition scene_system.cpp:549
bool mPreventHandledActionPropagation
When a child viewport handles an action, determines whether the action is sent along to this viewport...
Definition scene_system.hpp:1360
RenderSetID mRenderSet
The ID of the RenderSet registered with this viewport's RenderSystem corresponding to this ViewportNo...
Definition scene_system.hpp:1384
std::shared_ptr< SceneNodeCore > mActiveCamera
The active camera node associated with this viewport.
Definition scene_system.hpp:1372
float getGamma()
Gets the gamma value used by this viewport's RenderSet.
Definition scene_system.cpp:613
SDL_Rect getCenteredViewportCoordinates() const
Gets the region of this viewport's target texture that the rendered texture should be mapped to.
Definition scene_system.hpp:1315
void viewNextDebugTexture()
Sets the next debug texture listed in this viewport's render set to the texture considered "active" b...
Definition scene_system.cpp:591
void registerDomainCamera(std::shared_ptr< SceneNodeCore > cameraNode)
Registers a camera that belongs to this viewport, which is a descendant of it and not a descendant of...
Definition scene_system.cpp:772
std::vector< std::shared_ptr< ViewportNode > > getActiveDescendantViewports()
Gets active descendant viewports (in DFS order) under this Viewport.
Definition scene_system.cpp:961
void setSkybox(std::shared_ptr< Texture > skybox)
Sets the skybox texture for this object's RenderSystem.
Definition scene_system.cpp:587
std::vector< std::weak_ptr< ECSWorld > > getActiveDescendantWorlds()
Gets weak references to ECSWorlds belonging to descendant viewports.
Definition scene_system.cpp:975
float getExposure()
Gets the exposure value used by this viewport's RenderSet.
Definition scene_system.cpp:607
void onDeactivated() override
Deactivates this viewports ECSWorld (if there is one) when this ViewportNode is retired.
Definition scene_system.cpp:583
void setResizeType(RenderConfiguration::ResizeType type)
Sets this viewport's behaviour when request dimensions (or target dimensions) are changed.
Definition scene_system.cpp:744
std::shared_ptr< ECSWorld > mOwnWorld
The ECS world owned by this viewport (if any), as well as the world this node is a member of.
Definition scene_system.hpp:1202
static std::shared_ptr< ViewportNode > create(const std::string &name, bool inheritsWorld, bool allowActionFlowThrough, const RenderConfiguration &renderConfiguration, std::shared_ptr< Texture > skybox)
Creates a viewport node with components essential to it.
Definition scene_system.cpp:469
void setResizeMode(RenderConfiguration::ResizeMode mode)
When resize is enabled, determines how resized render dimensions are computed.
Definition scene_system.cpp:750
std::shared_ptr< Texture > mTextureResult
The result of rendering from running the rendering pipeline associated with this viewport.
Definition scene_system.hpp:1392
void updateGamma(float newGamma)
Updates the gamma value of this viewport's RenderSet.
Definition scene_system.cpp:601
RenderConfiguration getRenderConfiguration() const
Gets the render configuration for this viewport.
Definition scene_system.cpp:555
void onActivated() override
Override which for a viewport sets its active camera, and initializes the ECSWorld owned by this view...
Definition scene_system.cpp:565
ViewportNode(const Key &key, const Placement &placement, const std::string &name)
Constructs a new ViewportNode using a simplified constructor.
Definition scene_system.hpp:1243
ActionDispatch mActionDispatch
Dispatcher for received actions to their action handlers within the domain of this viewport.
Definition scene_system.hpp:1348
void render_(float simulationProgress)
Implementation responsible for actually computing a new render frame.
Definition scene_system.cpp:871
void setRenderScale(float renderScale)
Sets the scale relative to computed and design dimensions for the render pipeline target.
Definition scene_system.cpp:766
uint32_t mTimeSinceLastRender
The time, in milliseconds, since the last time a render request was honoured by this viewport.
Definition scene_system.hpp:1404
std::shared_ptr< SceneNodeCore > clone() const override
Creates a new ViewportNode using itself as a template.
Definition scene_system.cpp:535
void setUpdateMode(RenderConfiguration::UpdateMode updateMode)
Sets the behaviour for frequency of render updates w.r.t render requests.
Definition scene_system.cpp:756
ToyMaker Engine's implementation of an ECS system.
ECSType ComponentType
An unsigned integer representing the type of a component.
Definition ecs_world.hpp:103
std::bitset< kMaxComponents > Signature
A 255 bit number, where each enabled bit represents a relationship between an entity and some ECS rel...
Definition ecs_world.hpp:154
ECSType SystemType
An unsigned integer representing the type of a system.
Definition ecs_world.hpp:112
constexpr EntityID kMaxEntities
A user-set constant which limits the number of creatable entities in a single ECS system.
Definition ecs_world.hpp:119
std::pair< WorldID, EntityID > UniversalEntityID
An ID that uniquely identifies an entity.
Definition ecs_world.hpp:85
std::uint64_t EntityID
A single unsigned integer used as a name for an entity managed by an ECS system.
Definition ecs_world.hpp:68
std::uint64_t WorldID
An unsigned integer representing the name of an ECS world.
Definition ecs_world.hpp:76
SpecialEntity
(Perhaps unused) Special "reserved" entity IDs which the scene system might use.
Definition scene_system.hpp:69
RelativeTo
(Presently unused) A marker to indicate how transforms should be computed for a given scene node.
Definition scene_system.hpp:52
const std::string kSceneRootName
Special name for the scene root, unusable by any other scene object.
Definition scene_system.cpp:13
@ PARENT
Transform components are inherited from this object's parent.
Definition scene_components.hpp:58
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:25
Contains definitions relating to the render system defined for this object.
Headers relating to resources and their management for a given project.
Stores structs and classes for common components used by the SceneSystem and other related Systems.
Classes and structs representing data related to the engine's spatial query system (the precursor to ...
A component representing the position, rotation, and scale of an entity.
Definition scene_components.hpp:73
TransformInheritMode mInheritMode
Field specifying which coordinate system this object's transform is specified relative to.
Definition scene_components.hpp:105
TransformComponentSet mInheritedComponents
Field specifying which aspects of its parent's transform this object's transform is specified relativ...
Definition scene_components.hpp:99
RenderType
Enum listing the different rendering pipelines available.
Definition render_system.hpp:59
Component representing hierarchical information related to this entity.
Definition scene_components.hpp:212
A private struct to limit certain sensitive functions to this class and other closely coupled classes...
Definition scene_system.hpp:517
A helper intended to get scene nodes and related objects attached to the scene tree.
Definition scene_system.hpp:546
Helper struct for retrieving nodes based on their UniversalEntityIDs.
Definition scene_system.hpp:1663
A collection of data that specifies the behaviour and properties of the RenderSystem and target textu...
Definition scene_system.hpp:848
glm::u16vec2 mComputedDimensions
The dimensions finally computed for this viewport, per request from other parts of the application.
Definition scene_system.hpp:916
RenderSet::RenderType RenderType
Specifies the type of render pipeline requested by this viewport.
Definition scene_system.hpp:887
ResizeType
Different resize configurations available for this Viewport node that dictate how render textures (fr...
Definition scene_system.hpp:853
glm::u16vec2 mRequestedDimensions
The dimensions requested by other parts of the application, to which this viewport's render texture m...
Definition scene_system.hpp:922
ResizeMode
Determines which dimensions the end result of the viewport is allowed to expand on.
Definition scene_system.hpp:863
UpdateMode mUpdateMode
The frequency of rendering updates in real time made on this viewport.
Definition scene_system.hpp:940
ResizeMode mResizeMode
The resizing/scaling behaviour from render-> target texture for this viewport.
Definition scene_system.hpp:898
RenderType mRenderType
The type of render pipelien requested by this viewport.
Definition scene_system.hpp:904
glm::u16vec2 mBaseDimensions
The design dimensions for this viewport, specified at the time of its development.
Definition scene_system.hpp:910
float mFPSCap
If an FPS capped update mode is used, specifies the value of that cap.
Definition scene_system.hpp:947
ResizeType mResizeType
The type of resizing/scaling behaviour from render->target texture for this viewport.
Definition scene_system.hpp:893
float mRenderScale
A multiplier applied (in case resizing is enabled) determining multiplier to the base or computed dim...
Definition scene_system.hpp:934
UpdateMode
Configuration value determining when and how often render updates take place for this viewport.
Definition scene_system.hpp:874
Comparator used for determining priority of descendant viewports owned by a RenderSet::RenderType::AD...
Definition scene_system.hpp:1326
Header containing definitions of classes and functions related to loading and using Texture resources...