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

cleanup scene generation

parent 683fd35c
No related branches found
No related tags found
No related merge requests found
......@@ -19,17 +19,12 @@
*/
#include "rollball.hpp"
#include "fggl/data/model.hpp"
#include "fggl/data/procedural.hpp"
#include "fggl/gfx/camera.hpp"
#include "fggl/input/camera_input.h"
#include "fggl/util/service.h"
#include "fggl/ecs3/prototype/loader.hpp"
struct Prefabs {
fggl::ecs3::entity_t wallX;
fggl::ecs3::entity_t wallZ;
fggl::ecs3::entity_t floor;
fggl::ecs3::entity_t collectable;
fggl::ecs3::entity_t player;
};
......@@ -39,10 +34,6 @@ static void setupPrefabs(fggl::ecs3::World& world, Prefabs& prefabs) {
auto storage = fggl::util::ServiceLocator::instance().get<fggl::data::Storage>();
fggl::ecs3::load_prototype_file(world, *storage, "rollball.yml");
prefabs.wallX = world.findProtoype("wallX");
prefabs.wallZ = world.findProtoype("wallZ");
prefabs.floor = world.findProtoype("floor");
{
// player (cube because my sphere function doesn't exist yet
prefabs.player = world.findProtoype("player");
......@@ -73,33 +64,33 @@ static void setupCamera(fggl::ecs3::World& world) {
world.add<fggl::gfx::Camera>(prototype);
}
static fggl::ecs3::entity_t setupEnvironment(fggl::ecs3::World& world, const Prefabs prefabs, fggl::math::vec2& size) {
static fggl::ecs3::entity_t setupEnvironment(fggl::ecs3::World& world, fggl::math::vec2& size) {
{
auto northWall = world.copy(prefabs.wallX);
auto northWall = world.createFromPrototype("wallX");
auto* transform = world.get<fggl::math::Transform>(northWall);
transform->origin({size.x/2, 0.0f, 0.0f});
}
{
auto southWall = world.copy(prefabs.wallX);
auto southWall = world.createFromPrototype("wallX");
auto* transform = world.get<fggl::math::Transform>(southWall);
transform->origin({-size.x/2, 0.0f, 0.0f});
}
{
auto westWall = world.copy(prefabs.wallZ);
auto westWall = world.createFromPrototype("wallZ");
auto* transform = world.get<fggl::math::Transform>(westWall);
transform->origin({0.0f, 0.0f, -size.y/2});
}
{
auto eastWall = world.copy(prefabs.wallZ);
auto eastWall = world.createFromPrototype("wallZ");
auto* transform = world.get<fggl::math::Transform>(eastWall);
transform->origin({0.0f, 0.0f, size.y/2});
}
{
auto floor = world.copy(prefabs.floor);
auto floor = world.createFromPrototype("floor");
auto *transform = world.get<fggl::math::Transform>(floor);
transform->origin({0.0f, -2.5f, 0.0f});
}
......@@ -107,7 +98,7 @@ static fggl::ecs3::entity_t setupEnvironment(fggl::ecs3::World& world, const Pre
auto player = fggl::ecs3::NULL_ENTITY;
{
// player just starts off as the prefab dictates
player = world.copy(prefabs.player);
player = world.createFromPrototype("player");
}
{
......@@ -120,7 +111,7 @@ static fggl::ecs3::entity_t setupEnvironment(fggl::ecs3::World& world, const Pre
// build the collectables
for (auto& pos : collectPos) {
auto collectable = world.copy(prefabs.collectable);
auto collectable = world.createFromPrototype("collectable");
auto* transform = world.get<fggl::math::Transform>(collectable);
transform->origin(pos);
}
......@@ -154,7 +145,7 @@ namespace demo {
// create a 20x20 grid
fggl::math::vec2 size{40.0f, 40.0f};
player = setupEnvironment(world(), prefabs, size);
player = setupEnvironment(world(), size);
}
......
......@@ -26,10 +26,13 @@
#define FGGL_ECS3_PROTOTYPE_LOADER_HPP
#include "yaml-cpp/yaml.h"
#include "fggl/data/storage.hpp"
#include "fggl/ecs3/ecs.hpp"
#include "fggl/math/types.hpp"
#include "fggl/data/storage.hpp"
#include "fggl/data/model.hpp"
#include "fggl/data/procedural.hpp"
#include "fggl/ecs3/ecs.hpp"
namespace fggl::ecs3 {
......
......@@ -123,6 +123,10 @@ namespace fggl::ecs3::prototype {
return nextID;
}
inline entity_t createFromPrototype(const std::string& name) {
return copy(findProtoype(name) );
}
entity_t copy(entity_t prototype) {
auto clone = create(false);
......
......@@ -186,8 +186,7 @@ namespace fggl::ecs3 {
}
inline component_type_t find(const char *name) const {
for (auto &[type, meta] : m_types) {
std::cerr << meta->name() << std::endl;
for (const auto &[type, meta] : m_types) {
if (std::strcmp(name, meta->name()) == 0) {
return type;
}
......
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