2
Copyright (C) 2008 Romulo Fernandes Machado (nightz)
3
Copyright (C) 2008 Erik Hjortsberg <erik.hjortsberg@gmail.com>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#ifndef SOUND_ENTITY_H
21
#define SOUND_ENTITY_H
23
#include <wfmath/vector.h>
24
#include <wfmath/point.h>
26
#include <Atlas/Objects/Operation.h>
31
class EmberPhysicalEntity;
33
* @brief Represents an ingame EmberPhysicalEntity instance, providing sound bindings and making sure that the correct sound is played for actions and movements.
34
* Not all ingame entities have sounds attached to them, but for those that do, an instance of this class is responsible for making sure that the correct sounds are played for the correct action.
35
* Normally you only need to create an instance of this and it will take care of everything itself.
36
* The only thing that needs extra input is whenever the movement mode is changed, at which point playMovementSound() should be called.
37
* There can only be one single movement sound playing at any time, but there can be multiple actions being played simultanously
38
* All sound definition data used to set this class up is contained in the ModelDefinition of the Model attached to the EmberPhysicalEntity.
39
* @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
40
* @author Romulo Fernandes Machado
47
* At creation time, all SoundAction instances will be created and the class will begin listening to the signals on the EmberPhysicalEntity which are emitted when an action occurs.
48
* @param parentEntity The entity to which this instance belongs.
50
SoundEntity(EmberPhysicalEntity& parentEntity);
54
* At destruction all SoundActions that are allocated will be destroyed.
56
virtual ~SoundEntity();
59
* @brief Accessor for the predicted position of the entity to which this instance belongs.
60
* @see Eris::Entity::getPredictedPos()
61
* @return The predicted position of the entity, in world units.
63
WFMath::Point<3> getPosition() const;
66
* @brief Accessor for the predicted velocity of the entity to which this instance belongs.
67
* @see Eris::Entity::getPredictedVelocity()
68
* @return The predicted velocity of the entity, in world units.
70
WFMath::Vector<3> getVelocity() const;
73
* @brief Starts playing of the action with the specified name, granted that the action exists.
74
* @param name The name of the action to play.
75
* @return If the action exists, the SoundAction instance will be returned, else null.
77
const SoundAction* playAction(const std::string& name);
80
* @brief Starts playing the movement sound with the specified name, granted that it exists. If any other movement sound is currently being played that will be stopped.
81
* @param actionName The name of the action to play.
82
* @return If the action exists, the SoundAction instance will be returned, else null.
84
const SoundAction* playMovementSound(const std::string& actionName);
88
typedef std::map<std::string, SoundAction*> ActionStore;
91
* @brief The ingame entity to which this sound entity is attached.
93
EmberPhysicalEntity& mParentEntity;
96
* @brief List of SoundAction referenced by name. When the server sends an action to the client, the entity ask the specific action (if it exists) to be played.
97
* These are owned by this instance and will be destroyed when it's destroyed.
102
* @brief The movement actions differs a little from the normal action sounds in that they are always looping, and that there can only be one playing at any time.
103
* These are owned by this instance and will be destroyed when it's destroyed.
104
* @see mCurrentMovementAction
106
ActionStore mMovementActions;
109
* @brief This keeps track of the currently playing movement action sounds, or a null pointer if there's no currently playing.
110
* Since there can only be one movement action sound playing at any time, we need to keep track of which one is currently playing.
112
SoundAction* mCurrentMovementAction;
115
* @brief Listen for entity actions and play a sound if there's anyone registered for that action.
116
* @param act The action data struct. The name of the action can be obtained by looking at the parent of the operation.
118
void Entity_Action(const Atlas::Objects::Operation::RootOperation& act);
121
* @brief Parses the ModelDefinition for the Model attached to the EmberPhysicalEntity and creates the required sound actions.
123
void createActions();