Fixing a stupid bug where it would crash because a fact wasn't in the world.
This commit is contained in:
parent
93f53d1714
commit
5a6494acf5
7 changed files with 11 additions and 6 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "tser.hpp"
|
#include "tser.hpp"
|
||||||
|
#include "dbc.hpp"
|
||||||
|
|
||||||
namespace DinkyECS {
|
namespace DinkyECS {
|
||||||
|
|
||||||
|
@ -56,8 +57,11 @@ namespace DinkyECS {
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
Comp &get_the() {
|
Comp &get_the() {
|
||||||
|
auto comp_id = std::type_index(typeid(Comp));
|
||||||
|
dbc::check($facts.contains(comp_id), "!!!! ATTEMPT to access world fact that hasn't been set yet.");
|
||||||
|
|
||||||
// use .at to get std::out_of_range if fact not set
|
// use .at to get std::out_of_range if fact not set
|
||||||
std::any &res = $facts.at(std::type_index(typeid(Comp)));
|
std::any &res = $facts.at(comp_id);
|
||||||
return std::any_cast<Comp&>(res);
|
return std::any_cast<Comp&>(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
gui.cpp
1
gui.cpp
|
@ -262,6 +262,7 @@ void GUI::render_scene() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int GUI::main(bool run_once) {
|
int GUI::main(bool run_once) {
|
||||||
|
$world.set_the<Debug>({});
|
||||||
create_renderer();
|
create_renderer();
|
||||||
run_systems();
|
run_systems();
|
||||||
|
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -24,7 +24,6 @@ namespace fs = std::filesystem;
|
||||||
*/
|
*/
|
||||||
void configure_world(DinkyECS::World &world, Map &game_map) {
|
void configure_world(DinkyECS::World &world, Map &game_map) {
|
||||||
const auto &config = world.get_the<MapConfig>();
|
const auto &config = world.get_the<MapConfig>();
|
||||||
world.set_the<Debug>({});
|
|
||||||
// configure a player as a fact of the world
|
// configure a player as a fact of the world
|
||||||
Player player{world.entity()};
|
Player player{world.entity()};
|
||||||
world.set_the<Player>(player);
|
world.set_the<Player>(player);
|
||||||
|
|
|
@ -5,6 +5,7 @@ TODAY'S GOAL:
|
||||||
* Flame pillars icon \u2e3e
|
* Flame pillars icon \u2e3e
|
||||||
* Room should always be found.
|
* Room should always be found.
|
||||||
* matrix::in_box needs a rectangle alternative
|
* matrix::in_box needs a rectangle alternative
|
||||||
|
* DinkyECS needs to detect when a requested fact is missing and make a default.
|
||||||
|
|
||||||
* Study https://github.com/hirdrac/gx_lib/blob/main/gx/Unicode.hh
|
* Study https://github.com/hirdrac/gx_lib/blob/main/gx/Unicode.hh
|
||||||
* Study this https://en.cppreference.com/w/cpp/language/explicit
|
* Study this https://en.cppreference.com/w/cpp/language/explicit
|
||||||
|
|
|
@ -37,8 +37,8 @@ TEST_CASE("lighting a map works", "[lighting]") {
|
||||||
|
|
||||||
Matrix &lighting = lr.lighting();
|
Matrix &lighting = lr.lighting();
|
||||||
|
|
||||||
matrix::dump("WALLS=====", map.walls());
|
//matrix::dump("WALLS=====", map.walls());
|
||||||
matrix::dump("LIGHT PATHS======", lr.$paths.$paths);
|
//matrix::dump("LIGHT PATHS======", lr.$paths.$paths);
|
||||||
|
|
||||||
// confirm light is set at least at and around the two points
|
// confirm light is set at least at and around the two points
|
||||||
REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]);
|
REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]);
|
||||||
|
|
|
@ -237,12 +237,11 @@ TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
||||||
Matrix result = map.walls();
|
Matrix result = map.walls();
|
||||||
|
|
||||||
for(matrix::circle it{start, radius}; it.next();) {
|
for(matrix::circle it{start, radius}; it.next();) {
|
||||||
println("y={}, x0={}, x1={}", it.y, it.x0, it.x1);
|
|
||||||
for(int i = it.x0; i < it.x1; i++) {
|
for(int i = it.x0; i < it.x1; i++) {
|
||||||
result[it.y][i] += 1;
|
result[it.y][i] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix::dump("RESULT AFTER CIRCLE", result, start.x, start.y);
|
// matrix::dump("RESULT AFTER CIRCLE", result, start.x, start.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ TEST_CASE("can render a text", "[render]") {
|
||||||
builder.generate();
|
builder.generate();
|
||||||
|
|
||||||
Player player{world.entity()};
|
Player player{world.entity()};
|
||||||
|
world.set_the<Debug>({});
|
||||||
world.set_the<Player>(player);
|
world.set_the<Player>(player);
|
||||||
world.set<Tile>(player.entity, {config.PLAYER_TILE});
|
world.set<Tile>(player.entity, {config.PLAYER_TILE});
|
||||||
world.set<LightSource>(player.entity, {6,1});
|
world.set<LightSource>(player.entity, {6,1});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue