about summary refs log tree commit diff stats
path: root/tools/util/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'tools/util/CMakeLists.txt')
0 files changed, 0 insertions, 0 deletions
> 2021-02-03 01:11:31 -0500 Added camera system' href='/tanetane/commit/src/game.h?id=24918837c3ff9026d228657d14852c9cf39a5644'>2491883 ^
470b1d4 ^
996076c ^
0334d39 ^
a475b84 ^
b628c80 ^
2491883 ^
683e22c ^
871943d ^


410f971 ^
0334d39 ^


996076c ^
871943d ^
683e22c ^





2491883 ^















f449345 ^
0e1e97d ^
0334d39 ^
470b1d4 ^

763bd80 ^
0334d39 ^


f449345 ^



470b1d4 ^
f449345 ^
0334d39 ^

0e1e97d ^



763bd80 ^





be09120 ^



f316670 ^

aac57db ^
7166c9b ^
a475b84 ^
7166c9b ^
871943d ^

996076c ^

5df0d06 ^





0334d39 ^

683e22c ^


2491883 ^

f449345 ^
470b1d4 ^
aac57db ^
0334d39 ^
0e1e97d ^
a475b84 ^
871943d ^
996076c ^
5df0d06 ^
0334d39 ^


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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113


                       
                
               
                           
                 
                 
              
              
                 
                   
                
                   
                   
                  


                 
 


            
                                                                                                 
 





                                                 















                                                                                                    
 
                                       
 

                             
                                         


                           



                             
                                     
                      

   



                                                 





                                                                   



                                                             

   
                                     
 
                                             
 

                                               

                                          





                                                   

        


                           

                                              
 
                           
                              
                               
                                             
                            
             
                     
                       


                                                  
#ifndef GAME_H_E6F1396E
#define GAME_H_E6F1396E

#include <deque>
#include <list>
#include <range/v3/all.hpp>
#include <vector>
#include <memory>
#include <map>
#include <set>
#include <random>
#include "sprite.h"
#include "map.h"
#include "consts.h"
#include "system.h"
#include "mixer.h"
#include "font.h"

class Renderer;

class Game {
public:

  Game(Renderer& renderer, std::mt19937& rng) : font_("../res/font.txt", renderer), rng_(&rng) {}

  Mixer& getMixer() { return mixer_; }

  bool shouldQuit() const { return shouldQuit_; }

  void quit() { shouldQuit_ = true; }

  template <typename T>
  void emplaceSystem() {
    systems_.push_back(std::make_unique<T>(*this));
    systemByKey_[T::Key] = systems_.back().get();
  }

  template <typename T>
  T& getSystem() {
    return *dynamic_cast<T*>(systemByKey_.at(T::Key));
  }

  auto systems() {
    return systems_ | ranges::views::transform([&] (std::unique_ptr<System>& systemPtr) -> System& {
      return *systemPtr;
    });
  }

  int emplaceSprite(std::string alias);

  void destroySprite(int id);

  const Sprite& getSprite(int id) const {
    return sprites_.at(id);
  }

  Sprite& getSprite(int id) {
    return sprites_.at(id);
  }

  const std::set<int>& getSprites() {
    return spriteIds_;
  }

  int getSpriteByAlias(std::string alias) const {
    return spritesByAlias_.at(alias);
  }

  auto spriteView() const {
    return ranges::views::transform([&] (int id) -> const Sprite& {
      return sprites_.at(id);
    });
  }

  auto spriteView() {
    return ranges::views::transform([&] (int id) -> Sprite& {
      return sprites_.at(id);
    });
  }

  void loadMap(std::string filename);

  const Map& getMap() const { return *map_; }

  const Font& getFont() const { return font_; }

  std::mt19937& getRng() { return *rng_; }

  void pauseGameplay() { paused_ = true; }

  void unpauseGameplay() { paused_ = false; }

  bool isGameplayPaused() const { return paused_; }

private:

  Mixer mixer_;
  bool shouldQuit_ = false;

  std::list<std::unique_ptr<System>> systems_;
  std::map<SystemKey, System*> systemByKey_;

  std::set<int> spriteIds_;
  std::deque<int> idsToReuse_;
  std::vector<Sprite> sprites_;
  std::map<std::string, int> spritesByAlias_;
  std::unique_ptr<Map> map_;
  Font font_;
  std::mt19937* rng_;
  bool paused_ = false;
};

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