From 91dd78d4c963dbcc596e44bf6991c40bb2df90cb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 2 Jun 2018 12:09:04 -0400 Subject: dust now ripples outward --- src/main.cpp | 96 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 33 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 77c4510..67be361 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "util.h" #include "map.h" @@ -80,12 +82,16 @@ struct Input { bool down = false; }; +using coord = std::tuple; + struct Kickup { int x; int y; size_t cur; size_t radius; size_t chain; + std::set done; + std::set front; }; struct MapData { @@ -93,6 +99,7 @@ struct MapData { bool lit = false; bool wasLit = false; double visibility = 0.0; + size_t dustLife = 0; }; class Game { @@ -319,6 +326,7 @@ void movePlayer(Game& game, int x, int y) if (game.map.at(game.player_x, game.player_y).tile == Tile::Floor) { game.map.at(game.player_x, game.player_y).tile = Tile::Dust; + game.map.at(game.player_x, game.player_y).dustLife = 1; game.numDust++; } @@ -430,6 +438,8 @@ void kickUpDust(Game& game, int x, int y, size_t chain) dk.chain = chain; dk.cur = 0; dk.radius = RADIUS + (chain + 1) * (chain + 1); + dk.front.emplace(x, y); + dk.done.emplace(x, y); game.kickups.push_back(dk); } @@ -442,6 +452,7 @@ void popLamp(Game& game, int x, int y, size_t chain) } game.map.at(x,y).tile = Tile::Dust; + game.map.at(x,y).dustLife = 2; game.numDust++; game.dirtyLighting = true; @@ -454,32 +465,24 @@ void processKickup(Game& game) { kickup.cur++; - if (game.map.at(kickup.x, kickup.y).tile == Tile::Floor) + std::set newFront; + for (const coord& xy : kickup.front) { - game.map.at(kickup.x, kickup.y).tile = Tile::Dust; - game.numDust++; - } - - std::unique_ptr dusty(new fov_settings_type); - fov_settings_set_opacity_test_function( - dusty.get(), - [] (void* data, int x, int y) { - Game& game = *static_cast(data); + auto processDir = [&] (int x, int y) { + coord c {x,y}; - return game.map.inBounds(x,y) && game.map.at(x,y).tile == Tile::Wall; - }); - - fov_settings_set_apply_lighting_function( - dusty.get(), - [] (void* data, int x, int y, int, int, void* source) { - Game& game = *static_cast(data); - Kickup& kickup = *static_cast(source); - - if (game.map.inBounds(x,y)) + if (game.map.inBounds(x,y) && + (game.map.at(x,y).tile == Tile::Floor || + game.map.at(x,y).tile == Tile::Lamp) && + !kickup.done.count(c)) { + newFront.insert(c); + kickup.done.insert(c); + if (game.map.at(x,y).tile == Tile::Floor) { game.map.at(x,y).tile = Tile::Dust; + game.map.at(x,y).dustLife = 2; game.numDust++; game.dirtyLighting = true; } else if (game.map.at(x,y).tile == Tile::Lamp) @@ -487,15 +490,35 @@ void processKickup(Game& game) popLamp(game, x, y, kickup.chain + 1); } } - }); - - fov_circle( - dusty.get(), - static_cast(&game), - static_cast(&kickup), - kickup.x, - kickup.y, - kickup.cur); + }; + + processDir(std::get<0>(xy) - 1, std::get<1>(xy) ); + processDir(std::get<0>(xy) + 1, std::get<1>(xy) ); + processDir(std::get<0>(xy) , std::get<1>(xy) - 1); + processDir(std::get<0>(xy) , std::get<1>(xy) + 1); + + if (std::bernoulli_distribution(0.5)(game.rng)) + { + processDir(std::get<0>(xy) - 1, std::get<1>(xy) - 1); + } + + if (std::bernoulli_distribution(0.5)(game.rng)) + { + processDir(std::get<0>(xy) - 1, std::get<1>(xy) + 1); + } + + if (std::bernoulli_distribution(0.5)(game.rng)) + { + processDir(std::get<0>(xy) + 1, std::get<1>(xy) - 1); + } + + if (std::bernoulli_distribution(0.5)(game.rng)) + { + processDir(std::get<0>(xy) + 1, std::get<1>(xy) + 1); + } + } + + kickup.front.swap(newFront); } erase_if( @@ -716,17 +739,24 @@ int main(int, char**) while (dustAcc >= dustDt) { + game.numDust = 0; + for (MapData& md : game.map.data()) { if (md.tile == Tile::Dust) { - md.tile = Tile::Floor; - game.dirtyLighting = true; + md.dustLife--; + + if (md.dustLife <= 0) + { + md.tile = Tile::Floor; + game.dirtyLighting = true; + } else { + game.numDust++; + } } } - game.numDust = 0; - processKickup(game); dustAcc -= dustDt; -- cgit 1.4.1