SuperTuxKart
track_object_presentation.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2013-2015 Joerg Henrichs, Marianne Gagnon
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 
20 #ifndef HEADER_TRACK_OBJECT_PRESENTATION_HPP
21 #define HEADER_TRACK_OBJECT_PRESENTATION_HPP
22 
23 #include "graphics/lod_node.hpp"
24 #include "utils/cpp2011.hpp"
25 #include "utils/no_copy.hpp"
26 #include "utils/log.hpp"
27 #include "utils/leak_check.hpp"
28 #include "utils/time.hpp"
29 #include "utils/vec3.hpp"
30 
31 #include <vector3d.h>
32 
33 #include <memory>
34 #include <limits>
35 #include <string>
36 
37 class SFXBase;
38 class PhysicalObject;
39 class ThreeDAnimation;
41 namespace GE { class GERenderInfo; }
42 class STKInstancedSceneNode;
43 class XMLNode;
44 class TrackObject;
45 
46 #ifndef SERVER_ONLY
47 class ParticleEmitter;
48 #endif
49 
50 namespace irr
51 {
52  namespace scene { class IAnimatedMesh; class IMesh; class IMeshSceneNode; class ISceneNode; }
53 }
54 using namespace irr;
55 
60 {
61 protected:
63  core::vector3df m_init_xyz;
64 
66  core::vector3df m_init_hpr;
67 
69  core::vector3df m_init_scale;
70 
71 
72 public:
73 
74  TrackObjectPresentation(const XMLNode& xml_node);
75 
76  TrackObjectPresentation(const core::vector3df& xyz,
77  const core::vector3df& hpr = core::vector3df(0,0,0),
78  const core::vector3df& scale = core::vector3df(0,0,0))
79  {
80  m_init_xyz = xyz;
81  m_init_hpr = hpr;
82  m_init_scale = scale;
83  } // TrackObjectPresentation
84 
85  // ------------------------------------------------------------------------
86  virtual ~TrackObjectPresentation() {}
87  // ------------------------------------------------------------------------
88 
89  virtual void reset() {}
90  virtual void setEnable(bool enabled)
91  {
92  Log::warn("TrackObjectPresentation", "setEnable unimplemented for this presentation type");
93  }
94  virtual void updateGraphics(float dt) {}
95  virtual void update(float dt) {}
96  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
97  const core::vector3df& scale, bool isAbsoluteCoord) {}
98 
99  // ------------------------------------------------------------------------
101  virtual const core::vector3df& getPosition() const { return m_init_xyz; }
102  // ------------------------------------------------------------------------
105  virtual const core::vector3df getAbsolutePosition() const
106  {
107  return m_init_xyz;
108  } // getAbsolutePosition
109  // ------------------------------------------------------------------------
110  virtual const core::vector3df getAbsoluteCenterPosition() const
111  {
112  return m_init_xyz;
113  }
114  // ------------------------------------------------------------------------
116  virtual const core::vector3df& getRotation() const { return m_init_hpr; }
117  // ------------------------------------------------------------------------
119  virtual const core::vector3df& getScale() const { return m_init_scale; }
120 
121  LEAK_CHECK()
122 };
123 
124 // ============================================================================
130 {
131 protected:
133  scene::ISceneNode* m_node;
134 
135  bool m_force_always_hidden;
136 public:
137 
140  TrackObjectPresentation(xml_node)
141  {
142  m_node = NULL;
143  m_force_always_hidden = false;
144  } // TrackObjectPresentationSceneNode
145  // ------------------------------------------------------------------------
147  TrackObjectPresentationSceneNode(const core::vector3df& xyz,
148  const core::vector3df& hpr,
149  const core::vector3df& scale,
150  scene::ISceneNode* node = NULL) :
151  TrackObjectPresentation(xyz, hpr, scale)
152  {
153  m_node = node;
154  m_force_always_hidden = false;
155  } // TrackObjectPresentationSceneNode
156 
157  // ------------------------------------------------------------------------
158  virtual const core::vector3df& getPosition() const OVERRIDE;
159  virtual const core::vector3df getAbsolutePosition() const OVERRIDE;
160  virtual const core::vector3df getAbsoluteCenterPosition() const OVERRIDE;
161  virtual const core::vector3df& getRotation() const OVERRIDE;
162  virtual const core::vector3df& getScale() const OVERRIDE;
163  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
164  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
165  virtual void setEnable(bool enabled) OVERRIDE;
166  virtual void reset() OVERRIDE;
167 
168  // ------------------------------------------------------------------------
170  scene::ISceneNode* getNode() { return m_node; }
171  // ------------------------------------------------------------------------
173  const scene::ISceneNode* getNode() const { return m_node; }
174  // ------------------------------------------------------------------------
175  bool isAlwaysHidden() const { return m_force_always_hidden; }
176 }; // class TrackObjectPresentationSceneNode
177 
178 // ============================================================================
184 {
185 public:
186  TrackObjectPresentationEmpty(const XMLNode& xml_node);
187  virtual ~TrackObjectPresentationEmpty();
188 }; // class TrackObjectPresentationEmpty
189 
190 // ============================================================================
195 {
196  TrackObject* m_parent;
197  using TrackObjectPresentationSceneNode::move;
198  std::string m_name;
199  bool m_start_executed, m_reset_executed;
200 public:
202  const XMLNode& xml_node,
203  ModelDefinitionLoader& model_def_loader);
205  virtual void update(float dt) OVERRIDE;
206  virtual void reset() OVERRIDE
207  {
208  m_reset_executed = false;
209  TrackObjectPresentationSceneNode::reset();
210  }
211  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
212  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
213 }; // TrackObjectPresentationLibraryNode
214 
215 // ============================================================================
220 {
221 public:
222 
223  TrackObjectPresentationLOD(const XMLNode& xml_node,
224  scene::ISceneNode* parent,
225  ModelDefinitionLoader& model_def_loader,
226  std::shared_ptr<GE::GERenderInfo> ri);
227  virtual ~TrackObjectPresentationLOD();
228  virtual void reset() OVERRIDE;
229 };
230 
231 // ============================================================================
236 {
237 private:
240  scene::IMesh *m_mesh;
241 
244 
247 
248  std::string m_model_file;
249 
250  std::shared_ptr<GE::GERenderInfo> m_render_info;
251 
252  void init(const XMLNode* xml_node, scene::ISceneNode* parent, bool enabled);
253 
254 public:
255  TrackObjectPresentationMesh(const XMLNode& xml_node, bool enabled,
256  scene::ISceneNode* parent,
257  std::shared_ptr<GE::GERenderInfo> render_info);
258 
259  TrackObjectPresentationMesh(const std::string& model_file,
260  const core::vector3df& xyz,
261  const core::vector3df& hpr,
262  const core::vector3df& scale);
263  TrackObjectPresentationMesh(scene::IAnimatedMesh* mesh,
264  const core::vector3df& xyz,
265  const core::vector3df& hpr,
266  const core::vector3df& scale);
267  virtual ~TrackObjectPresentationMesh();
268  virtual void reset() OVERRIDE;
269  // ------------------------------------------------------------------------
271  const std::string& getModelFile() const { return m_model_file; }
272 }; // class TrackObjectPresentationMesh
273 
274 // ============================================================================
279 {
280 private:
281 
285 
287  std::string m_trigger_condition;
288 
289  core::vector3df m_xyz;
290 
291  bool m_enabled;
292 
293 public:
294 
295  TrackObjectPresentationSound(const XMLNode& xml_node,
296  scene::ISceneNode* parent,
297  bool disable_for_multiplayer);
298  virtual ~TrackObjectPresentationSound();
299  void onTriggerItemApproached(int kart_id);
300  virtual void updateGraphics(float dt) OVERRIDE;
301  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
302  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
303  void triggerSound(bool loop);
304  void stopSound();
305 
306  virtual void setEnable(bool enabled) OVERRIDE;
307 
308  // ------------------------------------------------------------------------
310  const std::string& getTriggerCondition() const { return m_trigger_condition; }
311 }; // TrackObjectPresentationSound
312 
313 // ============================================================================
318 {
324  float m_fade_out_start;
325  float m_fade_out_end;
326 public:
328  scene::ISceneNode* parent);
330  virtual void updateGraphics(float dt) OVERRIDE;
331 }; // TrackObjectPresentationBillboard
332 
333 
334 // ============================================================================
339 {
340 private:
341 #ifndef SERVER_ONLY
342  ParticleEmitter* m_emitter;
343 #endif
344  LODNode* m_lod_emitter_node;
345  std::string m_trigger_condition;
346  bool m_delayed_stop;
347  double m_delayed_stop_time;
348 
349 public:
351  scene::ISceneNode* parent);
353 
354  virtual void updateGraphics(float dt) OVERRIDE;
355  void triggerParticles();
356  void stop();
357  void stopIn(double delay);
358  void setRate(float rate);
359  // ------------------------------------------------------------------------
361  std::string& getTriggerCondition() { return m_trigger_condition; }
362 }; // TrackObjectPresentationParticles
363 
364 // ============================================================================
369 {
370 private:
371  video::SColor m_color;
372  float m_distance;
373  float m_energy;
374 public:
375  TrackObjectPresentationLight(const XMLNode& xml_node,
376  scene::ISceneNode* parent);
377  virtual ~TrackObjectPresentationLight();
378  float getEnergy() const { return m_energy; }
379  virtual void setEnable(bool enabled) OVERRIDE;
380  void setEnergy(float energy);
381 }; // TrackObjectPresentationLight
382 
383 // ============================================================================
384 
385 enum ActionTriggerType
386 {
387  TRIGGER_TYPE_POINT = 0,
388  TRIGGER_TYPE_CYLINDER = 1
389 };
390 
395 {
396 private:
398  std::string m_action, m_library_id, m_triggered_object, m_library_name;
399 
400  float m_xml_reenable_timeout;
401 
402  uint64_t m_reenable_timeout;
403 
404  ActionTriggerType m_type;
405 
406 public:
408  TrackObject* parent);
409  TrackObjectPresentationActionTrigger(const core::vector3df& xyz,
410  const std::string& scriptname,
411  float distance);
412 
414 
415  void onTriggerItemApproached(int kart_id);
416  // ------------------------------------------------------------------------
418  virtual void reset() OVERRIDE
419  { m_reenable_timeout = StkTime::getMonoTimeMs(); }
420  // ------------------------------------------------------------------------
423  virtual void setEnable(bool status) OVERRIDE
424  {
425  m_reenable_timeout = status ? StkTime::getMonoTimeMs() :
426  std::numeric_limits<uint64_t>::max();
427  }
428  // ------------------------------------------------------------------------
429  void setReenableTimeout(float time)
430  {
431  m_reenable_timeout =
432  StkTime::getMonoTimeMs() + (uint64_t)(time * 1000.0f);
433  }
434 }; // class TrackObjectPresentationActionTrigger
435 
436 
437 #endif // TRACKOBJECTPRESENTATION_HPP
438 
manages level-of-detail
Definition: lod_node.hpp:50
Utility class to load level-of-detail nodes and library nodes.
Definition: model_definition_loader.hpp:81
manages smoke particle effects
Definition: particle_emitter.hpp:44
Definition: physical_object.hpp:40
The base class for sound effects.
Definition: sfx_base.hpp:43
static uint64_t getMonoTimeMs()
Returns a time based since the starting of stk (monotonic clock).
Definition: time.hpp:113
A virtual base class for all animations.
Definition: three_d_animation.hpp:45
A track object representation that consists of an action trigger.
Definition: track_object_presentation.hpp:395
virtual void setEnable(bool status) OVERRIDE
Sets the trigger to be enabled or disabled.
Definition: track_object_presentation.hpp:423
virtual void reset() OVERRIDE
Reset the trigger (i.e.
Definition: track_object_presentation.hpp:418
std::string m_action
For action trigger objects.
Definition: track_object_presentation.hpp:398
A track object representation that consists of a billboard scene node.
Definition: track_object_presentation.hpp:318
bool m_fade_out_when_close
To make the billboard disappear when close to the camera.
Definition: track_object_presentation.hpp:323
A track object representation that is invisible and only consists of a location, rotation and scale.
Definition: track_object_presentation.hpp:184
A track object representation that consists of a level-of-detail scene node.
Definition: track_object_presentation.hpp:220
A track object representation that is a library node.
Definition: track_object_presentation.hpp:195
A track object representation that consists of a light emitter.
Definition: track_object_presentation.hpp:369
A track object representation that consists of a mesh scene node.
Definition: track_object_presentation.hpp:236
bool m_is_in_skybox
True if the object is in the skybox.
Definition: track_object_presentation.hpp:246
scene::IMesh * m_mesh
The mesh used here.
Definition: track_object_presentation.hpp:240
bool m_is_looped
True if it is a looped animation.
Definition: track_object_presentation.hpp:243
A track object representation that consists of a particle emitter.
Definition: track_object_presentation.hpp:339
std::string & getTriggerCondition()
Returns the trigger condition for this object.
Definition: track_object_presentation.hpp:361
Base class for all track object presentation classes using a scene node as presentation.
Definition: track_object_presentation.hpp:130
TrackObjectPresentationSceneNode(const XMLNode &xml_node)
Constructor based on data from xml.
Definition: track_object_presentation.hpp:139
TrackObjectPresentationSceneNode(const core::vector3df &xyz, const core::vector3df &hpr, const core::vector3df &scale, scene::ISceneNode *node=NULL)
Constructor based on a transform.
Definition: track_object_presentation.hpp:147
const scene::ISceneNode * getNode() const
Returns a pointer to the scene node, const version.
Definition: track_object_presentation.hpp:173
scene::ISceneNode * m_node
A pointer to the scene node of this object.
Definition: track_object_presentation.hpp:133
A track object representation that consists of a sound emitter.
Definition: track_object_presentation.hpp:279
SFXBase * m_sound
If a sound is attached to this object and/or this is a sound emitter object.
Definition: track_object_presentation.hpp:284
const std::string & getTriggerCondition() const
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:310
std::string m_trigger_condition
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:287
Base class for all track object presentation classes.
Definition: track_object_presentation.hpp:60
core::vector3df m_init_xyz
The initial XYZ position of the object.
Definition: track_object_presentation.hpp:63
core::vector3df m_init_hpr
The initial hpr of the object.
Definition: track_object_presentation.hpp:66
virtual const core::vector3df & getRotation() const
Returns the initial rotation.
Definition: track_object_presentation.hpp:116
core::vector3df m_init_scale
The initial scale of the object.
Definition: track_object_presentation.hpp:69
virtual const core::vector3df getAbsolutePosition() const
Returns a copy of the initial position.
Definition: track_object_presentation.hpp:105
virtual const core::vector3df & getPosition() const
Returns the position of this TrackObjectPresentation.
Definition: track_object_presentation.hpp:101
virtual const core::vector3df & getScale() const
Returns the initial scale.
Definition: track_object_presentation.hpp:119
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
utility class used to parse XML files
Definition: xml_node.hpp:48
void stopIn(float delay,)
Stop particle emission.
Definition: script_track.cpp:492
void stop()
Stop a sound.
Definition: script_track.cpp:456
void update(float dt)
Updates all widgets that need to be updated.
Definition: engine.cpp:872