aboutsummaryrefslogtreecommitdiff
path: root/src/sandbox.hpp
blob: 03a6a8533ae6ac3e42349ee56115640279031765 (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
#pragma once

#include "common.hpp"
#include "rand.hpp"

#include <cstdint>

const int MBIT_DISPLACABLE = 1;

struct Tile {
    enum Solid : unsigned char {
        AIR = 0,
        ROCK,
        SAND,
    };

    enum Fluid : unsigned char {
        NOTHING = 0,
        WATER,
    };

    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;
};