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

#include "pcg.hpp"

#include <cstdint>
#include <vector>

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 {
    std::vector<uint32_t> _bitmap;
    std::vector<Tile> _a;
    Pcg32 _pcg;
    Tile _wall_tile;
    int width, height;
    int _x, _y;
    int ncycle = 0;

    Sandbox(int w, int h);

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