diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sandbox.cpp | 37 | ||||
-rw-r--r-- | src/sandbox.hpp | 11 | ||||
-rw-r--r-- | src/ui.cpp | 44 | ||||
-rw-r--r-- | src/x/fluid_types.inc | 2 | ||||
-rw-r--r-- | src/x/tile_types.inc | 3 |
5 files changed, 70 insertions, 27 deletions
diff --git a/src/sandbox.cpp b/src/sandbox.cpp index efc2bd0..c6d0294 100644 --- a/src/sandbox.cpp +++ b/src/sandbox.cpp @@ -14,22 +14,27 @@ constexpr uint32_t bo(uint32_t n) { return n; } -static constexpr uint32_t material_color_lut[] = { - bo(0xffffff'ff), // AIR - bo(0xababab'ff), // SOLID - bo(0xe3dd24'ff), // SAND - bo(0x435bf7'ff), // WATER +static constexpr uint32_t TILE_COLORS_LUT[] = { +#define X(_0, _1, color) bo(color), +#include "x/tile_types.inc" +#undef X +}; + +static constexpr uint32_t FLUID_COLORS_LUT[] = { +#define X(_0, _1, color) bo(color), +#include "x/fluid_types.inc" +#undef X }; uint32_t Tile::get_color() const { - return material_color_lut[std::to_underlying(so)]; + return TILE_COLORS_LUT[std::to_underlying(so)]; } Sandbox::Sandbox(int w, int h, RandomState rand) : bitmap(new uint32_t[w * h]) , tiles(new Tile[w * h]) , _rand(std::move(rand)) - , _wall_tile{ Tile::ROCK } + , _wall_tile{ Tile::Ti_Rock } , width{ w } , height{ h } // { @@ -48,13 +53,13 @@ static void simulate_sand_tile(Sandbox& self, int x, int y) { } switch (at0.so) { - case Tile::AIR: break; + case Tile::Ti_Air: break; - case Tile::ROCK: break; + case Tile::Ti_Rock: break; - case Tile::SAND: { + case Tile::Ti_Sand: { const auto below = self.gs(x, y - 1); - if (below.so == Tile::AIR) { + if (below.so == Tile::Ti_Air) { self.set_sand(x, y, below); self.set_sand(x, y - 1, at0); } else { @@ -64,7 +69,7 @@ static void simulate_sand_tile(Sandbox& self, int x, int y) { for (int i = 0; i < bound; ++i) { // Try going to a side auto at1 = self.gs(loc1[i].x, loc1[i].y); - if (at1.so == Tile::AIR) { + if (at1.so == Tile::Ti_Air) { self.set_sand(x, y, at1); self.set_sand(loc1[i].x, loc1[i].y, at0); } @@ -74,16 +79,16 @@ static void simulate_sand_tile(Sandbox& self, int x, int y) { } break; } - if (at0.so == Tile::AIR) + if (at0.so == Tile::Ti_Air) switch (at0.fl) { - case Tile::NOTHING: break; + case Tile::Fl_Nothing: break; - case Tile::WATER: { + case Tile::Fl_Water: { // Pt neighs[]{ Pt(x - 1, y), Pt(x + 1, y), Pt(x, y + 1), Pt(x, y - 1) }; // int max_pressure = 0; // for (auto [x1, y1] : neighs) { // auto& neigh = self.gs(x1, y1); - // if (neigh.fl == Tile::WATER) { + // if (neigh.fl == Tile::Fl_Water) { // auto p = neigh.fmass; // max_pressure = max_pressure > p ? max_pressure : p; // } diff --git a/src/sandbox.hpp b/src/sandbox.hpp index 03a6a85..400f8ec 100644 --- a/src/sandbox.hpp +++ b/src/sandbox.hpp @@ -9,14 +9,15 @@ const int MBIT_DISPLACABLE = 1; struct Tile { enum Solid : unsigned char { - AIR = 0, - ROCK, - SAND, +#define X(name, _1, _2) Ti_##name, +#include "x/tile_types.inc" +#undef X }; enum Fluid : unsigned char { - NOTHING = 0, - WATER, +#define X(name, _1, _2) Fl_##name, +#include "x/fluid_types.inc" +#undef X }; Solid so = {}; @@ -71,6 +71,32 @@ enum BrushType_ { BrushType_Circle, }; +static const char* TILE_NAMES = +#define X(_0, str, _2) str "\0" +#include "x/tile_types.inc" +#undef X + ; + +static const char* FLUID_NAMES = +#define X(_0, str, _2) str "\0" +#include "x/fluid_types.inc" +#undef X + ; + +static void edit_tile_palette(Tile& palette) { + int tile = palette.so; + ImGui::Combo("Tile", &tile, TILE_NAMES); + palette.so = static_cast<Tile::Solid>(tile); + + int fluid = palette.fl; + ImGui::Combo("Fluid", &fluid, FLUID_NAMES); + palette.fl = static_cast<Tile::Fluid>(fluid); + + int fmass = palette.fmass; + ImGui::InputInt("Fluid mass", &fmass, 1); + palette.fmass = std::clamp(fmass, 1, 255); +} + static void paint_sand(Sandbox& sb, const Tile& palette, Pt pt, BrushType type, int size) { switch (type) { case BrushType_Box: { @@ -142,15 +168,21 @@ void ShowEverything() { ImGui::SameLine(); bool step = ImGui::Button("Step"); - static Tile palette{ .so = Tile::SAND }; + static Tile palette{ .so = Tile::Ti_Sand }; static int brush_size = 1; static BrushType brush_type = BrushType_Box; - ImGui::SliderInt("Brush radius", &brush_size, 1, 20); - ImGui::Combo("Brush type", - &brush_type, - "Box\0" - "Circle"); + if (ImGui::CollapsingHeader("Palette")) { + edit_tile_palette(palette); + } + + if (ImGui::CollapsingHeader("Brush")) { + ImGui::SliderInt("Brush radius", &brush_size, 1, 20); + ImGui::Combo("Brush type", + &brush_type, + "Box\0" + "Circle"); + } ImGui::End(); diff --git a/src/x/fluid_types.inc b/src/x/fluid_types.inc new file mode 100644 index 0000000..4e3a098 --- /dev/null +++ b/src/x/fluid_types.inc @@ -0,0 +1,2 @@ +X(Nothing, "nothing", 0x000000'00) +X(Water, "water", 0x435bf7'ff) diff --git a/src/x/tile_types.inc b/src/x/tile_types.inc new file mode 100644 index 0000000..58a1a23 --- /dev/null +++ b/src/x/tile_types.inc @@ -0,0 +1,3 @@ +X(Air, "air", 0xffffff'ff) +X(Rock, "rock", 0xababab'ff) +X(Sand, "sand", 0xe3dd24'ff) |