Skip to content

Commit

Permalink
Started scene rework
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Aug 29, 2023
1 parent b45bb09 commit 5ba0f88
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ find_package(unofficial-vulkan-memory-allocator CONFIG REQUIRED)
find_package(glslang CONFIG REQUIRED)
find_package(unofficial-spirv-reflect CONFIG REQUIRED)
find_package(SPIRV-Tools-opt CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)

add_subdirectory(${ATLAS_LOCATION})

Expand Down
27 changes: 26 additions & 1 deletion THIRDPARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,30 @@ volk

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nlohmann-json
--------------------------------------------------------------------------------
MIT License

Copyright (c) 2013-2022 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

spirv-reflect
--------------------------------------------------------------------------------
Apache License
Expand Down Expand Up @@ -1626,4 +1650,5 @@ glslang
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
*/

6 changes: 3 additions & 3 deletions src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endif()
if(WIN32)
set(ATLAS_ENGINE_COMPILE_DEFINITIONS ${ATLAS_ENGINE_COMPILE_DEFINITIONS} AE_OS_WINDOWS)

set(ATLAS_ENGINE_LIBS assimp::assimp SDL2::SDL2 SDL2::SDL2main SPIRV-Tools-opt
set(ATLAS_ENGINE_LIBS assimp::assimp SDL2::SDL2 SDL2::SDL2main SPIRV-Tools-opt nlohmann_json::nlohmann_json
volk::volk volk::volk_headers unofficial::vulkan-memory-allocator::vulkan-memory-allocator
unofficial::spirv-reflect::spirv-reflect glslang::SPIRV)
endif()
Expand All @@ -52,7 +52,7 @@ if(APPLE)
set(ATLAS_ENGINE_COMPILE_DEFINITIONS ${ATLAS_ENGINE_COMPILE_DEFINITIONS} AE_OS_MACOS)

set(ATLAS_ENGINE_LIBS assimp::assimp SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static
volk::volk volk::volk_headers SPIRV-Tools-opt
volk::volk volk::volk_headers SPIRV-Tools-opt nlohmann_json::nlohmann_json
unofficial::vulkan-memory-allocator::vulkan-memory-allocator
unofficial::spirv-reflect::spirv-reflect glslang::SPIRV)
endif()
Expand All @@ -75,7 +75,7 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
set(CMAKE_INSTALL_RPATH "./")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

set(ATLAS_ENGINE_LIBS assimp::assimp SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static
set(ATLAS_ENGINE_LIBS assimp::assimp SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static nlohmann_json::nlohmann_json
volk::volk volk::volk_headers unofficial::vulkan-memory-allocator::vulkan-memory-allocator
unofficial::spirv-reflect::spirv-reflect SPIRV-Tools-opt glslang::SPIRV)
endif()
Expand Down
76 changes: 76 additions & 0 deletions src/engine/common/SerializationHelper.cpp
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]);
}

}
34 changes: 34 additions & 0 deletions src/engine/common/SerializationHelper.h
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
12 changes: 12 additions & 0 deletions src/engine/ecs/EntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ namespace Atlas {
template<typename... Comp>
Subset<Comp...> GetSubset();

std::vector<Entity>::const_iterator begin() const {

return entities.begin();

}

std::vector<Entity>::const_iterator end() const {

return entities.end();

}

private:
Pools pools;

Expand Down
7 changes: 7 additions & 0 deletions src/engine/newscene/Components.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "Components.h"

namespace NewScene {



};
97 changes: 97 additions & 0 deletions src/engine/newscene/Components.h
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
7 changes: 7 additions & 0 deletions src/engine/newscene/Entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "Entity.h"

namespace NewScene {



};
60 changes: 60 additions & 0 deletions src/engine/newscene/Entity.h
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
Loading

0 comments on commit 5ba0f88

Please sign in to comment.