1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#pragma once
#include "common.hpp"
#include "rand.hpp"
#include <cstdint>
const int MBIT_DISPLACABLE = 1;
struct Tile {
enum Solid : unsigned char {
#define X(name, _1, _2) Ti_##name,
#include "x/tile_types.inc"
#undef X
};
enum Fluid : unsigned char {
#define X(name, _1, _2) Fl_##name,
#include "x/fluid_types.inc"
#undef X
};
Solid so = {};
Fluid fl = {};
uint8_t fmass = 0;
bool updated = false;
uint32_t get_color() const;
};
struct Sandbox {
uint32_t* bitmap;
Tile* tiles;
/// Dirty rects used by the current simulation step. Only used during it.
// TODO use multiple dirty rects?
Rect dirty_curr;
/// Dirty rects to be used, when the next simulation step happens. May write to this during simulation, or outside of simulation.
Rect dirty_writeto;
RandomState _rand;
Tile _wall_tile;
int width, height;
int _x, _y;
int ncycle = 0;
Sandbox(int w, int h, RandomState rand = {});
~Sandbox();
void simulate_step();
Tile& gs(int x, int y);
void set_sand(int x, int y, Tile sand);
void shift_sand(int x, int y);
// std::vector<uint32_t> to_bitmap() const;
};
|