Thrive
compound_absorber_system.h
1 #pragma once
2 
3 #include <boost/range/adaptor/map.hpp>
4 
5 #include "engine/component.h"
6 #include "engine/system.h"
7 #include "engine/touchable.h"
8 #include "scripting/luabind.h"
9 #include "engine/typedefs.h"
10 
11 #include <luabind/object.hpp>
12 #include <memory>
13 #include <OgreCommon.h>
14 #include <OgreMath.h>
15 #include <OgreVector3.h>
16 #include <unordered_set>
17 
18 namespace thrive {
19 
20 using BoostCompoundMapIterator = boost::range_detail::select_second_mutable_range<std::unordered_map<std::string, CompoundId>>;
21 using BoostAbsorbedMapIterator = boost::range_detail::select_first_range<std::unordered_map<CompoundId, float>>;
22 
27  COMPONENT(CompoundAbsorber)
28 
29 public:
30 
45  static luabind::scope
46  luaBindings();
47 
51  std::unordered_map<CompoundId, float> m_absorbedCompounds;
52 
56  std::unordered_set<CompoundId> m_canAbsorbCompound;
57 
61  bool m_enabled = true;
62 
67 
76  float
78  CompoundId id
79  ) const;
80 
89  bool
91  CompoundId id
92  ) const;
93 
100  void
102  double capacity
103  );
104 
108  void
109  enable();
110 
114  void
115  disable();
116 
117  void
118  load(
120  ) override;
121 
133  void
135  CompoundId id,
136  float amount
137  );
138 
139  BoostAbsorbedMapIterator
140  getAbsorbedCompounds();
141 
150  void
152  CompoundId id,
153  bool canAbsorb
154  );
155 
157  storage() const override;
158 
159 };
160 
161 
166 
167 public:
168 
177  static luabind::scope
178  luaBindings();
179 
184 
189 
195  void init(GameState* gameState) override;
196 
200  void shutdown() override;
201 
205  void update(int, int) override;
206 
207 private:
208 
209  struct Implementation;
210  std::unique_ptr<Implementation> m_impl;
211 };
212 
213 }
std::unordered_set< CompoundId > m_canAbsorbCompound
Whether a particular compound id can be absorbed.
Definition: compound_absorber_system.h:56
CompoundAbsorberSystem()
Constructor.
Definition: compound_absorber_system.cpp:187
std::unordered_map< CompoundId, float > m_absorbedCompounds
The compounds absorbed in the last time step.
Definition: compound_absorber_system.h:51
static luabind::scope luaBindings()
Lua bindings.
Definition: compound_absorber_system.cpp:161
void load(const StorageContainer &storage) override
Loads the component.
Definition: compound_absorber_system.cpp:99
float absorbedCompoundAmount(CompoundId id) const
The absorbed amount in the last time step.
Definition: compound_absorber_system.cpp:56
Despawns compounds for CompoundAbsorberComponent.
Definition: compound_absorber_system.h:165
bool m_enabled
Whether anything can be absorbed.
Definition: compound_absorber_system.h:61
void init(GameState *gameState) override
Initializes the system.
Definition: compound_absorber_system.cpp:197
Base class for components.
Definition: component.h:31
A system handles one specific part of the game.
Definition: system.h:23
void setAbsorbedCompoundAmount(CompoundId id, float amount)
Sets the amount of absorbed compounds.
Definition: compound_absorber_system.cpp:115
StorageContainer storage() const override
Serializes the component.
Definition: compound_absorber_system.cpp:138
void enable()
Definition: compound_absorber_system.cpp:89
bool canAbsorbCompound(CompoundId id) const
Whether an compound can be absorbed.
Definition: compound_absorber_system.cpp:75
Definition: bullet_ogre_conversion.h:6
void shutdown() override
Shuts the system down.
Definition: compound_absorber_system.cpp:208
GameState * gameState() const
Returns the system's game state.
Definition: system.cpp:183
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
void setCanAbsorbCompound(CompoundId id, bool canAbsorb)
Sets whether an compound can be absorbed.
Definition: compound_absorber_system.cpp:124
void update(int, int) override
Updates the system.
Definition: compound_absorber_system.cpp:217
~CompoundAbsorberSystem()
Destructor.
Definition: compound_absorber_system.cpp:193
void disable()
Definition: compound_absorber_system.cpp:94
static luabind::scope luaBindings()
Lua bindings.
Definition: compound_absorber_system.cpp:34
double m_absorbtionCapacity
The amount of compound volume that can be absorbed.
Definition: compound_absorber_system.h:66
Absorbs compound particles.
Definition: compound_absorber_system.h:26
A key-value storage for serialization.
Definition: serialization.h:36
void setAbsorbtionCapacity(double capacity)
Sets the absorbtion capacity.
Definition: compound_absorber_system.cpp:82