-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
518 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "SerializationHelper.h" | ||
|
||
namespace Atlas { | ||
|
||
void to_json(json& j, const vec2& p) { | ||
j = json{{"x", p.x}, {"y", p.y}}; | ||
} | ||
|
||
void from_json(const json& j, vec2& p) { | ||
j.at("x").get_to(p.x); | ||
j.at("y").get_to(p.y); | ||
} | ||
|
||
void to_json(json& j, const vec3& p) { | ||
j = json{{"x", p.x}, {"y", p.y}, {"z", p.z}}; | ||
} | ||
|
||
void from_json(const json& j, vec3& p) { | ||
j.at("x").get_to(p.x); | ||
j.at("y").get_to(p.y); | ||
j.at("z").get_to(p.z); | ||
} | ||
|
||
void to_json(json& j, const vec4& p) { | ||
j = json{{"x", p.x}, {"y", p.y}, {"z", p.z}, {"w", p.w}}; | ||
} | ||
|
||
void from_json(const json& j, vec4& p) { | ||
j.at("x").get_to(p.x); | ||
j.at("y").get_to(p.y); | ||
j.at("z").get_to(p.z); | ||
j.at("w").get_to(p.z); | ||
} | ||
|
||
void to_json(json& j, const mat3& p) { | ||
json j0, j1, j2; | ||
to_json(j0, p[0]); | ||
to_json(j1, p[1]); | ||
to_json(j2, p[2]); | ||
j = json{{"j0", j0}, {"j1", j1}, {"j2", j2}}; | ||
} | ||
|
||
void from_json(const json& j, mat3& p) { | ||
json j0, j1, j2; | ||
j.at("j0").get_to(j0); | ||
j.at("j1").get_to(j1); | ||
j.at("j2").get_to(j2); | ||
|
||
from_json(j0, p[0]); | ||
from_json(j1, p[1]); | ||
from_json(j2, p[2]); | ||
} | ||
|
||
void to_json(json& j, const mat4& p) { | ||
json j0, j1, j2, j3; | ||
to_json(j0, p[0]); | ||
to_json(j1, p[1]); | ||
to_json(j2, p[2]); | ||
to_json(j3, p[3]); | ||
j = json{{"j0", j0}, {"j1", j1}, {"j2", j2}, {"j3", j3}}; | ||
} | ||
|
||
void from_json(const json& j, mat4& p) { | ||
json j0, j1, j2, j3; | ||
j.at("j0").get_to(j0); | ||
j.at("j1").get_to(j1); | ||
j.at("j2").get_to(j2); | ||
j.at("j3").get_to(j3); | ||
|
||
from_json(j0, p[0]); | ||
from_json(j1, p[1]); | ||
from_json(j2, p[2]); | ||
from_json(j3, p[3]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef AE_SERIALIZERHELPER_H | ||
#define AE_SERIALIZERHELPER_H | ||
|
||
#include "../System.h" | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
namespace Atlas { | ||
|
||
void to_json(json& j, const vec2& p); | ||
|
||
void from_json(const json& j, vec2& p); | ||
|
||
void to_json(json& j, const vec3& p); | ||
|
||
void from_json(const json& j, vec3& p); | ||
|
||
void to_json(json& j, const vec4& p); | ||
|
||
void from_json(const json& j, vec4& p); | ||
|
||
void to_json(json& j, const mat3& p); | ||
|
||
void from_json(const json& j, mat3& p); | ||
|
||
void to_json(json& j, const mat4& p); | ||
|
||
void from_json(const json& j, mat4& p); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Components.h" | ||
|
||
namespace NewScene { | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#ifndef AE_COMPONENTS_H | ||
#define AE_COMPONENTS_H | ||
|
||
#include "Entity.h" | ||
#include "../System.h" | ||
|
||
#include "../mesh/Mesh.h" | ||
#include "../common/MatrixDecomposition.h" | ||
|
||
namespace Atlas { | ||
|
||
namespace NewScene { | ||
|
||
class NameComponent { | ||
|
||
public: | ||
NameComponent() = default; | ||
NameComponent(const NameComponent& that) = default; | ||
explicit NameComponent(const std::string& name) : name(name) {} | ||
|
||
std::string name; | ||
|
||
}; | ||
|
||
class TransformComponent { | ||
|
||
public: | ||
TransformComponent() = default; | ||
TransformComponent(const TransformComponent& that) = default; | ||
explicit TransformComponent(mat4 matrix) : matrix(matrix) {} | ||
|
||
void Translate(glm::vec3 translation); | ||
void Rotate(glm::vec3 rotation); | ||
void Scale(glm::vec3 scale); | ||
|
||
Common::MatrixDecomposition Decompose() const; | ||
void Compose(Common::MatrixDecomposition composition); | ||
|
||
glm::mat4 matrix; | ||
|
||
}; | ||
|
||
class MeshComponent { | ||
|
||
public: | ||
MeshComponent() = default; | ||
MeshComponent(const MeshComponent& that) = default; | ||
explicit MeshComponent(Ref<Mesh::Mesh> mesh) : mesh(mesh) {} | ||
|
||
Ref<Mesh::Mesh> mesh; | ||
|
||
}; | ||
|
||
class LightComponent { | ||
|
||
public: | ||
LightComponent() = default; | ||
LightComponent(const LightComponent& that) = default; | ||
|
||
}; | ||
|
||
class CameraComponent { | ||
|
||
public: | ||
CameraComponent() = default; | ||
CameraComponent(const CameraComponent& that) = default; | ||
|
||
bool main = true; | ||
|
||
|
||
|
||
}; | ||
|
||
class AudioComponent { | ||
|
||
public: | ||
AudioComponent() = default; | ||
AudioComponent(const AudioComponent& that) = default; | ||
|
||
}; | ||
|
||
class HierarchyComponent { | ||
|
||
public: | ||
HierarchyComponent() = default; | ||
HierarchyComponent(const HierarchyComponent& that) = default; | ||
|
||
bool root = false; | ||
std::vector<Entity> entities; | ||
|
||
}; | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "Entity.h" | ||
|
||
namespace NewScene { | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef AE_ENTITY_H | ||
#define AE_ENTITY_H | ||
|
||
#include "../System.h" | ||
#include "Scene.h" | ||
|
||
namespace Atlas { | ||
|
||
namespace NewScene { | ||
|
||
class Entity { | ||
|
||
public: | ||
Entity() = default; | ||
Entity(const Entity& that) = default; | ||
Entity(ECS::Entity entity, Scene* scene) : entity(entity), scene(scene) {} | ||
|
||
template<typename Comp, typename... Args> | ||
Comp& AddComponent(Args&&... args) { | ||
|
||
scene->entityManager.Emplace<Comp>(entity, std::forward<Args>(args)...); | ||
|
||
} | ||
|
||
template<typename Comp> | ||
void RemoveComponent() { | ||
|
||
assert(scene->entityManager.Contains<Comp>(entity)); | ||
|
||
scene->entityManager.Erase<Comp>(entity); | ||
|
||
} | ||
|
||
template<typename Comp> | ||
bool HasComponent() { | ||
|
||
return scene->entityManager.Contains<Comp>(entity); | ||
|
||
} | ||
|
||
template<typename Comp> | ||
Comp& GetComponent() const { | ||
|
||
return scene->entityManager.Get<Comp>(entity); | ||
|
||
} | ||
|
||
operator ECS::Entity() const { return entity; } | ||
|
||
private: | ||
ECS::Entity entity; | ||
Scene* scene; | ||
|
||
}; | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.