From d16137bcf0a36cd380fb66b2970cd6a70349dd93 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 20:54:53 +0200 Subject: [PATCH 1/7] Object constant StaticClassName --- Engine/Core/include/Core/Object.hpp | 37 +++++++++++++++++- Engine/Core/src/Core/Object.cpp | 6 +-- Engine/Core/test/test_Object.cpp | 58 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 Engine/Core/test/test_Object.cpp diff --git a/Engine/Core/include/Core/Object.hpp b/Engine/Core/include/Core/Object.hpp index 6e2668d..84f2aff 100644 --- a/Engine/Core/include/Core/Object.hpp +++ b/Engine/Core/include/Core/Object.hpp @@ -18,7 +18,19 @@ class Object : public std::enable_shared_from_this { uint32_t getId() const; - virtual const char *getClassName() const; + const static char *StaticClassName() { + return "Object"; + } + + static std::intptr_t StaticHashCode() { + return reinterpret_cast(StaticClassName()); + } + + virtual const char *getClassName() const = 0; + + std::intptr_t getClassHashCode() const { + return reinterpret_cast(getClassName()); + } virtual std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const; @@ -28,4 +40,27 @@ class Object : public std::enable_shared_from_this { } // namespace Stone::Core +#define STONE_ABSTRACT_OBJECT(ClassName) \ + \ +public: \ + static const char *StaticClassName() { \ + return #ClassName; \ + } \ + static std::intptr_t StaticHashCode() { \ + return reinterpret_cast(StaticClassName()); \ + } \ + \ +private: + +#define STONE_OBJECT(ClassName) \ + STONE_ABSTRACT_OBJECT(ClassName) \ + \ +public: \ + const char *getClassName() const override { \ + return StaticClassName(); \ + } \ + \ +private: + + std::ostream &operator<<(std::ostream &os, const Stone::Core::Object &obj); diff --git a/Engine/Core/src/Core/Object.cpp b/Engine/Core/src/Core/Object.cpp index b30f712..341d625 100644 --- a/Engine/Core/src/Core/Object.cpp +++ b/Engine/Core/src/Core/Object.cpp @@ -17,12 +17,8 @@ uint32_t Object::getId() const { return _id; } -const char *Object::getClassName() const { - return "Object"; -} - std::ostream &Object::writeToStream(std::ostream &stream, bool closing_bracer) const { - stream << "{id:" << _id; + stream << "{class:\"" << getClassName() << "\",id:" << _id; if (closing_bracer) stream << "}"; return stream; diff --git a/Engine/Core/test/test_Object.cpp b/Engine/Core/test/test_Object.cpp new file mode 100644 index 0000000..5f10ad5 --- /dev/null +++ b/Engine/Core/test/test_Object.cpp @@ -0,0 +1,58 @@ +#include "Core/Object.hpp" + +#include + +using namespace Stone; + +class MockObject : public Core::Object { + STONE_OBJECT(MockObject) +}; + +class MockSubObject : public MockObject { + STONE_OBJECT(MockSubObject) +}; + +TEST(Object, ClassName) { + auto mockObject = std::make_shared(); + EXPECT_STREQ(mockObject->getClassName(), "MockObject"); + + auto mockSubObject = std::make_shared(); + EXPECT_STREQ(mockSubObject->getClassName(), "MockSubObject"); + + const void *ptrFromObject = mockObject->getClassName(); + const void *ptrFromClass = MockObject::StaticClassName(); + + EXPECT_EQ(ptrFromObject, ptrFromClass); + + EXPECT_EQ(mockObject->getClassName(), MockObject::StaticClassName()); +} + +TEST(Object, HashCode) { + auto mockObject = std::make_shared(); + auto mockSubObject = std::make_shared(); + + EXPECT_EQ(mockObject->getClassHashCode(), MockObject::StaticHashCode()); + EXPECT_EQ(mockSubObject->getClassHashCode(), MockSubObject::StaticHashCode()); +} + +TEST(Object, SwitchClassName) { + + auto mockObject = std::make_shared(); + auto mockSubObject = std::make_shared(); + + std::map classCaster = { + { Core::Object::StaticHashCode(), 0}, + { MockObject::StaticHashCode(), 1}, + {MockSubObject::StaticHashCode(), 2} + }; + + EXPECT_EQ(classCaster[mockObject->getClassHashCode()], 1); + EXPECT_EQ(classCaster[mockSubObject->getClassHashCode()], 2); +} + +TEST(Object, Id) { + auto object = std::make_shared(); + auto object2 = std::make_shared(); + + EXPECT_NE(object->getId(), object2->getId()); +} From 5f59bbc03aed31fb92177a98441d3b7e52347e52 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 20:55:44 +0200 Subject: [PATCH 2/7] Stone Object Macro usage --- Engine/Core/include/Core/Assets/Bundle.hpp | 3 +-- Engine/Core/include/Core/Assets/Resource.hpp | 1 + Engine/Core/include/Core/Image/ImageData.hpp | 4 ++-- Engine/Core/include/Core/Image/ImageSource.hpp | 4 ++-- Engine/Core/src/Core/Assets/Bundle.cpp | 4 ---- Engine/Core/src/Core/Image/ImageData.cpp | 4 ---- Engine/Core/src/Core/Image/ImageSource.cpp | 4 ---- 7 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Engine/Core/include/Core/Assets/Bundle.hpp b/Engine/Core/include/Core/Assets/Bundle.hpp index 181eb43..6d82628 100644 --- a/Engine/Core/include/Core/Assets/Bundle.hpp +++ b/Engine/Core/include/Core/Assets/Bundle.hpp @@ -10,6 +10,7 @@ namespace Stone::Core::Assets { class Bundle : public Object { + STONE_OBJECT(Bundle) public: Bundle(const Bundle &other) = delete; @@ -18,8 +19,6 @@ class Bundle : public Object { ~Bundle() override = default; - const char *getClassName() const override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; template diff --git a/Engine/Core/include/Core/Assets/Resource.hpp b/Engine/Core/include/Core/Assets/Resource.hpp index 6a0ab2f..842235a 100644 --- a/Engine/Core/include/Core/Assets/Resource.hpp +++ b/Engine/Core/include/Core/Assets/Resource.hpp @@ -12,6 +12,7 @@ class Bundle; * @brief Represents a resource. */ class Resource : public Object { + STONE_ABSTRACT_OBJECT(Resource) public: Resource(const std::shared_ptr &bundle, const std::string &filepath); diff --git a/Engine/Core/include/Core/Image/ImageData.hpp b/Engine/Core/include/Core/Image/ImageData.hpp index 4e455c9..2a9f7bf 100644 --- a/Engine/Core/include/Core/Image/ImageData.hpp +++ b/Engine/Core/include/Core/Image/ImageData.hpp @@ -10,14 +10,14 @@ namespace Stone::Core::Image { class ImageSource; class ImageData : public Object { + STONE_OBJECT(ImageData) + public: ImageData() = delete; ImageData(const ImageData &other) = delete; ~ImageData() override; - [[nodiscard]] const char *getClassName() const override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; [[nodiscard]] const Size &getSize() const; diff --git a/Engine/Core/include/Core/Image/ImageSource.hpp b/Engine/Core/include/Core/Image/ImageSource.hpp index c300b22..eb6d503 100644 --- a/Engine/Core/include/Core/Image/ImageSource.hpp +++ b/Engine/Core/include/Core/Image/ImageSource.hpp @@ -15,6 +15,8 @@ class ImageData; * It is used to load the image data when needed and hold the reference to the loaded image data. */ class ImageSource : public Assets::Resource { + STONE_OBJECT(ImageSource) + public: ImageSource(const std::shared_ptr &bundle, const std::string &filepath, Channel channels = Channel::RGBA); @@ -24,8 +26,6 @@ class ImageSource : public Assets::Resource { ~ImageSource() override = default; - const char *getClassName() const override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; [[nodiscard]] const std::string &getFilePath() const; diff --git a/Engine/Core/src/Core/Assets/Bundle.cpp b/Engine/Core/src/Core/Assets/Bundle.cpp index 333eaf5..f70484b 100644 --- a/Engine/Core/src/Core/Assets/Bundle.cpp +++ b/Engine/Core/src/Core/Assets/Bundle.cpp @@ -14,10 +14,6 @@ Bundle::Bundle(std::string rootDirectory) : _rootDirectory(std::move(rootDirecto } } -const char *Bundle::getClassName() const { - return "Bundle"; -} - std::ostream &Bundle::writeToStream(std::ostream &stream, bool closing_bracer) const { Object::writeToStream(stream, false); stream << ",root_directory:\"" << _rootDirectory << "\""; diff --git a/Engine/Core/src/Core/Image/ImageData.cpp b/Engine/Core/src/Core/Image/ImageData.cpp index 9b25bd2..32ab1a2 100644 --- a/Engine/Core/src/Core/Image/ImageData.cpp +++ b/Engine/Core/src/Core/Image/ImageData.cpp @@ -16,10 +16,6 @@ ImageData::~ImageData() { } } -const char *ImageData::getClassName() const { - return "ImageData"; -} - std::ostream &ImageData::writeToStream(std::ostream &stream, bool closing_bracer) const { stream << "{size:" << _size << ",channels:" << _channels; if (closing_bracer) diff --git a/Engine/Core/src/Core/Image/ImageSource.cpp b/Engine/Core/src/Core/Image/ImageSource.cpp index 168d577..5b92a66 100644 --- a/Engine/Core/src/Core/Image/ImageSource.cpp +++ b/Engine/Core/src/Core/Image/ImageSource.cpp @@ -11,10 +11,6 @@ ImageSource::ImageSource(const std::shared_ptr &bundle, const st : Assets::Resource(bundle, filepath), _channels(channels) { } -const char *ImageSource::getClassName() const { - return "ImageSource"; -} - std::ostream &ImageSource::writeToStream(std::ostream &stream, bool closing_bracer) const { stream << "{path:" << _filepath << ",channels:" << _channels; if (closing_bracer) From fc863da09f5af060eb6ca6b2a5b7140824cea8a6 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 22:30:27 +0200 Subject: [PATCH 3/7] Update node macros using STONE_OBJECT --- .../Scene/include/Scene/Node/NodeMacros.hpp | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Engine/Scene/include/Scene/Node/NodeMacros.hpp b/Engine/Scene/include/Scene/Node/NodeMacros.hpp index 54a8efc..16f002e 100644 --- a/Engine/Scene/include/Scene/Node/NodeMacros.hpp +++ b/Engine/Scene/include/Scene/Node/NodeMacros.hpp @@ -4,34 +4,47 @@ #include +#define __STONE_NODE_BASE(NewClassName) \ + \ +public: \ + static const std::string nodeClassName; \ + virtual const char *getNodeClassName() const; + /** * @brief Macro to use inside an abstract node class to make the engine reconize this class as a node. */ #define STONE_ABSTRACT_NODE(NewClassName) \ - static const std::string className; \ - virtual const char *getClassName() const override; + STONE_ABSTRACT_OBJECT(NewClassName) \ + __STONE_NODE_BASE(NewClassName) \ + \ +private: + /** * @brief Macro to use inside a node class to make the engine reconize this class as a node. */ -#define STONE_NODE(NewClassName) STONE_ABSTRACT_NODE(NewClassName) +#define STONE_NODE(NewClassName) \ + STONE_OBJECT(NewClassName) \ + __STONE_NODE_BASE(NewClassName) \ + \ +private: /* Cpp Implementations */ #include "Utils/DynamicObjectFactory.hpp" -#define STONE_NODE_BASE_IMPLEMENTATION(NewClassName) \ - const char *NewClassName::getClassName() const { \ - return NewClassName::className.c_str(); \ +#define __STONE_NODE_IMPLEMENTATION_BASE(NewClassName) \ + const char *NewClassName::getNodeClassName() const { \ + return NewClassName::nodeClassName.c_str(); \ } /** * @brief Macro to use inside the cpp implementation of a node class that have used the STONE_NODE macro in its class. */ #define STONE_NODE_IMPLEMENTATION(NewClassName) \ - STONE_NODE_BASE_IMPLEMENTATION(NewClassName) \ + __STONE_NODE_IMPLEMENTATION_BASE(NewClassName) \ \ - const std::string NewClassName::className = [] { \ + const std::string NewClassName::nodeClassName = [] { \ auto constructor = [](const std::string &nodeName) { \ return std::make_shared(nodeName); \ }; \ @@ -45,6 +58,6 @@ * macro in its class. */ #define STONE_ABSTRACT_NODE_IMPLEMENTATION(NewClassName) \ - STONE_NODE_BASE_IMPLEMENTATION(NewClassName) \ + __STONE_NODE_IMPLEMENTATION_BASE(NewClassName) \ \ - const std::string NewClassName::className = #NewClassName; + const std::string NewClassName::nodeClassName = #NewClassName; From 681521934b74701b330d42770181a6cd72d8c1b2 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 22:30:49 +0200 Subject: [PATCH 4/7] Use macros for all stone objects --- Engine/Scene/include/Scene.hpp | 1 - Engine/Scene/include/Scene/Assets/AssetResource.hpp | 3 +-- Engine/Scene/include/Scene/Node/CameraNode.hpp | 6 +++--- .../Scene/include/Scene/Node/InstancedMeshNode.hpp | 2 +- Engine/Scene/include/Scene/Node/LightNode.hpp | 12 ++++++------ Engine/Scene/include/Scene/Node/MeshNode.hpp | 2 +- Engine/Scene/include/Scene/Node/Node.hpp | 2 +- Engine/Scene/include/Scene/Node/PivotNode.hpp | 2 +- Engine/Scene/include/Scene/Node/RenderableNode.hpp | 2 +- Engine/Scene/include/Scene/Node/SkeletonNode.hpp | 2 +- Engine/Scene/include/Scene/Node/SkinMeshNode.hpp | 2 +- Engine/Scene/include/Scene/Node/WorldNode.hpp | 2 +- .../Scene/include/Scene/Renderable/IMeshObject.hpp | 2 ++ Engine/Scene/include/Scene/Renderable/Material.hpp | 9 ++------- Engine/Scene/include/Scene/Renderable/Mesh.hpp | 4 ++++ Engine/Scene/include/Scene/Renderable/Shader.hpp | 7 ++----- Engine/Scene/include/Scene/Renderable/SkinMesh.hpp | 4 ++++ Engine/Scene/include/Scene/Renderable/Texture.hpp | 7 ++----- Engine/Scene/src/Scene/Assets/AssetResource.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/Material.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/Shader.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/Texture.cpp | 4 ---- 22 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Engine/Scene/include/Scene.hpp b/Engine/Scene/include/Scene.hpp index f4d5832..17d723a 100644 --- a/Engine/Scene/include/Scene.hpp +++ b/Engine/Scene/include/Scene.hpp @@ -7,7 +7,6 @@ #include "Scene/Node/LightNode.hpp" #include "Scene/Node/MeshNode.hpp" #include "Scene/Node/Node.hpp" -#include "Scene/Node/NodeMacros.hpp" #include "Scene/Node/PivotNode.hpp" #include "Scene/Node/SkeletonNode.hpp" #include "Scene/Node/SkinMeshNode.hpp" diff --git a/Engine/Scene/include/Scene/Assets/AssetResource.hpp b/Engine/Scene/include/Scene/Assets/AssetResource.hpp index 79547cc..b9ab03f 100644 --- a/Engine/Scene/include/Scene/Assets/AssetResource.hpp +++ b/Engine/Scene/include/Scene/Assets/AssetResource.hpp @@ -11,6 +11,7 @@ namespace Stone::Scene { * @brief Represents a resource that contains meshes, textures, and other assets. */ class AssetResource : public Core::Assets::Resource { + STONE_OBJECT(AssetResource) public: AssetResource() = delete; @@ -20,8 +21,6 @@ class AssetResource : public Core::Assets::Resource { ~AssetResource() override = default; - const char *getClassName() const override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; const std::vector> &getMeshes() const; diff --git a/Engine/Scene/include/Scene/Node/CameraNode.hpp b/Engine/Scene/include/Scene/Node/CameraNode.hpp index 13e7035..c89e6f4 100644 --- a/Engine/Scene/include/Scene/Node/CameraNode.hpp +++ b/Engine/Scene/include/Scene/Node/CameraNode.hpp @@ -15,9 +15,9 @@ namespace Stone::Scene { * This class is abstract and cannot be instantiated directly. Use `PerspectiveCameraNode` or `OrthographicCameraNode` */ class CameraNode : public PivotNode { -public: STONE_ABSTRACT_NODE(CameraNode); +public: explicit CameraNode(const std::string &name = "camera"); CameraNode(const CameraNode &other); @@ -41,9 +41,9 @@ class CameraNode : public PivotNode { }; class PerspectiveCameraNode : public CameraNode { -public: STONE_NODE(PerspectiveCameraNode); +public: explicit PerspectiveCameraNode(const std::string &name = "perspective_camera"); PerspectiveCameraNode(const PerspectiveCameraNode &other); @@ -65,9 +65,9 @@ class PerspectiveCameraNode : public CameraNode { }; class OrthographicCameraNode : public CameraNode { -public: STONE_NODE(OrthographicCameraNode); +public: explicit OrthographicCameraNode(const std::string &name = "orthographic_camera"); OrthographicCameraNode(const OrthographicCameraNode &other); diff --git a/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp b/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp index 36d93ec..13a4ed8 100644 --- a/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp @@ -8,9 +8,9 @@ namespace Stone::Scene { class InstancedMeshNode : public MeshNode { -public: STONE_NODE(InstancedMeshNode); +public: explicit InstancedMeshNode(const std::string &name = "instancedmesh"); InstancedMeshNode(const InstancedMeshNode &other) = default; diff --git a/Engine/Scene/include/Scene/Node/LightNode.hpp b/Engine/Scene/include/Scene/Node/LightNode.hpp index 5bd2e0f..7245533 100644 --- a/Engine/Scene/include/Scene/Node/LightNode.hpp +++ b/Engine/Scene/include/Scene/Node/LightNode.hpp @@ -7,9 +7,9 @@ namespace Stone::Scene { class LightNode : public PivotNode { -public: STONE_ABSTRACT_NODE(LightNode); +public: explicit LightNode(const std::string &name = "light"); LightNode(const LightNode &other) = default; @@ -33,9 +33,9 @@ class LightNode : public PivotNode { }; class AmbientLightNode : public LightNode { -public: STONE_NODE(AmbientLightNode); +public: explicit AmbientLightNode(const std::string &name = "ambientlight"); AmbientLightNode(const AmbientLightNode &other); @@ -45,9 +45,9 @@ class AmbientLightNode : public LightNode { }; class PointLightNode : public LightNode { -public: STONE_NODE(PointLightNode); +public: explicit PointLightNode(const std::string &name = "pointlight"); PointLightNode(const PointLightNode &other); @@ -67,9 +67,9 @@ class PointLightNode : public LightNode { }; class CastingLightNode : public LightNode { -public: STONE_ABSTRACT_NODE(CastingLightNode); +public: explicit CastingLightNode(const std::string &name = "castinglight"); CastingLightNode(const CastingLightNode &other); @@ -104,9 +104,9 @@ class CastingLightNode : public LightNode { }; class DirectionalLightNode : public CastingLightNode { -public: STONE_NODE(DirectionalLightNode); +public: explicit DirectionalLightNode(const std::string &name = "directionallight"); DirectionalLightNode(const DirectionalLightNode &other); @@ -128,9 +128,9 @@ class DirectionalLightNode : public CastingLightNode { }; class SpotLightNode : public CastingLightNode { -public: STONE_NODE(SpotLightNode); +public: explicit SpotLightNode(const std::string &name = "spotlight"); SpotLightNode(const SpotLightNode &other); diff --git a/Engine/Scene/include/Scene/Node/MeshNode.hpp b/Engine/Scene/include/Scene/Node/MeshNode.hpp index 02f37de..f083b9f 100644 --- a/Engine/Scene/include/Scene/Node/MeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/MeshNode.hpp @@ -10,9 +10,9 @@ class IMeshInterface; class Material; class MeshNode : public RenderableNode { -public: STONE_NODE(MeshNode); +public: explicit MeshNode(const std::string &name = "mesh"); MeshNode(const MeshNode &other) = default; diff --git a/Engine/Scene/include/Scene/Node/Node.hpp b/Engine/Scene/include/Scene/Node/Node.hpp index 17166ec..a29ffb9 100644 --- a/Engine/Scene/include/Scene/Node/Node.hpp +++ b/Engine/Scene/include/Scene/Node/Node.hpp @@ -22,9 +22,9 @@ class WorldNode; * the node hierarchy, updating and rendering nodes, and accessing node properties. */ class Node : public Core::Object { -public: STONE_NODE(Node); +public: explicit Node(const std::string &name = "node"); Node(const Node &other) = default; diff --git a/Engine/Scene/include/Scene/Node/PivotNode.hpp b/Engine/Scene/include/Scene/Node/PivotNode.hpp index 39bc947..6d7a38c 100644 --- a/Engine/Scene/include/Scene/Node/PivotNode.hpp +++ b/Engine/Scene/include/Scene/Node/PivotNode.hpp @@ -18,9 +18,9 @@ namespace Stone::Scene { * All transformations applied to the pivot node are also applied to its children but not to its parent. */ class PivotNode : public Node { -public: STONE_NODE(PivotNode); +public: explicit PivotNode(const std::string &name = "pivot"); PivotNode(const PivotNode &other) = default; diff --git a/Engine/Scene/include/Scene/Node/RenderableNode.hpp b/Engine/Scene/include/Scene/Node/RenderableNode.hpp index 3b74ba5..6f6195d 100644 --- a/Engine/Scene/include/Scene/Node/RenderableNode.hpp +++ b/Engine/Scene/include/Scene/Node/RenderableNode.hpp @@ -12,9 +12,9 @@ namespace Stone::Scene { * @brief Represents a node that can be rendered. */ class RenderableNode : public Node, public IRenderable { -public: STONE_ABSTRACT_NODE(RenderableNode) +public: explicit RenderableNode(const std::string &name = "renderable"); RenderableNode(const RenderableNode &other) = default; diff --git a/Engine/Scene/include/Scene/Node/SkeletonNode.hpp b/Engine/Scene/include/Scene/Node/SkeletonNode.hpp index debe251..6127aeb 100644 --- a/Engine/Scene/include/Scene/Node/SkeletonNode.hpp +++ b/Engine/Scene/include/Scene/Node/SkeletonNode.hpp @@ -17,9 +17,9 @@ class PivotNode; * Each bone is represented by a pivot node and its rest pose. */ class SkeletonNode : public Node { -public: STONE_NODE(SkeletonNode); +public: struct Bone { std::weak_ptr pivot; glm::mat4 inverseBindMatrix; diff --git a/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp b/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp index ffe6f54..a540364 100644 --- a/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp @@ -11,9 +11,9 @@ class SkeletonNode; class Material; class SkinMeshNode : public RenderableNode { -public: STONE_NODE(SkinMeshNode); +public: explicit SkinMeshNode(const std::string &name = "skinmesh"); SkinMeshNode(const SkinMeshNode &other) = default; diff --git a/Engine/Scene/include/Scene/Node/WorldNode.hpp b/Engine/Scene/include/Scene/Node/WorldNode.hpp index 8b525e7..7ef0c77 100644 --- a/Engine/Scene/include/Scene/Node/WorldNode.hpp +++ b/Engine/Scene/include/Scene/Node/WorldNode.hpp @@ -15,9 +15,9 @@ class CameraNode; * The `WorldNode` class is the root node of the scene graph. */ class WorldNode : public Node { -public: STONE_NODE(WorldNode); +public: static std::shared_ptr create(); explicit WorldNode(const std::string &name = "world"); diff --git a/Engine/Scene/include/Scene/Renderable/IMeshObject.hpp b/Engine/Scene/include/Scene/Renderable/IMeshObject.hpp index a38ecc0..51d708a 100644 --- a/Engine/Scene/include/Scene/Renderable/IMeshObject.hpp +++ b/Engine/Scene/include/Scene/Renderable/IMeshObject.hpp @@ -17,6 +17,8 @@ class Material; * @see StaticMesh, DynamicMesh, SkinMesh, SkinMeshSource */ class IMeshObject : public Core::Object, public IRenderable { + STONE_ABSTRACT_OBJECT(IMeshObject) + public: /** * @brief Destructor diff --git a/Engine/Scene/include/Scene/Renderable/Material.hpp b/Engine/Scene/include/Scene/Renderable/Material.hpp index a84187c..bfd6922 100644 --- a/Engine/Scene/include/Scene/Renderable/Material.hpp +++ b/Engine/Scene/include/Scene/Renderable/Material.hpp @@ -21,19 +21,14 @@ class Shader; * to configure the appearance of rendered objects. */ class Material : public Core::Object, public IRenderable { + STONE_OBJECT(Material) + public: Material() = default; Material(const Material &other) = default; ~Material() override = default; - /** - * @brief Get the class name of the Material object. - * - * @return The class name as a null-terminated string. - */ - const char *getClassName() const override; - /** * @brief Write the Material object to an output stream. * diff --git a/Engine/Scene/include/Scene/Renderable/Mesh.hpp b/Engine/Scene/include/Scene/Renderable/Mesh.hpp index 8e68b34..937eaa2 100644 --- a/Engine/Scene/include/Scene/Renderable/Mesh.hpp +++ b/Engine/Scene/include/Scene/Renderable/Mesh.hpp @@ -23,6 +23,8 @@ class IMeshInterface : public IMeshObject {}; * It provides functionality for managing vertices and indices of the mesh. */ class DynamicMesh : public IMeshInterface { + STONE_OBJECT(DynamicMesh); + public: DynamicMesh() = default; DynamicMesh(const DynamicMesh &other) = default; @@ -90,6 +92,8 @@ class DynamicMesh : public IMeshInterface { * It is generated from a dynamic mesh. */ class StaticMesh : public IMeshInterface { + STONE_OBJECT(StaticMesh); + public: StaticMesh() = default; StaticMesh(const StaticMesh &other) = default; diff --git a/Engine/Scene/include/Scene/Renderable/Shader.hpp b/Engine/Scene/include/Scene/Renderable/Shader.hpp index ab9585e..1fa5f97 100644 --- a/Engine/Scene/include/Scene/Renderable/Shader.hpp +++ b/Engine/Scene/include/Scene/Renderable/Shader.hpp @@ -13,6 +13,8 @@ namespace Stone::Scene { * @brief The Shader class represents a shader used in rendering. */ class Shader : public Core::Object, public IRenderable { + STONE_OBJECT(Shader); + public: enum class ContentType { SourceCode, /** The content is the full shader code in a readable shading language (cf. `.glsl`, `.metal`) */ @@ -28,11 +30,6 @@ class Shader : public Core::Object, public IRenderable { ~Shader() override = default; - /** - * @brief Get the class name of the Shader object. - */ - const char *getClassName() const override; - /** * @brief Write the Shader object to an output stream. * diff --git a/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp b/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp index eadca5b..5519af3 100644 --- a/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp +++ b/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp @@ -17,6 +17,8 @@ namespace Stone::Scene { class ISkinMeshInterface : public IMeshObject {}; class DynamicSkinMesh : public ISkinMeshInterface { + STONE_OBJECT(DynamicSkinMesh); + public: DynamicSkinMesh() = default; DynamicSkinMesh(const DynamicSkinMesh &other) = default; @@ -78,6 +80,8 @@ class DynamicSkinMesh : public ISkinMeshInterface { class StaticSkinMesh : public ISkinMeshInterface { + STONE_OBJECT(StaticSkinMesh); + public: StaticSkinMesh() = default; StaticSkinMesh(const StaticSkinMesh &other) = default; diff --git a/Engine/Scene/include/Scene/Renderable/Texture.hpp b/Engine/Scene/include/Scene/Renderable/Texture.hpp index df06d3d..41900f7 100644 --- a/Engine/Scene/include/Scene/Renderable/Texture.hpp +++ b/Engine/Scene/include/Scene/Renderable/Texture.hpp @@ -28,17 +28,14 @@ enum class TextureWrap { * @brief The Texture class represents a texture used in rendering. */ class Texture : public Core::Object, public IRenderable { + STONE_OBJECT(Texture); + public: Texture() = default; Texture(const Texture &other) = default; ~Texture() override = default; - /** - * @brief Get the class name of the Texture object. - */ - const char *getClassName() const override; - /** * @brief Write the Texture object to an output stream. * diff --git a/Engine/Scene/src/Scene/Assets/AssetResource.cpp b/Engine/Scene/src/Scene/Assets/AssetResource.cpp index dde7c34..2e4aeb4 100644 --- a/Engine/Scene/src/Scene/Assets/AssetResource.cpp +++ b/Engine/Scene/src/Scene/Assets/AssetResource.cpp @@ -15,10 +15,6 @@ AssetResource::AssetResource(const std::shared_ptr &bundle loadData(); }; -const char *AssetResource::getClassName() const { - return "AssetResource"; -} - std::ostream &AssetResource::writeToStream(std::ostream &stream, bool closing_bracer) const { Core::Assets::Resource::writeToStream(stream, false); stream << ",meshes:["; diff --git a/Engine/Scene/src/Scene/Renderable/Material.cpp b/Engine/Scene/src/Scene/Renderable/Material.cpp index 4eccca9..b0efe6a 100644 --- a/Engine/Scene/src/Scene/Renderable/Material.cpp +++ b/Engine/Scene/src/Scene/Renderable/Material.cpp @@ -8,10 +8,6 @@ namespace Stone::Scene { -const char *Material::getClassName() const { - return "Material"; -} - std::ostream &Material::writeToStream(std::ostream &stream, bool closing_bracer) const { Object::writeToStream(stream, false); stream << ",textures:{"; diff --git a/Engine/Scene/src/Scene/Renderable/Shader.cpp b/Engine/Scene/src/Scene/Renderable/Shader.cpp index 5d86573..7e5a26e 100644 --- a/Engine/Scene/src/Scene/Renderable/Shader.cpp +++ b/Engine/Scene/src/Scene/Renderable/Shader.cpp @@ -26,10 +26,6 @@ Shader::Shader(ContentType contentType, std::string content) : Object(), IRenderable(), _contentType(contentType), _content(std::move(content)) { } -const char *Shader::getClassName() const { - return "Shader"; -} - std::ostream &Shader::writeToStream(std::ostream &stream, bool closing_bracer) const { Object::writeToStream(stream, false); stream << ",function:\"" << _function << '"'; diff --git a/Engine/Scene/src/Scene/Renderable/Texture.cpp b/Engine/Scene/src/Scene/Renderable/Texture.cpp index 717dbef..fa07970 100644 --- a/Engine/Scene/src/Scene/Renderable/Texture.cpp +++ b/Engine/Scene/src/Scene/Renderable/Texture.cpp @@ -7,10 +7,6 @@ namespace Stone::Scene { -const char *Texture::getClassName() const { - return "Texture"; -} - std::ostream &Texture::writeToStream(std::ostream &stream, bool closing_bracer) const { Object::writeToStream(stream, false); stream << ",image:" << *_image; From f2bdb3e4a69e3dc518284feb1c5d87e58c485b3d Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 22:31:00 +0200 Subject: [PATCH 5/7] Update examples using macros --- examples/scene_usage/test_Node.hpp | 6 +++--- examples/scop/main.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/scene_usage/test_Node.hpp b/examples/scene_usage/test_Node.hpp index 5800854..5236d01 100644 --- a/examples/scene_usage/test_Node.hpp +++ b/examples/scene_usage/test_Node.hpp @@ -71,10 +71,10 @@ void testNode() { // getc(stdin); } -template -std::shared_ptr makeNode(const std::string &type, const std::string &name) { +template +std::shared_ptr makeNode(const std::string &type, Args... args) { return std::dynamic_pointer_cast( - Stone::DynamicObjectFactory::getInstance().create(type, name)); + Stone::DynamicObjectFactory::getInstance().create(type, args...)); } void testNodeDynamic() { diff --git a/examples/scop/main.cpp b/examples/scop/main.cpp index 9443a11..c49b569 100644 --- a/examples/scop/main.cpp +++ b/examples/scop/main.cpp @@ -13,9 +13,9 @@ #include class RotatingNode : public Stone::Scene::PivotNode { -public: STONE_NODE(RotatingNode) +public: RotatingNode(const std::string &name = "rotating_node") : PivotNode(name) { } From ad8bbce050ae24ef5bdcea1939d7385e67adcf97 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 23:15:48 +0200 Subject: [PATCH 6/7] Update renderable casting using class hash code --- .../Vulkan/VulkanRenderer_ISceneRenderer.cpp | 2 +- .../include/Scene/RendererObjectManager.hpp | 11 +++++++ .../Scene/src/Scene/RendererObjectManager.cpp | 29 +++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Engine/Render/src/Render/Vulkan/VulkanRenderer_ISceneRenderer.cpp b/Engine/Render/src/Render/Vulkan/VulkanRenderer_ISceneRenderer.cpp index 8211aa0..425ff21 100644 --- a/Engine/Render/src/Render/Vulkan/VulkanRenderer_ISceneRenderer.cpp +++ b/Engine/Render/src/Render/Vulkan/VulkanRenderer_ISceneRenderer.cpp @@ -17,7 +17,7 @@ void VulkanRenderer::updateDataForWorld(const std::shared_ptr world->traverseTopDown([&manager](const std::shared_ptr &node) { auto renderElement = std::dynamic_pointer_cast(node); if (renderElement && renderElement->isDirty()) { - renderElement->updateRenderObject(manager); + manager.updateRenderable(node); } }); } diff --git a/Engine/Scene/include/Scene/RendererObjectManager.hpp b/Engine/Scene/include/Scene/RendererObjectManager.hpp index 666af82..0467c0f 100644 --- a/Engine/Scene/include/Scene/RendererObjectManager.hpp +++ b/Engine/Scene/include/Scene/RendererObjectManager.hpp @@ -5,6 +5,10 @@ #include "Scene/Renderable/IRenderable.hpp" #include "SceneTypes.hpp" +namespace Stone::Core { +class Object; +} + namespace Stone::Scene { /** @@ -20,6 +24,13 @@ class RendererObjectManager { RendererObjectManager() = default; virtual ~RendererObjectManager() = default; + /** + * Updates the renderable object with the given node. + * + * @param node The shared pointer to the renderable object. + */ + virtual void updateRenderable(const std::shared_ptr &renderable); + /** * @brief Updates the renderer data for a given mesh node. * @param meshNode The mesh node to be updated. diff --git a/Engine/Scene/src/Scene/RendererObjectManager.cpp b/Engine/Scene/src/Scene/RendererObjectManager.cpp index 64f23a2..0161cf8 100644 --- a/Engine/Scene/src/Scene/RendererObjectManager.cpp +++ b/Engine/Scene/src/Scene/RendererObjectManager.cpp @@ -6,11 +6,34 @@ namespace Stone::Scene { +using CastFunction = std::function &)>; + +#define CASTED_FUNCTION_MAP_ENTRY(ClassName) \ + {ClassName::StaticHashCode(), \ + [](RendererObjectManager &manager, const std::shared_ptr &renderable) { \ + manager.update##ClassName(std::static_pointer_cast(renderable)); \ + }} + +const std::unordered_map updateCastedFunctions = { + CASTED_FUNCTION_MAP_ENTRY(MeshNode), CASTED_FUNCTION_MAP_ENTRY(InstancedMeshNode), + CASTED_FUNCTION_MAP_ENTRY(SkinMeshNode), CASTED_FUNCTION_MAP_ENTRY(Material), + CASTED_FUNCTION_MAP_ENTRY(DynamicMesh), CASTED_FUNCTION_MAP_ENTRY(StaticMesh), + CASTED_FUNCTION_MAP_ENTRY(DynamicSkinMesh), CASTED_FUNCTION_MAP_ENTRY(StaticSkinMesh), + CASTED_FUNCTION_MAP_ENTRY(Texture), CASTED_FUNCTION_MAP_ENTRY(Shader), +}; + +void RendererObjectManager::updateRenderable(const std::shared_ptr &renderable) { + auto it = updateCastedFunctions.find(renderable->getClassHashCode()); + if (it != updateCastedFunctions.end()) { + it->second(*this, renderable); + } +} + void RendererObjectManager::updateMeshNode(const std::shared_ptr &meshNode) { if (meshNode->getMaterial() && meshNode->getMaterial()->isDirty()) updateMaterial(meshNode->getMaterial()); if (meshNode->getMesh() && meshNode->getMesh()->isDirty()) - meshNode->getMesh()->updateRenderObject(*this); + updateRenderable(meshNode->getMesh()); meshNode->markUndirty(); } @@ -18,7 +41,7 @@ void RendererObjectManager::updateInstancedMeshNode(const std::shared_ptrgetMaterial() && instancedMeshNode->getMaterial()->isDirty()) updateMaterial(instancedMeshNode->getMaterial()); if (instancedMeshNode->getMesh() && instancedMeshNode->getMesh()->isDirty()) - instancedMeshNode->getMesh()->updateRenderObject(*this); + updateRenderable(instancedMeshNode->getMesh()); instancedMeshNode->markUndirty(); } @@ -26,7 +49,7 @@ void RendererObjectManager::updateSkinMeshNode(const std::shared_ptrgetMaterial() && skinMeshNode->getMaterial()->isDirty()) updateMaterial(skinMeshNode->getMaterial()); if (skinMeshNode->getSkinMesh() && skinMeshNode->getSkinMesh()->isDirty()) - skinMeshNode->getSkinMesh()->updateRenderObject(*this); + updateRenderable(skinMeshNode->getSkinMesh()); skinMeshNode->markUndirty(); } From dd0fc7a8fde994ea933d98d1ec377857ea81e002 Mon Sep 17 00:00:00 2001 From: amasson Date: Mon, 2 Sep 2024 23:16:13 +0200 Subject: [PATCH 7/7] remove useless IRenderable::updateRenderObject method --- .../Scene/include/Scene/Node/InstancedMeshNode.hpp | 2 -- Engine/Scene/include/Scene/Node/MeshNode.hpp | 2 -- Engine/Scene/include/Scene/Node/SkinMeshNode.hpp | 2 -- .../Scene/include/Scene/Renderable/IRenderable.hpp | 10 ---------- Engine/Scene/include/Scene/Renderable/Material.hpp | 7 ------- Engine/Scene/include/Scene/Renderable/Mesh.hpp | 14 -------------- Engine/Scene/include/Scene/Renderable/Shader.hpp | 7 ------- Engine/Scene/include/Scene/Renderable/SkinMesh.hpp | 14 -------------- Engine/Scene/include/Scene/Renderable/Texture.hpp | 7 ------- Engine/Scene/src/Scene/Node/InstancedMeshNode.cpp | 4 ---- Engine/Scene/src/Scene/Node/MeshNode.cpp | 4 ---- Engine/Scene/src/Scene/Node/SkinMeshNode.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/Material.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/Mesh.cpp | 8 -------- Engine/Scene/src/Scene/Renderable/Shader.cpp | 4 ---- Engine/Scene/src/Scene/Renderable/SkinMesh.cpp | 8 -------- Engine/Scene/src/Scene/Renderable/Texture.cpp | 4 ---- 17 files changed, 105 deletions(-) diff --git a/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp b/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp index 13a4ed8..b6f7eb3 100644 --- a/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/InstancedMeshNode.hpp @@ -16,8 +16,6 @@ class InstancedMeshNode : public MeshNode { ~InstancedMeshNode() override = default; - void updateRenderObject(RendererObjectManager &manager) override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; void addInstance(const Transform3D &transform); diff --git a/Engine/Scene/include/Scene/Node/MeshNode.hpp b/Engine/Scene/include/Scene/Node/MeshNode.hpp index f083b9f..2df3850 100644 --- a/Engine/Scene/include/Scene/Node/MeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/MeshNode.hpp @@ -18,8 +18,6 @@ class MeshNode : public RenderableNode { ~MeshNode() override = default; - void updateRenderObject(RendererObjectManager &manager) override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; [[nodiscard]] std::shared_ptr getMesh() const; diff --git a/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp b/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp index a540364..3bd7779 100644 --- a/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp +++ b/Engine/Scene/include/Scene/Node/SkinMeshNode.hpp @@ -19,8 +19,6 @@ class SkinMeshNode : public RenderableNode { ~SkinMeshNode() override = default; - void updateRenderObject(RendererObjectManager &manager) override; - std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; [[nodiscard]] std::shared_ptr getSkinMesh() const; diff --git a/Engine/Scene/include/Scene/Renderable/IRenderable.hpp b/Engine/Scene/include/Scene/Renderable/IRenderable.hpp index 0361baa..4d0ecf5 100644 --- a/Engine/Scene/include/Scene/Renderable/IRenderable.hpp +++ b/Engine/Scene/include/Scene/Renderable/IRenderable.hpp @@ -50,16 +50,6 @@ class IRenderable { virtual ~IRenderable() = default; - /** - * @brief Update the render object associated with the render element - * - * This function will call the correct method in the renderer object manager to update the associated renderer - * object. - * - * @param manager The renderer object manager - */ - virtual void updateRenderObject(RendererObjectManager &manager) = 0; - /** * @brief Check if the render element is dirty */ diff --git a/Engine/Scene/include/Scene/Renderable/Material.hpp b/Engine/Scene/include/Scene/Renderable/Material.hpp index bfd6922..6f09d4c 100644 --- a/Engine/Scene/include/Scene/Renderable/Material.hpp +++ b/Engine/Scene/include/Scene/Renderable/Material.hpp @@ -38,13 +38,6 @@ class Material : public Core::Object, public IRenderable { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Update the render object associated with the Material. - * - * @param manager The RendererObjectManager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Set a texture parameter for the Material. * diff --git a/Engine/Scene/include/Scene/Renderable/Mesh.hpp b/Engine/Scene/include/Scene/Renderable/Mesh.hpp index 937eaa2..90a9403 100644 --- a/Engine/Scene/include/Scene/Renderable/Mesh.hpp +++ b/Engine/Scene/include/Scene/Renderable/Mesh.hpp @@ -40,13 +40,6 @@ class DynamicMesh : public IMeshInterface { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Updates the render object associated with the mesh. - * - * @param manager The renderer object manager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Retrieves the vertices of the mesh. * @@ -109,13 +102,6 @@ class StaticMesh : public IMeshInterface { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Updates the render object associated with the mesh. - * - * @param manager The renderer object manager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Retrieves the source mesh being used to generate the static mesh. * It's expected to be a nullptr once the buffers are initialized. diff --git a/Engine/Scene/include/Scene/Renderable/Shader.hpp b/Engine/Scene/include/Scene/Renderable/Shader.hpp index 1fa5f97..723b0f5 100644 --- a/Engine/Scene/include/Scene/Renderable/Shader.hpp +++ b/Engine/Scene/include/Scene/Renderable/Shader.hpp @@ -39,13 +39,6 @@ class Shader : public Core::Object, public IRenderable { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Update the render object associated with the Texture. - * - * @param manager The RendererObjectManager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Get the content of the shader paired with its type. See `Stone::Scene::Shader::ContentType` for more * information. diff --git a/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp b/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp index 5519af3..1a9f668 100644 --- a/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp +++ b/Engine/Scene/include/Scene/Renderable/SkinMesh.hpp @@ -34,13 +34,6 @@ class DynamicSkinMesh : public ISkinMeshInterface { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Updates the render object using the specified RendererObjectManager. - * - * @param manager The RendererObjectManager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Returns a const reference to the vector of WeightVertex objects representing the vertices of the mesh. * @@ -97,13 +90,6 @@ class StaticSkinMesh : public ISkinMeshInterface { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Updates the render object using the specified RendererObjectManager. - * - * @param manager The RendererObjectManager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Retrieves the source mesh used to generate the static mesh. * diff --git a/Engine/Scene/include/Scene/Renderable/Texture.hpp b/Engine/Scene/include/Scene/Renderable/Texture.hpp index 41900f7..0fc3eff 100644 --- a/Engine/Scene/include/Scene/Renderable/Texture.hpp +++ b/Engine/Scene/include/Scene/Renderable/Texture.hpp @@ -45,13 +45,6 @@ class Texture : public Core::Object, public IRenderable { */ std::ostream &writeToStream(std::ostream &stream, bool closing_bracer) const override; - /** - * @brief Update the render object associated with the Texture. - * - * @param manager The RendererObjectManager used to update the render object. - */ - void updateRenderObject(RendererObjectManager &manager) override; - /** * @brief Set the image associated with the Texture. * diff --git a/Engine/Scene/src/Scene/Node/InstancedMeshNode.cpp b/Engine/Scene/src/Scene/Node/InstancedMeshNode.cpp index acba149..f685d42 100644 --- a/Engine/Scene/src/Scene/Node/InstancedMeshNode.cpp +++ b/Engine/Scene/src/Scene/Node/InstancedMeshNode.cpp @@ -11,10 +11,6 @@ STONE_NODE_IMPLEMENTATION(InstancedMeshNode) InstancedMeshNode::InstancedMeshNode(const std::string &name) : MeshNode(name), _instancesTransforms() { } -void InstancedMeshNode::updateRenderObject(RendererObjectManager &manager) { - manager.updateInstancedMeshNode(std::dynamic_pointer_cast(shared_from_this())); -} - std::ostream &InstancedMeshNode::writeToStream(std::ostream &stream, bool closing_bracer) const { MeshNode::writeToStream(stream, false); stream << ",instances:" << _instancesTransforms.size(); diff --git a/Engine/Scene/src/Scene/Node/MeshNode.cpp b/Engine/Scene/src/Scene/Node/MeshNode.cpp index 1f73d03..4e2ef29 100644 --- a/Engine/Scene/src/Scene/Node/MeshNode.cpp +++ b/Engine/Scene/src/Scene/Node/MeshNode.cpp @@ -13,10 +13,6 @@ STONE_NODE_IMPLEMENTATION(MeshNode) MeshNode::MeshNode(const std::string &name) : RenderableNode(name), _mesh(nullptr), _material(nullptr) { } -void MeshNode::updateRenderObject(RendererObjectManager &manager) { - manager.updateMeshNode(std::dynamic_pointer_cast(shared_from_this())); -} - std::ostream &MeshNode::writeToStream(std::ostream &stream, bool closing_bracer) const { RenderableNode::writeToStream(stream, false); stream << ",mesh:" << (_mesh ? std::to_string(_mesh->getId()) : "null"); diff --git a/Engine/Scene/src/Scene/Node/SkinMeshNode.cpp b/Engine/Scene/src/Scene/Node/SkinMeshNode.cpp index 5d54499..c2f3f7d 100644 --- a/Engine/Scene/src/Scene/Node/SkinMeshNode.cpp +++ b/Engine/Scene/src/Scene/Node/SkinMeshNode.cpp @@ -14,10 +14,6 @@ STONE_NODE_IMPLEMENTATION(SkinMeshNode) SkinMeshNode::SkinMeshNode(const std::string &name) : RenderableNode(name), _mesh(), _material(), _skeleton() { } -void SkinMeshNode::updateRenderObject(RendererObjectManager &manager) { - manager.updateSkinMeshNode(std::dynamic_pointer_cast(shared_from_this())); -} - std::ostream &SkinMeshNode::writeToStream(std::ostream &stream, bool closing_bracer) const { RenderableNode::writeToStream(stream, false); stream << ",mesh:" << (_mesh == nullptr ? "null" : std::to_string(_mesh->getId())); diff --git a/Engine/Scene/src/Scene/Renderable/Material.cpp b/Engine/Scene/src/Scene/Renderable/Material.cpp index b0efe6a..5f8ebe2 100644 --- a/Engine/Scene/src/Scene/Renderable/Material.cpp +++ b/Engine/Scene/src/Scene/Renderable/Material.cpp @@ -25,10 +25,6 @@ std::ostream &Material::writeToStream(std::ostream &stream, bool closing_bracer) return stream; } -void Material::updateRenderObject(RendererObjectManager &manager) { - manager.updateMaterial(std::static_pointer_cast(shared_from_this())); -} - void Material::setTextureParameter(const std::string &name, std::shared_ptr texture) { _textures[name] = std::move(texture); markDirty(); diff --git a/Engine/Scene/src/Scene/Renderable/Mesh.cpp b/Engine/Scene/src/Scene/Renderable/Mesh.cpp index f8e5f2d..7695e03 100644 --- a/Engine/Scene/src/Scene/Renderable/Mesh.cpp +++ b/Engine/Scene/src/Scene/Renderable/Mesh.cpp @@ -15,10 +15,6 @@ std::ostream &DynamicMesh::writeToStream(std::ostream &stream, bool closing_brac return stream; } -void DynamicMesh::updateRenderObject(RendererObjectManager &manager) { - manager.updateDynamicMesh(std::static_pointer_cast(shared_from_this())); -} - const std::vector &DynamicMesh::getVertices() const { return _vertices; } @@ -46,10 +42,6 @@ std::ostream &StaticMesh::writeToStream(std::ostream &stream, bool closing_brace return stream; } -void StaticMesh::updateRenderObject(RendererObjectManager &manager) { - manager.updateStaticMesh(std::static_pointer_cast(shared_from_this())); -} - const std::shared_ptr &StaticMesh::getSourceMesh() const { return _dynamicMesh; } diff --git a/Engine/Scene/src/Scene/Renderable/Shader.cpp b/Engine/Scene/src/Scene/Renderable/Shader.cpp index 7e5a26e..3c07a11 100644 --- a/Engine/Scene/src/Scene/Renderable/Shader.cpp +++ b/Engine/Scene/src/Scene/Renderable/Shader.cpp @@ -47,10 +47,6 @@ std::ostream &Shader::writeToStream(std::ostream &stream, bool closing_bracer) c return stream; } -void Shader::updateRenderObject(RendererObjectManager &manager) { - manager.updateShader(std::static_pointer_cast(shared_from_this())); -} - std::pair Shader::getContent() const { return {_contentType, _content}; } diff --git a/Engine/Scene/src/Scene/Renderable/SkinMesh.cpp b/Engine/Scene/src/Scene/Renderable/SkinMesh.cpp index 1f61d96..4789075 100644 --- a/Engine/Scene/src/Scene/Renderable/SkinMesh.cpp +++ b/Engine/Scene/src/Scene/Renderable/SkinMesh.cpp @@ -16,10 +16,6 @@ std::ostream &DynamicSkinMesh::writeToStream(std::ostream &stream, bool closing_ return stream; } -void DynamicSkinMesh::updateRenderObject(RendererObjectManager &manager) { - manager.updateDynamicSkinMesh(std::static_pointer_cast(shared_from_this())); -} - const std::vector &DynamicSkinMesh::getVertices() const { return _vertices; } @@ -47,10 +43,6 @@ std::ostream &StaticSkinMesh::writeToStream(std::ostream &stream, bool closing_b return stream; } -void StaticSkinMesh::updateRenderObject(RendererObjectManager &manager) { - manager.updateStaticSkinMesh(std::static_pointer_cast(shared_from_this())); -} - const std::shared_ptr &StaticSkinMesh::getSourceMesh() const { return _dynamicMesh; } diff --git a/Engine/Scene/src/Scene/Renderable/Texture.cpp b/Engine/Scene/src/Scene/Renderable/Texture.cpp index fa07970..0d0f2f4 100644 --- a/Engine/Scene/src/Scene/Renderable/Texture.cpp +++ b/Engine/Scene/src/Scene/Renderable/Texture.cpp @@ -15,10 +15,6 @@ std::ostream &Texture::writeToStream(std::ostream &stream, bool closing_bracer) return stream; } -void Texture::updateRenderObject(RendererObjectManager &manager) { - manager.updateTexture(std::static_pointer_cast(shared_from_this())); -} - void Texture::setImage(const std::shared_ptr &image) { _image = image; markDirty();