Fixed worldgen to only use tiles without collision in filling rooms, then a couple more changes to lighting so that if the light is <= 1 it just assumes the base light strength which ends up looking nicer and more like the kind of light I want.

main
Zed A. Shaw 7 days ago
parent 59bbae0af0
commit 28d19d80a2
  1. 10
      assets/tiles.json
  2. 11
      config.cpp
  3. 4
      config.hpp
  4. 15
      lights.cpp
  5. 14
      tilemap.cpp
  6. 2
      tilemap.hpp
  7. 1
      tools/designer.cpp
  8. 8
      worldbuilder.cpp

@ -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"
}
}

@ -17,17 +17,6 @@ std::wstring Config::wstring(const std::string key) {
return $converter.from_bytes(str_val);
}
std::vector<std::string> Config::keys() {
// BUG: I mean, c'mon seriously this is how?
std::vector<std::string> 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<std::codecvt_utf8_utf16<wchar_t>> $converter;
const std::string& str_val = $config[main_key][sub_key];

@ -12,10 +12,8 @@ struct Config {
Config(nlohmann::json config, std::string src_path)
: $config(config), $src_path(src_path) {}
std::vector<std::string> 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);
};

@ -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;
}

@ -57,8 +57,18 @@ const TileCell &TileMap::at(size_t x, size_t y) {
return $display[y][x];
}
std::vector<std::string> TileMap::tile_names() {
return $config.keys();
std::vector<std::string> TileMap::tile_names(bool collision) {
const auto &json = $config.json();
std::vector<std::string> 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() {

@ -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<std::string> tile_names();
std::vector<std::string> tile_names(bool collision);
void dump(int show_x=-1, int show_y=-1);
bool INVARIANT();

@ -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);

@ -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<size_t>(0, room_types.size() - 1);
int room_size = Random::uniform<int>(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);
}
}

Loading…
Cancel
Save