blob: bb778062a877bbcc881bc9db8e0415edeb169d8d (
plain) (
blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#ifndef SIMULATION_H_7BF6EEA4
#define SIMULATION_H_7BF6EEA4
#include "state.h"
#include "entity.h"
#include "schedule.h"
#include <range/v3/all.hpp>
#include <vector>
#include <deque>
#include <set>
class Level;
class Simulation : public State {
public:
// Constructor
explicit Simulation(const Level& level);
void tick(
double dt,
const Uint8* keystate) override;
void render(SDL_Renderer* ren) override;
id_type emplaceEntity();
void deleteEntity(id_type id);
Entity& getEntity(id_type id)
{
return entities_.at(id);
}
const Entity& getEntity(id_type id) const
{
return entities_.at(id);
}
const std::set<id_type>& getActive() const
{
return active_;
}
const Level& getLevel() const
{
return level_;
}
auto entityView()
{
return ranges::view::transform([&] (id_type id) -> Entity& {
return entities_.at(id);
});
}
auto entityView() const
{
return ranges::view::transform([&] (id_type id) -> const Entity& {
return entities_.at(id);
});
}
auto entityRange()
{
return active_ | entityView();
}
auto entityRange() const
{
return active_ | entityView();
}
private:
bool moveEntityOnGrid(
Entity& entity,
Direction moveDir,
bool validate = false);
const Level& level_;
Schedule schedule_ { 90 };
std::vector<Entity> entities_;
std::deque<id_type> available_;
std::set<id_type> active_;
texture_ptr renderedMap_;
};
#endif /* end of include guard: SIMULATION_H_7BF6EEA4 */
|