17#ifndef TOYMAKERENGINE_SCENESYSTEM_H
18#define TOYMAKERENGINE_SCENESYSTEM_H
22#include <unordered_map>
26#include <glm/gtc/quaternion.hpp>
61 {RelativeTo::PARENT,
"parent"},
86 class SceneNodeCore:
public std::enable_shared_from_this<SceneNodeCore> {
112 template <
typename TComponent>
113 void addComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
121 void addComponent(
const nlohmann::json& jsonComponent,
const bool bypassSceneActivityCheck=
false);
131 template <
typename TComponent>
132 TComponent
getComponent(
const float simulationProgress=1.f)
const;
141 template <
typename TComponent>
159 template <
typename TComponent>
176 template <
typename TComponent>
177 void addOrUpdateComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
185 void addOrUpdateComponent(
const nlohmann::json& component,
const bool bypassSceneActivityCheck=
false);
192 template <
typename TComponent>
203 template <
typename TSystem>
213 template <
typename TSystem>
242 std::weak_ptr<ECSWorld>
getWorld()
const;
273 bool isAncestorOf(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
283 bool hasNode(
const std::string& pathToChild)
const;
291 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
298 std::vector<std::shared_ptr<SceneNodeCore>>
getChildren();
305 std::vector<std::shared_ptr<const SceneNodeCore>>
getChildren()
const;
321 template <
typename TObject=std::shared_ptr<SceneNode>>
322 TObject
getByPath(
const std::string& where);
331 template <
typename TSceneNode=SceneNode>
362 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
384 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
405 void setName(
const std::string& name);
443 static std::shared_ptr<SceneNodeCore>
copy(
const std::shared_ptr<const SceneNodeCore> other);
453 template<
typename ...TComponents>
528 template<
typename ...TComponents>
546 template <
typename TObject,
typename Enable=
void>
548 static TObject get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where);
549 static constexpr bool s_valid {
false };
557 virtual std::shared_ptr<SceneNodeCore>
clone()
const;
575 static void setParentViewport(std::shared_ptr<SceneNodeCore> node, std::shared_ptr<ViewportNode> newViewport);
583 static std::shared_ptr<SceneNodeCore>
disconnectNode(std::shared_ptr<SceneNodeCore> node);
592 static bool detectCycle(std::shared_ptr<SceneNodeCore> node);
603 static std::tuple<std::string, std::string>
nextInPath(
const std::string& where);
668 std::vector<std::shared_ptr<SceneNodeCore>>
mChildren {};
685 template<
typename TSceneNode>
697 template <
typename TSceneNode>
713 template <
typename ...TComponents>
714 static std::shared_ptr<TSceneNode>
create(
const Key&,
const Placement& placement,
const std::string& name, TComponents...components);
727 template <
typename ...TComponents>
728 static std::shared_ptr<TSceneNode>
create(
const Placement& placement,
const std::string& name, TComponents...components);
738 static std::shared_ptr<TSceneNode>
create(
const nlohmann::json& sceneNodeDescription);
750 static std::shared_ptr<TSceneNode>
copy(
const std::shared_ptr<const TSceneNode> sceneNode);
751 template <
typename...TComponents>
762 SceneNodeCore{ key, placement, name, components... }
773 template<
typename ...TComponents>
775 SceneNodeCore{ placement, name, components... }
783 BaseSceneNode(
const nlohmann::json& nodeDescription) : SceneNodeCore { nodeDescription } {}
804 template <
typename ...TComponents>
805 static std::shared_ptr<SceneNode> create(
const Placement& placement,
const std::string& name, TComponents...components);
806 static std::shared_ptr<SceneNode> create(
const nlohmann::json& sceneNodeDescription);
807 static std::shared_ptr<SceneNode> copy(
const std::shared_ptr<const SceneNode> other);
809 static inline std::string getResourceTypeName() {
return "SceneNode"; }
812 template<
typename ...TComponents>
813 SceneNode(
const Placement& placement,
const std::string& name, TComponents...components):
818 SceneNode(
const nlohmann::json& jsonSceneNode):
823 SceneNode(
const SceneNode& sceneObject):
961 static std::shared_ptr<ViewportNode>
create(
const std::string& name,
bool inheritsWorld,
bool allowActionFlowThrough,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
974 static std::shared_ptr<ViewportNode>
create(
const nlohmann::json& sceneNodeDescription);
982 static std::shared_ptr<ViewportNode>
copy(
const std::shared_ptr<const ViewportNode> other);
1043 virtual std::shared_ptr<const ViewportNode>
getLocalViewport()
const override;
1097 void setSkybox(std::shared_ptr<Texture> skybox);
1157 bool handleAction(std::pair<ActionDefinition, ActionData> pendingAction);
1187 *
this,
"RenderConfigurationUpdated"
1193 Resource<ViewportNode>{0},
1196 ViewportNode(
const nlohmann::json& jsonSceneNode):
1197 BaseSceneNode<ViewportNode>{jsonSceneNode},
1201 ViewportNode(
const ViewportNode& sceneObject):
1202 BaseSceneNode<ViewportNode>{sceneObject},
1243 static std::shared_ptr<ViewportNode>
create(
const Key& key,
const std::string& name,
bool inheritsWorld,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
1262 std::shared_ptr<SceneNodeCore>
clone()
const override;
1283 std::shared_ptr<SceneNodeCore> findFallbackCamera();
1316 uint32_t
render(
float simulationProgress, uint32_t variableStep);
1324 void render_(
float simulationProgress);
1344 bool operator() (
const std::shared_ptr<ViewportNode>& one,
const std::shared_ptr<ViewportNode>& two)
const {
1345 return one->getViewportLoadOrdinal() < two->getViewportLoadOrdinal();
1395 std::set<std::shared_ptr<SceneNodeCore>, std::owner_less<std::shared_ptr<SceneNodeCore>>>
mDomainCameras {};
1435 class SceneSystem:
public System<SceneSystem, std::tuple<>, std::tuple<Placement, SceneHierarchyData, Transform>> {
1470 template<
typename TObject=std::shared_ptr<SceneNode>>
1471 TObject
getByPath(
const std::string& where);
1480 template <
typename TSceneNode>
1489 std::vector<std::shared_ptr<SceneNodeCore>>
getNodesByID(
const std::vector<UniversalEntityID>& universalEntityIDs);
1497 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
1505 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
1513 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
1558 void simulationStep(uint32_t simStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1571 void variableStep(
float simulationProgress, uint32_t simulationLagMillis, uint32_t variableStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1604 class PlacementUpdateReporter:
public System<PlacementUpdateReporter, std::tuple<Placement>, std::tuple<Transform, SceneHierarchyData>> {
1606 explicit PlacementUpdateReporter(std::weak_ptr<ECSWorld> world):
1609 static std::string
getSystemTypeName() {
return "SceneSystem::PlacementUpdateReporter"; }
1644 class TransformUpdateReporter:
public System<TransformUpdateReporter, std::tuple<Transform>, std::tuple<Placement, SceneHierarchyData>> {
1646 explicit TransformUpdateReporter(std::weak_ptr<ECSWorld> world):
1649 static std::string
getSystemTypeName() {
return "SceneSystem::TransformUpdateReporter"; }
1682 template <
typename TSceneNode,
typename Enable=
void>
1694 bool isActive(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1712 bool inScene(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1810 void nodeAdded(std::shared_ptr<SceneNodeCore> sceneNode);
1817 void nodeRemoved(std::shared_ptr<SceneNodeCore> sceneNode);
1875 std::map<UniversalEntityID, std::weak_ptr<SceneNodeCore>, std::less<UniversalEntityID>>
mEntityToNode {};
1901 template <
typename TSceneNode>
1902 template <
typename ...TComponents>
1904 std::shared_ptr<SceneNodeCore> newNode (
new TSceneNode(placement, name, components...), &
SceneNodeCore_del_);
1905 newNode->onCreated();
1906 return std::static_pointer_cast<TSceneNode>(newNode);
1909 template <
typename TSceneNode>
1910 template <
typename ...TComponents>
1912 std::shared_ptr<SceneNodeCore> newNode(
new TSceneNode(key, placement, name, components...), &
SceneNodeCore_del_);
1913 newNode->onCreated();
1914 return std::static_pointer_cast<TSceneNode>(newNode);
1917 template <
typename TSceneNode>
1919 std::shared_ptr<SceneNodeCore> newNode{
new TSceneNode{ sceneNodeDescription }, &
SceneNodeCore_del_};
1920 newNode->onCreated();
1921 return std::static_pointer_cast<TSceneNode>(newNode);
1924 template <
typename TSceneNode>
1927 newNode->onCreated();
1928 return std::static_pointer_cast<TSceneNode>(newNode);
1931 template<
typename ...TComponents>
1932 std::shared_ptr<SceneNode> SceneNode::create(
const Placement& placement,
const std::string& name, TComponents...components) {
1936 template <
typename TObject>
1938 return getByPath_Helper<TObject>::get(shared_from_this(), where);
1941 template <
typename TObject>
1943 return mRootNode->getByPath<TObject>(where);
1946 template <
typename TSceneNode>
1948 return getNodeByID_Helper<TSceneNode>::get(universalEntityID, *
this);
1953 template <
typename TObject,
typename Enable>
1954 inline TObject SceneNodeCore::getByPath_Helper<TObject, Enable>::get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1955 static_assert(
false &&
"No Object-by-Path method for this type exists");
1959 template <
typename TSceneNode,
typename Enable>
1960 inline std::shared_ptr<TSceneNode> SceneSystem::getNodeByID_Helper<TSceneNode, Enable>::get(
const UniversalEntityID& universalEntityID,
SceneSystem& sceneSystem) {
1961 static_assert(
false &&
"No scene node of this type exists");
1962 return std::shared_ptr<TSceneNode>{};
1965 template <
typename TSceneNode>
1968 return std::static_pointer_cast<TSceneNode>(sceneSystem.
getNodeByID(universalEntityID));
1972 template <
typename TObject>
1974 static std::shared_ptr<TObject> get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1975 return std::static_pointer_cast<TObject>(rootNode->getNode(where));
1977 static constexpr bool s_valid {
true };
1980 template <
typename ...TComponents>
1984 mEntity = std::make_shared<Entity>(
1989 .mModelMatrix { glm::mat4{1.f} },
2002 template <
typename ...TComponents>
2005 mEntity = std::make_shared<Entity>(
2010 .mModelMatrix { glm::mat4{1.f} },
2023 template <
typename TComponent>
2025 mEntity->addComponent<TComponent>(component);
2030 if(!bypassSceneActivityCheck &&
isActive()) {
2038 template <
typename TComponent>
2040 return mEntity->getComponent<TComponent>(simulationProgress);
2043 template <
typename TComponent>
2045 return mEntity->hasComponent<TComponent>();
2048 template <
typename TComponent>
2050 mEntity->updateComponent<TComponent>(component);
2053 template <
typename TComponent>
2062 template <
typename TComponent>
2064 mEntity->removeComponent<TComponent>();
2067 template <
typename TSystem>
2069 return mEntity->isEnabled<TSystem>();
2072 template <
typename TSystem>
2074 const SystemType systemType {
mEntity->getWorld().lock()->getSystemType<TSystem>() };
2096 mEntity->getWorld().lock()->getSystem<SceneSystem>()->nodeActivationChanged(
2105 assert(
false &&
"Cannot remove a scene node's Placement component");
2110 assert(
false &&
"Cannot remove a scene node's Transform component");
2113 template <
typename TSceneNode>
2120 {ViewportNode::RenderConfiguration::ResizeType::OFF,
"off"},
2121 {ViewportNode::RenderConfiguration::ResizeType::VIEWPORT_DIMENSIONS,
"viewport-dimensions"},
2122 {ViewportNode::RenderConfiguration::ResizeType::TEXTURE_DIMENSIONS,
"texture-dimensions"},
2127 {ViewportNode::RenderConfiguration::ResizeMode::FIXED_ASPECT,
"fixed-aspect"},
2128 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_VERTICALLY,
"expand-vertically"},
2129 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_HORIZONTALLY,
"expand-horizontally"},
2130 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_FILL,
"expand-fill"},
2135 {ViewportNode::RenderConfiguration::UpdateMode::NEVER,
"never"},
2136 {ViewportNode::RenderConfiguration::UpdateMode::ONCE,
"once"},
2137 {ViewportNode::RenderConfiguration::UpdateMode::ON_FETCH,
"on-fetch"},
2138 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER,
"on-render"},
2139 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER_CAP_FPS,
"on-render-cap-fps"},
2144 {ViewportNode::RenderConfiguration::RenderType::BASIC_3D,
"basic-3d"},
2145 {ViewportNode::RenderConfiguration::RenderType::ADDITION,
"addition"},
2151 {
"base_dimensions", nlohmann::json::array({renderConfiguration.mBaseDimensions.x, renderConfiguration.mBaseDimensions.y})},
2152 {
"update_mode", renderConfiguration.mUpdateMode},
2153 {
"resize_type", renderConfiguration.mResizeType},
2154 {
"resize_mode", renderConfiguration.mResizeMode},
2155 {
"render_scale", renderConfiguration.mRenderScale},
2156 {
"render_type", renderConfiguration.mRenderType},
2157 {
"fps_cap", renderConfiguration.mFPSCap},
2163 assert(json.find(
"base_dimensions") != json.end() &&
"Viewport descriptions must contain the \"base_dimensions\" size 2 array of Numbers attribute");
2164 json.at(
"base_dimensions")[0].get_to(renderConfiguration.mBaseDimensions.x);
2165 json.at(
"base_dimensions")[1].get_to(renderConfiguration.mBaseDimensions.y);
2166 json.at(
"render_type").get_to(renderConfiguration.mRenderType);
2167 renderConfiguration.mRequestedDimensions = renderConfiguration.mBaseDimensions;
2168 renderConfiguration.mComputedDimensions = renderConfiguration.mBaseDimensions;
2169 assert(renderConfiguration.mBaseDimensions.x > 0 && renderConfiguration.mBaseDimensions.y > 0 &&
"Base dimensions cannot include a 0 in either dimension");
2171 assert(json.find(
"update_mode") != json.end() &&
"Viewport render configuration must include the \"update_mode\" enum attribute");
2172 json.at(
"update_mode").get_to(renderConfiguration.mUpdateMode);
2174 assert(json.find(
"resize_type") != json.end() &&
"Viewport render configuration must include the \"resize_type\" enum attribute");
2175 json.at(
"resize_type").get_to(renderConfiguration.mResizeType);
2177 assert(json.find(
"resize_mode") != json.end() &&
"Viewport render configuration must include the \"resize_mode\" enum attribute");
2178 json.at(
"resize_mode").get_to(renderConfiguration.mResizeMode);
2180 assert(json.find(
"render_scale") != json.end() &&
"Viewport render configuration must include the \"render_scale\" float attribute");
2181 json.at(
"render_scale").get_to(renderConfiguration.mRenderScale);
2182 assert(renderConfiguration.mRenderScale > 0.f &&
"Render scale must be a positive non-zero decimal number");
2184 assert(json.find(
"fps_cap") != json.end() &&
"Viewport must include the \"fps_cap\" float attribute");
2185 json.at(
"fps_cap").get_to(renderConfiguration.mFPSCap);
2186 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:698
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:761
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:1925
BaseSceneNode(const SceneNodeCore &other)
Constructs a new node of a certain type as a copy of another node.
Definition scene_system.hpp:790
BaseSceneNode(const nlohmann::json &nodeDescription)
Constructs a new node of a certain type based on its json description.
Definition scene_system.hpp:783
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:1911
BaseSceneNode(const Placement &placement, const std::string &name, TComponents...components)
General constructor for a single node of a subclass.
Definition scene_system.hpp:774
A class that represents a set of systems, entities, and components, that are all interrelated,...
Definition ecs_world.hpp:1462
static Entity createEntityPrototype(TComponents...components)
Create a prototype entity object.
Definition ecs_world.hpp:2805
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:86
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:662
void addComponent(const TComponent &component, const bool bypassSceneActivityCheck=false)
Adds a component of type TComponent to the node.
Definition scene_system.hpp:2024
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:2114
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:636
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:1981
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:425
std::string mName
The name of this scene node.
Definition scene_system.hpp:622
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:668
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:2054
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:2049
std::shared_ptr< Entity > mEntity
The ECSWorld entity which this node is a wrapper over.
Definition scene_system.hpp:642
TComponent getComponent(const float simulationProgress=1.f) const
Retrieves a component belonging to this node.
Definition scene_system.hpp:2039
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:2044
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:630
Signature mSystemMask
A bitset, each position of which indicates whether a system should influence this node when it is par...
Definition scene_system.hpp:682
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:654
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:1937
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:674
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:2073
std::weak_ptr< SceneNodeCore > mParent
A reference to this node's parent scene node.
Definition scene_system.hpp:648
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:2063
StateFlags
Flags that indicate whether this node is enabled and active for the SceneSystem.
Definition scene_system.hpp:535
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:2068
The most basic vanilla flavour of scene node comprised of no more than a name and some components.
Definition scene_system.hpp:802
void onEntityUpdated(EntityID entityID, ComponentType updatedComponent) override
Notifies scene system that a placement component in its world has been updated.
Definition scene_system.cpp:1544
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:1629
std::set< EntityID > mReportedEntities
Entities whose placement updates this system has reported.
Definition scene_system.hpp:1616
The SceneSystem, a singleton System, responsible for tracking all objects in the scene,...
Definition scene_system.hpp:1435
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:1461
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:1132
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:1895
std::vector< std::weak_ptr< ECSWorld > > getActiveWorlds()
Returns the ECSWorlds owned by ViewportNodes active in the scene tree.
Definition scene_system.cpp:1164
std::weak_ptr< ECSWorld > getRootWorld() const
Gets the world associated with the root ViewportNode of the scene system.
Definition scene_system.cpp:1156
ViewportNode & getRootViewport() const
Gets a reference to the root viewport of the SceneSystem, usually used to adjust its rendering config...
Definition scene_system.cpp:1177
std::vector< std::shared_ptr< SceneNodeCore > > getNodesByID(const std::vector< UniversalEntityID > &universalEntityIDs)
Gets nodes by their world-entity ID pair.
Definition scene_system.cpp:1572
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:1881
void markDirtyPlacement(UniversalEntityID universalEntityID)
Marks a node as in need of a placement update based on its universal entity id.
Definition scene_system.cpp:1517
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:1108
void deactivateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Deactivates this node and its descendants.
Definition scene_system.cpp:1349
void activateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Activates this node and its descendants.
Definition scene_system.cpp:1333
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:1887
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:1012
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:1301
std::shared_ptr< TSceneNode > getNodeByID(const UniversalEntityID &universalEntityID)
Gets a scene node by its world-entity ID pair.
Definition scene_system.hpp:1947
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:1185
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:1530
std::shared_ptr< SceneNodeCore > removeNode(const std::string &where)
Removes a node present at the path specified in the call.
Definition scene_system.cpp:1151
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:1456
void onApplicationEnd()
Clean up tasks the SceneSystem should perform before the application is terminated.
Definition scene_system.cpp:1127
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:1067
static std::string getSystemTypeName()
The system type string associated with the SceneSystem.
Definition scene_system.hpp:1451
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:1262
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:1522
std::weak_ptr< ECSWorld > getWorld(WorldID world)
Returns a reference to the world with a particular ID.
Definition scene_system.cpp:1168
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:1226
void updateTransformsPlacements()
Updates transforms of objects in the scene per changes in those object's Placement component.
Definition scene_system.cpp:1365
SceneSystem(std::weak_ptr< ECSWorld > world)
Constructs a new SceneSystem object.
Definition scene_system.hpp:1442
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:1160
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:1317
void transformStep(uint32_t timestepMillis)
Updates transforms and placements as needed after a system update step.
Definition scene_system.cpp:1088
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:1526
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:1181
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:1462
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:1443
std::shared_ptr< SceneNodeCore > getNode(const std::string &where)
Gets a node by its scene node path.
Definition scene_system.cpp:1146
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:1942
void markDirtyTransform(UniversalEntityID universalEntityID)
Marks a node as in need of a transform update based on its universal entity id.
Definition scene_system.cpp:1511
void onApplicationStart()
Method to be called by main to initialize the SceneSystem as a whole.
Definition scene_system.cpp:1539
std::shared_ptr< ViewportNode > mRootNode
The root node of the SceneSystem, alive and active throughout the lifetime of the application.
Definition scene_system.hpp:1869
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:1875
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:1139
SignalTracker()
Constructs a new SignalTracker object.
A system template that disables systems with this form of declaration.
Definition ecs_world.hpp:1085
A type of node capable of and responsible for interacting sensibly with the engine's RenderSystem and...
Definition scene_system.hpp:843
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:1395
ActionDispatch & getActionDispatch()
Gets the action dispatch object for this viewport, which is the central location from which all actio...
Definition scene_system.cpp:971
bool mActionFlowthrough
Whether or not handled actions are propagated to this viewport's descendant viewports.
Definition scene_system.hpp:1371
void unregisterDomainCamera(std::shared_ptr< SceneNodeCore > cameraNode)
Removes a camera from this viewport's domain.
Definition scene_system.cpp:779
std::shared_ptr< Texture > fetchRenderResult(float simulationProgress)
Fetches the render result for the most recently computed render frame.
Definition scene_system.cpp:819
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:1353
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:1359
std::shared_ptr< ViewportNode > getLocalViewport() override
Returns this viewport instead of base class return value.
Definition scene_system.cpp:975
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:1383
uint32_t render(float simulationProgress, uint32_t variableStep)
Requests execution of the render pipeline.
Definition scene_system.cpp:852
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:931
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:763
RenderConfiguration mRenderConfiguration
The render configuration associated with this viewport.
Definition scene_system.hpp:1415
bool disallowsHandledActionPropagation() const
Returns whether an action handled by one of this viewport's (high precedence) child viewports,...
Definition scene_system.hpp:1165
~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:989
uint32_t getViewportLoadOrdinal() const
(When this viewport is the immediate descendant of a RenderSet::RenderType::ADDITION viewport) The pr...
Definition scene_system.hpp:1180
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:1377
RenderSetID mRenderSet
The ID of the RenderSet registered with this viewport's RenderSystem corresponding to this ViewportNo...
Definition scene_system.hpp:1401
std::shared_ptr< SceneNodeCore > mActiveCamera
The active camera node associated with this viewport.
Definition scene_system.hpp:1389
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:1332
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:774
std::vector< std::shared_ptr< ViewportNode > > getActiveDescendantViewports()
Gets active descendant viewports (in DFS order) under this Viewport.
Definition scene_system.cpp:983
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:997
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:746
void resizeDomainCameras(const glm::vec2 &computedDimensions)
Readjusts all viewport cameras to match the size of the viewport.
Definition scene_system.cpp:785
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:1211
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:752
std::shared_ptr< Texture > mTextureResult
The result of rendering from running the rendering pipeline associated with this viewport.
Definition scene_system.hpp:1409
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
Signal< RenderConfiguration > mRenderConfigurationUpdated
Signal emitted whenever this viewport's render configuration is updated.
Definition scene_system.hpp:1186
ViewportNode(const Key &key, const Placement &placement, const std::string &name)
Constructs a new ViewportNode using a simplified constructor.
Definition scene_system.hpp:1252
ActionDispatch mActionDispatch
Dispatcher for received actions to their action handlers within the domain of this viewport.
Definition scene_system.hpp:1365
void render_(float simulationProgress)
Implementation responsible for actually computing a new render frame.
Definition scene_system.cpp:893
void setRenderScale(float renderScale)
Sets the scale relative to computed and design dimensions for the render pipeline target.
Definition scene_system.cpp:768
uint32_t mTimeSinceLastRender
The time, in milliseconds, since the last time a render request was honoured by this viewport.
Definition scene_system.hpp:1421
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:758
ToyMaker Engine's implementation of an ECS system.
ECSType ComponentType
An unsigned integer representing the type of a component.
Definition ecs_world.hpp:101
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:152
ECSType SystemType
An unsigned integer representing the type of a system.
Definition ecs_world.hpp:110
constexpr EntityID kMaxEntities
A user-set constant which limits the number of creatable entities in a single ECS system.
Definition ecs_world.hpp:117
std::pair< WorldID, EntityID > UniversalEntityID
An ID that uniquely identifies an entity.
Definition ecs_world.hpp:83
std::uint64_t EntityID
A single unsigned integer used as a name for an entity managed by an ECS system.
Definition ecs_world.hpp:66
std::uint64_t WorldID
An unsigned integer representing the name of an ECS world.
Definition ecs_world.hpp:74
SpecialEntity
(Perhaps unused) Special "reserved" entity IDs which the scene system might use.
Definition scene_system.hpp:70
RelativeTo
(Presently unused) A marker to indicate how transforms should be computed for a given scene node.
Definition scene_system.hpp:53
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:26
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 relating to this engine's implementation of signals. Contains template classes used to define...
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:518
A helper intended to get scene nodes and related objects attached to the scene tree.
Definition scene_system.hpp:547
Helper struct for retrieving nodes based on their UniversalEntityIDs.
Definition scene_system.hpp:1683
A collection of data that specifies the behaviour and properties of the RenderSystem and target textu...
Definition scene_system.hpp:849
glm::u16vec2 mComputedDimensions
The dimensions finally computed for this viewport, per request from other parts of the application.
Definition scene_system.hpp:917
RenderSet::RenderType RenderType
Specifies the type of render pipeline requested by this viewport.
Definition scene_system.hpp:888
ResizeType
Different resize configurations available for this Viewport node that dictate how render textures (fr...
Definition scene_system.hpp:854
glm::u16vec2 mRequestedDimensions
The dimensions requested by other parts of the application, to which this viewport's render texture m...
Definition scene_system.hpp:923
ResizeMode
Determines which dimensions the end result of the viewport is allowed to expand on.
Definition scene_system.hpp:864
UpdateMode mUpdateMode
The frequency of rendering updates in real time made on this viewport.
Definition scene_system.hpp:941
ResizeMode mResizeMode
The resizing/scaling behaviour from render-> target texture for this viewport.
Definition scene_system.hpp:899
RenderType mRenderType
The type of render pipelien requested by this viewport.
Definition scene_system.hpp:905
glm::u16vec2 mBaseDimensions
The design dimensions for this viewport, specified at the time of its development.
Definition scene_system.hpp:911
float mFPSCap
If an FPS capped update mode is used, specifies the value of that cap.
Definition scene_system.hpp:948
ResizeType mResizeType
The type of resizing/scaling behaviour from render->target texture for this viewport.
Definition scene_system.hpp:894
float mRenderScale
A multiplier applied (in case resizing is enabled) determining multiplier to the base or computed dim...
Definition scene_system.hpp:935
UpdateMode
Configuration value determining when and how often render updates take place for this viewport.
Definition scene_system.hpp:875
Comparator used for determining priority of descendant viewports owned by a RenderSet::RenderType::AD...
Definition scene_system.hpp:1343
Header containing definitions of classes and functions related to loading and using Texture resources...