Fixing a stupid bug where it would crash because a fact wasn't in the world.

main
Zed A. Shaw 2 days ago
parent 93f53d1714
commit 5a6494acf5
  1. 6
      dinkyecs.hpp
  2. 1
      gui.cpp
  3. 1
      main.cpp
  4. 1
      status.txt
  5. 4
      tests/lighting.cpp
  6. 3
      tests/matrix.cpp
  7. 1
      tests/render.cpp

@ -8,6 +8,7 @@
#include <tuple>
#include <queue>
#include "tser.hpp"
#include "dbc.hpp"
namespace DinkyECS {
@ -56,8 +57,11 @@ namespace DinkyECS {
template <typename Comp>
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
std::any &res = $facts.at(std::type_index(typeid(Comp)));
std::any &res = $facts.at(comp_id);
return std::any_cast<Comp&>(res);
}

@ -262,6 +262,7 @@ void GUI::render_scene() {
}
int GUI::main(bool run_once) {
$world.set_the<Debug>({});
create_renderer();
run_systems();

@ -24,7 +24,6 @@ namespace fs = std::filesystem;
*/
void configure_world(DinkyECS::World &world, Map &game_map) {
const auto &config = world.get_the<MapConfig>();
world.set_the<Debug>({});
// configure a player as a fact of the world
Player player{world.entity()};
world.set_the<Player>(player);

@ -5,6 +5,7 @@ TODAY'S GOAL:
* Flame pillars icon \u2e3e
* Room should always be found.
* 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 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::dump("WALLS=====", map.walls());
matrix::dump("LIGHT PATHS======", lr.$paths.$paths);
//matrix::dump("WALLS=====", map.walls());
//matrix::dump("LIGHT PATHS======", lr.$paths.$paths);
// confirm light is set at least at and around the two points
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();
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++) {
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();
Player player{world.entity()};
world.set_the<Debug>({});
world.set_the<Player>(player);
world.set<Tile>(player.entity, {config.PLAYER_TILE});
world.set<LightSource>(player.entity, {6,1});

Loading…
Cancel
Save