Thrive
compound_cloud_system.h
1 #pragma once
2 
3 #include <vector>
4 #include <OgreEntity.h>
5 #include <OgreSceneManager.h>
6 #include "OgreHardwarePixelBuffer.h"
7 
8 #include "engine/component.h"
9 #include "engine/system.h"
10 #include "engine/touchable.h"
11 #include "scripting/luabind.h"
12 #include "engine/typedefs.h"
13 
14 #include "general/perlin_noise.h"
15 #include "ogre/scene_node_system.h"
16 #include "microbe_stage/compound_registry.h"
17 
18 namespace thrive {
19 
20 static const CompoundId NULL_COMPOUND = 0;
21 
22 class CompoundCloudSystem;
23 
28  COMPONENT(CompoundCloudComponent)
29 
30 public:
32  int width, height;
33  int offsetX, offsetY;
34  float gridSize;
35 
37  std::vector< std::vector<float> > density;
38  std::vector< std::vector<float> > oldDens;
39 
41  //std::vector< std::vector<float> > density_11;
42  //std::vector< std::vector<float> > density_12;
43  //std::vector< std::vector<float> > density_13;
44  //std::vector< std::vector<float> > density_21;
45  //std::vector< std::vector<float> > density_23;
46  //std::vector< std::vector<float> > density_31;
47  //std::vector< std::vector<float> > density_32;
48  //std::vector< std::vector<float> > density_33;
49 
51  Ogre::ColourValue color;
52 
56  CompoundId m_compoundId = NULL_COMPOUND;
57 
58 public:
59 
60  void initialize(CompoundId Id, float red, float green, float blue);
61 
70  static luabind::scope
71  luaBindings();
72 
73  void
74  load(
76  ) override;
77 
79  storage() const override;
80 
81  void
82  addCloud(
83  float density,
84  int x,
85  int y
86  );
87 
89  int
91  int x,
92  int y,
93  float rate
94  );
95 
97  int
99  int x,
100  int y,
101  float rate
102  );
103 };
104 
105 
106 
110 class CompoundCloudSystem : public System {
111 
112 public:
121  static luabind::scope
122  luaBindings();
123 
128 
133 
139  void init(GameState* gameState) override;
140 
144  void shutdown() override;
145 
149  void update(int renderTime, int logicTime) override;
150 
151 private:
152  struct Implementation;
153  std::unique_ptr<Implementation> m_impl;
155  Ogre::Entity* compoundCloudsPlane;
156  OgreSceneNodeComponent* playerNode;
157 
158  PerlinNoise fieldPotential;
159  float noiseScale;
160 
162  int width, height;
163  int offsetX, offsetY;
164  float gridSize;
165 
167  std::vector< std::vector<float> > xVelocity;
168  std::vector< std::vector<float> > yVelocity;
169 
170  void CreateVelocityField();
171  void diffuse(float diffRate, std::vector< std::vector<float> >& oldDens, const std::vector< std::vector<float> >& density, int dt);
172  void advect(std::vector< std::vector<float> >& oldDens, std::vector< std::vector<float> >& density, int dt);
173 
174  // Clears the density field file to blank (black).
175  void initializeFile(std::string compoundName);
176  // Draws the density field of the compound to a .bmp, which can then be read by the fragment shader.
177  void writeToFile(std::vector< std::vector<float> >& density, std::string compoundName, Ogre::ColourValue color);
178 };
179 
180 }
Definition: perlin_noise.h:15
Moves the compound clouds.
Definition: compound_cloud_system.h:110
~CompoundCloudSystem()
Destructor.
Definition: compound_cloud_system.cpp:180
void load(const StorageContainer &storage) override
Loads the component.
Definition: compound_cloud_system.cpp:71
int amountAvailable(int x, int y, float rate)
Rate should be less than one.
Definition: compound_cloud_system.cpp:124
int takeCompound(int x, int y, float rate)
Rate should be less than one.
Definition: compound_cloud_system.cpp:108
Base class for components.
Definition: component.h:31
A system handles one specific part of the game.
Definition: system.h:23
StorageContainer storage() const override
Serializes the component.
Definition: compound_cloud_system.cpp:86
void shutdown() override
Shuts the system down.
Definition: compound_cloud_system.cpp:203
static luabind::scope luaBindings()
Lua bindings.
Definition: compound_cloud_system.cpp:41
CompoundCloudSystem()
Constructor.
Definition: compound_cloud_system.cpp:164
Ogre::ColourValue color
The 3x3 grid of density tiles around the player for seamless movement.
Definition: compound_cloud_system.h:51
std::vector< std::vector< float > > density
The 2D array that contains the current compound clouds and those from last frame. ...
Definition: compound_cloud_system.h:37
A component for a Ogre scene nodes.
Definition: scene_node_system.h:34
Definition: bullet_ogre_conversion.h:6
void update(int renderTime, int logicTime) override
Updates the system.
Definition: compound_cloud_system.cpp:211
static luabind::scope luaBindings()
Lua bindings.
Definition: compound_cloud_system.cpp:145
GameState * gameState() const
Returns the system's game state.
Definition: system.cpp:183
void init(GameState *gameState) override
Initializes the system.
Definition: compound_cloud_system.cpp:185
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
CompoundId m_compoundId
The compound id.
Definition: compound_cloud_system.h:56
Compound clouds that flow in the environment.
Definition: compound_cloud_system.h:27
A key-value storage for serialization.
Definition: serialization.h:36
int width
The size of the compound cloud grid.
Definition: compound_cloud_system.h:32