aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sandbox.cpp29
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);
}