diff options
author | rtk0c <[email protected]> | 2025-04-25 16:57:13 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-04-25 16:57:13 -0700 |
commit | 03f4c32dd3a868c2ff1858b029429ca7929a11d7 (patch) | |
tree | 84a6db8a044e58fa045ff38aca5757e9f1ca9280 /src | |
parent | c62f0470273a3f4d12e5702398dc4b6e4c6f31fb (diff) |
Fix update loop direction
Going up to down causes the sand to collide in mid-air
Diffstat (limited to 'src')
-rw-r--r-- | src/sandbox.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/sandbox.cpp b/src/sandbox.cpp index ccfde52..6daa807 100644 --- a/src/sandbox.cpp +++ b/src/sandbox.cpp @@ -7,15 +7,22 @@ // Copied from IM_COL32 #define COL_U32(r, g, b, a) (((uint32_t)(A) << IM_COL32_A_SHIFT) | ((uint32_t)(B) << IM_COL32_B_SHIFT) | ((uint32_t)(G) << IM_COL32_G_SHIFT) | ((uint32_t)(R) << IM_COL32_R_SHIFT)) -static constexpr uint32_t MAT_COLOR_LUT[] = { - 0xffffff'ff, // AIR - 0xababab'ff, // SOLID - 0xfffca8'ff, // SAND - 0x435bf7'ff, // WATER +// Correct byte order for this platform +constexpr uint32_t bo(uint32_t n) { + if (std::endian::native == std::endian::little) + return std::byteswap(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 }; uint32_t Tile::get_color() const { - return MAT_COLOR_LUT[std::to_underlying(so)]; + return material_color_lut[std::to_underlying(so)]; } Sandbox::Sandbox(int w, int h) @@ -28,7 +35,11 @@ Sandbox::Sandbox(int w, int h) , height{ h } // { memset(_bitmap.data(), 0xff, _bitmap.size() * sizeof(_bitmap[0])); - set_sand(10, 80, Tile{ .so = Tile::SAND }); + for (int y = 80; y <= 90; ++y) { + for (int x = 10; x <= 13; ++x) { + set_sand(x, y, Tile{ .so = Tile::SAND }); + } + } } static void simulate_sand_tile(Sandbox& self, int x, int y) { @@ -86,8 +97,8 @@ static void simulate_sand_tile(Sandbox& self, int x, int y) { void Sandbox::simulate_step() { _x = 0; - _y = height ; - for (; _y >= 0; --_y) { + _y = 0; + for (; _y < height; ++_y) { for (; _x < width; ++_x) { simulate_sand_tile(*this, _x, _y); } |