Skip to content
Snippets Groups Projects
Commit 8c590ca6 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

be less lax with header/implemnetation seperation

parent 54309754
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ target_sources(${PROJECT_NAME} ...@@ -42,6 +42,7 @@ target_sources(${PROJECT_NAME}
ecs/ecs.cpp ecs/ecs.cpp
ecs3/module/module.cpp ecs3/module/module.cpp
ecs3/fast/Container.cpp ecs3/fast/Container.cpp
ecs3/prototype/loader.cpp
ecs3/prototype/world.cpp ecs3/prototype/world.cpp
scenes/menu.cpp scenes/menu.cpp
......
#include "fggl/ecs3/prototype/loader.hpp" #include "fggl/ecs3/prototype/loader.hpp"
namespace fggl::ecs3 {
void load_prototype_node( ecs3::World& world, const YAML::Node& node) {
auto prototype = world.create(true);
auto& typeReg = world.types();
// store the prototype's name for future use
auto* nameComp = world.get<ecs3::EntityMeta>( prototype );
nameComp->typeName = node["name"].as<std::string>();
// grab the components and iterate them
if ( node["components"] ) {
world.createFromSpec( prototype, node["components"]);
}
}
void load_prototype_file( ecs3::World& world, data::Storage& storage, const std::string& name ) {
auto path = storage.resolvePath( data::Data, name );
auto root = YAML::LoadFile( path.string().c_str() );
for (const auto& node : root["prefabs"] ) {
load_prototype_node(world, node);
}
}
}
namespace fggl::ecs { namespace fggl::ecs {
static void process_mesh(data::Mesh& out, const YAML::Node& shape) {
auto transform = data::OFFSET_NONE;
if ( shape["offset"] ) {
auto scaleFactor = shape["offset"].as<math::vec3>();
transform = glm::translate(transform, scaleFactor);
}
if ( shape["scale"] ) {
auto scaleFactor = shape["scale"].as<math::vec3>();
transform = glm::scale(transform, scaleFactor);
}
// now the shape itself
auto shapeType = shape["type"].as<std::string>();
if ( shapeType == SHAPE_BOX_VALUE ) {
data::make_cube(out, transform);
} else if ( shapeType == SHAPE_SPHERE_VALUE ) {
int stacks = shape["stacks"].as<int>(DEFAULT_STACKS);
int slices = shape["slices"].as<int>(DEFAULT_SLICES);
data::make_sphere(out, transform, stacks, slices);
}
}
template<> template<>
bool restore_config(math::Transform* comp, const YAML::Node& node) { bool restore_config(math::Transform* comp, const YAML::Node& node) {
comp->origin(node["origin"].as<math::vec3>( math::VEC3_ZERO )); comp->origin(node["origin"].as<math::vec3>( math::VEC3_ZERO ));
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
#include "fggl/math/types.hpp" #include "fggl/math/types.hpp"
#include "fggl/phys/types.hpp"
#include "fggl/gfx/phong.hpp"
#include "fggl/data/storage.hpp" #include "fggl/data/storage.hpp"
#include "fggl/data/model.hpp" #include "fggl/data/model.hpp"
#include "fggl/data/procedural.hpp" #include "fggl/data/procedural.hpp"
...@@ -30,29 +33,8 @@ ...@@ -30,29 +33,8 @@
namespace fggl::ecs3 { namespace fggl::ecs3 {
void load_prototype_node( ecs3::World& world, const YAML::Node& node);
void load_prototype_node( ecs3::World& world, const YAML::Node& node) { void load_prototype_file( ecs3::World& world, data::Storage& storage, const std::string& name );
auto prototype = world.create(true);
auto& typeReg = world.types();
// store the prototype's name for future use
auto* nameComp = world.get<ecs3::EntityMeta>( prototype );
nameComp->typeName = node["name"].as<std::string>();
// grab the components and iterate them
if ( node["components"] ) {
world.createFromSpec( prototype, node["components"]);
}
}
void load_prototype_file( ecs3::World& world, data::Storage& storage, const std::string& name ) {
auto path = storage.resolvePath( data::Data, name );
auto root = YAML::LoadFile( path.string().c_str() );
for (const auto& node : root["prefabs"] ) {
load_prototype_node(world, node);
}
}
} // namespace fggl::ecs3 } // namespace fggl::ecs3
...@@ -104,12 +86,12 @@ namespace YAML { ...@@ -104,12 +86,12 @@ namespace YAML {
} }
}; };
constexpr const char* TYPE_KINEMATIC = "kinematic";
constexpr const char* TYPE_STATIC = "static";
constexpr const char* TYPE_DYNAMIC = "dynamic";
template<> template<>
struct convert<fggl::phys::BodyType> { struct convert<fggl::phys::BodyType> {
const static std::string TYPE_KINEMATIC;
const static std::string TYPE_STATIC;
const static std::string TYPE_DYN;
static Node encode(const fggl::phys::BodyType& rhs) { static Node encode(const fggl::phys::BodyType& rhs) {
switch (rhs) { switch (rhs) {
case fggl::phys::BodyType::KINEMATIC: case fggl::phys::BodyType::KINEMATIC:
...@@ -118,9 +100,10 @@ namespace YAML { ...@@ -118,9 +100,10 @@ namespace YAML {
return Node(TYPE_STATIC); return Node(TYPE_STATIC);
default: default:
case fggl::phys::BodyType::DYNAMIC: case fggl::phys::BodyType::DYNAMIC:
return Node(TYPE_DYN); return Node(TYPE_DYNAMIC);
} }
} }
static bool decode(const Node& node, fggl::phys::BodyType& rhs) { static bool decode(const Node& node, fggl::phys::BodyType& rhs) {
const auto value = node.as<std::string>(); const auto value = node.as<std::string>();
if ( value == TYPE_KINEMATIC ) { if ( value == TYPE_KINEMATIC ) {
...@@ -134,9 +117,6 @@ namespace YAML { ...@@ -134,9 +117,6 @@ namespace YAML {
} }
}; };
const std::string convert<fggl::phys::BodyType>::TYPE_KINEMATIC = "kinematic";
const std::string convert<fggl::phys::BodyType>::TYPE_STATIC = "static";
const std::string convert<fggl::phys::BodyType>::TYPE_DYN = "dynamic";
} }
...@@ -147,29 +127,24 @@ namespace fggl::ecs { ...@@ -147,29 +127,24 @@ namespace fggl::ecs {
constexpr const char* SHAPE_SPHERE_VALUE{"sphere"}; constexpr const char* SHAPE_SPHERE_VALUE{"sphere"};
constexpr const char* SHAPE_BOX_VALUE{"box"}; constexpr const char* SHAPE_BOX_VALUE{"box"};
static void process_mesh(data::Mesh& out, const YAML::Node& shape) { // scene template specialisations
auto transform = data::OFFSET_NONE; template<>
if ( shape["offset"] ) { bool restore_config(math::Transform* comp, const YAML::Node& node);
auto scaleFactor = shape["offset"].as<math::vec3>();
transform = glm::translate(transform, scaleFactor);
}
if ( shape["scale"] ) { template<>
auto scaleFactor = shape["scale"].as<math::vec3>(); bool restore_config(gfx::PhongMaterial* comp, const YAML::Node& node);
transform = glm::scale(transform, scaleFactor);
}
// now the shape itself template<>
auto shapeType = shape["type"].as<std::string>(); bool restore_config(data::StaticMesh* meshComp, const YAML::Node& node);
if ( shapeType == SHAPE_BOX_VALUE ) {
data::make_cube(out, transform);
} else if ( shapeType == SHAPE_SPHERE_VALUE ) {
int stacks = shape["stacks"].as<int>(DEFAULT_STACKS);
int slices = shape["slices"].as<int>(DEFAULT_SLICES);
data::make_sphere(out, transform, stacks, slices);
}
}
template<>
bool restore_config(phys::RigidBody* body, const YAML::Node& node);
template<>
bool restore_config(phys::CollisionCallbacks* callbacks, const YAML::Node& node);
template<>
bool restore_config(phys::CollisionCache* cache, const YAML::Node& node);
} }
#endif //FGGL_ECS3_PROTOTYPE_LOADER_HPP #endif //FGGL_ECS3_PROTOTYPE_LOADER_HPP
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <functional> #include <functional>
#include <unordered_set> #include <unordered_set>
#include "fggl/ecs3/types.hpp"
namespace fggl::phys { namespace fggl::phys {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment