Commit e858f5ba authored by Georg Schäfer's avatar Georg Schäfer
Browse files

Replace horizontal and vertical wall tile with universal wall tile.

parent 80617cdc
Pipeline #3241 failed with stage
in 1 minute and 49 seconds
......@@ -7,7 +7,7 @@
}
},
"Model": {
"aid": "model:dummy_wall_vertical"
"aid": "model:dummy_wall"
},
"Shadowcaster": {}
}
{
"Transform": {
"scale": {
"x": 2.0,
"y": 2.0,
"z": 2.0
}
},
"Model": {
"aid": "model:dummy_wall_horizontal"
},
"Shadowcaster": {}
}
dummy
########
##----##
#| |#
#| p |#
#| |#
##----##
########
##################
##----############
#| |---------##
#| p |#
#| |---- |#
##----####| |#
##########| |#
###########-----##
##################
......@@ -2,11 +2,11 @@
"tile_size": 4,
"tiles": {
"|": {
"blueprint": "dummy_wall_vertical",
"blueprint": "dummy_wall",
"solid": true
},
"-": {
"blueprint": "dummy_wall_horizontal",
"blueprint": "dummy_wall",
"solid": true
},
" ": {
......
#include "level_system.hpp"
#include "../gameplay/viewtarget_comp.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
#include <mirrage/ecs/ecs.hpp>
namespace phase_shifter::level {
using namespace mirrage;
using namespace mirrage::ecs::components;
Level_system::Level_system(mirrage::ecs::Entity_manager& entities, mirrage::asset::Asset_manager& assets)
: _entities(entities), _assets(assets)
{
_spawners.emplace("p", [&](const Tile& tile, const glm::vec3& position) {
mirrage::ecs::Entity_facet player =
_entities.entity_builder(tile.spawns).position(position).create();
auto playerhandle = player.handle();
auto cam_elevation = 0.3f * glm::pi<float>();
auto cam_azimuth = 0.0f;
auto cam_dir = glm::quat(glm::vec3(
(cam_elevation - 2.f) * glm::pi<float>() / 2.f, glm::pi<float>() * cam_azimuth, 0.f));
_entities.entity_builder("camera")
.rotation(cam_dir)
.position(glm::rotate(cam_dir, glm::vec3(0, 0, -1)) * 8.f + position)
.post_create([=](ecs::Entity_facet entity) {
entity.process<Transform_comp>([&](auto& transform) {
transform.position = transform.direction() * -10.f + position;
transform.look_at(position);
});
entity.process([=](gameplay::Viewtarget_comp& viewtarget) {
viewtarget.target = playerhandle;
});
})
.create();
});
}
auto Level_system::load(const std::string& name) -> void
......@@ -18,11 +46,12 @@ namespace phase_shifter::level {
for(auto&& row : level._tiles) {
position.x = 0.f;
for(auto&& tile_key : row) {
if(auto tile_it = tiles.find(std::string(1, tile_key)); tile_it != tiles.end()) {
std::string key(1, tile_key);
if(auto tile_it = tiles.find(key); tile_it != tiles.end()) {
auto& tile = tile_it->second;
_entities.entity_builder(tile.blueprint).position(position).create();
if(tile.spawn) {
_entities.entity_builder(tile.spawns).position(position).create();
_spawn_function(key)(tile, position);
}
position.x += offset;
}
......@@ -30,4 +59,15 @@ namespace phase_shifter::level {
position.z += offset;
}
}
auto Level_system::_spawn_function(const std::string& key)
-> std::function<auto(const Tile&, const glm::vec3&)->void>
{
if(auto spawner_it = _spawners.find(key); spawner_it != _spawners.end()) {
return spawner_it->second;
}
return [&](const Tile& tile, const glm::vec3& position) {
_entities.entity_builder(tile.spawns).position(position).create();
};
}
} // namespace phase_shifter::level
......@@ -2,6 +2,9 @@
#include "level.hpp"
#include <functional>
#include <unordered_map>
namespace mirrage::ecs {
class Entity_manager;
}
......@@ -18,9 +21,13 @@ namespace phase_shifter::level {
auto load(const std::string& name) -> void;
private:
auto _spawn_function(const std::string& key)
-> std::function<auto(const Tile&, const glm::vec3&)->void>;
mirrage::ecs::Entity_manager& _entities;
mirrage::asset::Asset_manager& _assets;
Level_ptr _current_level;
std::unordered_map<std::string, std::function<auto(const Tile&, const glm::vec3&)->void>> _spawners;
};
} // namespace phase_shifter::level
......@@ -79,11 +79,6 @@ namespace phase_shifter {
// TODO: replace with level-loading / generation code
auto cam_elevation = 0.3f * glm::pi<float>();
auto cam_azimuth = 0.0f;
auto cam_dir = glm::quat(glm::vec3(
(cam_elevation - 2.f) * glm::pi<float>() / 2.f, glm::pi<float>() * cam_azimuth, 0.f));
auto sun_elevation = 0.05f * glm::pi<float>();
auto sun_azimuth = 0.7f;
auto sun_dir = glm::quat(glm::vec3(
......@@ -93,22 +88,6 @@ namespace phase_shifter {
.rotation(sun_dir)
.position(glm::rotate(sun_dir, glm::vec3(0, 0, 1)) * 40.f)
.create();
mirrage::ecs::Entity_facet player = entities().entity_builder("player").position({0, 1, 0}).create();
auto playerhandle = player.handle();
entities()
.entity_builder("camera")
.rotation(cam_dir)
.position(glm::rotate(cam_dir, glm::vec3(0, 0, -1)) * 8.f)
.post_create([=](ecs::Entity_facet entity) {
entity.process<Transform_comp>([&](auto& transform) {
transform.position = transform.direction() * -10.f;
transform.look_at({0, 0, 0});
});
entity.process(
[=](gameplay::Viewtarget_comp& viewtarget) { viewtarget.target = playerhandle; });
})
.create();
}
Meta_system::~Meta_system()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment