Serialization work

This commit is contained in:
Antoine Pilote
2021-05-15 23:57:26 -04:00
parent b53d2e729e
commit 5f364dabb2
27 changed files with 368 additions and 305 deletions

View File

@@ -1,7 +1,8 @@
#pragma once
#include "TransformComponent.h"
#include "../Core/Core.h"
class __declspec(dllexport) CameraComponent {
#include "../Resource/Serializable.h"
class CameraComponent {
public:
Ref<Camera> CameraInstance;
TransformComponent* transformComponent;
@@ -9,4 +10,11 @@ public:
CameraComponent();
void DrawEditor();
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_OBJECT(CameraInstance);
END_SERIALIZE();
}
};

View File

@@ -5,13 +5,13 @@
#include "../Rendering/Camera.h"
#include "../../../Rendering/Framebuffer.h"
#include "BaseComponent.h";
#include "../Resource/Serializable.h"
enum LightType {
Directional, Point, Spot
};
class __declspec(dllexport) LightComponent {
class LightComponent {
public:
glm::vec2 yes = glm::vec2(2, 2);
@@ -201,4 +201,17 @@ public:
void SetType(LightType type);
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(Type);
SERIALIZE_VEC3(Direction);
SERIALIZE_VEC3(Color);
SERIALIZE_VAL(IsVolumetric);
SERIALIZE_VAL(Strength);
SERIALIZE_VAL(SyncDirectionWithSky);
SERIALIZE_VAL(CastShadows);
END_SERIALIZE();
}
};

View File

@@ -3,7 +3,7 @@
#include <glm\ext\matrix_float4x4.hpp>
#include "BaseComponent.h";
class __declspec(dllexport) MeshComponent {
class MeshComponent {
private:
unsigned int VAO;

View File

@@ -1,5 +1,14 @@
#pragma once
#include "../Resource/Serializable.h"
class NameComponent {
public:
std::string Name = "Entity";
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(Name);
END_SERIALIZE();
}
};

View File

@@ -2,10 +2,18 @@
#include "../Entity.h"
struct ParentComponent
{
Entity Parent;
bool HasParent = false;
std::vector<Entity> Children = std::vector<Entity>();
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(HasParent);
if(HasParent)
SERIALIZE_VAL_LBL("Parent", Parent.GetHandle());
END_SERIALIZE();
}
};

View File

@@ -3,7 +3,9 @@
#include <vector>
#include "../Rendering/Mesh/Mesh.h"
#include "../Resource/TrenchbroomMap.h"
class __declspec(dllexport) QuakeMap {
#include "../Resource/Serializable.h"
class QuakeMap {
private:
@@ -18,4 +20,11 @@ public:
void Draw();
void DrawEditor();
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(HasCollisions);
SERIALIZE_VAL(Path);
END_SERIALIZE();
}
};

View File

@@ -32,7 +32,6 @@ float RigidBodyComponent::GetMass() {
return 0.0f;
}
void RigidBodyComponent::SetMass(float m)
{
if (!m_Rigidbody)

View File

@@ -1,7 +1,8 @@
#pragma once
#include <glm\ext\matrix_float4x4.hpp>
#include "BaseComponent.h";
class __declspec(dllexport) TransformComponent {
#include "../Resource/Serializable.h"
class TransformComponent {
public:
glm::vec3 Translation;
glm::vec3 Rotation;
@@ -11,4 +12,14 @@ public:
glm::mat4 GetTransform();
void DrawEditor();
json Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VAL_LBL("Type", "TransformComponent");
SERIALIZE_VEC3(Translation);
SERIALIZE_VEC3(Rotation);
SERIALIZE_VEC3(Scale);
END_SERIALIZE();
}
};

View File

@@ -2,6 +2,11 @@
#include "Components/ParentComponent.h"
#include "Entity.h"
#include "Components/NameComponent.h"
#include "Components/TransformComponent.h"
#include "Components/CameraComponent.h"
#include "Components/QuakeMap.h"
#include "Components/LightComponent.h"
void Entity::AddChild(Entity ent)
{
if ((int)m_EntityHandle != ent.GetHandle())
@@ -13,6 +18,26 @@ void Entity::AddChild(Entity ent)
}
}
json Entity::Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_OBJECT_REF_LBL("NameComponent", GetComponent<NameComponent>());
SERIALIZE_OBJECT_REF_LBL("ParentComponent", GetComponent<ParentComponent>());
SERIALIZE_OBJECT_REF_LBL("TransformComponent", GetComponent<TransformComponent>());
if(HasComponent<CameraComponent>())
SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent<CameraComponent>());
if(HasComponent<QuakeMap>())
SERIALIZE_OBJECT_REF_LBL("QuakemapComponent", GetComponent<QuakeMap>());
if (HasComponent<LightComponent>())
SERIALIZE_OBJECT_REF_LBL("LightComponent", GetComponent<LightComponent>());
END_SERIALIZE();
}
bool Entity::Deserialize(const std::string& str)
{
return false;
}
Entity::Entity(entt::entity handle, Scene* scene)
{
m_EntityHandle = handle;

View File

@@ -3,7 +3,9 @@
#include <glm\ext\matrix_float4x4.hpp>
#include "../Scene.h"
#include "Components/BaseComponent.h"
class __declspec(dllexport) Entity
#include "../Resource/Serializable.h"
class __declspec(dllexport) Entity : public ISerializable
{
public:
Entity(entt::entity handle, Scene* scene);
@@ -49,6 +51,10 @@ public:
{
return !(*this == other);
}
json Serialize() override;
bool Deserialize(const std::string& str);
private:
entt::entity m_EntityHandle;
Scene* m_Scene;