diff --git a/demo/data/topdown.yml b/demo/data/topdown.yml index defd6c044a4be342a64fa5e4ab40e4d2d9811122..d6c6658842e1e10eaf18ab0bf487d4e69badec30 100644 --- a/demo/data/topdown.yml +++ b/demo/data/topdown.yml @@ -8,11 +8,16 @@ prefabs: shape: type: box scale: [1.0, 5.0, 41] - phys::Body: - type: static - shape: - type: box - extents: [0.5, 2.5, 20.5] + gfx::material: + ambient: [0.25, 0.25, 0.25] + diffuse: [0.4, 0.4, 0.4] + specular: [0.774597,0.774597,0.774597] + shininess: 0.6 +# phys::Body: +# type: static +# shape: +# type: box +# extents: [0.5, 2.5, 20.5] # Wall Z shorter to avoid z-fighting - name: "wallZ" components: @@ -22,11 +27,16 @@ prefabs: shape: type: box scale: [39, 5, 1] - phys::Body: - type: static - shape: - type: box - extents: [ 19.5, 2.5, 0.5 ] + gfx::material: + ambient: [0.25, 0.25, 0.25] + diffuse: [0.4, 0.4, 0.4] + specular: [0.774597,0.774597,0.774597] + shininess: 0.6 +# phys::Body: +# type: static +# shape: +# type: box +# extents: [ 19.5, 2.5, 0.5 ] - name: "floor" components: Transform: @@ -35,11 +45,16 @@ prefabs: shape: type: box # we don't (currently) support planes... scale: [39, 0.5, 39] - phys::Body: - type: static - shape: - type: box # we don't (currently) support planes... - extents: [19.5, 0.25, 19.5] + gfx::material: + ambient: [0.25, 0.25, 0.25] + diffuse: [0.4, 0.4, 0.4] + specular: [0.774597,0.774597,0.774597] + 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 components: Transform: @@ -52,10 +67,10 @@ prefabs: diffuse: [0.4, 0.4, 0.4] specular: [0.774597,0.774597,0.774597] shininess: 0.6 - phys::Body: - shape: - type: sphere - radius: 1 +# phys::Body: +# shape: +# type: sphere +# radius: 1 - name: collectable components: Transform: @@ -68,9 +83,9 @@ prefabs: diffuse: [1, 1, 1] specular: [0.0633, 0.727811, 0.633] shininess: 0.6 - phys::Body: - type: kinematic - shape: - type: box - phys::Callbacks: - phys::Cache: \ No newline at end of file +# phys::Body: +# type: kinematic +# shape: +# type: box +# phys::Callbacks: +# phys::Cache: \ No newline at end of file diff --git a/demo/demo/rollball.cpp b/demo/demo/rollball.cpp index 88cc9269175199e4af3d489b866edfbb5b338063..7236d40792623910f059440061fcbf818edec93d 100644 --- a/demo/demo/rollball.cpp +++ b/demo/demo/rollball.cpp @@ -127,7 +127,6 @@ namespace demo { Game::activate(); fggl::debug::log(fggl::debug::Level::info, "RollBall::activate()"); - auto* assetLoader = m_owner.service<fggl::assets::Loader>(); assetLoader->load("rollball.yml", fggl::entity::PROTOTYPE_ASSET); diff --git a/demo/demo/topdown.cpp b/demo/demo/topdown.cpp index c424dc3652050555d7a87e19f5be1a526f521553..4316c2a9093f7fe834d764b1d28d4352979f63cc 100644 --- a/demo/demo/topdown.cpp +++ b/demo/demo/topdown.cpp @@ -24,8 +24,8 @@ #include "fggl/entity/loader/loader.hpp" static const fggl::util::GUID collectablePrefab = "collectable"_fid; -static const fggl::util::GUID WallNPrefab = "wallN"_fid; -static const fggl::util::GUID WallEPrefab = "wallE"_fid; +static const fggl::util::GUID WallNPrefab = "wallX"_fid; +static const fggl::util::GUID WallEPrefab = "wallZ"_fid; static const fggl::util::GUID floorPrefab = "floor"_fid; namespace demo { @@ -116,6 +116,10 @@ TopDown::TopDown(fggl::App& app) : fggl::scenes::Game(app) { void TopDown::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>(); //fggl::ecs3::load_prototype_file(world(), *storage, "topdown.yml"); diff --git a/fggl/data/procedural.cpp b/fggl/data/procedural.cpp index 5461b51ec807fc575a648b3ceacc10ce64410cb4..4b6c46e5b7e197e7d743e877d44c666c4ddc87d9 100644 --- a/fggl/data/procedural.cpp +++ b/fggl/data/procedural.cpp @@ -131,15 +131,15 @@ static void populateMesh(fggl::data::Mesh& mesh, 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; - for (int vertical = 0; vertical < stacks; vertical++) { - for (int horz = 0; horz < slices; horz++) { - const int topLeft = vertical * HORZ_SIZE + horz; - const int topRight = vertical * HORZ_SIZE + (horz + 1); - const int bottomLeft = (vertical + 1) * HORZ_SIZE + horz; - const int bottomRight = (vertical + 1) * HORZ_SIZE + (horz + 1); + for (uint32_t vertical = 0; vertical < stacks; vertical++) { + for (uint32_t horz = 0; horz < slices; horz++) { + const auto topLeft = vertical * HORZ_SIZE + horz; + const auto topRight = vertical * HORZ_SIZE + (horz + 1); + const auto bottomLeft = (vertical + 1) * HORZ_SIZE + horz; + const auto bottomRight = (vertical + 1) * HORZ_SIZE + (horz + 1); indexList.push_back(topLeft); indexList.push_back(bottomLeft); @@ -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; - float verticalAngularStride = math::PI / stacks; - float horizontalAngularStride = math::TAU / slices; + float verticalAngularStride = math::PI / (float)stacks; + float horizontalAngularStride = math::TAU / (float)slices; // calculate vertex positions - for (int vertical = 0; vertical < (stacks + 1); vertical++) { - float theta = (math::HALF_PI) - verticalAngularStride * vertical; - for ( int horz = 0; horz < (slices + 1); horz++ ) { - float phi = horizontalAngularStride * horz; + for (uint32_t vertical = 0; vertical < (stacks + 1); vertical++) { + float theta = (math::HALF_PI) - verticalAngularStride * (float)vertical; + for ( uint32_t horz = 0; horz < (slices + 1); horz++ ) { + float phi = horizontalAngularStride * (float)horz; math::vec3 position { cosf(theta) * cosf(phi), cosf(theta) * sinf(phi), diff --git a/fggl/entity/module.cpp b/fggl/entity/module.cpp index ab79b1b211d3864e9c1f5848c69b5ea8bf195661..4037902587a33107b8eb6bfea594aa2e671627da 100644 --- a/fggl/entity/module.cpp +++ b/fggl/entity/module.cpp @@ -22,7 +22,10 @@ namespace fggl::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) { diff --git a/fggl/gfx/ogl4/models.cpp b/fggl/gfx/ogl4/models.cpp index bfed052ff445c5e5e53a5e0ebc2fe6fc721e1134..1149e911230e172575280e6edb1c4bcf5d93d755 100644 --- a/fggl/gfx/ogl4/models.cpp +++ b/fggl/gfx/ogl4/models.cpp @@ -74,8 +74,6 @@ namespace fggl::gfx::ogl4 { } auto& meshComp = world.get<data::StaticMesh>(renderable); - auto& modelComp = world.add<StaticModel>(renderable); - auto shader = m_phong; try { shader = std::make_shared<ogl::Shader>( m_shaders->get( meshComp.pipeline ) ); @@ -83,10 +81,9 @@ namespace fggl::gfx::ogl4 { debug::log(debug::Level::warning, "Could not find shader: {}", meshComp.pipeline); } + auto& modelComp = world.add<StaticModel>(renderable); setupComponent(modelComp, shader, meshComp.mesh); - - // no active model, we need to resolve/load one. - //spdlog::info("looks like {} needs a static mesh", renderable); + debug::log(debug::Level::info, "Added static mesh to {}", (uint64_t)renderable); } // terrain @@ -149,6 +146,7 @@ namespace fggl::gfx::ogl4 { auto renderables = world.find<StaticModel>(); for ( const auto& entity : renderables ){ + // ensure that the model pipeline actually exists... const StaticModel& model = world.get<StaticModel>(entity); if ( model.pipeline == nullptr ) { diff --git a/fggl/gfx/ogl4/module.cpp b/fggl/gfx/ogl4/module.cpp index aad07e8c91bb5672d189f400b6b54c8b718fabb9..4f44bf3dc552dee90687b0bbeb6a7a8fd42f3683 100644 --- a/fggl/gfx/ogl4/module.cpp +++ b/fggl/gfx/ogl4/module.cpp @@ -24,8 +24,8 @@ namespace fggl::gfx { - constexpr int DEFAULT_STACKS = 16; - constexpr int DEFAULT_SLICES = 16; + constexpr uint32_t DEFAULT_STACKS = 16; + constexpr uint32_t DEFAULT_SLICES = 16; constexpr const char* SHAPE_SPHERE{"sphere"}; constexpr const char* SHAPE_BOX{"box"}; @@ -46,8 +46,8 @@ namespace fggl::gfx { if ( type == SHAPE_BOX ) { data::make_cube(mesh, transform); } else if ( type == SHAPE_SPHERE ) { - int stacks = node["stacks"].as<uint32_t>(DEFAULT_STACKS); - int slices = node["slices"].as<uint32_t>(DEFAULT_SLICES); + auto stacks = node["stacks"].as<uint32_t>(DEFAULT_STACKS); + auto slices = node["slices"].as<uint32_t>(DEFAULT_SLICES); data::make_sphere(mesh, transform, stacks, slices); } else { debug::log(debug::Level::warning, "unknown shape type requested: {}", type); @@ -75,6 +75,10 @@ namespace fggl::gfx { void attach_material(const entity::ComponentSpec& spec, entity::EntityManager& manager, const entity::EntityID& 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) { diff --git a/include/fggl/data/procedural.hpp b/include/fggl/data/procedural.hpp index a33c72ea5c6a37c63fe837f6a18fc3d39608d5b9..522ea0434377286cd3e1f3446830ea0c858761b1 100644 --- a/include/fggl/data/procedural.hpp +++ b/include/fggl/data/procedural.hpp @@ -44,7 +44,7 @@ namespace fggl::data { // other useful types people expect 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 \ No newline at end of file diff --git a/include/fggl/entity/entity.hpp b/include/fggl/entity/entity.hpp index 5d12ccb985527ff8fa1e1aba29c77e942ec1c9e7..05c3ba555a2fcc487a9893f85ac314b1cd1c6298 100644 --- a/include/fggl/entity/entity.hpp +++ b/include/fggl/entity/entity.hpp @@ -50,6 +50,7 @@ namespace fggl::entity { const Component& get(EntityID entity) const { return m_registry.get<Component>(entity); } + template<typename Component> Component* tryGet(EntityID entity) { return m_registry.try_get<Component>(entity);