Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CCmpSoundManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
21 #include "ICmpSoundManager.h"
22 
27 
29 
31 {
32 public:
33  static void ClassInit(CComponentManager& UNUSED(componentManager) )
34  {
35  }
36 
38 
39  static std::string GetSchema()
40  {
41  return "<a:component type='system'/><empty/>";
42  }
43 
44  virtual void Init(const CParamNode& UNUSED(paramNode))
45  {
46  }
47 
48  virtual void Deinit()
49  {
50  }
51 
52  virtual void Serialize(ISerializer& UNUSED(serialize))
53  {
54  // Do nothing here - sounds are purely local, and don't need to be preserved across saved games etc
55  // (If we add music support in here then we might want to save the music state, though)
56  }
57 
58  virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize))
59  {
60  Init(paramNode);
61  }
62 
63  virtual void PlaySoundGroup(std::wstring name, entity_id_t source)
64  {
65  if ( ! g_SoundManager || (source == INVALID_ENTITY) )
66  return;
67 
68  CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
69  int currentPlayer = GetSimContext().GetCurrentDisplayedPlayer();
70 
71  if ( !cmpRangeManager ||
72  ( cmpRangeManager->GetLosVisibility(source, currentPlayer) != ICmpRangeManager::VIS_VISIBLE ) )
73  return;
74 
75  CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source);
76  if (cmpPosition && cmpPosition->IsInWorld())
77  {
78  bool playerOwned = false;
79  CmpPtr<ICmpOwnership> cmpOwnership( GetSimContext(), source);
80  if (cmpOwnership)
81  playerOwned = cmpOwnership->GetOwner() == currentPlayer;
82 
83  CVector3D sourcePos = CVector3D(cmpPosition->GetPosition());
84  g_SoundManager->PlayAsGroup(name, sourcePos, source, playerOwned);
85  }
86  }
87 
88 };
89 
90 REGISTER_COMPONENT_TYPE(SoundManager)
91 
92 
An entity initialisation parameter node.
Definition: ParamNode.h:112
#define REGISTER_COMPONENT_TYPE(cname)
Definition: Component.h:30
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
ISoundManager * g_SoundManager
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
virtual void PlayAsGroup(const VfsPath &groupPath, CVector3D sourcePos, entity_id_t source, bool ownedSound)=0
virtual void Deserialize(const CParamNode &paramNode, IDeserializer &deserialize)
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
virtual ELosVisibility GetLosVisibility(CEntityHandle ent, player_id_t player, bool forceRetainInFog=false)=0
Returns the visibility status of the given entity, with respect to the given player.
virtual void Init(const CParamNode &paramNode)
Interface to the engine&#39;s sound system.
virtual void Deinit()
virtual player_id_t GetOwner()=0
static void ClassInit(CComponentManager &componentManager)
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:44
const CSimContext & GetSimContext() const
Definition: IComponent.h:52
virtual void Serialize(ISerializer &serialize)
A simplified syntax for accessing entity components.
Definition: CmpPtr.h:55
int GetCurrentDisplayedPlayer() const
Returns the player ID that the current display is being rendered for.
Definition: SimContext.cpp:68
CEntityHandle GetSystemEntity() const
Definition: IComponent.h:50
virtual CFixedVector3D GetPosition()=0
Returns the current x,y,z position (no interpolation).
static std::string GetSchema()
virtual void PlaySoundGroup(std::wstring name, entity_id_t source)
Start playing audio defined by a sound group file.
const entity_id_t INVALID_ENTITY
Invalid entity ID.
Definition: Entity.h:36
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34