Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
scene_system.hpp
Go to the documentation of this file.
1
10
16
17#ifndef FOOLSENGINE_SCENESYSTEM_H
18#define FOOLSENGINE_SCENESYSTEM_H
19
20#include <vector>
21#include <memory>
22#include <unordered_map>
23#include <algorithm>
24#include <cctype>
25#include <type_traits>
26
27#include <glm/glm.hpp>
28#include <glm/gtc/quaternion.hpp>
29
30#include "core/ecs_world.hpp"
32#include "scene_components.hpp"
34#include "render_system.hpp"
35#include "texture.hpp"
37
38namespace ToyMaker {
39
40 class SceneNodeCore;
41 class SceneNode;
42 class ViewportNode;
43 class SceneSystem;
44
54 enum class RelativeTo : uint8_t {
55 PARENT=0, //< Compute relative to/on top of this node's parent's transform.
56 // WORLD=1,
57 // CAMERA=2,
58 };
59
61 NLOHMANN_JSON_SERIALIZE_ENUM(RelativeTo, {
62 {RelativeTo::PARENT, "parent"},
63 });
64
72 ENTITY_NULL = kMaxEntities,
73 };
74
80 extern const std::string kSceneRootName;
81
87 class SceneNodeCore: public std::enable_shared_from_this<SceneNodeCore> {
88 public:
96 static void SceneNodeCore_del_(SceneNodeCore* sceneNode);
97
104 virtual ~SceneNodeCore()=default;
105
113 template <typename TComponent>
114 void addComponent(const TComponent& component, const bool bypassSceneActivityCheck=false);
115
122 void addComponent(const nlohmann::json& jsonComponent, const bool bypassSceneActivityCheck=false);
123
132 template <typename TComponent>
133 TComponent getComponent(const float simulationProgress=1.f) const;
134
142 template <typename TComponent>
143 bool hasComponent() const;
144
152 bool hasComponent(const std::string& type) const;
153
160 template <typename TComponent>
161 void updateComponent(const TComponent& component);
162
168 void updateComponent(const nlohmann::json& component);
169
177 template <typename TComponent>
178 void addOrUpdateComponent(const TComponent& component, const bool bypassSceneActivityCheck=false);
179
186 void addOrUpdateComponent(const nlohmann::json& component, const bool bypassSceneActivityCheck=false);
187
193 template <typename TComponent>
194 void removeComponent();
195
204 template <typename TSystem>
205 void setEnabled(bool state);
206
214 template <typename TSystem>
215 bool getEnabled() const;
216
222 EntityID getEntityID() const;
223
229 WorldID getWorldID() const;
230
237
243 std::weak_ptr<ECSWorld> getWorld() const;
244
253 bool inScene() const;
254
265 bool isActive() const;
266
274 bool isAncestorOf(std::shared_ptr<const SceneNodeCore> sceneNode) const;
275
284 bool hasNode(const std::string& pathToChild) const;
285
292 void addNode(std::shared_ptr<SceneNodeCore> node, const std::string& where);
293
299 std::vector<std::shared_ptr<SceneNodeCore>> getChildren();
300
306 std::vector<std::shared_ptr<const SceneNodeCore>> getChildren() const;
307
313 std::vector<std::shared_ptr<SceneNodeCore>> getDescendants();
314
322 template <typename TObject=std::shared_ptr<SceneNode>>
323 TObject getByPath(const std::string& where);
324
332 template <typename TSceneNode=SceneNode>
333 std::shared_ptr<TSceneNode> getNodeByID(EntityID entityID);
334
341 std::string getPathFromAncestor(std::shared_ptr<const SceneNodeCore> ancestor) const;
342
348 virtual std::shared_ptr<ViewportNode> getLocalViewport();
349
355 virtual std::shared_ptr<const ViewportNode> getLocalViewport() const;
356
363 std::shared_ptr<SceneNodeCore> getNode(const std::string& where);
364
370 std::shared_ptr<SceneNodeCore> getParentNode();
371
377 std::shared_ptr<const SceneNodeCore> getParentNode() const;
378
385 std::shared_ptr<SceneNodeCore> removeNode(const std::string& where);
386
392 std::vector<std::shared_ptr<SceneNodeCore>> removeChildren();
393
399 std::string getName() const;
400
406 void setName(const std::string& name);
407
415 std::string getViewportLocalPath() const;
416
426 inline void setPrototype_(std::shared_ptr<SceneNodeCore> prototype) { mPrototype=prototype; }
427
428 protected:
429
435 virtual void joinWorld(ECSWorld& world);
436
444 static std::shared_ptr<SceneNodeCore> copy(const std::shared_ptr<const SceneNodeCore> other);
445
454 template<typename ...TComponents>
455 SceneNodeCore(const Placement& placement, const std::string& name, TComponents...components);
456
463 SceneNodeCore(const nlohmann::json& jsonSceneNode);
464
470 SceneNodeCore(const SceneNodeCore& sceneObject);
471
472 // /**
473 // * @brief Copy assignment operator.
474 // *
475 // * @todo Sit down and figure out whether this operator will ever actually need to be used.
476 // */
477 // BaseSceneNode& operator=(const BaseSceneNode& sceneObject);
478
483 virtual void onCreated();
484
489 virtual void onActivated();
490
495 virtual void onDeactivated();
496
503 virtual void onDestroyed();
504
512 static void validateName(const std::string& nodeName);
513
514 private:
519 struct Key {};
520
529 template<typename ...TComponents>
530 SceneNodeCore(const Key&, const Placement& placement, const std::string& name, TComponents...components);
531
536 enum StateFlags: uint8_t {
537 ENABLED=0x1, //< This node is intended to be made active as soon as its added to the SceneSystem's scene tree.
538 ACTIVE=0x2, //< This node is presently active on the SceneSystem's scene tree.
539 };
540
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 };
551 };
552
558 virtual std::shared_ptr<SceneNodeCore> clone() const;
559
566 void copyDescendants(const SceneNodeCore& other);
567
576 static void setParentViewport(std::shared_ptr<SceneNodeCore> node, std::shared_ptr<ViewportNode> newViewport);
577
584 static std::shared_ptr<SceneNodeCore> disconnectNode(std::shared_ptr<SceneNodeCore> node);
585
593 static bool detectCycle(std::shared_ptr<SceneNodeCore> node);
594
604 static std::tuple<std::string, std::string> nextInPath(const std::string& where);
605
611 void copyAndReplaceAttributes(const SceneNodeCore& other);
612
618
623 std::string mName {};
624
631 uint8_t mStateFlags { 0x00 | StateFlags::ENABLED };
632
637 RelativeTo mRelativeTo{ RelativeTo::PARENT };
638
643 std::shared_ptr<Entity> mEntity { nullptr };
644
649 std::weak_ptr<SceneNodeCore> mParent {};
650
655 std::weak_ptr<ViewportNode> mParentViewport {};
656
663 std::unordered_map<std::string, std::size_t> mChildNameToNode {};
664
669 std::vector<std::shared_ptr<SceneNodeCore>> mChildren {};
670
675 std::shared_ptr<SceneNodeCore> mPrototype { nullptr };
676
684
685 friend class SceneSystem;
686 template<typename TSceneNode>
687 friend class BaseSceneNode;
688 friend class ViewportNode;
689 };
690
691
698 template <typename TSceneNode>
699 class BaseSceneNode: public SceneNodeCore {
700 public:
701
702 protected:
714 template <typename ...TComponents>
715 static std::shared_ptr<TSceneNode> create(const Key&, const Placement& placement, const std::string& name, TComponents...components);
716
728 template <typename ...TComponents>
729 static std::shared_ptr<TSceneNode> create(const Placement& placement, const std::string& name, TComponents...components);
730
739 static std::shared_ptr<TSceneNode> create(const nlohmann::json& sceneNodeDescription);
740
741
751 static std::shared_ptr<TSceneNode> copy(const std::shared_ptr<const TSceneNode> sceneNode);
752 template <typename...TComponents>
753
762 BaseSceneNode(const Key& key, const Placement& placement, const std::string& name, TComponents...components):
763 SceneNodeCore{ key, placement, name, components... }
764 {}
765
774 template<typename ...TComponents>
775 BaseSceneNode(const Placement& placement, const std::string& name, TComponents...components):
776 SceneNodeCore{ placement, name, components... }
777 {}
778
784 BaseSceneNode(const nlohmann::json& nodeDescription) : SceneNodeCore { nodeDescription } {}
785
791 BaseSceneNode(const SceneNodeCore& other): SceneNodeCore{ other } {}
792
793 friend class SceneNodeCore;
794 };
795
803 class SceneNode: public BaseSceneNode<SceneNode>, public Resource<SceneNode> {
804 public:
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);
809
810 static inline std::string getResourceTypeName() { return "SceneNode"; }
811
812 protected:
813 template<typename ...TComponents>
814 SceneNode(const Placement& placement, const std::string& name, TComponents...components):
815 BaseSceneNode<SceneNode>{placement, name, components...},
817 {}
818
819 SceneNode(const nlohmann::json& jsonSceneNode):
820 BaseSceneNode<SceneNode>{jsonSceneNode},
822 {}
823
824 SceneNode(const SceneNode& sceneObject):
825 BaseSceneNode<SceneNode>{sceneObject},
827 {}
828 friend class BaseSceneNode<SceneNode>;
829 };
830
844 class ViewportNode: public BaseSceneNode<ViewportNode>, public Resource<ViewportNode> {
845 public:
855 enum class ResizeType: uint8_t {
856 OFF=0, //< No resize, render texture is rendered as is with no scaling.
857 VIEWPORT_DIMENSIONS, //< Viewport transform configured per stretch mode and requested dimensions
858 TEXTURE_DIMENSIONS, //< Texture result rendered in base dimensions, and then warped to fit request dimensions
859 };
860
865 enum class ResizeMode: uint8_t {
866 FIXED_ASPECT=0, //< both, while retaining aspect ratio.
867 EXPAND_VERTICALLY, //< Expand vertically if permitted by target dimensions, otherwise constrain to aspect.
868 EXPAND_HORIZONTALLY, //< Expand horiontally if possible by target dimensions, otherwise constrain to aspect.
869 EXPAND_FILL, //< No constraint in either dimension, expand to fill target dimensions always.
870 };
871
876 enum class UpdateMode: uint8_t {
877 NEVER=0, //< No rerender takes place even when render is called for this viewport.
878 ONCE, //< Update on next render frame, then set to UpdateMode::NEVER
879 ON_FETCH, //< Update whenever a request for the texture is made, where frequency is entirely dependent on caller.
880 ON_FETCH_CAP_FPS, //< Update on request, but ignore requests exceeding FPS cap. Final frequency is constrained to the FPS cap configured for this viewport, but may be lower than it.
881 ON_RENDER, //< Update every render call with no constraint, so frequency depends entirely on the render frequency of the application loop.
882 ON_RENDER_CAP_FPS, //< Update on render call when fps cap isn't exceeded. Final FPS may be lower than specified as a cap.
883 };
884
890
895 ResizeType mResizeType { ResizeType::VIEWPORT_DIMENSIONS };
900 ResizeMode mResizeMode { ResizeMode::EXPAND_HORIZONTALLY };
901
906 RenderType mRenderType { RenderType::BASIC_3D };
907
912 glm::u16vec2 mBaseDimensions { 800, 600 };
913
918 glm::u16vec2 mComputedDimensions { 800, 600 };
919
924 glm::u16vec2 mRequestedDimensions { 800, 600 };
925
936 float mRenderScale { 1.f };
937
942 UpdateMode mUpdateMode { UpdateMode::ON_RENDER_CAP_FPS };
943
949 float mFPSCap { 60.f };
950 };
951
962 static std::shared_ptr<ViewportNode> create(const std::string& name, bool inheritsWorld, bool allowActionFlowThrough, const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
963
975 static std::shared_ptr<ViewportNode> create(const nlohmann::json& sceneNodeDescription);
976
983 static std::shared_ptr<ViewportNode> copy(const std::shared_ptr<const ViewportNode> other);
984
990 static inline std::string getResourceTypeName() { return "ViewportNode"; }
991
998
1006 void updateExposure(float newExposure);
1007
1016 void updateGamma(float newGamma);
1017
1023 float getExposure();
1024
1030 float getGamma();
1031
1037 std::shared_ptr<ViewportNode> getLocalViewport() override;
1038
1044 virtual std::shared_ptr<const ViewportNode> getLocalViewport() const override;
1045
1052 std::shared_ptr<Texture> fetchRenderResult(float simulationProgress);
1053
1059 void setActiveCamera(const std::string& cameraPath);
1060
1066 void setActiveCamera(std::shared_ptr<SceneNodeCore> cameraNode);
1067
1073 RenderConfiguration getRenderConfiguration() const;
1074
1080 void setRenderConfiguration(const RenderConfiguration& renderConfiguration);
1081
1091 void setSkybox(std::shared_ptr<Texture> skybox);
1092
1099
1106
1112 void setRenderScale(float renderScale);
1113
1120
1126 void setFPSCap(float fpsCap);
1127
1135 void requestDimensions(glm::u16vec2 requestedDimensions);
1136
1143
1151 bool handleAction(std::pair<ActionDefinition, ActionData> pendingAction);
1152
1160
1165 ~ViewportNode() override;
1166
1174 inline uint32_t getViewportLoadOrdinal() const { return mViewportLoadOrdinal; }
1175
1176 protected:
1177 ViewportNode(const Placement& placement, const std::string& name):
1178 BaseSceneNode<ViewportNode>{placement, name},
1179 Resource<ViewportNode>{0},
1180 mViewportLoadOrdinal { SDL_GetTicks() }
1181 {}
1182 ViewportNode(const nlohmann::json& jsonSceneNode):
1183 BaseSceneNode<ViewportNode>{jsonSceneNode},
1185 mViewportLoadOrdinal { SDL_GetTicks() }
1186 {}
1187 ViewportNode(const ViewportNode& sceneObject):
1188 BaseSceneNode<ViewportNode>{sceneObject},
1190 mViewportLoadOrdinal { SDL_GetTicks() }
1191 {}
1192
1197 std::shared_ptr<ECSWorld> mOwnWorld { nullptr };
1198
1203 void onActivated() override;
1204
1209 void onDeactivated() override;
1210
1216 void joinWorld(ECSWorld& world) override;
1217
1218 private:
1229 static std::shared_ptr<ViewportNode> create(const Key& key, const std::string& name, bool inheritsWorld, const RenderConfiguration& renderConfiguration, std::shared_ptr<Texture> skybox);
1230
1238 ViewportNode(const Key& key, const Placement& placement, const std::string& name):
1239 BaseSceneNode<ViewportNode>{key, Placement{}, name},
1241 {(void)placement; /*prevent unused parameter warnings*/}
1242
1248 std::shared_ptr<SceneNodeCore> clone() const override;
1249
1254 void createAndJoinWorld();
1255
1261 void registerDomainCamera(std::shared_ptr<SceneNodeCore> cameraNode);
1262
1268 void unregisterDomainCamera(std::shared_ptr<SceneNodeCore> cameraNode);
1269 std::shared_ptr<SceneNodeCore> findFallbackCamera();
1270
1276 std::vector<std::shared_ptr<ViewportNode>> getActiveDescendantViewports();
1277
1283 std::vector<std::weak_ptr<ECSWorld>> getActiveDescendantWorlds();
1284
1294 uint32_t render(float simulationProgress, uint32_t variableStep);
1295
1302 void render_(float simulationProgress);
1303
1310 inline SDL_Rect getCenteredViewportCoordinates() const {
1311 return {
1312 mRenderConfiguration.mRequestedDimensions.x/2 - mRenderConfiguration.mComputedDimensions.x/2, mRenderConfiguration.mRequestedDimensions.y/2 - mRenderConfiguration.mComputedDimensions.y/2,
1313 mRenderConfiguration.mComputedDimensions.x, mRenderConfiguration.mComputedDimensions.y
1314 };
1315 }
1316
1322 bool operator() (const std::shared_ptr<ViewportNode>& one, const std::shared_ptr<ViewportNode>& two) const {
1323 return one->getViewportLoadOrdinal() < two->getViewportLoadOrdinal();
1324 }
1325 };
1326
1331 uint32_t mViewportLoadOrdinal { std::numeric_limits<uint32_t>::max() };
1332
1338
1344
1349 bool mActionFlowthrough { false };
1350
1356
1361 std::set<std::shared_ptr<ViewportNode>, ViewportChildComp_> mChildViewports {};
1362
1367 std::shared_ptr<SceneNodeCore> mActiveCamera { nullptr };
1368
1373 std::set<std::shared_ptr<SceneNodeCore>, std::owner_less<std::shared_ptr<SceneNodeCore>>> mDomainCameras {};
1374
1379 RenderSetID mRenderSet;
1380
1387 std::shared_ptr<Texture> mTextureResult { nullptr };
1388
1394
1399 uint32_t mTimeSinceLastRender { static_cast<uint32_t>(1000/mRenderConfiguration.mFPSCap) };
1400
1401 friend class BaseSceneNode<ViewportNode>;
1402 friend class SceneNodeCore;
1403 friend class SceneSystem;
1404 };
1405
1413 class SceneSystem: public System<SceneSystem, std::tuple<>, std::tuple<Placement, SceneHierarchyData, Transform>> {
1414 public:
1420 explicit SceneSystem(std::weak_ptr<ECSWorld> world):
1421 System<SceneSystem, std::tuple<>, std::tuple<Placement, SceneHierarchyData, Transform>> { world }
1422 {}
1423
1429 static std::string getSystemTypeName() { return "SceneSystem"; }
1430
1439 bool isSingleton() const override { return true; }
1440
1448 template<typename TObject=std::shared_ptr<SceneNode>>
1449 TObject getByPath(const std::string& where);
1450
1458 template <typename TSceneNode>
1459 std::shared_ptr<TSceneNode> getNodeByID(const UniversalEntityID& universalEntityID);
1460
1467 std::vector<std::shared_ptr<SceneNodeCore>> getNodesByID(const std::vector<UniversalEntityID>& universalEntityIDs);
1468
1475 std::shared_ptr<SceneNodeCore> getNode(const std::string& where);
1476
1483 std::shared_ptr<SceneNodeCore> removeNode(const std::string& where);
1484
1491 void addNode(std::shared_ptr<SceneNodeCore> node, const std::string& where);
1492
1498 std::weak_ptr<ECSWorld> getRootWorld() const;
1499
1506
1512 void onApplicationInitialize(const ViewportNode::RenderConfiguration& rootViewportRenderConfiguration);
1513
1518 void onApplicationStart();
1519
1524 void onApplicationEnd();
1525
1533 void simulationStep(uint32_t simStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1534
1545 void variableStep(float simulationProgress, uint32_t simulationLagMillis, uint32_t variableStepMillis, std::vector<std::pair<ActionDefinition, ActionData>> triggeredActions={});
1546
1551 void updateTransforms();
1552
1560 uint32_t render(float simulationProgress, uint32_t variableStep);
1561
1562 private:
1572 class SceneSubworld: public System<SceneSubworld, std::tuple<Placement>, std::tuple<Transform, SceneHierarchyData>> {
1573 public:
1574 explicit SceneSubworld(std::weak_ptr<ECSWorld> world):
1575 System<SceneSubworld, std::tuple<Placement>, std::tuple<Transform, SceneHierarchyData>> { world }
1576 {}
1577 static std::string getSystemTypeName() { return "SceneSubworld"; }
1578 private:
1579 void onEntityUpdated(EntityID entityID) override;
1580 };
1581
1590 template <typename TSceneNode, typename Enable=void>
1592 static std::shared_ptr<TSceneNode> get(const UniversalEntityID& universalEntityID, SceneSystem& sceneSystem);
1593 };
1594
1602 bool isActive(std::shared_ptr<const SceneNodeCore> sceneNode) const;
1603
1612
1620 bool inScene(std::shared_ptr<const SceneNodeCore> sceneNode) const;
1621
1630
1637
1643 std::vector<std::shared_ptr<ViewportNode>> getActiveViewports();
1644
1650 std::vector<std::weak_ptr<ECSWorld>> getActiveWorlds();
1651
1658 Transform getLocalTransform(std::shared_ptr<const SceneNodeCore> sceneNode) const;
1659
1666 Transform getCachedWorldTransform(std::shared_ptr<const SceneNodeCore> sceneNode) const;
1667
1673 void updateHierarchyDataInsertion(std::shared_ptr<SceneNodeCore> insertedNode);
1674
1680 void updateHierarchyDataRemoval(std::shared_ptr<SceneNodeCore> removedNode);
1681
1687 void nodeAdded(std::shared_ptr<SceneNodeCore> sceneNode);
1688
1694 void nodeRemoved(std::shared_ptr<SceneNodeCore> sceneNode);
1695
1702 void nodeActivationChanged(std::shared_ptr<SceneNodeCore> sceneNode, bool state);
1703
1709 void activateSubtree(std::shared_ptr<SceneNodeCore> sceneNode);
1710
1716 void deactivateSubtree(std::shared_ptr<SceneNodeCore> sceneNode);
1717
1724
1731 std::shared_ptr<SceneNodeCore> getNodeByID(const UniversalEntityID& universalEntityID);
1732
1737 std::shared_ptr<ViewportNode> mRootNode{ nullptr };
1738
1743 std::map<UniversalEntityID, std::weak_ptr<SceneNodeCore>, std::less<UniversalEntityID>> mEntityToNode {};
1744
1749 std::set<UniversalEntityID, std::less<UniversalEntityID>> mActiveEntities {};
1750
1755 std::set<UniversalEntityID, std::less<UniversalEntityID>> mComputeTransformQueue {};
1756
1757 friend class SceneNodeCore;
1758 };
1759
1760
1761 template <typename TSceneNode>
1762 template <typename ...TComponents>
1763 std::shared_ptr<TSceneNode> BaseSceneNode<TSceneNode>::create(const Placement& placement, const std::string& name, TComponents...components) {
1764 std::shared_ptr<SceneNodeCore> newNode ( new TSceneNode(placement, name, components...), &SceneNodeCore_del_);
1765 newNode->onCreated();
1766 return std::static_pointer_cast<TSceneNode>(newNode);
1767 }
1768
1769 template <typename TSceneNode>
1770 template <typename ...TComponents>
1771 std::shared_ptr<TSceneNode> BaseSceneNode<TSceneNode>::create(const Key& key, const Placement& placement, const std::string& name, TComponents...components) {
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);
1775 }
1776
1777 template <typename TSceneNode>
1778 std::shared_ptr<TSceneNode> BaseSceneNode<TSceneNode>::create(const nlohmann::json& sceneNodeDescription) {
1779 std::shared_ptr<SceneNodeCore> newNode{ new TSceneNode{ sceneNodeDescription }, &SceneNodeCore_del_};
1780 newNode->onCreated();
1781 return std::static_pointer_cast<TSceneNode>(newNode);
1782 }
1783
1784 template <typename TSceneNode>
1785 std::shared_ptr<TSceneNode> BaseSceneNode<TSceneNode>::copy(const std::shared_ptr<const TSceneNode> sceneNode) {
1786 std::shared_ptr<SceneNodeCore> newNode { SceneNodeCore::copy(sceneNode) };
1787 newNode->onCreated();
1788 return std::static_pointer_cast<TSceneNode>(newNode);
1789 }
1790
1791 template<typename ...TComponents>
1792 std::shared_ptr<SceneNode> SceneNode::create(const Placement& placement, const std::string& name, TComponents...components) {
1793 return BaseSceneNode<SceneNode>::create<TComponents...>(placement, name, components...);
1794 }
1795
1796 template <typename TObject>
1797 TObject SceneNodeCore::getByPath(const std::string& where) {
1798 return getByPath_Helper<TObject>::get(shared_from_this(), where);
1799 }
1800
1801 template <typename TObject>
1802 TObject SceneSystem::getByPath(const std::string& where) {
1803 return mRootNode->getByPath<TObject>(where);
1804 }
1805
1806 template <typename TSceneNode>
1807 inline std::shared_ptr<TSceneNode> SceneSystem::getNodeByID(const UniversalEntityID& universalEntityID) {
1808 return SceneSystem::getNodeByID_Helper<TSceneNode>(universalEntityID, *this);
1809 }
1810
1811 // Fail retrieval in cases where no explicitly defined object by path
1812 // method exists
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");
1816 return TObject{}; // this is just to shut the compiler up about no returned value
1817 }
1818
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>{};
1823 }
1824
1825 template <typename TSceneNode>
1826 struct SceneSystem::getNodeByID_Helper<TSceneNode, typename std::enable_if_t<std::is_base_of<SceneNodeCore, TSceneNode>::value>> {
1827 std::shared_ptr<TSceneNode> get(const UniversalEntityID& universalEntityID, SceneSystem& sceneSystem) {
1828 return std::static_pointer_cast<TSceneNode>(sceneSystem.getNodeByID(universalEntityID));
1829 }
1830 };
1831
1832 template <typename TObject>
1833 struct SceneNodeCore::getByPath_Helper<std::shared_ptr<TObject>, typename std::enable_if_t<std::is_base_of<SceneNodeCore, TObject>::value>> {
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));
1836 }
1837 static constexpr bool s_valid { true };
1838 };
1839
1840 template <typename ...TComponents>
1841 SceneNodeCore::SceneNodeCore(const Placement& placement, const std::string& name, TComponents...components) {
1842 validateName(name);
1843 mName = name;
1844 mEntity = std::make_shared<Entity>(
1846 placement,
1848 Transform{glm::mat4{1.f}},
1849 ObjectBounds {},
1851 components...
1852 )
1853 );
1854 }
1855
1856 template <typename ...TComponents>
1857 SceneNodeCore::SceneNodeCore(const Key&, const Placement& placement, const std::string& name, TComponents...components) {
1858 mName = name;
1859 mEntity = std::make_shared<Entity>(
1861 placement,
1863 Transform{glm::mat4{1.f}},
1864 ObjectBounds {},
1866 components...
1867 )
1868 );
1869 }
1870
1871 template <typename TComponent>
1872 void SceneNodeCore::addComponent(const TComponent& component, bool bypassSceneActivityCheck) {
1873 mEntity->addComponent<TComponent>(component);
1874
1875 // NOTE: required because even though this node's entity's signature changes, it
1876 // is disabled by default on any systems it is eligible for. We need to activate
1877 // the node according to its system mask
1878 if(!bypassSceneActivityCheck && isActive()) {
1879 mEntity->enableSystems(mSystemMask);
1880 }
1881 // NOTE: no removeComponent() equivalent required, as systems that depend on the removed
1882 // component will automatically have this entity removed from their list, and hence
1883 // be disabled
1884 }
1885
1886 template <typename TComponent>
1887 TComponent SceneNodeCore::getComponent(const float simulationProgress) const {
1888 return mEntity->getComponent<TComponent>(simulationProgress);
1889 }
1890
1891 template <typename TComponent>
1893 return mEntity->hasComponent<TComponent>();
1894 }
1895
1896 template <typename TComponent>
1897 void SceneNodeCore::updateComponent(const TComponent& component) {
1898 mEntity->updateComponent<TComponent>(component);
1899 }
1900
1901 template <typename TComponent>
1902 void SceneNodeCore::addOrUpdateComponent(const TComponent& component, const bool bypassSceneActivityCheck) {
1904 addComponent<TComponent>(component, bypassSceneActivityCheck);
1905 return;
1906 }
1907 updateComponent<TComponent>(component);
1908 }
1909
1910 template <typename TComponent>
1912 mEntity->removeComponent<TComponent>();
1913 }
1914
1915 template <typename TSystem>
1917 return mEntity->isEnabled<TSystem>();
1918 }
1919
1920 template <typename TSystem>
1921 void SceneNodeCore::setEnabled(bool state) {
1922 const SystemType systemType { mEntity->getWorld().lock()->getSystemType<TSystem>() };
1923 mSystemMask.set(systemType, state);
1924
1925 // since the system mask has been changed, we'll want the scene
1926 // to talk to ECS and make this node visible to the system that
1927 // was enabled, if eligible
1928 if(state == true && isActive()){
1929 mEntity->enableSystems(mSystemMask);
1930 }
1931 }
1932
1933 // Specialization for when the scene system itself is marked
1934 // enabled or disabled
1935 template <>
1936 inline void SceneNodeCore::setEnabled<SceneSystem>(bool state) {
1937 const SystemType systemType { mEntity->getWorld().lock()->getSystemType<SceneSystem>() };
1938 // TODO: enabled entities are tracked in both SceneSystem's
1939 // mActiveNodes and ECS getEnabledEntities, which is
1940 // redundant and may eventually cause errors
1941 mSystemMask.set(systemType, state);
1942 //TODO: More redundancy. Why?
1943 mStateFlags = state? (mStateFlags | SceneNodeCore::StateFlags::ENABLED): (mStateFlags & ~SceneNodeCore::StateFlags::ENABLED);
1944 mEntity->getWorld().lock()->getSystem<SceneSystem>()->nodeActivationChanged(
1945 shared_from_this(),
1946 state
1947 );
1948 }
1949
1950 // Prevent removal of components essential to a scene node
1951 template <>
1953 assert(false && "Cannot remove a scene node's Placement component");
1954 }
1955 template <>
1957 assert(false && "Cannot remove a scene node's Transform component");
1958 }
1959
1960 template <typename TSceneNode>
1961 std::shared_ptr<TSceneNode> SceneNodeCore::getNodeByID(EntityID entityID) {
1962 return getWorld().lock()->getSystem<SceneSystem>()->getNodeByID<TSceneNode>({getWorldID(), entityID});
1963 }
1964
1966 NLOHMANN_JSON_SERIALIZE_ENUM(ViewportNode::RenderConfiguration::ResizeType, {
1967 {ViewportNode::RenderConfiguration::ResizeType::OFF, "off"},
1968 {ViewportNode::RenderConfiguration::ResizeType::VIEWPORT_DIMENSIONS, "viewport-dimensions"},
1969 {ViewportNode::RenderConfiguration::ResizeType::TEXTURE_DIMENSIONS, "texture-dimensions"},
1970 });
1971
1973 NLOHMANN_JSON_SERIALIZE_ENUM(ViewportNode::RenderConfiguration::ResizeMode, {
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"},
1978 });
1979
1981 NLOHMANN_JSON_SERIALIZE_ENUM(ViewportNode::RenderConfiguration::UpdateMode, {
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"},
1987 });
1988
1990 NLOHMANN_JSON_SERIALIZE_ENUM(ViewportNode::RenderConfiguration::RenderType, {
1991 {ViewportNode::RenderConfiguration::RenderType::BASIC_3D, "basic-3d"},
1992 {ViewportNode::RenderConfiguration::RenderType::ADDITION, "addition"},
1993 });
1994
1996 inline void to_json(nlohmann::json& json, const ViewportNode::RenderConfiguration& renderConfiguration) {
1997 json = {
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},
2005 };
2006 }
2007
2009 inline void from_json(const nlohmann::json& json, ViewportNode::RenderConfiguration& renderConfiguration) {
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");
2017
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);
2020
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);
2023
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);
2026
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");
2030
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");
2034 }
2035
2036}
2037
2038#endif
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
STL namespace.
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
The transform component, which moves the vertices of a model to their world space coordinates during ...
Definition scene_components.hpp:94
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...