Cafu Engine
CompSound.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GAMESYS_COMPONENT_SOUND_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_SOUND_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 class SoundI;
14 
15 
16 namespace cf
17 {
18  namespace GameSys
19  {
20  /// This component adds 3D sound output to its entity.
22  {
23  public:
24 
25  /// The constructor.
27 
28  /// The copy constructor.
29  /// @param Comp The component to create a copy of.
30  ComponentSoundT(const ComponentSoundT& Comp);
31 
32  /// The destructor.
34 
35  // Base class overrides.
36  ComponentSoundT* Clone() const;
37  const char* GetName() const { return "Sound"; }
38  unsigned int GetEditorColor() const { return 0xFF0000; }
39  void DoClientFrame(float t);
40 
41 
42  // The TypeSys related declarations for this class.
43  const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; }
44  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
45  static const cf::TypeSys::TypeInfoT TypeInfo;
46 
47 
48  protected:
49 
50  // The Lua API methods of this class.
51  static int Play(lua_State* LuaState);
52  static int toString(lua_State* LuaState);
53 
54  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
55  static const char* DocClass;
56  static const cf::TypeSys::MethsDocT DocMethods[];
57  static const cf::TypeSys::VarsDocT DocVars[];
58 
59 
60  private:
61 
62  SoundI* GetSound();
63 
64  TypeSys::VarT<std::string> m_Name; ///< The name of the sound shader or sound file to play.
65  TypeSys::VarT<bool> m_AutoPlay; ///< Whether the sound is played automatically in interval-spaced loops. If `false`, playbacks of the sound must be triggered by explicit calls to the Play() method.
66  TypeSys::VarT<float> m_Interval; ///< If `m_AutoPlay` is `true`, this is the time in seconds between successive playbacks of the sound.
67 
68  std::string m_PrevName; ///< The previous file name, used to detect changes in `m_Name`.
69  SoundI* m_Sound; ///< The sound instance of this component, NULL for none.
70  float m_PauseLeft; ///< If `m_AutoPlay` is `true`, how much of `m_Interval` is left before the sound is played again?
71  };
72  }
73 }
74 
75 #endif
const char * GetName() const
Returns the name of this component.
Definition: CompSound.hpp:37
This component adds 3D sound output to its entity.
Definition: CompSound.hpp:21
ComponentSoundT * Clone() const
The virtual copy constructor.
Definition: CompSound.cpp:89
ComponentSoundT()
The constructor.
Definition: CompSound.cpp:45
~ComponentSoundT()
The destructor.
Definition: CompSound.cpp:75
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompSound.hpp:54
This class represents a sound.
Definition: Sound.hpp:15
void DoClientFrame(float t)
Derived classes override this method in order to implement the real work proposed by OnClientFrame()...
Definition: CompSound.cpp:95
unsigned int GetEditorColor() const
Returns a color that the Map Editor can use to render the representation of this component's entity...
Definition: CompSound.hpp:38
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54