Removed the variable limit setting since it's never used and instead just have WALL_PATH_LIMIT.
This commit is contained in:
parent
9abb39a3bf
commit
eb0ca38e30
19 changed files with 50 additions and 58 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <fstream>
|
||||
#include <codecvt>
|
||||
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
struct Config {
|
||||
|
|
11
constants.hpp
Normal file
11
constants.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
* Eventually move most of these into runtime locations.
|
||||
*/
|
||||
const int INV_WALL = 0;
|
||||
const int INV_SPACE = 1;
|
||||
const int WALL_VALUE = 1;
|
||||
const int SPACE_VALUE = 0;
|
||||
const int WALL_PATH_LIMIT = 1000;
|
||||
const int WALL_LIGHT_LEVEL = 3;
|
2
gui.cpp
2
gui.cpp
|
@ -36,7 +36,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
|
|||
$log({{"Welcome to the game!"}}),
|
||||
$status_ui(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
|
||||
$map_view(GAME_MAP_POS, 0, 0, 0, true),
|
||||
$lights(game_map.width(), game_map.height(), game_map.limit()),
|
||||
$lights(game_map.width(), game_map.height()),
|
||||
$world(world),
|
||||
$sounds("./assets"),
|
||||
$renderer()
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#include "lights.hpp"
|
||||
#include "constants.hpp"
|
||||
#include <vector>
|
||||
|
||||
const int WALL_LIGHT_LEVEL = 3;
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace lighting {
|
||||
void LightRender::render_light(LightSource source, Point at) {
|
||||
const int UNPATH = $limit;
|
||||
Point min, max;
|
||||
light_box(source, at, min, max);
|
||||
clear_light_target(at);
|
||||
|
@ -18,7 +16,7 @@ namespace lighting {
|
|||
auto &path_row = $paths.$paths[y];
|
||||
|
||||
for(size_t x = min.x; x <= max.x; ++x) {
|
||||
if(path_row[x] != UNPATH) {
|
||||
if(path_row[x] != WALL_PATH_LIMIT) {
|
||||
light_row[x] = light_level(source.strength, x, y);
|
||||
has_light.push_back({x,y});
|
||||
}
|
||||
|
@ -32,7 +30,7 @@ namespace lighting {
|
|||
auto &light_row = $lightmap[point.y+j];
|
||||
|
||||
for(int i = -1; point.x+i >= 0 && i <= 1 && point.x+i < $width; i++) {
|
||||
if(path_row[point.x+i] == UNPATH) {
|
||||
if(path_row[point.x+i] == WALL_PATH_LIMIT) {
|
||||
light_row[point.x+i] = light_level(wall_light, point.x, point.y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,18 +32,16 @@ namespace lighting {
|
|||
|
||||
class LightRender {
|
||||
public:
|
||||
int $limit;
|
||||
size_t $width;
|
||||
size_t $height;
|
||||
Matrix $lightmap;
|
||||
Pathing $paths;
|
||||
|
||||
LightRender(size_t width, size_t height, int limit) :
|
||||
$limit(limit),
|
||||
LightRender(size_t width, size_t height) :
|
||||
$width(width),
|
||||
$height(height),
|
||||
$lightmap(height, MatrixRow(width, 0)),
|
||||
$paths(width, height, limit)
|
||||
$paths(width, height)
|
||||
{}
|
||||
|
||||
void reset_light();
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -53,7 +53,6 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
|
|||
world.set<Loot>(gold, {100});
|
||||
world.set<Tile>(gold, {"$"});
|
||||
|
||||
|
||||
auto wall_torch = world.entity();
|
||||
world.set<Position>(wall_torch, {game_map.place_entity(4)});
|
||||
world.set<LightSource>(wall_torch, {2,3});
|
||||
|
|
6
map.cpp
6
map.cpp
|
@ -30,15 +30,13 @@ void dump_map(const std::string &msg, Matrix &map, int show_x, int show_y) {
|
|||
}
|
||||
|
||||
Map::Map(size_t width, size_t height) :
|
||||
$limit(WALL_PATH_LIMIT),
|
||||
$width(width),
|
||||
$height(height),
|
||||
$walls(height, MatrixRow(width, INV_WALL)),
|
||||
$paths(height, width, WALL_PATH_LIMIT)
|
||||
$paths(height, width)
|
||||
{}
|
||||
|
||||
Map::Map(Matrix &walls, Pathing &paths, int limit) :
|
||||
$limit(limit),
|
||||
Map::Map(Matrix &walls, Pathing &paths) :
|
||||
$walls(walls),
|
||||
$paths(paths)
|
||||
{
|
||||
|
|
11
map.hpp
11
map.hpp
|
@ -10,12 +10,7 @@
|
|||
#include "lights.hpp"
|
||||
#include "pathing.hpp"
|
||||
#include "matrix.hpp"
|
||||
|
||||
const int INV_WALL = 0;
|
||||
const int INV_SPACE = 1;
|
||||
const int WALL_VALUE = 1;
|
||||
const int SPACE_VALUE = 0;
|
||||
const int WALL_PATH_LIMIT = 1000;
|
||||
#include "constants.hpp"
|
||||
|
||||
using lighting::LightSource;
|
||||
|
||||
|
@ -35,7 +30,6 @@ void dump_map(const std::string &msg, Matrix &map, int show_x=-1, int show_y=-1)
|
|||
|
||||
class Map {
|
||||
public:
|
||||
int $limit;
|
||||
size_t $width;
|
||||
size_t $height;
|
||||
Matrix $walls;
|
||||
|
@ -44,7 +38,7 @@ public:
|
|||
|
||||
Map(size_t width, size_t height);
|
||||
|
||||
Map(Matrix &walls, Pathing &paths, int limit);
|
||||
Map(Matrix &walls, Pathing &paths);
|
||||
|
||||
// disable copying
|
||||
Map(Map &map) = delete;
|
||||
|
@ -52,7 +46,6 @@ public:
|
|||
Matrix& paths() { return $paths.paths(); }
|
||||
Matrix& input_map() { return $paths.input(); }
|
||||
Matrix& walls() { return $walls; }
|
||||
int limit() { return $limit; }
|
||||
size_t width() { return $width; }
|
||||
size_t height() { return $height; }
|
||||
int distance(Point to) { return $paths.distance(to); }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "constants.hpp"
|
||||
#include "pathing.hpp"
|
||||
#include "dbc.hpp"
|
||||
#include <vector>
|
||||
|
@ -30,9 +31,7 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
|
|||
void Pathing::compute_paths(Matrix &walls) {
|
||||
INVARIANT();
|
||||
// Initialize the new array with every pixel at limit distance
|
||||
// NOTE: this is normally ones() * limit
|
||||
int limit = $limit == 0 ? $height * $width : $limit;
|
||||
matrix_assign($paths, limit);
|
||||
matrix_assign($paths, WALL_PATH_LIMIT);
|
||||
|
||||
Matrix closed = walls;
|
||||
PointList starting_pixels;
|
||||
|
@ -56,7 +55,7 @@ void Pathing::compute_paths(Matrix &walls) {
|
|||
|
||||
// Third pass: Iterate filling in the open list
|
||||
int counter = 1; // leave this here so it's available below
|
||||
for(; counter < limit && !open_pixels.empty(); ++counter) {
|
||||
for(; counter < WALL_PATH_LIMIT && !open_pixels.empty(); ++counter) {
|
||||
PointList next_open;
|
||||
for(auto sp : open_pixels) {
|
||||
$paths[sp.y][sp.x] = counter;
|
||||
|
|
|
@ -4,14 +4,12 @@
|
|||
|
||||
class Pathing {
|
||||
public:
|
||||
int $limit;
|
||||
size_t $width;
|
||||
size_t $height;
|
||||
Matrix $paths;
|
||||
Matrix $input;
|
||||
|
||||
Pathing(size_t width, size_t height, int limit) :
|
||||
$limit(limit),
|
||||
Pathing(size_t width, size_t height) :
|
||||
$width(width),
|
||||
$height(height),
|
||||
$paths(height, MatrixRow(width, 1)),
|
||||
|
|
7
save.cpp
7
save.cpp
|
@ -22,7 +22,7 @@ void save::to_file(fs::path path, DinkyECS::World &world, Map &map) {
|
|||
|
||||
save_data.facts.player = world.get_the<Player>();
|
||||
save_data.map = MapData{
|
||||
map.$limit, map.$width, map.$height,
|
||||
map.$width, map.$height,
|
||||
map.$rooms, map.$walls};
|
||||
|
||||
// BUG: lights aren't saved/restored
|
||||
|
@ -76,10 +76,9 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) {
|
|||
|
||||
size_t width = save_data.map.width;
|
||||
size_t height = save_data.map.height;
|
||||
int limit = save_data.map.limit;
|
||||
|
||||
Pathing paths(width, height, limit);
|
||||
map_out = Map(save_data.map.walls, paths, limit);
|
||||
Pathing paths(width, height);
|
||||
map_out = Map(save_data.map.walls, paths);
|
||||
|
||||
save::load_configs(world_out);
|
||||
}
|
||||
|
|
3
save.hpp
3
save.hpp
|
@ -11,13 +11,12 @@ namespace save {
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
struct MapData {
|
||||
int limit;
|
||||
size_t width;
|
||||
size_t height;
|
||||
std::vector<Room> rooms;
|
||||
Matrix walls;
|
||||
|
||||
DEFINE_SERIALIZABLE(MapData, limit, width, height, rooms, walls);
|
||||
DEFINE_SERIALIZABLE(MapData, width, height, rooms, walls);
|
||||
};
|
||||
|
||||
struct Facts {
|
||||
|
|
16
status.txt
16
status.txt
|
@ -1,16 +1,20 @@
|
|||
TODAY'S GOAL:
|
||||
* Big Code Review
|
||||
* Clean up and document as much code as possible.
|
||||
* color namespace is too ambiguous
|
||||
|
||||
* Lua integration
|
||||
|
||||
TODO:
|
||||
* $limit is pointless, just use a constant.
|
||||
* Pathing::compute_paths can take a starting level to implement lower directions, or possibly setting a value lower?
|
||||
|
||||
* Fix " room should always be found"
|
||||
|
||||
* Pathing::set_target isn't using value, but that implements the above.
|
||||
https://www.roguebasin.com/index.php/Dijkstra_Maps_Visualized
|
||||
|
||||
* Fix BUG markers as much as possible.
|
||||
|
||||
* Make room generation have "texture" or state like mossy, flooded, etc.
|
||||
|
||||
TODO:
|
||||
* Lua integration
|
||||
|
||||
* When fighting two enemies with lots of attacks it crashes because one dies and isn't there. Test by making enemies immortal.
|
||||
* LightRender can just use the Dijkstra map paths to calculate light strenght from the point rather than doing the box thing.
|
||||
* $paths.$paths is annoying.
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
[1, 0, 1, 1],
|
||||
[1, 0, 10, 2],
|
||||
[1, 1, 10, 3]
|
||||
],
|
||||
"limit": 10
|
||||
]
|
||||
},{
|
||||
"input": [
|
||||
[1, 1, 1, 0],
|
||||
|
@ -36,6 +35,5 @@
|
|||
[1, 0, 1, 1],
|
||||
[1, 0, 16, 2],
|
||||
[1, 1, 16, 3]
|
||||
],
|
||||
"limit": 0
|
||||
]
|
||||
}]
|
||||
|
|
|
@ -19,7 +19,7 @@ TEST_CASE("lighting a map works", "[lighting]") {
|
|||
LightSource source1{7,1};
|
||||
LightSource source2{3,2};
|
||||
|
||||
LightRender lr(map.width(), map.height(), map.limit());
|
||||
LightRender lr(map.width(), map.height());
|
||||
|
||||
lr.reset_light();
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
|||
Matrix walls = test["walls"];
|
||||
Map map(input.size(), input[0].size());
|
||||
map.$walls = walls;
|
||||
map.$limit = test["limit"];
|
||||
map.$paths.$input = input;
|
||||
|
||||
REQUIRE(map.INVARIANT());
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "pathing.hpp"
|
||||
#include "map.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
|
@ -19,9 +20,8 @@ TEST_CASE("dijkstra algo test", "[pathing]") {
|
|||
for(auto &test : data) {
|
||||
Matrix expected = test["expected"];
|
||||
Matrix walls = test["walls"];
|
||||
int limit = test["limit"];
|
||||
|
||||
Pathing pathing(walls[0].size(), walls.size(), limit);
|
||||
Pathing pathing(walls[0].size(), walls.size());
|
||||
|
||||
pathing.$input = test["input"];
|
||||
|
||||
|
@ -29,6 +29,7 @@ TEST_CASE("dijkstra algo test", "[pathing]") {
|
|||
pathing.compute_paths(walls);
|
||||
|
||||
REQUIRE(pathing.INVARIANT());
|
||||
REQUIRE(pathing.$paths == expected);
|
||||
|
||||
// REQUIRE(pathing.$paths == expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ TEST_CASE("can render a text", "[render]") {
|
|||
|
||||
world.set<Position>(player.entity, {map.place_entity(0)});
|
||||
|
||||
LightRender lights(map.width(), map.height(), map.limit());
|
||||
LightRender lights(map.width(), map.height());
|
||||
|
||||
Canvas map_canvas(map_view.width * 2, map_view.height * 4);
|
||||
|
||||
|
|
|
@ -171,12 +171,9 @@ void WorldBuilder::place_rooms() {
|
|||
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
||||
Matrix &paths = $map.paths();
|
||||
|
||||
// BUG: limit should be a constant since it never changes
|
||||
int limit = $map.limit();
|
||||
|
||||
dbc::check(paths[src.y][src.x] != limit,
|
||||
dbc::check(paths[src.y][src.x] != WALL_PATH_LIMIT,
|
||||
"source room has path as a wall");
|
||||
dbc::check(paths[target.y][target.x] != limit,
|
||||
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
||||
"target room has path as a wall");
|
||||
|
||||
bool found = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue