diff --git a/assets/tiles.json b/assets/tiles.json index 5c11134..cd93831 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -2,51 +2,61 @@ "WALL_TILE": { "foreground": [230, 20, 30], "background": [230, 20, 120], + "collision": true, "display": "\ua5b8" }, "FLOOR_TILE": { "foreground": [40, 15, 125], "background": [200, 15, 75], + "collision": false, "display":"\u289e" }, "MOSAIC_TILE_1": { "foreground": [40, 15, 125], "background": [200, 29, 75], + "collision": false, "display":"\u19f0" }, "MOSAIC_TILE_2": { "foreground": [40, 15, 125], "background": [200, 29, 75], + "collision": false, "display":"\u16de" }, "MOSAIC_TILE_3": { "foreground": [40, 15, 125], "background": [200, 29, 75], + "collision": false, "display":"\u1378" }, "BG_TILE": { "foreground": [230, 20, 125], "background": [230, 20, 125], + "collision": true, "display":"█" }, "WATER_TILE": { "foreground": [156, 164, 238], "background": [200, 15, 75], + "collision": false, "display":"\u2a93" }, "SAND_TILE": { "foreground": [24, 106, 180], "background": [24, 123, 100], + "collision": false, "display":"\u17f6" }, "GRASS_TILE": { "foreground": [41, 180, 180], "background": [75, 100, 100], + "collision": false, "display":"\u0799" }, "BROKEN_TILE": { "foreground": [159, 164, 15], "background": [199, 15, 79], + "collision": false, "display":"\u2274" } } diff --git a/config.cpp b/config.cpp index 7c9eb60..7d169af 100644 --- a/config.cpp +++ b/config.cpp @@ -17,17 +17,6 @@ std::wstring Config::wstring(const std::string key) { return $converter.from_bytes(str_val); } -std::vector Config::keys() { - // BUG: I mean, c'mon seriously this is how? - std::vector keys; - - for(const auto& el : $config.items()) { - keys.push_back(el.key()); - } - - return keys; -} - std::wstring Config::wstring(const std::string main_key, const std::string sub_key) { std::wstring_convert> $converter; const std::string& str_val = $config[main_key][sub_key]; diff --git a/config.hpp b/config.hpp index b7daaa3..2c2e295 100644 --- a/config.hpp +++ b/config.hpp @@ -12,10 +12,8 @@ struct Config { Config(nlohmann::json config, std::string src_path) : $config(config), $src_path(src_path) {} - std::vector keys(); - nlohmann::json &operator[](const std::string &key); - + nlohmann::json &json() { return $config; }; std::wstring wstring(const std::string main_key); std::wstring wstring(const std::string main_key, const std::string sub_key); }; diff --git a/lights.cpp b/lights.cpp index c32129b..f589f03 100644 --- a/lights.cpp +++ b/lights.cpp @@ -14,6 +14,13 @@ namespace lighting { } } + /* + * NOTE: This really doesn't need to calculate light all the time. It doesn't + * change around the light source until the lightsource is changed, so the + * light levels could be placed in a Matrix inside LightSource, calculated once + * and then simply "applied" to the area where the entity is located. The only + * thing that would need to be calculated each time is the walls. + */ void LightRender::render_light(LightSource source, Point at) { Point min, max; clear_light_target(at); @@ -21,22 +28,18 @@ namespace lighting { render_square_light(source, at, has_light); - const int wall_light = source.strength + WALL_LIGHT_LEVEL; for(auto point : has_light) { for(matrix::compass it{$lightmap, point.x, point.y}; it.next();) { if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) { - // BUG: include the distance in the list of walls to light - // so that they will be closer to the light level at that point - $lightmap[it.y][it.x] = light_level(wall_light, 1.0f, point.x, point.y); + $lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y); } } } } int LightRender::light_level(int strength, float distance, size_t x, size_t y) { + int new_level = distance <= 1.0f ? strength : strength / sqrt(distance); int cur_level = $lightmap[y][x]; - int new_level = strength / sqrt(distance + 0.6f); - return cur_level < new_level ? new_level : cur_level; } diff --git a/tilemap.cpp b/tilemap.cpp index 0bc0901..ad71665 100644 --- a/tilemap.cpp +++ b/tilemap.cpp @@ -57,8 +57,18 @@ const TileCell &TileMap::at(size_t x, size_t y) { return $display[y][x]; } -std::vector TileMap::tile_names() { - return $config.keys(); +std::vector TileMap::tile_names(bool collision) { + const auto &json = $config.json(); + std::vector keys; + + for(const auto& el : json.items()) { + const auto &val = el.value(); + if(val["collision"] == collision) { + keys.push_back(el.key()); + } + } + + return keys; } bool TileMap::INVARIANT() { diff --git a/tilemap.hpp b/tilemap.hpp index be3df9d..6f334a7 100644 --- a/tilemap.hpp +++ b/tilemap.hpp @@ -40,7 +40,7 @@ public: void load(matrix::Matrix &walls); const TileCell &at(size_t x, size_t y); void set_tile(size_t x, size_t y, std::string tile_name); - std::vector tile_names(); + std::vector tile_names(bool collision); void dump(int show_x=-1, int show_y=-1); bool INVARIANT(); diff --git a/tools/designer.cpp b/tools/designer.cpp index db22d22..1af6916 100644 --- a/tools/designer.cpp +++ b/tools/designer.cpp @@ -153,7 +153,6 @@ class GUI { } void resize_fonts(int new_size) { - println("RESIZE MAP TO {}", new_size); $renderer.resize_grid(new_size, $font_view); // set canvas to best size $canvas = Canvas($font_view.width * 2, $font_view.height * 4); diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 896a596..c5a2b8c 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -155,16 +155,14 @@ void WorldBuilder::generate() { $map.expand(); $map.load_tiles(); - auto room_types = $map.$tiles.tile_names(); + // get only the tiles with no collision to fill rooms + auto room_types = $map.$tiles.tile_names(false); for(size_t i = 0; i < $map.$rooms.size() - 1; i++) { size_t room_type = Random::uniform(0, room_types.size() - 1); int room_size = Random::uniform(100, 800); string tile_name = room_types[room_type]; - // BUG: really tiles should be configured as collision or not - if(tile_name != "WALL_TILE") { - stylize_room(i, tile_name, room_size * 0.01f); - } + stylize_room(i, tile_name, room_size * 0.01f); } }