From 12b6275a80636995a009a2ba798a19a97e0574ab Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 30 Sep 2021 12:49:16 -0400 Subject: [PATCH 1/3] Variadic and template specializations for serialize and deserialize I split the serialize and deserialize functions into template specializations. Then I used the `AllComponents{}` variadic templates to call each of the templated specializations. The catch all / default function is deleted so you get a compile time error if you forgot to handle one of the Components. add tag to Serialize All. add comments add static Correct spelling mistake --- Hazel/src/Hazel/Scene/SceneSerializer.cpp | 417 ++++++++++++++-------- 1 file changed, 260 insertions(+), 157 deletions(-) diff --git a/Hazel/src/Hazel/Scene/SceneSerializer.cpp b/Hazel/src/Hazel/Scene/SceneSerializer.cpp index 2630123cb..a7129a53b 100644 --- a/Hazel/src/Hazel/Scene/SceneSerializer.cpp +++ b/Hazel/src/Hazel/Scene/SceneSerializer.cpp @@ -88,6 +88,10 @@ namespace YAML { } namespace Hazel { + static void SerializeAllEntityComponents(YAML::Emitter& out, Entity entity); + + static void DeserializeAllEntryComponents(YAML::detail::iterator_value& entity, Entity& deserializedEntity); + YAML::Emitter& operator<<(YAML::Emitter& out, const glm::vec2& v) { out << YAML::Flow; @@ -113,9 +117,9 @@ namespace Hazel { { switch (bodyType) { - case Rigidbody2DComponent::BodyType::Static: return "Static"; - case Rigidbody2DComponent::BodyType::Dynamic: return "Dynamic"; - case Rigidbody2DComponent::BodyType::Kinematic: return "Kinematic"; + case Rigidbody2DComponent::BodyType::Static: return "Static"; + case Rigidbody2DComponent::BodyType::Dynamic: return "Dynamic"; + case Rigidbody2DComponent::BodyType::Kinematic: return "Kinematic"; } HZ_CORE_ASSERT(false, "Unknown body type"); @@ -127,7 +131,7 @@ namespace Hazel { if (bodyTypeString == "Static") return Rigidbody2DComponent::BodyType::Static; if (bodyTypeString == "Dynamic") return Rigidbody2DComponent::BodyType::Dynamic; if (bodyTypeString == "Kinematic") return Rigidbody2DComponent::BodyType::Kinematic; - + HZ_CORE_ASSERT(false, "Unknown body type"); return Rigidbody2DComponent::BodyType::Static; } @@ -144,6 +148,114 @@ namespace Hazel { out << YAML::BeginMap; // Entity out << YAML::Key << "Entity" << YAML::Value << entity.GetUUID(); + // Serialize components (except IDComponent) + SerializeAllEntityComponents(out,entity); + + if (entity.HasComponent()) + { + out << YAML::Key << "CircleCollider2DComponent"; + out << YAML::BeginMap; // CircleCollider2DComponent + + auto& cc2dComponent = entity.GetComponent(); + out << YAML::Key << "Offset" << YAML::Value << cc2dComponent.Offset; + out << YAML::Key << "Radius" << YAML::Value << cc2dComponent.Radius; + out << YAML::Key << "Density" << YAML::Value << cc2dComponent.Density; + out << YAML::Key << "Friction" << YAML::Value << cc2dComponent.Friction; + out << YAML::Key << "Restitution" << YAML::Value << cc2dComponent.Restitution; + out << YAML::Key << "RestitutionThreshold" << YAML::Value << cc2dComponent.RestitutionThreshold; + + out << YAML::EndMap; // CircleCollider2DComponent + } + + out << YAML::EndMap; // Entity + } + + void SceneSerializer::Serialize(const std::string& filepath) + { + YAML::Emitter out; + out << YAML::BeginMap; + out << YAML::Key << "Scene" << YAML::Value << "Untitled"; + out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; + m_Scene->m_Registry.each([&](auto entityID) + { + Entity entity = { entityID, m_Scene.get() }; + if (!entity) + return; + + SerializeEntity(out, entity); + }); + out << YAML::EndSeq; + out << YAML::EndMap; + + std::ofstream fout(filepath); + fout << out.c_str(); + } + + void SceneSerializer::SerializeRuntime(const std::string& filepath) + { + // Not implemented + HZ_CORE_ASSERT(false); + } + + bool SceneSerializer::Deserialize(const std::string& filepath) + { + YAML::Node data; + try + { + data = YAML::LoadFile(filepath); + } + catch (YAML::ParserException e) + { + HZ_CORE_ERROR("Failed to load .hazel file '{0}'\n {1}", filepath, e.what()); + return false; + } + + if (!data["Scene"]) + return false; + + std::string sceneName = data["Scene"].as(); + HZ_CORE_TRACE("Deserializing scene '{0}'", sceneName); + + auto entities = data["Entities"]; + if (entities) + { + for (auto entity : entities) + { + uint64_t uuid = entity["Entity"].as(); + + std::string name; + auto tagComponent = entity["TagComponent"]; + if (tagComponent) + name = tagComponent["Tag"].as(); + + HZ_CORE_TRACE("Deserialized entity with ID = {0}, name = {1}", uuid, name); + + Entity deserializedEntity = m_Scene->CreateEntityWithUUID(uuid, name); + + // Deserialize components (except IDComponent and TagComponent) + DeserializeAllEntryComponents(entity, deserializedEntity); + } + } + + return true; + } + + bool SceneSerializer::DeserializeRuntime(const std::string& filepath) + { + // Not implemented + HZ_CORE_ASSERT(false); + return false; + } + + template + static void SerializeEntityComponent(YAML::Emitter&, Entity) = delete; + + template + void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity&) = delete; + + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "TagComponent"; @@ -154,7 +266,11 @@ namespace Hazel { out << YAML::EndMap; // TagComponent } + } + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "TransformComponent"; @@ -168,6 +284,25 @@ namespace Hazel { out << YAML::EndMap; // TransformComponent } + } + + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto transformComponent = entity["TransformComponent"]; + if (transformComponent) + { + // Entities always have transforms + auto& tc = deserializedEntity.GetComponent(); + tc.Translation = transformComponent["Translation"].as(); + tc.Rotation = transformComponent["Rotation"].as(); + tc.Scale = transformComponent["Scale"].as(); + } + } + + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "CameraComponent"; @@ -192,7 +327,35 @@ namespace Hazel { out << YAML::EndMap; // CameraComponent } + } + + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto cameraComponent = entity["CameraComponent"]; + if (cameraComponent) + { + auto& cc = deserializedEntity.AddComponent(); + + auto& cameraProps = cameraComponent["Camera"]; + cc.Camera.SetProjectionType((SceneCamera::ProjectionType)cameraProps["ProjectionType"].as()); + + cc.Camera.SetPerspectiveVerticalFOV(cameraProps["PerspectiveFOV"].as()); + cc.Camera.SetPerspectiveNearClip(cameraProps["PerspectiveNear"].as()); + cc.Camera.SetPerspectiveFarClip(cameraProps["PerspectiveFar"].as()); + cc.Camera.SetOrthographicSize(cameraProps["OrthographicSize"].as()); + cc.Camera.SetOrthographicNearClip(cameraProps["OrthographicNear"].as()); + cc.Camera.SetOrthographicFarClip(cameraProps["OrthographicFar"].as()); + + cc.Primary = cameraComponent["Primary"].as(); + cc.FixedAspectRatio = cameraComponent["FixedAspectRatio"].as(); + } + } + + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "SpriteRendererComponent"; @@ -200,10 +363,28 @@ namespace Hazel { auto& spriteRendererComponent = entity.GetComponent(); out << YAML::Key << "Color" << YAML::Value << spriteRendererComponent.Color; + out << YAML::Key << "TilingFactor" << YAML::Value << spriteRendererComponent.TilingFactor; out << YAML::EndMap; // SpriteRendererComponent } + } + + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto spriteRendererComponent = entity["SpriteRendererComponent"]; + if (spriteRendererComponent) + { + auto& src = deserializedEntity.AddComponent(); + src.Color = spriteRendererComponent["Color"].as(); + if (spriteRendererComponent["TilingFactor"]) + src.TilingFactor = spriteRendererComponent["TilingFactor"].as(); + } + } + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "CircleRendererComponent"; @@ -212,11 +393,26 @@ namespace Hazel { auto& circleRendererComponent = entity.GetComponent(); out << YAML::Key << "Color" << YAML::Value << circleRendererComponent.Color; out << YAML::Key << "Thickness" << YAML::Value << circleRendererComponent.Thickness; - out << YAML::Key << "Fade" << YAML::Value << circleRendererComponent.Fade; out << YAML::EndMap; // CircleRendererComponent } + } + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto circleRendererComponent = entity["CircleRendererComponent"]; + if (circleRendererComponent) + { + auto& src = deserializedEntity.AddComponent(); + src.Color = circleRendererComponent["Color"].as(); + src.Thickness = circleRendererComponent["Thickness"].as(); + } + } + + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "Rigidbody2DComponent"; @@ -228,7 +424,23 @@ namespace Hazel { out << YAML::EndMap; // Rigidbody2DComponent } + } + + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto rigidbody2DComponent = entity["Rigidbody2DComponent"]; + if (rigidbody2DComponent) + { + auto& rb2d = deserializedEntity.AddComponent(); + rb2d.Type = RigidBody2DBodyTypeFromString(rigidbody2DComponent["BodyType"].as()); + rb2d.FixedRotation = rigidbody2DComponent["FixedRotation"].as(); + } + } + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { if (entity.HasComponent()) { out << YAML::Key << "BoxCollider2DComponent"; @@ -244,176 +456,67 @@ namespace Hazel { out << YAML::EndMap; // BoxCollider2DComponent } + } - if (entity.HasComponent()) + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto boxCollider2DComponent = entity["BoxCollider2DComponent"]; + if (boxCollider2DComponent) { - out << YAML::Key << "CircleCollider2DComponent"; - out << YAML::BeginMap; // CircleCollider2DComponent - - auto& cc2dComponent = entity.GetComponent(); - out << YAML::Key << "Offset" << YAML::Value << cc2dComponent.Offset; - out << YAML::Key << "Radius" << YAML::Value << cc2dComponent.Radius; - out << YAML::Key << "Density" << YAML::Value << cc2dComponent.Density; - out << YAML::Key << "Friction" << YAML::Value << cc2dComponent.Friction; - out << YAML::Key << "Restitution" << YAML::Value << cc2dComponent.Restitution; - out << YAML::Key << "RestitutionThreshold" << YAML::Value << cc2dComponent.RestitutionThreshold; - - out << YAML::EndMap; // CircleCollider2DComponent + auto& bc2d = deserializedEntity.AddComponent(); + bc2d.Offset = boxCollider2DComponent["Offset"].as(); + bc2d.Size = boxCollider2DComponent["Size"].as(); + bc2d.Density = boxCollider2DComponent["Density"].as(); + bc2d.Friction = boxCollider2DComponent["Friction"].as(); + bc2d.Restitution = boxCollider2DComponent["Restitution"].as(); + bc2d.RestitutionThreshold = boxCollider2DComponent["RestitutionThreshold"].as(); } - - out << YAML::EndMap; // Entity } - void SceneSerializer::Serialize(const std::string& filepath) + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) { - YAML::Emitter out; - out << YAML::BeginMap; - out << YAML::Key << "Scene" << YAML::Value << "Untitled"; - out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; - m_Scene->m_Registry.each([&](auto entityID) - { - Entity entity = { entityID, m_Scene.get() }; - if (!entity) - return; - - SerializeEntity(out, entity); - }); - out << YAML::EndSeq; - out << YAML::EndMap; - - std::ofstream fout(filepath); - fout << out.c_str(); + //TODO: serialize NativeScriptComponent? } - void SceneSerializer::SerializeRuntime(const std::string& filepath) + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value&, Entity&) { - // Not implemented - HZ_CORE_ASSERT(false); + //TODO: deserialize NativeScriptComponent? } - bool SceneSerializer::Deserialize(const std::string& filepath) + template + static void SerializeEntityComponents(YAML::Emitter& out, Entity entity) { - YAML::Node data; - try - { - data = YAML::LoadFile(filepath); - } - catch (YAML::ParserException e) - { - HZ_CORE_ERROR("Failed to load .hazel file '{0}'\n {1}", filepath, e.what()); - return false; - } - - if (!data["Scene"]) - return false; - - std::string sceneName = data["Scene"].as(); - HZ_CORE_TRACE("Deserializing scene '{0}'", sceneName); - - auto entities = data["Entities"]; - if (entities) - { - for (auto entity : entities) - { - uint64_t uuid = entity["Entity"].as(); - - std::string name; - auto tagComponent = entity["TagComponent"]; - if (tagComponent) - name = tagComponent["Tag"].as(); - - HZ_CORE_TRACE("Deserialized entity with ID = {0}, name = {1}", uuid, name); + (SerializeEntityComponent(out, entity), ...); + } - Entity deserializedEntity = m_Scene->CreateEntityWithUUID(uuid, name); + template + static void DeserializeEntryComponents(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + (DeserializeEntryComponent(entity, deserializedEntity), ...); + } - auto transformComponent = entity["TransformComponent"]; - if (transformComponent) - { - // Entities always have transforms - auto& tc = deserializedEntity.GetComponent(); - tc.Translation = transformComponent["Translation"].as(); - tc.Rotation = transformComponent["Rotation"].as(); - tc.Scale = transformComponent["Scale"].as(); - } - - auto cameraComponent = entity["CameraComponent"]; - if (cameraComponent) - { - auto& cc = deserializedEntity.AddComponent(); - - auto& cameraProps = cameraComponent["Camera"]; - cc.Camera.SetProjectionType((SceneCamera::ProjectionType)cameraProps["ProjectionType"].as()); - - cc.Camera.SetPerspectiveVerticalFOV(cameraProps["PerspectiveFOV"].as()); - cc.Camera.SetPerspectiveNearClip(cameraProps["PerspectiveNear"].as()); - cc.Camera.SetPerspectiveFarClip(cameraProps["PerspectiveFar"].as()); - - cc.Camera.SetOrthographicSize(cameraProps["OrthographicSize"].as()); - cc.Camera.SetOrthographicNearClip(cameraProps["OrthographicNear"].as()); - cc.Camera.SetOrthographicFarClip(cameraProps["OrthographicFar"].as()); - - cc.Primary = cameraComponent["Primary"].as(); - cc.FixedAspectRatio = cameraComponent["FixedAspectRatio"].as(); - } - - auto spriteRendererComponent = entity["SpriteRendererComponent"]; - if (spriteRendererComponent) - { - auto& src = deserializedEntity.AddComponent(); - src.Color = spriteRendererComponent["Color"].as(); - } - - auto circleRendererComponent = entity["CircleRendererComponent"]; - if (circleRendererComponent) - { - auto& crc = deserializedEntity.AddComponent(); - crc.Color = circleRendererComponent["Color"].as(); - crc.Thickness = circleRendererComponent["Thickness"].as(); - crc.Fade = circleRendererComponent["Fade"].as(); - } - - auto rigidbody2DComponent = entity["Rigidbody2DComponent"]; - if (rigidbody2DComponent) - { - auto& rb2d = deserializedEntity.AddComponent(); - rb2d.Type = RigidBody2DBodyTypeFromString(rigidbody2DComponent["BodyType"].as()); - rb2d.FixedRotation = rigidbody2DComponent["FixedRotation"].as(); - } - - auto boxCollider2DComponent = entity["BoxCollider2DComponent"]; - if (boxCollider2DComponent) - { - auto& bc2d = deserializedEntity.AddComponent(); - bc2d.Offset = boxCollider2DComponent["Offset"].as(); - bc2d.Size = boxCollider2DComponent["Size"].as(); - bc2d.Density = boxCollider2DComponent["Density"].as(); - bc2d.Friction = boxCollider2DComponent["Friction"].as(); - bc2d.Restitution = boxCollider2DComponent["Restitution"].as(); - bc2d.RestitutionThreshold = boxCollider2DComponent["RestitutionThreshold"].as(); - } - - auto circleCollider2DComponent = entity["CircleCollider2DComponent"]; - if (circleCollider2DComponent) - { - auto& cc2d = deserializedEntity.AddComponent(); - cc2d.Offset = circleCollider2DComponent["Offset"].as(); - cc2d.Radius = circleCollider2DComponent["Radius"].as(); - cc2d.Density = circleCollider2DComponent["Density"].as(); - cc2d.Friction = circleCollider2DComponent["Friction"].as(); - cc2d.Restitution = circleCollider2DComponent["Restitution"].as(); - cc2d.RestitutionThreshold = circleCollider2DComponent["RestitutionThreshold"].as(); - } - } - } + template + static void SerializeEntityComponents(ComponentGroup, YAML::Emitter& out, Entity entity) + { + SerializeEntityComponents(out, entity); + } - return true; + template + static void DeserializeEntryComponents(ComponentGroup, YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + DeserializeEntryComponents(entity, deserializedEntity); } - bool SceneSerializer::DeserializeRuntime(const std::string& filepath) + static void SerializeAllEntityComponents(YAML::Emitter& out, Entity entity) { - // Not implemented - HZ_CORE_ASSERT(false); - return false; + SerializeEntityComponents(AllComponents{}, out, entity); } + static void DeserializeAllEntryComponents(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + DeserializeEntryComponents(AllComponents{}, entity, deserializedEntity); + } } From 73d478e0eb8fc98d21ffa2c3d802fb4edbc6a938 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 28 Jun 2022 12:57:18 -0400 Subject: [PATCH 2/3] Fixed CircleCollider2DComponent and Texture not saving. Added CircleCollider2DComponent to SerializeEntityComponent and DeserializeEntryComponent Added `GetPath()` to `Texture` and `OpenGLTexture` Added TextureExample.hazel --- Hazel/src/Hazel/Renderer/Texture.h | 1 + Hazel/src/Hazel/Scene/SceneSerializer.cpp | 58 ++++++++++++++------ Hazel/src/Platform/OpenGL/OpenGLTexture.h | 1 + Hazelnut/assets/scenes/TextureExample.hazel | 60 +++++++++++++++++++++ 4 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 Hazelnut/assets/scenes/TextureExample.hazel diff --git a/Hazel/src/Hazel/Renderer/Texture.h b/Hazel/src/Hazel/Renderer/Texture.h index dce8b1e6a..c1145be0e 100644 --- a/Hazel/src/Hazel/Renderer/Texture.h +++ b/Hazel/src/Hazel/Renderer/Texture.h @@ -14,6 +14,7 @@ namespace Hazel { virtual uint32_t GetWidth() const = 0; virtual uint32_t GetHeight() const = 0; virtual uint32_t GetRendererID() const = 0; + virtual const std::string & GetPath() const = 0; virtual void SetData(void* data, uint32_t size) = 0; diff --git a/Hazel/src/Hazel/Scene/SceneSerializer.cpp b/Hazel/src/Hazel/Scene/SceneSerializer.cpp index a7129a53b..fef54fcb4 100644 --- a/Hazel/src/Hazel/Scene/SceneSerializer.cpp +++ b/Hazel/src/Hazel/Scene/SceneSerializer.cpp @@ -151,22 +151,6 @@ namespace Hazel { // Serialize components (except IDComponent) SerializeAllEntityComponents(out,entity); - if (entity.HasComponent()) - { - out << YAML::Key << "CircleCollider2DComponent"; - out << YAML::BeginMap; // CircleCollider2DComponent - - auto& cc2dComponent = entity.GetComponent(); - out << YAML::Key << "Offset" << YAML::Value << cc2dComponent.Offset; - out << YAML::Key << "Radius" << YAML::Value << cc2dComponent.Radius; - out << YAML::Key << "Density" << YAML::Value << cc2dComponent.Density; - out << YAML::Key << "Friction" << YAML::Value << cc2dComponent.Friction; - out << YAML::Key << "Restitution" << YAML::Value << cc2dComponent.Restitution; - out << YAML::Key << "RestitutionThreshold" << YAML::Value << cc2dComponent.RestitutionThreshold; - - out << YAML::EndMap; // CircleCollider2DComponent - } - out << YAML::EndMap; // Entity } @@ -362,6 +346,10 @@ namespace Hazel { out << YAML::BeginMap; // SpriteRendererComponent auto& spriteRendererComponent = entity.GetComponent(); + if (spriteRendererComponent.Texture && std::filesystem::exists(spriteRendererComponent.Texture->GetPath())) + { + out << YAML::Key << "TexturePath" << YAML::Value << spriteRendererComponent.Texture->GetPath(); + } out << YAML::Key << "Color" << YAML::Value << spriteRendererComponent.Color; out << YAML::Key << "TilingFactor" << YAML::Value << spriteRendererComponent.TilingFactor; @@ -376,6 +364,8 @@ namespace Hazel { if (spriteRendererComponent) { auto& src = deserializedEntity.AddComponent(); + if(spriteRendererComponent["TexturePath"]) + src.Texture = Texture2D::Create(spriteRendererComponent["TexturePath"].as()); src.Color = spriteRendererComponent["Color"].as(); if (spriteRendererComponent["TilingFactor"]) src.TilingFactor = spriteRendererComponent["TilingFactor"].as(); @@ -473,6 +463,42 @@ namespace Hazel { bc2d.RestitutionThreshold = boxCollider2DComponent["RestitutionThreshold"].as(); } } + template<> + static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) + { + + if (entity.HasComponent()) + { + out << YAML::Key << "CircleCollider2DComponent"; + out << YAML::BeginMap; // CircleCollider2DComponent + + auto& cc2dComponent = entity.GetComponent(); + out << YAML::Key << "Offset" << YAML::Value << cc2dComponent.Offset; + out << YAML::Key << "Radius" << YAML::Value << cc2dComponent.Radius; + out << YAML::Key << "Density" << YAML::Value << cc2dComponent.Density; + out << YAML::Key << "Friction" << YAML::Value << cc2dComponent.Friction; + out << YAML::Key << "Restitution" << YAML::Value << cc2dComponent.Restitution; + out << YAML::Key << "RestitutionThreshold" << YAML::Value << cc2dComponent.RestitutionThreshold; + + out << YAML::EndMap; // CircleCollider2DComponent + } + } + + template<> + static void DeserializeEntryComponent(YAML::detail::iterator_value& entity, Entity& deserializedEntity) + { + auto circleCollider2DComponent = entity["CircleCollider2DComponent"]; + if (circleCollider2DComponent) + { + auto& bc2d = deserializedEntity.AddComponent(); + bc2d.Offset = circleCollider2DComponent["Offset"].as(); + bc2d.Radius = circleCollider2DComponent["Radius"].as(); + bc2d.Density = circleCollider2DComponent["Density"].as(); + bc2d.Friction = circleCollider2DComponent["Friction"].as(); + bc2d.Restitution = circleCollider2DComponent["Restitution"].as(); + bc2d.RestitutionThreshold = circleCollider2DComponent["RestitutionThreshold"].as(); + } + } template<> static void SerializeEntityComponent(YAML::Emitter& out, Entity entity) diff --git a/Hazel/src/Platform/OpenGL/OpenGLTexture.h b/Hazel/src/Platform/OpenGL/OpenGLTexture.h index 3f590fe71..fbc92e0c7 100644 --- a/Hazel/src/Platform/OpenGL/OpenGLTexture.h +++ b/Hazel/src/Platform/OpenGL/OpenGLTexture.h @@ -16,6 +16,7 @@ namespace Hazel { virtual uint32_t GetWidth() const override { return m_Width; } virtual uint32_t GetHeight() const override { return m_Height; } virtual uint32_t GetRendererID() const override { return m_RendererID; } + virtual const std::string& GetPath() const override { return m_Path; } virtual void SetData(void* data, uint32_t size) override; diff --git a/Hazelnut/assets/scenes/TextureExample.hazel b/Hazelnut/assets/scenes/TextureExample.hazel new file mode 100644 index 000000000..7327a4f62 --- /dev/null +++ b/Hazelnut/assets/scenes/TextureExample.hazel @@ -0,0 +1,60 @@ +Scene: Untitled +Entities: + - Entity: 6963903425255029957 + TagComponent: + Tag: Camera B + TransformComponent: + Translation: [0, 0, 0] + Rotation: [0, 0, 0] + Scale: [1, 1, 1] + CameraComponent: + Camera: + ProjectionType: 1 + PerspectiveFOV: 0.785398185 + PerspectiveNear: 0.00999999978 + PerspectiveFar: 1000 + OrthographicSize: 10 + OrthographicNear: -1 + OrthographicFar: 1 + Primary: false + FixedAspectRatio: false + - Entity: 10881116728385524032 + TagComponent: + Tag: Camera A + TransformComponent: + Translation: [0, 0, 0] + Rotation: [0, 0, 0] + Scale: [1, 1, 1] + CameraComponent: + Camera: + ProjectionType: 1 + PerspectiveFOV: 0.785398185 + PerspectiveNear: 0.00999999978 + PerspectiveFar: 1000 + OrthographicSize: 10 + OrthographicNear: -1 + OrthographicFar: 1 + Primary: true + FixedAspectRatio: false + - Entity: 5955965714161965918 + TagComponent: + Tag: Red Square + TransformComponent: + Translation: [0, 1.10000002, 0] + Rotation: [0, 0, 0] + Scale: [1, 1, 1] + SpriteRendererComponent: + TexturePath: assets\textures\ChernoLogo.png + Color: [1, 0.999989986, 0.999989986, 1] + TilingFactor: 1 + - Entity: 16837712394659778935 + TagComponent: + Tag: Green Square + TransformComponent: + Translation: [2.4000001, 0, 0] + Rotation: [0, 0, 0] + Scale: [1, 1, 1] + SpriteRendererComponent: + TexturePath: assets\textures\Checkerboard.png + Color: [1, 0.999989986, 0.999989986, 1] + TilingFactor: 1 \ No newline at end of file From 44ea684ee812169679993502be3241e340fa11da Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 5 Jul 2022 00:37:28 -0400 Subject: [PATCH 3/3] Fix not compiling after merge. Had duplicate GetPath delete duplicate GetPath() The example isn't really needed to pull request. Cherno has his own. --- Hazel/src/Hazel/Renderer/Texture.h | 1 - Hazelnut/assets/scenes/TextureExample.hazel | 60 --------------------- 2 files changed, 61 deletions(-) delete mode 100644 Hazelnut/assets/scenes/TextureExample.hazel diff --git a/Hazel/src/Hazel/Renderer/Texture.h b/Hazel/src/Hazel/Renderer/Texture.h index 6212292fe..309cebfdd 100644 --- a/Hazel/src/Hazel/Renderer/Texture.h +++ b/Hazel/src/Hazel/Renderer/Texture.h @@ -14,7 +14,6 @@ namespace Hazel { virtual uint32_t GetWidth() const = 0; virtual uint32_t GetHeight() const = 0; virtual uint32_t GetRendererID() const = 0; - virtual const std::string & GetPath() const = 0; virtual const std::string& GetPath() const = 0; diff --git a/Hazelnut/assets/scenes/TextureExample.hazel b/Hazelnut/assets/scenes/TextureExample.hazel deleted file mode 100644 index 7327a4f62..000000000 --- a/Hazelnut/assets/scenes/TextureExample.hazel +++ /dev/null @@ -1,60 +0,0 @@ -Scene: Untitled -Entities: - - Entity: 6963903425255029957 - TagComponent: - Tag: Camera B - TransformComponent: - Translation: [0, 0, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - CameraComponent: - Camera: - ProjectionType: 1 - PerspectiveFOV: 0.785398185 - PerspectiveNear: 0.00999999978 - PerspectiveFar: 1000 - OrthographicSize: 10 - OrthographicNear: -1 - OrthographicFar: 1 - Primary: false - FixedAspectRatio: false - - Entity: 10881116728385524032 - TagComponent: - Tag: Camera A - TransformComponent: - Translation: [0, 0, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - CameraComponent: - Camera: - ProjectionType: 1 - PerspectiveFOV: 0.785398185 - PerspectiveNear: 0.00999999978 - PerspectiveFar: 1000 - OrthographicSize: 10 - OrthographicNear: -1 - OrthographicFar: 1 - Primary: true - FixedAspectRatio: false - - Entity: 5955965714161965918 - TagComponent: - Tag: Red Square - TransformComponent: - Translation: [0, 1.10000002, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - TexturePath: assets\textures\ChernoLogo.png - Color: [1, 0.999989986, 0.999989986, 1] - TilingFactor: 1 - - Entity: 16837712394659778935 - TagComponent: - Tag: Green Square - TransformComponent: - Translation: [2.4000001, 0, 0] - Rotation: [0, 0, 0] - Scale: [1, 1, 1] - SpriteRendererComponent: - TexturePath: assets\textures\Checkerboard.png - Color: [1, 0.999989986, 0.999989986, 1] - TilingFactor: 1 \ No newline at end of file