summary refs log tree commit diff stats
path: root/src/simulation.h
blob: 096377c20912f60aadf5d7f63df5d792dc162d06 (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
#ifndef SIMULATION_H_7BF6EEA4
#define SIMULATION_H_7BF6EEA4

#include "entity.h"
#include "renderer.h"
#include "schedule.h"
#include <range/v3/all.hpp>
#include <vector>
#include <deque>
#include <set>

class Level;

class Simulation {
public:

  // Constructor
  explicit Simulation(const 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_;
  }

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

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

#endif /* end of include guard: SIMULATION_H_7BF6EEA4 */