17#ifndef FOOLSENGINE_SCENESYSTEM_H
18#define FOOLSENGINE_SCENESYSTEM_H
22#include <unordered_map>
28#include <glm/gtc/quaternion.hpp>
62 {RelativeTo::PARENT,
"parent"},
87 class SceneNodeCore:
public std::enable_shared_from_this<SceneNodeCore> {
113 template <
typename TComponent>
114 void addComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
122 void addComponent(
const nlohmann::json& jsonComponent,
const bool bypassSceneActivityCheck=
false);
132 template <
typename TComponent>
133 TComponent
getComponent(
const float simulationProgress=1.f)
const;
142 template <
typename TComponent>
160 template <
typename TComponent>
177 template <
typename TComponent>
178 void addOrUpdateComponent(
const TComponent& component,
const bool bypassSceneActivityCheck=
false);
186 void addOrUpdateComponent(
const nlohmann::json& component,
const bool bypassSceneActivityCheck=
false);
193 template <
typename TComponent>
204 template <
typename TSystem>
214 template <
typename TSystem>
243 std::weak_ptr<ECSWorld>
getWorld()
const;
274 bool isAncestorOf(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
284 bool hasNode(
const std::string& pathToChild)
const;
292 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
299 std::vector<std::shared_ptr<SceneNodeCore>>
getChildren();
306 std::vector<std::shared_ptr<const SceneNodeCore>>
getChildren()
const;
322 template <
typename TObject=std::shared_ptr<SceneNode>>
323 TObject
getByPath(
const std::string& where);
332 template <
typename TSceneNode=SceneNode>
363 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
385 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
406 void setName(
const std::string& name);
444 static std::shared_ptr<SceneNodeCore>
copy(
const std::shared_ptr<const SceneNodeCore> other);
454 template<
typename ...TComponents>
529 template<
typename ...TComponents>
547 template <
typename TObject,
typename Enable=
void>
549 static TObject get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where);
550 static constexpr bool s_valid {
false };
558 virtual std::shared_ptr<SceneNodeCore>
clone()
const;
576 static void setParentViewport(std::shared_ptr<SceneNodeCore> node, std::shared_ptr<ViewportNode> newViewport);
584 static std::shared_ptr<SceneNodeCore>
disconnectNode(std::shared_ptr<SceneNodeCore> node);
593 static bool detectCycle(std::shared_ptr<SceneNodeCore> node);
604 static std::tuple<std::string, std::string>
nextInPath(
const std::string& where);
669 std::vector<std::shared_ptr<SceneNodeCore>>
mChildren {};
686 template<
typename TSceneNode>
698 template <
typename TSceneNode>
714 template <
typename ...TComponents>
715 static std::shared_ptr<TSceneNode>
create(
const Key&,
const Placement& placement,
const std::string& name, TComponents...components);
728 template <
typename ...TComponents>
729 static std::shared_ptr<TSceneNode>
create(
const Placement& placement,
const std::string& name, TComponents...components);
739 static std::shared_ptr<TSceneNode>
create(
const nlohmann::json& sceneNodeDescription);
751 static std::shared_ptr<TSceneNode>
copy(
const std::shared_ptr<const TSceneNode> sceneNode);
752 template <
typename...TComponents>
763 SceneNodeCore{ key, placement, name, components... }
774 template<
typename ...TComponents>
776 SceneNodeCore{ placement, name, components... }
784 BaseSceneNode(
const nlohmann::json& nodeDescription) : SceneNodeCore { nodeDescription } {}
805 template <
typename ...TComponents>
806 static std::shared_ptr<SceneNode> create(
const Placement& placement,
const std::string& name, TComponents...components);
807 static std::shared_ptr<SceneNode> create(
const nlohmann::json& sceneNodeDescription);
808 static std::shared_ptr<SceneNode> copy(
const std::shared_ptr<const SceneNode> other);
810 static inline std::string getResourceTypeName() {
return "SceneNode"; }
813 template<
typename ...TComponents>
814 SceneNode(
const Placement& placement,
const std::string& name, TComponents...components):
819 SceneNode(
const nlohmann::json& jsonSceneNode):
824 SceneNode(
const SceneNode& sceneObject):
962 static std::shared_ptr<ViewportNode>
create(
const std::string& name,
bool inheritsWorld,
bool allowActionFlowThrough,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
975 static std::shared_ptr<ViewportNode>
create(
const nlohmann::json& sceneNodeDescription);
983 static std::shared_ptr<ViewportNode>
copy(
const std::shared_ptr<const ViewportNode> other);
1044 virtual std::shared_ptr<const ViewportNode>
getLocalViewport()
const override;
1091 void setSkybox(std::shared_ptr<Texture> skybox);
1151 bool handleAction(std::pair<ActionDefinition, ActionData> pendingAction);
1179 Resource<ViewportNode>{0},
1182 ViewportNode(
const nlohmann::json& jsonSceneNode):
1183 BaseSceneNode<ViewportNode>{jsonSceneNode},
1187 ViewportNode(
const ViewportNode& sceneObject):
1188 BaseSceneNode<ViewportNode>{sceneObject},
1229 static std::shared_ptr<ViewportNode>
create(
const Key& key,
const std::string& name,
bool inheritsWorld,
const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
1248 std::shared_ptr<SceneNodeCore>
clone()
const override;
1269 std::shared_ptr<SceneNodeCore> findFallbackCamera();
1294 uint32_t
render(
float simulationProgress, uint32_t variableStep);
1302 void render_(
float simulationProgress);
1322 bool operator() (
const std::shared_ptr<ViewportNode>& one,
const std::shared_ptr<ViewportNode>& two)
const {
1323 return one->getViewportLoadOrdinal() < two->getViewportLoadOrdinal();
1373 std::set<std::shared_ptr<SceneNodeCore>, std::owner_less<std::shared_ptr<SceneNodeCore>>>
mDomainCameras {};
1413 class SceneSystem:
public System<SceneSystem, std::tuple<>, std::tuple<Placement, SceneHierarchyData, Transform>> {
1448 template<
typename TObject=std::shared_ptr<SceneNode>>
1449 TObject
getByPath(
const std::string& where);
1458 template <
typename TSceneNode>
1467 std::vector<std::shared_ptr<SceneNodeCore>>
getNodesByID(
const std::vector<UniversalEntityID>& universalEntityIDs);
1475 std::shared_ptr<SceneNodeCore>
getNode(
const std::string& where);
1483 std::shared_ptr<SceneNodeCore>
removeNode(
const std::string& where);
1491 void addNode(std::shared_ptr<SceneNodeCore> node,
const std::string& where);
1533 void simulationStep(uint32_t simStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1545 void variableStep(
float simulationProgress, uint32_t simulationLagMillis, uint32_t variableStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1572 class SceneSubworld:
public System<SceneSubworld, std::tuple<Placement>, std::tuple<Transform, SceneHierarchyData>> {
1574 explicit SceneSubworld(std::weak_ptr<ECSWorld> world):
1577 static std::string getSystemTypeName() {
return "SceneSubworld"; }
1579 void onEntityUpdated(
EntityID entityID)
override;
1590 template <
typename TSceneNode,
typename Enable=
void>
1602 bool isActive(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1620 bool inScene(std::shared_ptr<const SceneNodeCore> sceneNode)
const;
1687 void nodeAdded(std::shared_ptr<SceneNodeCore> sceneNode);
1694 void nodeRemoved(std::shared_ptr<SceneNodeCore> sceneNode);
1743 std::map<UniversalEntityID, std::weak_ptr<SceneNodeCore>, std::less<UniversalEntityID>>
mEntityToNode {};
1761 template <
typename TSceneNode>
1762 template <
typename ...TComponents>
1764 std::shared_ptr<SceneNodeCore> newNode (
new TSceneNode(placement, name, components...), &
SceneNodeCore_del_);
1765 newNode->onCreated();
1766 return std::static_pointer_cast<TSceneNode>(newNode);
1769 template <
typename TSceneNode>
1770 template <
typename ...TComponents>
1772 std::shared_ptr<SceneNodeCore> newNode(
new TSceneNode(key, placement, name, components...), &
SceneNodeCore_del_);
1773 newNode->onCreated();
1774 return std::static_pointer_cast<TSceneNode>(newNode);
1777 template <
typename TSceneNode>
1779 std::shared_ptr<SceneNodeCore> newNode{
new TSceneNode{ sceneNodeDescription }, &
SceneNodeCore_del_};
1780 newNode->onCreated();
1781 return std::static_pointer_cast<TSceneNode>(newNode);
1784 template <
typename TSceneNode>
1787 newNode->onCreated();
1788 return std::static_pointer_cast<TSceneNode>(newNode);
1791 template<
typename ...TComponents>
1792 std::shared_ptr<SceneNode> SceneNode::create(
const Placement& placement,
const std::string& name, TComponents...components) {
1796 template <
typename TObject>
1798 return getByPath_Helper<TObject>::get(shared_from_this(), where);
1801 template <
typename TObject>
1803 return mRootNode->getByPath<TObject>(where);
1806 template <
typename TSceneNode>
1813 template <
typename TObject,
typename Enable>
1814 TObject SceneNodeCore::getByPath_Helper<TObject, Enable>::get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1815 static_assert(
false &&
"No Object-by-Path method for this type exists");
1819 template <
typename TSceneNode,
typename Enable>
1820 std::shared_ptr<TSceneNode> SceneSystem::getNodeByID_Helper<TSceneNode, Enable>::get(
const UniversalEntityID& universalEntityID,
SceneSystem& sceneSystem) {
1821 static_assert(
false &&
"No scene node of this type exists");
1822 return std::shared_ptr<TSceneNode>{};
1825 template <
typename TSceneNode>
1828 return std::static_pointer_cast<TSceneNode>(sceneSystem.
getNodeByID(universalEntityID));
1832 template <
typename TObject>
1834 static std::shared_ptr<TObject> get(std::shared_ptr<SceneNodeCore> rootNode,
const std::string& where) {
1835 return std::static_pointer_cast<TObject>(rootNode->getNode(where));
1837 static constexpr bool s_valid {
true };
1840 template <
typename ...TComponents>
1844 mEntity = std::make_shared<Entity>(
1856 template <
typename ...TComponents>
1859 mEntity = std::make_shared<Entity>(
1871 template <
typename TComponent>
1873 mEntity->addComponent<TComponent>(component);
1878 if(!bypassSceneActivityCheck &&
isActive()) {
1886 template <
typename TComponent>
1888 return mEntity->getComponent<TComponent>(simulationProgress);
1891 template <
typename TComponent>
1893 return mEntity->hasComponent<TComponent>();
1896 template <
typename TComponent>
1898 mEntity->updateComponent<TComponent>(component);
1901 template <
typename TComponent>
1910 template <
typename TComponent>
1912 mEntity->removeComponent<TComponent>();
1915 template <
typename TSystem>
1917 return mEntity->isEnabled<TSystem>();
1920 template <
typename TSystem>
1922 const SystemType systemType {
mEntity->getWorld().lock()->getSystemType<TSystem>() };
1944 mEntity->getWorld().lock()->getSystem<SceneSystem>()->nodeActivationChanged(
1953 assert(
false &&
"Cannot remove a scene node's Placement component");
1957 assert(
false &&
"Cannot remove a scene node's Transform component");
1960 template <
typename TSceneNode>
1967 {ViewportNode::RenderConfiguration::ResizeType::OFF,
"off"},
1968 {ViewportNode::RenderConfiguration::ResizeType::VIEWPORT_DIMENSIONS,
"viewport-dimensions"},
1969 {ViewportNode::RenderConfiguration::ResizeType::TEXTURE_DIMENSIONS,
"texture-dimensions"},
1974 {ViewportNode::RenderConfiguration::ResizeMode::FIXED_ASPECT,
"fixed-aspect"},
1975 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_VERTICALLY,
"expand-vertically"},
1976 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_HORIZONTALLY,
"expand-horizontally"},
1977 {ViewportNode::RenderConfiguration::ResizeMode::EXPAND_FILL,
"expand-fill"},
1982 {ViewportNode::RenderConfiguration::UpdateMode::NEVER,
"never"},
1983 {ViewportNode::RenderConfiguration::UpdateMode::ONCE,
"once"},
1984 {ViewportNode::RenderConfiguration::UpdateMode::ON_FETCH,
"on-fetch"},
1985 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER,
"on-render"},
1986 {ViewportNode::RenderConfiguration::UpdateMode::ON_RENDER_CAP_FPS,
"on-render-cap-fps"},
1991 {ViewportNode::RenderConfiguration::RenderType::BASIC_3D,
"basic-3d"},
1992 {ViewportNode::RenderConfiguration::RenderType::ADDITION,
"addition"},
1998 {
"base_dimensions", nlohmann::json::array({renderConfiguration.mBaseDimensions.x, renderConfiguration.mBaseDimensions.y})},
1999 {
"update_mode", renderConfiguration.mUpdateMode},
2000 {
"resize_type", renderConfiguration.mResizeType},
2001 {
"resize_mode", renderConfiguration.mResizeMode},
2002 {
"render_scale", renderConfiguration.mRenderScale},
2003 {
"render_type", renderConfiguration.mRenderType},
2004 {
"fps_cap", renderConfiguration.mFPSCap},
2010 assert(json.find(
"base_dimensions") != json.end() &&
"Viewport descriptions must contain the \"base_dimensions\" size 2 array of Numbers attribute");
2011 json.at(
"base_dimensions")[0].get_to(renderConfiguration.mBaseDimensions.x);
2012 json.at(
"base_dimensions")[1].get_to(renderConfiguration.mBaseDimensions.y);
2013 json.at(
"render_type").get_to(renderConfiguration.mRenderType);
2014 renderConfiguration.mRequestedDimensions = renderConfiguration.mBaseDimensions;
2015 renderConfiguration.mComputedDimensions = renderConfiguration.mBaseDimensions;
2016 assert(renderConfiguration.mBaseDimensions.x > 0 && renderConfiguration.mBaseDimensions.y > 0 &&
"Base dimensions cannot include a 0 in either dimension");
2018 assert(json.find(
"update_mode") != json.end() &&
"Viewport render configuration must include the \"update_mode\" enum attribute");
2019 json.at(
"update_mode").get_to(renderConfiguration.mUpdateMode);
2021 assert(json.find(
"resize_type") != json.end() &&
"Viewport render configuration must include the \"resize_type\" enum attribute");
2022 json.at(
"resize_type").get_to(renderConfiguration.mResizeType);
2024 assert(json.find(
"resize_mode") != json.end() &&
"Viewport render configuration must include the \"resize_mode\" enum attribute");
2025 json.at(
"resize_mode").get_to(renderConfiguration.mResizeMode);
2027 assert(json.find(
"render_scale") != json.end() &&
"Viewport render configuration must include the \"render_scale\" float attribute");
2028 json.at(
"render_scale").get_to(renderConfiguration.mRenderScale);
2029 assert(renderConfiguration.mRenderScale > 0.f &&
"Render scale must be a positive non-zero decimal number");
2031 assert(json.find(
"fps_cap") != json.end() &&
"Viewport must include the \"fps_cap\" float attribute");
2032 json.at(
"fps_cap").get_to(renderConfiguration.mFPSCap);
2033 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 spatial_query_math.hpp:317
A CRTP template for all the scene node types present in the project.
Definition scene_system.hpp:699
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:762
static std::shared_ptr< TSceneNode > create(const nlohmann::json &sceneNodeDescription)
Creates a scene node of a type based on its description in JSON.
Definition scene_system.hpp:1778
static std::shared_ptr< TSceneNode > create(const Placement &placement, const std::string &name, TComponents...components)
A method for creating a scene node of a specific type (TSceneNode)
Definition scene_system.hpp:1763
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:1785
BaseSceneNode(const SceneNodeCore &other)
Constructs a new node of a certain type as a copy of another node.
Definition scene_system.hpp:791
BaseSceneNode(const nlohmann::json &nodeDescription)
Constructs a new node of a certain type based on its json description.
Definition scene_system.hpp:784
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:1771
BaseSceneNode(const Placement &placement, const std::string &name, TComponents...components)
General constructor for a single node of a subclass.
Definition scene_system.hpp:775
A class that represents a set of systems, entities, and components, that are all interrelated,...
Definition ecs_world.hpp:1439
static Entity createEntityPrototype(TComponents...components)
Create a prototype entity object.
Definition ecs_world.hpp:2767
The base class for any type whose creation and storage should be managed by the ResourceDatabase.
Definition resource_database.hpp:372
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:389
The core of a node in the SceneSystem, a set of components and methods overridable or usable by all t...
Definition scene_system.hpp:87
virtual void onCreated()
Copy assignment operator.
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:341
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:663
void addComponent(const TComponent &component, const bool bypassSceneActivityCheck=false)
Adds a component of type TComponent to the node.
Definition scene_system.hpp:1872
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:1961
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:162
RelativeTo mRelativeTo
A marker indicating how this node's transform component should be computed.
Definition scene_system.hpp:637
std::weak_ptr< ECSWorld > getWorld() const
Gets a reference to the ECSWorld this node belongs to.
Definition scene_system.cpp:398
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:304
SceneNodeCore(const Placement &placement, const std::string &name, TComponents...components)
Constructs a scene node object from essential and extra components.
Definition scene_system.hpp:1841
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:325
void recomputeChildNameIndexMapping()
Utility function for updating SceneHierarchyData components belonging to a single ECSWorld in the Sce...
Definition scene_system.cpp:75
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:426
std::string mName
The name of this scene node.
Definition scene_system.hpp:623
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:376
std::vector< std::shared_ptr< SceneNodeCore > > getChildren()
Returns a list of all of this node's immediate children scene nodes.
Definition scene_system.cpp:241
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:185
std::vector< std::shared_ptr< SceneNodeCore > > mChildren
A list of this node's child nodes.
Definition scene_system.hpp:669
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:401
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:266
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:252
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:1902
std::string getName() const
Returns the name string for this node.
Definition scene_system.cpp:177
std::string getViewportLocalPath() const
Gets the path of this node relative to its local viewport node.
Definition scene_system.cpp:181
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:416
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:158
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:98
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:1897
std::shared_ptr< Entity > mEntity
The ECSWorld entity which this node is a wrapper over.
Definition scene_system.hpp:643
TComponent getComponent(const float simulationProgress=1.f) const
Retrieves a component belonging to this node.
Definition scene_system.hpp:1887
std::shared_ptr< SceneNodeCore > getParentNode()
Gets the parent node of this node, if one is present.
Definition scene_system.cpp:311
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:82
bool hasComponent() const
Tests whether this node has a component of a specific type.
Definition scene_system.hpp:1892
std::vector< std::shared_ptr< SceneNodeCore > > getDescendants()
Gets all of the descendant nodes belonging to this scene node.
Definition scene_system.cpp:366
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:218
uint8_t mStateFlags
Flags indicating the state of this scene node in the scene system.
Definition scene_system.hpp:631
Signature mSystemMask
A bitset, each position of which indicates whether a system should influence this node when it is par...
Definition scene_system.hpp:683
void setName(const std::string &name)
Sets the name of this node.
Definition scene_system.cpp:172
std::vector< std::shared_ptr< SceneNodeCore > > removeChildren()
Disconnects and removes all the child nodes attached to this node.
Definition scene_system.cpp:356
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:655
UniversalEntityID getUniversalEntityID() const
Gets the UniversalEntityID aka the world-entity-id pair associated with this node.
Definition scene_system.cpp:395
TObject getByPath(const std::string &where)
Gets a reference to a node or related object by its path.
Definition scene_system.hpp:1797
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:675
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:201
void setEnabled(bool state)
Sets whether or not a given system should be able to influence this scene object.
Definition scene_system.hpp:1921
std::weak_ptr< SceneNodeCore > mParent
A reference to this node's parent scene node.
Definition scene_system.hpp:649
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:389
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:140
WorldID getWorldID() const
Returns the ID of the ECSWorld this node belongs to.
Definition scene_system.cpp:392
void removeComponent()
Removes a component present on this node.
Definition scene_system.hpp:1911
StateFlags
Flags that indicate whether this node is enabled and active for the SceneSystem.
Definition scene_system.hpp:536
bool inScene() const
Returns whether this node is present as part of the SceneSystem's scene tree.
Definition scene_system.cpp:154
bool getEnabled() const
Returns whether a particular system has been enabled for this node.
Definition scene_system.hpp:1916
The most basic vanilla flavour of scene node comprised of no more than a name and some components.
Definition scene_system.hpp:803
The SceneSystem, a singleton System, responsible for tracking all objects in the scene,...
Definition scene_system.hpp:1413
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:1439
void markDirty(UniversalEntityID UniversalEntityID)
Marks a node as in need of a transform update based on its universal entity id.
Definition scene_system.cpp:1373
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:1096
std::vector< std::weak_ptr< ECSWorld > > getActiveWorlds()
Returns the ECSWorlds owned by ViewportNodes active in the scene tree.
Definition scene_system.cpp:1127
std::weak_ptr< ECSWorld > getRootWorld() const
Gets the world associated with the root ViewportNode of the scene system.
Definition scene_system.cpp:1120
ViewportNode & getRootViewport() const
Gets a reference to the root viewport of the SceneSystem, usually used to adjust its rendering config...
Definition scene_system.cpp:1131
std::vector< std::shared_ptr< SceneNodeCore > > getNodesByID(const std::vector< UniversalEntityID > &universalEntityIDs)
Gets nodes by their world-entity ID pair.
Definition scene_system.cpp:1406
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:1749
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:1072
void deactivateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Deactivates this node and its descendants.
Definition scene_system.cpp:1300
void activateSubtree(std::shared_ptr< SceneNodeCore > sceneNode)
Activates this node and its descendants.
Definition scene_system.cpp:1287
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:1755
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:977
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:1255
std::shared_ptr< TSceneNode > getNodeByID(const UniversalEntityID &universalEntityID)
Gets a scene node by its world-entity ID pair.
Definition scene_system.hpp:1807
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:1139
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:1382
std::shared_ptr< SceneNodeCore > removeNode(const std::string &where)
Removes a node present at the path specified in the call.
Definition scene_system.cpp:1115
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:1367
void onApplicationEnd()
Clean up tasks the SceneSystem should perform before the application is terminated.
Definition scene_system.cpp:1091
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:1032
static std::string getSystemTypeName()
The system type string associated with the SceneSystem.
Definition scene_system.hpp:1429
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:1216
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:1180
SceneSystem(std::weak_ptr< ECSWorld > world)
Constructs a new SceneSystem object.
Definition scene_system.hpp:1420
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:1124
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:1271
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:1135
void updateTransforms()
Updates transforms of objects in the scene per changes in those object's Placement component.
Definition scene_system.cpp:1315
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:1354
std::shared_ptr< SceneNodeCore > getNode(const std::string &where)
Gets a node by its scene node path.
Definition scene_system.cpp:1110
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:1802
void onApplicationStart()
Method to be called by main to initialize the SceneSystem as a whole.
Definition scene_system.cpp:1391
void onWorldEntityUpdate(UniversalEntityID UniversalEntityID)
A callback used by this system's subsystem to notify the SceneSystem that an entity has been updated.
Definition scene_system.cpp:1378
std::shared_ptr< ViewportNode > mRootNode
The root node of the SceneSystem, alive and active throughout the lifetime of the application.
Definition scene_system.hpp:1737
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:1743
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:1103
A system template that disables systems with this form of declaration.
Definition ecs_world.hpp:1062
A type of node capable of and responsible for interacting sensibly with the engine's RenderSystem and...
Definition scene_system.hpp:844
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:1373
ActionDispatch & getActionDispatch()
Gets the action dispatch object for this viewport, which is the central location from which all actio...
Definition scene_system.cpp:936
bool mActionFlowthrough
Whether or not handled actions are propagated to this viewport's descendant viewports.
Definition scene_system.hpp:1349
void unregisterDomainCamera(std::shared_ptr< SceneNodeCore > cameraNode)
Removes a camera from this viewport's domain.
Definition scene_system.cpp:764
std::shared_ptr< Texture > fetchRenderResult(float simulationProgress)
Fetches the render result for the most recently computed render frame.
Definition scene_system.cpp:784
void requestDimensions(glm::u16vec2 requestedDimensions)
Target dimensions that another part of the program specifies for this viewport.
Definition scene_system.cpp:631
void updateExposure(float newExposure)
Updates the exposure of this viewport's RenderSet.
Definition scene_system.cpp:587
uint32_t mViewportLoadOrdinal
Number dictating when this viewport should be computed relative to other viewports,...
Definition scene_system.hpp:1331
void createAndJoinWorld()
Creates and joins its own ECSWorld.
Definition scene_system.cpp:550
uint32_t mNLifetimeChildrenAdded
A number that is incremented whenever a child viewport is added to this viewport, guaranteeing unique...
Definition scene_system.hpp:1337
std::shared_ptr< ViewportNode > getLocalViewport() override
Returns this viewport instead of base class return value.
Definition scene_system.cpp:940
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:521
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:1361
uint32_t render(float simulationProgress, uint32_t variableStep)
Requests execution of the render pipeline.
Definition scene_system.cpp:817
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:896
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:404
void setFPSCap(float fpsCap)
If an FPS capped update mode is selected, sets what that cap actually is.
Definition scene_system.cpp:748
RenderConfiguration mRenderConfiguration
The render configuration associated with this viewport.
Definition scene_system.hpp:1393
bool disallowsHandledActionPropagation() const
Returns whether an action handled by one of this viewport's (high precedence) child viewports,...
Definition scene_system.hpp:1159
~ViewportNode() override
Destroys this viewport object.
Definition scene_system.cpp:428
static std::string getResourceTypeName()
Gets the resource type string associated with the ViewportNode.
Definition scene_system.hpp:990
uint32_t getViewportLoadOrdinal() const
(When this viewport is the immediate descendant of a RenderSet::RenderType::ADDITION viewport) The pr...
Definition scene_system.hpp:1174
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:610
void setRenderConfiguration(const RenderConfiguration &renderConfiguration)
Sets the render configuration for this viewport.
Definition scene_system.cpp:540
bool mPreventHandledActionPropagation
When a child viewport handles an action, determines whether the action is sent along to this viewport...
Definition scene_system.hpp:1355
RenderSetID mRenderSet
The ID of the RenderSet registered with this viewport's RenderSystem corresponding to this ViewportNo...
Definition scene_system.hpp:1379
std::shared_ptr< SceneNodeCore > mActiveCamera
The active camera node associated with this viewport.
Definition scene_system.hpp:1367
float getGamma()
Gets the gamma value used by this viewport's RenderSet.
Definition scene_system.cpp:604
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:1310
void viewNextDebugTexture()
Sets the next debug texture listed in this viewport's render set to the texture considered "active" b...
Definition scene_system.cpp:582
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:759
std::vector< std::shared_ptr< ViewportNode > > getActiveDescendantViewports()
Gets active descendant viewports (in DFS order) under this Viewport.
Definition scene_system.cpp:948
void setSkybox(std::shared_ptr< Texture > skybox)
Sets the skybox texture for this object's RenderSystem.
Definition scene_system.cpp:578
std::vector< std::weak_ptr< ECSWorld > > getActiveDescendantWorlds()
Gets weak references to ECSWorlds belonging to descendant viewports.
Definition scene_system.cpp:962
float getExposure()
Gets the exposure value used by this viewport's RenderSet.
Definition scene_system.cpp:598
void onDeactivated() override
Deactivates this viewports ECSWorld (if there is one) when this ViewportNode is retired.
Definition scene_system.cpp:574
void setResizeType(RenderConfiguration::ResizeType type)
Sets this viewport's behaviour when request dimensions (or target dimensions) are changed.
Definition scene_system.cpp:731
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:1197
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:460
void setResizeMode(RenderConfiguration::ResizeMode mode)
When resize is enabled, determines how resized render dimensions are computed.
Definition scene_system.cpp:737
std::shared_ptr< Texture > mTextureResult
The result of rendering from running the rendering pipeline associated with this viewport.
Definition scene_system.hpp:1387
void updateGamma(float newGamma)
Updates the gamma value of this viewport's RenderSet.
Definition scene_system.cpp:592
RenderConfiguration getRenderConfiguration() const
Gets the render configuration for this viewport.
Definition scene_system.cpp:546
void onActivated() override
Override which for a viewport sets its active camera, and initializes the ECSWorld owned by this view...
Definition scene_system.cpp:556
ViewportNode(const Key &key, const Placement &placement, const std::string &name)
Constructs a new ViewportNode using a simplified constructor.
Definition scene_system.hpp:1238
ActionDispatch mActionDispatch
Dispatcher for received actions to their action handlers within the domain of this viewport.
Definition scene_system.hpp:1343
void render_(float simulationProgress)
Implementation responsible for actually computing a new render frame.
Definition scene_system.cpp:858
void setRenderScale(float renderScale)
Sets the scale relative to computed and design dimensions for the render pipeline target.
Definition scene_system.cpp:753
uint32_t mTimeSinceLastRender
The time, in milliseconds, since the last time a render request was honoured by this viewport.
Definition scene_system.hpp:1399
std::shared_ptr< SceneNodeCore > clone() const override
Creates a new ViewportNode using itself as a template.
Definition scene_system.cpp:526
void setUpdateMode(RenderConfiguration::UpdateMode updateMode)
Sets the behaviour for frequency of render updates w.r.t render requests.
Definition scene_system.cpp:743
ToyMaker Engine's implementation of an ECS system.
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:71
RelativeTo
(Presently unused) A marker to indicate how transforms should be computed for a given scene node.
Definition scene_system.hpp:54
const std::string kSceneRootName
Special name for the scene root, unusable by any other scene object.
Definition scene_system.cpp:13
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
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.
Geometrical, mathematical functions and related structs used to answer some simple questions about sh...
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition spatial_query_math.hpp:130
A component representing the position, rotation, and scale of an entity.
Definition scene_components.hpp:30
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:118
A private struct to limit certain sensitive functions to this class and other closely coupled classes...
Definition scene_system.hpp:519
A helper intended to get scene nodes and related objects attached to the scene tree.
Definition scene_system.hpp:548
Helper struct for retrieving nodes based on their UniversalEntityIDs.
Definition scene_system.hpp:1591
A collection of data that specifies the behaviour and properties of the RenderSystem and target textu...
Definition scene_system.hpp:850
glm::u16vec2 mComputedDimensions
The dimensions finally computed for this viewport, per request from other parts of the application.
Definition scene_system.hpp:918
RenderSet::RenderType RenderType
Specifies the type of render pipeline requested by this viewport.
Definition scene_system.hpp:889
ResizeType
Different resize configurations available for this Viewport node that dictate how render textures (fr...
Definition scene_system.hpp:855
glm::u16vec2 mRequestedDimensions
The dimensions requested by other parts of the application, to which this viewport's render texture m...
Definition scene_system.hpp:924
ResizeMode
Determines which dimensions the end result of the viewport is allowed to expand on.
Definition scene_system.hpp:865
UpdateMode mUpdateMode
The frequency of rendering updates in real time made on this viewport.
Definition scene_system.hpp:942
ResizeMode mResizeMode
The resizing/scaling behaviour from render-> target texture for this viewport.
Definition scene_system.hpp:900
RenderType mRenderType
The type of render pipelien requested by this viewport.
Definition scene_system.hpp:906
glm::u16vec2 mBaseDimensions
The design dimensions for this viewport, specified at the time of its development.
Definition scene_system.hpp:912
float mFPSCap
If an FPS capped update mode is used, specifies the value of that cap.
Definition scene_system.hpp:949
ResizeType mResizeType
The type of resizing/scaling behaviour from render->target texture for this viewport.
Definition scene_system.hpp:895
float mRenderScale
A multiplier applied (in case resizing is enabled) determining multiplier to the base or computed dim...
Definition scene_system.hpp:936
UpdateMode
Configuration value determining when and how often render updates take place for this viewport.
Definition scene_system.hpp:876
Comparator used for determining priority of descendant viewports owned by a RenderSet::RenderType::AD...
Definition scene_system.hpp:1321
Header containing definitions of classes and functions related to loading and using Texture resources...