~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/sound/SoundEntity.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2008 Romulo Fernandes Machado (nightz)
 
3
    Copyright (C) 2008 Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
4
 
 
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.
 
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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
*/
 
19
 
 
20
#ifndef SOUND_ENTITY_H
 
21
#define SOUND_ENTITY_H
 
22
 
 
23
#include <wfmath/vector.h>
 
24
#include <wfmath/point.h>
 
25
#include <map>
 
26
#include <Atlas/Objects/Operation.h>
 
27
 
 
28
namespace EmberOgre
 
29
{
 
30
class SoundAction;
 
31
class EmberPhysicalEntity;
 
32
/**
 
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
 
41
*/
 
42
class SoundEntity
 
43
{
 
44
public:
 
45
        /**
 
46
         * @brief Ctor.
 
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.
 
49
         */
 
50
        SoundEntity(EmberPhysicalEntity& parentEntity);
 
51
        
 
52
        /**
 
53
         * @brief Dtor.
 
54
         * At destruction all SoundActions that are allocated will be destroyed.
 
55
         */
 
56
        virtual ~SoundEntity();
 
57
 
 
58
        /**
 
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.
 
62
        */
 
63
        WFMath::Point<3> getPosition() const;
 
64
 
 
65
        /**
 
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.
 
69
        */
 
70
        WFMath::Vector<3> getVelocity() const;
 
71
 
 
72
        /**
 
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.
 
76
         */
 
77
        const SoundAction* playAction(const std::string& name);
 
78
        
 
79
        /**
 
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.
 
83
         */
 
84
        const SoundAction* playMovementSound(const std::string& actionName);
 
85
 
 
86
protected:
 
87
 
 
88
        typedef std::map<std::string, SoundAction*> ActionStore;
 
89
        
 
90
        /**
 
91
         * @brief The ingame entity to which this sound entity is attached. 
 
92
         */
 
93
        EmberPhysicalEntity& mParentEntity;
 
94
        
 
95
        /**
 
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.
 
98
         */
 
99
        ActionStore mActions;
 
100
        
 
101
        /**
 
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
 
105
         */
 
106
        ActionStore mMovementActions;
 
107
        
 
108
        /**
 
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.
 
111
         */
 
112
        SoundAction* mCurrentMovementAction;
 
113
                
 
114
        /**
 
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.
 
117
         */
 
118
        void Entity_Action(const Atlas::Objects::Operation::RootOperation& act);
 
119
                
 
120
        /**
 
121
         * @brief Parses the ModelDefinition for the Model attached to the EmberPhysicalEntity and creates the required sound actions.
 
122
         */
 
123
        void createActions();
 
124
};
 
125
}
 
126
 
 
127
#endif
 
128