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

ensure that partial loading of levels is possible using the new system

parent d5f02528
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,16 @@ prefabs: ...@@ -8,11 +8,16 @@ prefabs:
shape: shape:
type: box type: box
scale: [1.0, 5.0, 41] scale: [1.0, 5.0, 41]
phys::Body: gfx::material:
type: static ambient: [0.25, 0.25, 0.25]
shape: diffuse: [0.4, 0.4, 0.4]
type: box specular: [0.774597,0.774597,0.774597]
extents: [0.5, 2.5, 20.5] shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [0.5, 2.5, 20.5]
# Wall Z shorter to avoid z-fighting # Wall Z shorter to avoid z-fighting
- name: "wallZ" - name: "wallZ"
components: components:
...@@ -22,11 +27,16 @@ prefabs: ...@@ -22,11 +27,16 @@ prefabs:
shape: shape:
type: box type: box
scale: [39, 5, 1] scale: [39, 5, 1]
phys::Body: gfx::material:
type: static ambient: [0.25, 0.25, 0.25]
shape: diffuse: [0.4, 0.4, 0.4]
type: box specular: [0.774597,0.774597,0.774597]
extents: [ 19.5, 2.5, 0.5 ] shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [ 19.5, 2.5, 0.5 ]
- name: "floor" - name: "floor"
components: components:
Transform: Transform:
...@@ -35,11 +45,16 @@ prefabs: ...@@ -35,11 +45,16 @@ prefabs:
shape: shape:
type: box # we don't (currently) support planes... type: box # we don't (currently) support planes...
scale: [39, 0.5, 39] scale: [39, 0.5, 39]
phys::Body: gfx::material:
type: static ambient: [0.25, 0.25, 0.25]
shape: diffuse: [0.4, 0.4, 0.4]
type: box # we don't (currently) support planes... specular: [0.774597,0.774597,0.774597]
extents: [19.5, 0.25, 19.5] shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box # we don't (currently) support planes...
# extents: [19.5, 0.25, 19.5]
- name: player - name: player
components: components:
Transform: Transform:
...@@ -52,10 +67,10 @@ prefabs: ...@@ -52,10 +67,10 @@ prefabs:
diffuse: [0.4, 0.4, 0.4] diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597] specular: [0.774597,0.774597,0.774597]
shininess: 0.6 shininess: 0.6
phys::Body: # phys::Body:
shape: # shape:
type: sphere # type: sphere
radius: 1 # radius: 1
- name: collectable - name: collectable
components: components:
Transform: Transform:
...@@ -68,9 +83,9 @@ prefabs: ...@@ -68,9 +83,9 @@ prefabs:
diffuse: [1, 1, 1] diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633] specular: [0.0633, 0.727811, 0.633]
shininess: 0.6 shininess: 0.6
phys::Body: # phys::Body:
type: kinematic # type: kinematic
shape: # shape:
type: box # type: box
phys::Callbacks: # phys::Callbacks:
phys::Cache: # phys::Cache:
\ No newline at end of file \ No newline at end of file
...@@ -127,7 +127,6 @@ namespace demo { ...@@ -127,7 +127,6 @@ namespace demo {
Game::activate(); Game::activate();
fggl::debug::log(fggl::debug::Level::info, "RollBall::activate()"); fggl::debug::log(fggl::debug::Level::info, "RollBall::activate()");
auto* assetLoader = m_owner.service<fggl::assets::Loader>(); auto* assetLoader = m_owner.service<fggl::assets::Loader>();
assetLoader->load("rollball.yml", fggl::entity::PROTOTYPE_ASSET); assetLoader->load("rollball.yml", fggl::entity::PROTOTYPE_ASSET);
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include "fggl/entity/loader/loader.hpp" #include "fggl/entity/loader/loader.hpp"
static const fggl::util::GUID collectablePrefab = "collectable"_fid; static const fggl::util::GUID collectablePrefab = "collectable"_fid;
static const fggl::util::GUID WallNPrefab = "wallN"_fid; static const fggl::util::GUID WallNPrefab = "wallX"_fid;
static const fggl::util::GUID WallEPrefab = "wallE"_fid; static const fggl::util::GUID WallEPrefab = "wallZ"_fid;
static const fggl::util::GUID floorPrefab = "floor"_fid; static const fggl::util::GUID floorPrefab = "floor"_fid;
namespace demo { namespace demo {
...@@ -116,6 +116,10 @@ TopDown::TopDown(fggl::App& app) : fggl::scenes::Game(app) { ...@@ -116,6 +116,10 @@ TopDown::TopDown(fggl::App& app) : fggl::scenes::Game(app) {
void TopDown::activate() { void TopDown::activate() {
Game::activate(); Game::activate();
fggl::debug::log(fggl::debug::Level::info, "TopDown::activate()");
auto* assetLoader = m_owner.service<fggl::assets::Loader>();
assetLoader->load("topdown.yml", fggl::entity::PROTOTYPE_ASSET);
auto* factory = m_owner.service<fggl::entity::EntityFactory>(); auto* factory = m_owner.service<fggl::entity::EntityFactory>();
//fggl::ecs3::load_prototype_file(world(), *storage, "topdown.yml"); //fggl::ecs3::load_prototype_file(world(), *storage, "topdown.yml");
......
...@@ -131,15 +131,15 @@ static void populateMesh(fggl::data::Mesh& mesh, ...@@ -131,15 +131,15 @@ static void populateMesh(fggl::data::Mesh& mesh,
namespace fggl::data { namespace fggl::data {
static void quads2Tris(std::vector<Mesh::IndexType>& indexList, int stacks, int slices) { static void quads2Tris(std::vector<Mesh::IndexType>& indexList, uint32_t stacks, uint32_t slices) {
const auto HORZ_SIZE = slices + 1; const auto HORZ_SIZE = slices + 1;
for (int vertical = 0; vertical < stacks; vertical++) { for (uint32_t vertical = 0; vertical < stacks; vertical++) {
for (int horz = 0; horz < slices; horz++) { for (uint32_t horz = 0; horz < slices; horz++) {
const int topLeft = vertical * HORZ_SIZE + horz; const auto topLeft = vertical * HORZ_SIZE + horz;
const int topRight = vertical * HORZ_SIZE + (horz + 1); const auto topRight = vertical * HORZ_SIZE + (horz + 1);
const int bottomLeft = (vertical + 1) * HORZ_SIZE + horz; const auto bottomLeft = (vertical + 1) * HORZ_SIZE + horz;
const int bottomRight = (vertical + 1) * HORZ_SIZE + (horz + 1); const auto bottomRight = (vertical + 1) * HORZ_SIZE + (horz + 1);
indexList.push_back(topLeft); indexList.push_back(topLeft);
indexList.push_back(bottomLeft); indexList.push_back(bottomLeft);
...@@ -152,18 +152,18 @@ namespace fggl::data { ...@@ -152,18 +152,18 @@ namespace fggl::data {
} }
} }
void make_sphere(Mesh &mesh, const math::mat4& offset, int slices, int stacks) { void make_sphere(Mesh &mesh, const math::mat4& offset, uint32_t slices, uint32_t stacks) {
std::vector<math::vec3> positions; std::vector<math::vec3> positions;
float verticalAngularStride = math::PI / stacks; float verticalAngularStride = math::PI / (float)stacks;
float horizontalAngularStride = math::TAU / slices; float horizontalAngularStride = math::TAU / (float)slices;
// calculate vertex positions // calculate vertex positions
for (int vertical = 0; vertical < (stacks + 1); vertical++) { for (uint32_t vertical = 0; vertical < (stacks + 1); vertical++) {
float theta = (math::HALF_PI) - verticalAngularStride * vertical; float theta = (math::HALF_PI) - verticalAngularStride * (float)vertical;
for ( int horz = 0; horz < (slices + 1); horz++ ) { for ( uint32_t horz = 0; horz < (slices + 1); horz++ ) {
float phi = horizontalAngularStride * horz; float phi = horizontalAngularStride * (float)horz;
math::vec3 position { math::vec3 position {
cosf(theta) * cosf(phi), cosf(theta) * cosf(phi),
cosf(theta) * sinf(phi), cosf(theta) * sinf(phi),
......
...@@ -22,7 +22,10 @@ ...@@ -22,7 +22,10 @@
namespace fggl::entity { namespace fggl::entity {
void make_transform(const entity::ComponentSpec& spec, EntityManager& manager, const entity::EntityID entity){ void make_transform(const entity::ComponentSpec& spec, EntityManager& manager, const entity::EntityID entity){
manager.add<math::Transform>(entity); auto& transform = manager.add<math::Transform>(entity);
transform.origin( spec.get<math::vec3>( "origin", math::VEC3_ZERO ) );
transform.euler( spec.get<math::vec3>( "rotation", math::VEC3_ZERO ) );
transform.scale( spec.get<math::vec3>( "scale", math::VEC3_ONES ) );
} }
void install_component_factories(entity::EntityFactory* factory) { void install_component_factories(entity::EntityFactory* factory) {
......
...@@ -74,8 +74,6 @@ namespace fggl::gfx::ogl4 { ...@@ -74,8 +74,6 @@ namespace fggl::gfx::ogl4 {
} }
auto& meshComp = world.get<data::StaticMesh>(renderable); auto& meshComp = world.get<data::StaticMesh>(renderable);
auto& modelComp = world.add<StaticModel>(renderable);
auto shader = m_phong; auto shader = m_phong;
try { try {
shader = std::make_shared<ogl::Shader>( m_shaders->get( meshComp.pipeline ) ); shader = std::make_shared<ogl::Shader>( m_shaders->get( meshComp.pipeline ) );
...@@ -83,10 +81,9 @@ namespace fggl::gfx::ogl4 { ...@@ -83,10 +81,9 @@ namespace fggl::gfx::ogl4 {
debug::log(debug::Level::warning, "Could not find shader: {}", meshComp.pipeline); debug::log(debug::Level::warning, "Could not find shader: {}", meshComp.pipeline);
} }
auto& modelComp = world.add<StaticModel>(renderable);
setupComponent(modelComp, shader, meshComp.mesh); setupComponent(modelComp, shader, meshComp.mesh);
debug::log(debug::Level::info, "Added static mesh to {}", (uint64_t)renderable);
// no active model, we need to resolve/load one.
//spdlog::info("looks like {} needs a static mesh", renderable);
} }
// terrain // terrain
...@@ -149,6 +146,7 @@ namespace fggl::gfx::ogl4 { ...@@ -149,6 +146,7 @@ namespace fggl::gfx::ogl4 {
auto renderables = world.find<StaticModel>(); auto renderables = world.find<StaticModel>();
for ( const auto& entity : renderables ){ for ( const auto& entity : renderables ){
// ensure that the model pipeline actually exists... // ensure that the model pipeline actually exists...
const StaticModel& model = world.get<StaticModel>(entity); const StaticModel& model = world.get<StaticModel>(entity);
if ( model.pipeline == nullptr ) { if ( model.pipeline == nullptr ) {
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
namespace fggl::gfx { namespace fggl::gfx {
constexpr int DEFAULT_STACKS = 16; constexpr uint32_t DEFAULT_STACKS = 16;
constexpr int DEFAULT_SLICES = 16; constexpr uint32_t DEFAULT_SLICES = 16;
constexpr const char* SHAPE_SPHERE{"sphere"}; constexpr const char* SHAPE_SPHERE{"sphere"};
constexpr const char* SHAPE_BOX{"box"}; constexpr const char* SHAPE_BOX{"box"};
...@@ -46,8 +46,8 @@ namespace fggl::gfx { ...@@ -46,8 +46,8 @@ namespace fggl::gfx {
if ( type == SHAPE_BOX ) { if ( type == SHAPE_BOX ) {
data::make_cube(mesh, transform); data::make_cube(mesh, transform);
} else if ( type == SHAPE_SPHERE ) { } else if ( type == SHAPE_SPHERE ) {
int stacks = node["stacks"].as<uint32_t>(DEFAULT_STACKS); auto stacks = node["stacks"].as<uint32_t>(DEFAULT_STACKS);
int slices = node["slices"].as<uint32_t>(DEFAULT_SLICES); auto slices = node["slices"].as<uint32_t>(DEFAULT_SLICES);
data::make_sphere(mesh, transform, stacks, slices); data::make_sphere(mesh, transform, stacks, slices);
} else { } else {
debug::log(debug::Level::warning, "unknown shape type requested: {}", type); debug::log(debug::Level::warning, "unknown shape type requested: {}", type);
...@@ -75,6 +75,10 @@ namespace fggl::gfx { ...@@ -75,6 +75,10 @@ namespace fggl::gfx {
void attach_material(const entity::ComponentSpec& spec, entity::EntityManager& manager, const entity::EntityID& id) { void attach_material(const entity::ComponentSpec& spec, entity::EntityManager& manager, const entity::EntityID& id) {
auto& mat = manager.add<gfx::PhongMaterial>(id); auto& mat = manager.add<gfx::PhongMaterial>(id);
mat.ambient = spec.get<math::vec3>("ambient", gfx::DEFAULT_AMBIENT);
mat.diffuse = spec.get<math::vec3>("diffuse", gfx::DEFAULT_DIFFUSE);
mat.specular = spec.get<math::vec3>("ambient", gfx::DEFAULT_SPECULAR);
mat.shininess = spec.get<float>("ambient", gfx::DEFAULT_SHININESS);
} }
void attach_light(const entity::ComponentSpec& spec, entity::EntityManager& manager, const entity::EntityID& id) { void attach_light(const entity::ComponentSpec& spec, entity::EntityManager& manager, const entity::EntityID& id) {
......
...@@ -44,7 +44,7 @@ namespace fggl::data { ...@@ -44,7 +44,7 @@ namespace fggl::data {
// other useful types people expect // other useful types people expect
void make_capsule(Mesh& mesh); void make_capsule(Mesh& mesh);
void make_sphere(Mesh &mesh, const math::mat4& offset = OFFSET_NONE, int stacks = 16, int slices = 16); void make_sphere(Mesh &mesh, const math::mat4& offset = OFFSET_NONE, uint32_t stacks = 16U, uint32_t slices = 16U);
} }
#endif #endif
\ No newline at end of file
...@@ -50,6 +50,7 @@ namespace fggl::entity { ...@@ -50,6 +50,7 @@ namespace fggl::entity {
const Component& get(EntityID entity) const { const Component& get(EntityID entity) const {
return m_registry.get<Component>(entity); return m_registry.get<Component>(entity);
} }
template<typename Component> template<typename Component>
Component* tryGet(EntityID entity) { Component* tryGet(EntityID entity) {
return m_registry.try_get<Component>(entity); return m_registry.try_get<Component>(entity);
......
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