aboutsummaryrefslogtreecommitdiff
path: root/src/sandbox.hpp
blob: 0ae80824b9e1932e4230b6d961c3b976ff000877 (plain)
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
56
57
58
59
#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();

    // "Get Sand"
    Tile& gs(int x, int y);
    // "Set Sand"
    void ss(int x, int y, Tile sand);
    void shift_sand(int x, int y);

    void mark_dirty(int x, int y); // UNCHECKED

    // std::vector<uint32_t> to_bitmap() const;
};