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 #include <IAnimatedMeshSceneNode.h>
33 
34 #include <memory>
35 #include <limits>
36 #include <string>
37 
38 class SFXBase;
39 class ParticleEmitter;
40 class PhysicalObject;
41 class ThreeDAnimation;
43 class RenderInfo;
44 class STKInstancedSceneNode;
45 class XMLNode;
46 class TrackObject;
47 
48 namespace irr
49 {
50  namespace scene { class IAnimatedMesh; class IMeshSceneNode; class ISceneNode; }
51 }
52 using namespace irr;
53 
58 {
59 protected:
61  core::vector3df m_init_xyz;
62 
64  core::vector3df m_init_hpr;
65 
67  core::vector3df m_init_scale;
68 
69 
70 public:
71 
72  TrackObjectPresentation(const XMLNode& xml_node);
73 
74  TrackObjectPresentation(const core::vector3df& xyz,
75  const core::vector3df& hpr = core::vector3df(0,0,0),
76  const core::vector3df& scale = core::vector3df(0,0,0))
77  {
78  m_init_xyz = xyz;
79  m_init_hpr = hpr;
80  m_init_scale = scale;
81  } // TrackObjectPresentation
82 
83  // ------------------------------------------------------------------------
84  virtual ~TrackObjectPresentation() {}
85  // ------------------------------------------------------------------------
86 
87  virtual void reset() {}
88  virtual void setEnable(bool enabled)
89  {
90  Log::warn("TrackObjectPresentation", "setEnable unimplemented for this presentation type");
91  }
92  virtual void updateGraphics(float dt) {}
93  virtual void update(float dt) {}
94  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
95  const core::vector3df& scale, bool isAbsoluteCoord) {}
96 
97  // ------------------------------------------------------------------------
99  virtual const core::vector3df& getPosition() const { return m_init_xyz; }
100  // ------------------------------------------------------------------------
103  virtual const core::vector3df getAbsolutePosition() const
104  {
105  return m_init_xyz;
106  } // getAbsolutePosition
107  // ------------------------------------------------------------------------
108  virtual const core::vector3df getAbsoluteCenterPosition() const
109  {
110  return m_init_xyz;
111  }
112  // ------------------------------------------------------------------------
114  virtual const core::vector3df& getRotation() const { return m_init_hpr; }
115  // ------------------------------------------------------------------------
117  virtual const core::vector3df& getScale() const { return m_init_scale; }
118 
119  LEAK_CHECK()
120 };
121 
122 // ============================================================================
128 {
129 protected:
131  scene::ISceneNode* m_node;
132 
133  bool m_force_always_hidden;
134 public:
135 
138  TrackObjectPresentation(xml_node)
139  {
140  m_node = NULL;
141  m_force_always_hidden = false;
142  } // TrackObjectPresentationSceneNode
143  // ------------------------------------------------------------------------
145  TrackObjectPresentationSceneNode(const core::vector3df& xyz,
146  const core::vector3df& hpr,
147  const core::vector3df& scale,
148  scene::ISceneNode* node = NULL) :
149  TrackObjectPresentation(xyz, hpr, scale)
150  {
151  m_node = node;
152  m_force_always_hidden = false;
153  } // TrackObjectPresentationSceneNode
154 
155  // ------------------------------------------------------------------------
156  virtual const core::vector3df& getPosition() const OVERRIDE;
157  virtual const core::vector3df getAbsolutePosition() const OVERRIDE;
158  virtual const core::vector3df getAbsoluteCenterPosition() const OVERRIDE;
159  virtual const core::vector3df& getRotation() const OVERRIDE;
160  virtual const core::vector3df& getScale() const OVERRIDE;
161  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
162  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
163  virtual void setEnable(bool enabled) OVERRIDE;
164  virtual void reset() OVERRIDE;
165 
166  // ------------------------------------------------------------------------
168  scene::ISceneNode* getNode() { return m_node; }
169  // ------------------------------------------------------------------------
171  const scene::ISceneNode* getNode() const { return m_node; }
172  // ------------------------------------------------------------------------
173  bool isAlwaysHidden() const { return m_force_always_hidden; }
174 }; // class TrackObjectPresentationSceneNode
175 
176 // ============================================================================
182 {
183 public:
184  TrackObjectPresentationEmpty(const XMLNode& xml_node);
185  virtual ~TrackObjectPresentationEmpty();
186 }; // class TrackObjectPresentationEmpty
187 
188 // ============================================================================
193 {
194  TrackObject* m_parent;
195  using TrackObjectPresentationSceneNode::move;
196  std::string m_name;
197  bool m_start_executed, m_reset_executed;
198 public:
200  const XMLNode& xml_node,
201  ModelDefinitionLoader& model_def_loader);
203  virtual void update(float dt) OVERRIDE;
204  virtual void reset() OVERRIDE
205  {
206  m_reset_executed = false;
207  TrackObjectPresentationSceneNode::reset();
208  }
209  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
210  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
211 }; // TrackObjectPresentationLibraryNode
212 
213 // ============================================================================
218 {
219 public:
220 
221  TrackObjectPresentationLOD(const XMLNode& xml_node,
222  scene::ISceneNode* parent,
223  ModelDefinitionLoader& model_def_loader,
224  std::shared_ptr<RenderInfo> ri);
225  virtual ~TrackObjectPresentationLOD();
226  virtual void reset() OVERRIDE;
227 };
228 
229 // ============================================================================
234 {
235 private:
238  scene::IMesh *m_mesh;
239 
242 
245 
246  std::string m_model_file;
247 
248  std::shared_ptr<RenderInfo> m_render_info;
249 
250  void init(const XMLNode* xml_node, scene::ISceneNode* parent, bool enabled);
251 
252 public:
253  TrackObjectPresentationMesh(const XMLNode& xml_node, bool enabled,
254  scene::ISceneNode* parent,
255  std::shared_ptr<RenderInfo> render_info);
256 
257  TrackObjectPresentationMesh(const std::string& model_file,
258  const core::vector3df& xyz,
259  const core::vector3df& hpr,
260  const core::vector3df& scale);
261  TrackObjectPresentationMesh(scene::IAnimatedMesh* mesh,
262  const core::vector3df& xyz,
263  const core::vector3df& hpr,
264  const core::vector3df& scale);
265  virtual ~TrackObjectPresentationMesh();
266  virtual void reset() OVERRIDE;
267  // ------------------------------------------------------------------------
269  const std::string& getModelFile() const { return m_model_file; }
270 }; // class TrackObjectPresentationMesh
271 
272 // ============================================================================
277 {
278 private:
279 
283 
285  std::string m_trigger_condition;
286 
287  core::vector3df m_xyz;
288 
289  bool m_enabled;
290 
291 public:
292 
293  TrackObjectPresentationSound(const XMLNode& xml_node,
294  scene::ISceneNode* parent,
295  bool disable_for_multiplayer);
296  virtual ~TrackObjectPresentationSound();
297  void onTriggerItemApproached(int kart_id);
298  virtual void updateGraphics(float dt) OVERRIDE;
299  virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
300  const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
301  void triggerSound(bool loop);
302  void stopSound();
303 
304  virtual void setEnable(bool enabled) OVERRIDE;
305 
306  // ------------------------------------------------------------------------
308  const std::string& getTriggerCondition() const { return m_trigger_condition; }
309 }; // TrackObjectPresentationSound
310 
311 // ============================================================================
316 {
322  float m_fade_out_start;
323  float m_fade_out_end;
324 public:
326  scene::ISceneNode* parent);
328  virtual void updateGraphics(float dt) OVERRIDE;
329 }; // TrackObjectPresentationBillboard
330 
331 
332 // ============================================================================
337 {
338 private:
339  ParticleEmitter* m_emitter;
340  LODNode* m_lod_emitter_node;
341  std::string m_trigger_condition;
342  bool m_delayed_stop;
343  double m_delayed_stop_time;
344 
345 public:
347  scene::ISceneNode* parent);
349 
350  virtual void updateGraphics(float dt) OVERRIDE;
351  void triggerParticles();
352  void stop();
353  void stopIn(double delay);
354  void setRate(float rate);
355  // ------------------------------------------------------------------------
357  std::string& getTriggerCondition() { return m_trigger_condition; }
358 }; // TrackObjectPresentationParticles
359 
360 // ============================================================================
365 {
366 private:
367  video::SColor m_color;
368  float m_distance;
369  float m_energy;
370 public:
371  TrackObjectPresentationLight(const XMLNode& xml_node,
372  scene::ISceneNode* parent);
373  virtual ~TrackObjectPresentationLight();
374  float getEnergy() const { return m_energy; }
375  virtual void setEnable(bool enabled) OVERRIDE;
376  void setEnergy(float energy);
377 }; // TrackObjectPresentationLight
378 
379 // ============================================================================
380 
381 enum ActionTriggerType
382 {
383  TRIGGER_TYPE_POINT = 0,
384  TRIGGER_TYPE_CYLINDER = 1
385 };
386 
391 {
392 private:
394  std::string m_action, m_library_id, m_triggered_object, m_library_name;
395 
396  float m_xml_reenable_timeout;
397 
398  uint64_t m_reenable_timeout;
399 
400  ActionTriggerType m_type;
401 
402 public:
404  TrackObject* parent);
405  TrackObjectPresentationActionTrigger(const core::vector3df& xyz,
406  const std::string& scriptname,
407  float distance);
408 
410 
411  void onTriggerItemApproached(int kart_id);
412  // ------------------------------------------------------------------------
414  virtual void reset() OVERRIDE
415  { m_reenable_timeout = StkTime::getMonoTimeMs(); }
416  // ------------------------------------------------------------------------
419  virtual void setEnable(bool status) OVERRIDE
420  {
421  m_reenable_timeout = status ? StkTime::getMonoTimeMs() :
422  std::numeric_limits<uint64_t>::max();
423  }
424  // ------------------------------------------------------------------------
425  void setReenableTimeout(float time)
426  {
427  m_reenable_timeout =
428  StkTime::getMonoTimeMs() + (uint64_t)(time * 1000.0f);
429  }
430 }; // class TrackObjectPresentationActionTrigger
431 
432 
433 #endif // TRACKOBJECTPRESENTATION_HPP
434 
core::vector3df m_init_scale
The initial scale of the object.
Definition: track_object_presentation.hpp:67
A track object representation that is invisible and only consists of a location, rotation and scale.
Definition: track_object_presentation.hpp:181
std::string m_trigger_condition
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:285
A track object representation that consists of a billboard scene node.
Definition: track_object_presentation.hpp:315
scene::ISceneNode * m_node
A pointer to the scene node of this object.
Definition: track_object_presentation.hpp:131
virtual const core::vector3df getAbsolutePosition() const
Returns a copy of the initial position.
Definition: track_object_presentation.hpp:103
A track object representation that consists of a sound emitter.
Definition: track_object_presentation.hpp:276
virtual const core::vector3df & getScale() const
Returns the initial scale.
Definition: track_object_presentation.hpp:117
TrackObjectPresentationSceneNode(const XMLNode &xml_node)
Constructor based on data from xml.
Definition: track_object_presentation.hpp:137
static uint64_t getMonoTimeMs()
Returns a time based since the starting of stk (monotonic clock).
Definition: time.hpp:102
core::vector3df m_init_xyz
The initial XYZ position of the object.
Definition: track_object_presentation.hpp:61
void stop()
Stop a sound.
Definition: script_track.cpp:441
manages smoke particle effects
Definition: particle_emitter.hpp:41
bool m_is_in_skybox
True if the object is in the skybox.
Definition: track_object_presentation.hpp:244
core::vector3df m_init_hpr
The initial hpr of the object.
Definition: track_object_presentation.hpp:64
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:145
Base class for all track object presentation classes.
Definition: track_object_presentation.hpp:57
Definition: physical_object.hpp:40
A track object representation that consists of a particle emitter.
Definition: track_object_presentation.hpp:336
std::string & getTriggerCondition()
Returns the trigger condition for this object.
Definition: track_object_presentation.hpp:357
Base class for all track object presentation classes using a scene node as presentation.
Definition: track_object_presentation.hpp:127
A track object representation that consists of a level-of-detail scene node.
Definition: track_object_presentation.hpp:217
A track object representation that consists of a light emitter.
Definition: track_object_presentation.hpp:364
const std::string & getTriggerCondition() const
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:308
manages level-of-detail
Definition: lod_node.hpp:48
const scene::ISceneNode * getNode() const
Returns a pointer to the scene node, const version.
Definition: track_object_presentation.hpp:171
A track object representation that consists of an action trigger.
Definition: track_object_presentation.hpp:390
virtual const core::vector3df & getRotation() const
Returns the initial rotation.
Definition: track_object_presentation.hpp:114
scene::IMesh * m_mesh
The mesh used here.
Definition: track_object_presentation.hpp:238
bool m_fade_out_when_close
To make the billboard disappear when close to the camera.
Definition: track_object_presentation.hpp:321
void update(float dt)
Updates all widgets that need to be updated.
Definition: engine.cpp:846
SFXBase * m_sound
If a sound is attached to this object and/or this is a sound emitter object.
Definition: track_object_presentation.hpp:282
utility class used to parse XML files
Definition: xml_node.hpp:47
virtual void reset() OVERRIDE
Reset the trigger (i.e.
Definition: track_object_presentation.hpp:414
void stopIn(float delay,)
Stop particle emission.
Definition: script_track.cpp:477
virtual void setEnable(bool status) OVERRIDE
Sets the trigger to be enabled or disabled.
Definition: track_object_presentation.hpp:419
A track object representation that consists of a mesh scene node.
Definition: track_object_presentation.hpp:233
A track object representation that is a library node.
Definition: track_object_presentation.hpp:192
Definition: render_info.hpp:27
virtual const core::vector3df & getPosition() const
Returns the position of this TrackObjectPresentation.
Definition: track_object_presentation.hpp:99
bool m_is_looped
True if it is a looped animation.
Definition: track_object_presentation.hpp:241
The base class for sound effects.
Definition: sfx_base.hpp:42
A virtual base class for all animations.
Definition: three_d_animation.hpp:44
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:46
Utility class to load level-of-detail nodes and library nodes.
Definition: model_definition_loader.hpp:81
std::string m_action
For action trigger objects.
Definition: track_object_presentation.hpp:394