Thrive
membrane_system.h
1 #pragma once
2 
3 #include "engine/component.h"
4 #include "engine/system.h"
5 #include "engine/touchable.h"
6 #include "scripting/luabind.h"
7 #include "engine/typedefs.h"
8 
9 #include <luabind/object.hpp>
10 #include <OgreCommon.h>
11 #include <OgreColourValue.h>
12 #include <OgreMath.h>
13 #include <OgreVector3.h>
14 #include <vector>
15 #include <algorithm>
16 
17 
18 namespace thrive {
19 
20 class MembraneSystem;
21 class CompoundCloudSystem;
22 
26 class MembraneComponent : public Component {
27  COMPONENT(MembraneComponent)
28 
29 public:
30 
40  static luabind::scope
41  luaBindings();
42 
44 
45  void
46  load(
48  ) override;
49 
51  storage() const override;
52 
53  // The colour of the membrane.
54  Ogre::ColourValue colour;
55 
56  // Gets organelle positions from the .lua file.
57  void sendOrganelles(double x, double y);
58 
59  // Sets the colour of the membrane.
60  void setColour(float red, float green, float blue, float alpha);
61 
62  // Returns the color of the membrane.
63  Ogre::Vector3 getColour();
64 
65  // Gets the amount of a certain compound the membrane absorbed.
66  int getAbsorbedCompounds();
67 
68  // Creates the 2D points in the membrane by looking at the positions of the organelles.
69  void DrawMembrane();
70 
71  // Sees if the given point is inside the membrane.
72  bool contains(float x, float y);
73 
74  void Initialize();
75 
76  void Update();
77 
78  // Creates a 3D prism from the 2D vertices.
79  void MakePrism();
80 
81  // Returns the length of the bounding membrane "box".
82  int getCellDimensions() {return cellDimensions;}
83 
84  // Adds absorbed compound to the membrane.
85  // These are later queried and added to the vacuoles.
86  void absorbCompounds(int amount);
87 
88  // Finds the position of external organelles based on its "internal" location.
89  Ogre::Vector3 GetExternalOrganelle(double x, double y);
90 
91  // Return the position of the closest organelle to the target point if it is less then a certain threshold away.
92  Ogre::Vector3 FindClosestOrganelles(Ogre::Vector3 target);
93 
94  // Decides where the point needs to move based on the position of the closest organelle.
95  Ogre::Vector3 GetMovement(Ogre::Vector3 target, Ogre::Vector3 closestOrganelle);
96 
97 
98  // Gets the position of the closest membrane point
99  luabind::object getExternOrganellePos(double x, double y);
100 
101  bool isInitialized;
102  bool wantsMembrane;
103 
104  // Finds the UV coordinates be projecting onto a plane and stretching to fit a circle.
105  void CalcUVCircle();
106 
107  // Finds the normals for the mesh.
108  void CalcNormals();
109 
110  // Stores the Mesh in a vector such that every 3 points make up a triangle.
111  std::vector<Ogre::Vector3> MeshPoints;
112 
113  // Stores the UV coordinates for the MeshPoints.
114  std::vector<Ogre::Vector3> UVs;
115 
116  // Stores the normals for every point described in MeshPoints.
117  std::vector<Ogre::Vector3> Normals;
118 
119 
120 private:
121  friend class MembraneSystem;
122  friend class CompoundCloudSystem;
123 
124  // Stores the positions of the organelles.
125  std::vector<Ogre::Vector3> organellePositions;
126 
127  // The length in pixels of a side of the square that bounds the membrane.
128  int cellDimensions;
129  // The amount of points on the side of the membrane.
130  int membraneResolution;
131  // Stores the generated 2-Dimensional membrane.
132  std::vector<Ogre::Vector3> vertices2D;
133 
134 
135  // The amount of compounds stored in the membrane.
136  int compoundAmount;
137 };
138 
139 
140 
144 class MembraneSystem : public System {
145 
146 public:
147 
156  static luabind::scope
157  luaBindings();
158 
162  MembraneSystem();
163 
167  ~MembraneSystem();
168 
174  void init(GameState* gameState) override;
175 
179  void shutdown() override;
180 
184  void update(int, int) override;
185 
186 
187 private:
188 
189  struct Implementation;
190  std::unique_ptr<Implementation> m_impl;
191 };
192 
193 }
void load(const StorageContainer &storage) override
Loads the component.
Definition: membrane_system.cpp:77
StorageContainer storage() const override
Serializes the component.
Definition: membrane_system.cpp:85
Moves the compound clouds.
Definition: compound_cloud_system.h:110
void update(int, int) override
Updates the system.
Definition: membrane_system.cpp:380
Spawns compound particles for CompoundEmitterComponent.
Definition: membrane_system.h:144
Base class for components.
Definition: component.h:31
MembraneSystem()
Constructor.
Definition: membrane_system.cpp:352
A system handles one specific part of the game.
Definition: system.h:23
~MembraneSystem()
Destructor.
Definition: membrane_system.cpp:358
static luabind::scope luaBindings()
Lua bindings.
Definition: membrane_system.cpp:331
Definition: bullet_ogre_conversion.h:6
Emitter for compound particles.
Definition: membrane_system.h:26
void shutdown() override
Shuts the system down.
Definition: membrane_system.cpp:372
GameState * gameState() const
Returns the system's game state.
Definition: system.cpp:183
static luabind::scope luaBindings()
Lua bindings.
Definition: membrane_system.cpp:32
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
void init(GameState *gameState) override
Initializes the system.
Definition: membrane_system.cpp:362
A key-value storage for serialization.
Definition: serialization.h:36