Thrive
scene_node_system.h
1 #pragma once
2 
3 #include "engine/component.h"
4 #include "engine/system.h"
5 #include "engine/touchable.h"
6 #include "luabind/object.hpp"
7 
8 #include <memory>
9 #include <OgreVector3.h>
10 #include <OgreQuaternion.h>
11 #include <vector>
12 #include <map>
13 
14 #include <iostream>
15 
16 namespace luabind {
17 class scope;
18 }
19 
20 namespace Ogre {
21 class SceneNode;
22 }
23 
24 namespace thrive {
25  class SoundManager;
26 }
27 
28 namespace thrive {
29 
35  COMPONENT(OgreSceneNode)
36 
37 public:
38 
42  struct Transform : public Touchable {
43 
49  Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY;
50 
56  Ogre::Vector3 position = {0, 0, 0};
57 
63  Ogre::Vector3 scale = {1, 1, 1};
64 
65  };
66 
89  static luabind::scope
90  luaBindings();
91 
92  void
93  load(
95  ) override;
96 
98  storage() const override;
99 
110  void
112  std::string name,
113  bool loop
114  );
115 
123  void
125  std::string name
126  );
127 
131  void
133 
141  void
143  float factor
144  );
145 
154  void
155  attachObject(
156  Ogre::MovableObject* obj
157  );
158 
162  void
164 
169 
174 
178  Transform
180 
185  Ogre::SceneNode* m_sceneNode = nullptr;
186 
190  Ogre::Entity* m_entity = nullptr;
191 
192 
197 
202 
203 private:
204 
205  friend class OgreUpdateSceneNodeSystem;
207  TouchableValue<bool> m_attachToListener = false;
208 
209  void
210  _attachObject(
211  Ogre::MovableObject* obj
212  );
213 
214  std::vector<std::pair<std::string, bool>> m_animationsToStart;
215  std::vector<std::string> m_animationsToHalt;
216  bool m_animationChange = false;
217  bool m_fullAnimationHalt = false;
218  float m_animationSpeedFactor = 1.0f;
219 
220  static bool s_soundListenerAttached;
221 
222 
223 
224 };
225 
230 
231 public:
232 
241  static luabind::scope
242  luaBindings();
243 
248 
253 
258  void init(GameState* gameState) override;
259 
263  void shutdown() override;
264 
268  void update(int, int) override;
269 
270 private:
271 
272  struct Implementation;
273  std::unique_ptr<Implementation> m_impl;
274 };
275 
276 
281 
282 public:
283 
292  static luabind::scope
293  luaBindings();
294 
299 
304 
309  void init(GameState* gameState) override;
310 
314  void shutdown() override;
315 
319  void update(int, int) override;
320 
321 private:
322 
323  struct Implementation;
324  std::unique_ptr<Implementation> m_impl;
325 };
326 
331 
332 public:
333 
342  static luabind::scope
343  luaBindings();
344 
349 
354 
359  void init(GameState* gameState) override;
360 
364  void shutdown() override;
365 
369  void update(int, int) override;
370 
371 
372 private:
373 
374  struct Implementation;
375  std::unique_ptr<Implementation> m_impl;
376 };
377 
378 }
379 
380 
Creates scene nodes for new OgreSceneNodeComponents.
Definition: scene_node_system.h:229
Ogre::Vector3 position
Position.
Definition: scene_node_system.h:56
void load(const StorageContainer &storage) override
Loads the component.
Definition: scene_node_system.cpp:138
Removes scene nodes for removed OgreSceneNodeComponents.
Definition: scene_node_system.h:280
Helper class for keeping track of changing data.
Definition: touchable.h:18
TouchableValue< Ogre::String > m_meshName
The name of the mesh to attach to this scene node.
Definition: scene_node_system.h:168
void init(GameState *gameState) override
Initializes the system.
Definition: scene_node_system.cpp:250
void shutdown() override
Shuts the system down.
Definition: scene_node_system.cpp:428
Properties.
Definition: scene_node_system.h:42
Transform m_transform
Transform.
Definition: scene_node_system.h:179
Base class for components.
Definition: component.h:31
void attachObject(Ogre::MovableObject *obj)
Attaches a MovableObject to the underlying scenenode.
Definition: scene_node_system.cpp:197
void init(GameState *gameState) override
Initializes the system.
Definition: scene_node_system.cpp:418
static luabind::scope luaBindings()
Lua bindings.
Definition: scene_node_system.cpp:389
A system handles one specific part of the game.
Definition: system.h:23
TouchableValue< EntityId > m_parentId
The entity id of the parent scene node.
Definition: scene_node_system.h:173
void update(int, int) override
Removes stale scene nodes.
Definition: scene_node_system.cpp:354
Ogre::SceneNode * m_sceneNode
Pointer to the underlying Ogre::SceneNode.
Definition: scene_node_system.h:185
~OgreUpdateSceneNodeSystem()
Destructor.
Definition: scene_node_system.cpp:414
A component for a Ogre scene nodes.
Definition: scene_node_system.h:34
void shutdown() override
Shuts the system down.
Definition: scene_node_system.cpp:346
Definition: bullet_to_ogre_system.h:5
void setAnimationSpeed(float factor)
Sets the speed for all animations for this scenenode.
Definition: scene_node_system.cpp:176
StorageContainer storage() const override
Serializes the component.
Definition: scene_node_system.cpp:154
Definition: bullet_ogre_conversion.h:6
~OgreRemoveSceneNodeSystem()
Destructor.
Definition: scene_node_system.cpp:329
GameState * gameState() const
Returns the system's game state.
Definition: system.cpp:183
static luabind::scope luaBindings()
Lua bindings.
Definition: scene_node_system.cpp:303
OgreUpdateSceneNodeSystem()
Constructor.
Definition: scene_node_system.cpp:408
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
void stopAllAnimations()
Stops all animations playing on this sceneNode.
Definition: scene_node_system.cpp:191
Definition: debug_drawing.h:8
TouchableValue< bool > m_visible
Whether the scenenode is visible.
Definition: scene_node_system.h:196
void update(int, int) override
Updates the scene nodes.
Definition: scene_node_system.cpp:437
TouchableValue< std::string > m_planeTexture
Whether the scenenode is a simple plane.
Definition: scene_node_system.h:201
void update(int, int) override
Adds new scene nodes.
Definition: scene_node_system.cpp:269
Ogre::Entity * m_entity
Pointer to the underlying Ogre::Entity.
Definition: scene_node_system.h:190
static luabind::scope luaBindings()
Lua bindings.
Definition: scene_node_system.cpp:224
void init(GameState *gameState) override
Initializes the system.
Definition: scene_node_system.cpp:333
static luabind::scope luaBindings()
Lua bindings.
Definition: scene_node_system.cpp:106
void playAnimation(std::string name, bool loop)
Sets the current animation to be played.
Definition: scene_node_system.cpp:167
void shutdown() override
Shuts the system down.
Definition: scene_node_system.cpp:261
Ogre::Vector3 scale
Scale.
Definition: scene_node_system.h:63
OgreRemoveSceneNodeSystem()
Constructor.
Definition: scene_node_system.cpp:323
~OgreAddSceneNodeSystem()
Destructor.
Definition: scene_node_system.cpp:246
void stopAnimation(std::string name)
Stops a specific animation.
Definition: scene_node_system.cpp:183
Updates scene node transformations.
Definition: scene_node_system.h:330
OgreAddSceneNodeSystem()
Constructor.
Definition: scene_node_system.cpp:240
void attachSoundListener()
Attaches the sound-listener to the underlying scenenode, having the sound perspective move with it...
Definition: scene_node_system.cpp:212
A key-value storage for serialization.
Definition: serialization.h:36
Ogre::Quaternion orientation
Rotation.
Definition: scene_node_system.h:49