blob: 2f80f9f3fef3cc5c8c472b7c02fc72231131e93d (
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
|
#ifndef SIMULATION_H_7BF6EEA4
#define SIMULATION_H_7BF6EEA4
#include "entity.h"
#include "renderer.h"
#include <vector>
#include <deque>
#include <set>
#include <unordered_map>
#include <unordered_set>
class Level;
class Simulation {
public:
using id_type = std::vector<Entity>::size_type;
// Constructor
explicit Simulation(const Level& level) : level_(level) {}
void tick(
double dt,
const Uint8* keystate);
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_;
}
void setGridPos(id_type id, vec2s pos);
private:
const std::unordered_set<id_type>& getGridEntities(vec2s pos) const;
bool moveEntityOnGrid(
id_type id,
Direction moveDir,
bool validate = false);
const Level& level_;
std::vector<Entity> entities_;
std::deque<id_type> available_;
std::set<id_type> active_;
mutable std::unordered_map<size_t, std::unordered_set<id_type>> gridCache_;
};
#endif /* end of include guard: SIMULATION_H_7BF6EEA4 */
|