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

« back to all changes in this revision

Viewing changes to src/components/ogre/manipulation/EntityMoveAdjuster.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
// C++ Interface: EntityMoveAdjuster
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2006
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifndef EMBEROGREENTITYMOVEADJUSTER_H
 
24
#define EMBEROGREENTITYMOVEADJUSTER_H
 
25
 
 
26
#include <Eris/Timeout.h>
 
27
#include <vector>
 
28
 
 
29
namespace EmberOgre {
 
30
 
 
31
class EmberEntity;
 
32
class EntityMoveAdjuster;
 
33
class EntityMoveManager;
 
34
 
 
35
/**
 
36
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
37
        @see EntityMoveAdjuster
 
38
        An instance of a adjustment operation. After time out, the entity encapsuled by this instance will be synchronized with the server.
 
39
*/
 
40
class EntityMoveAdjustmentInstance
 
41
{
 
42
public: 
 
43
        /**
 
44
         *    Default ctor.
 
45
         * @param moveAdjuster 
 
46
         * @param entity 
 
47
         * @return 
 
48
         */
 
49
        EntityMoveAdjustmentInstance(EntityMoveAdjuster* moveAdjuster, EmberEntity* entity);
 
50
        
 
51
private:
 
52
        /**
 
53
        The actual entity.
 
54
        */
 
55
        EmberEntity* mEntity;
 
56
        
 
57
        /**
 
58
        The timeout object which provides timeout functionality.
 
59
        */
 
60
        Eris::Timeout mTimeout;
 
61
        
 
62
        /**
 
63
         *    Called when the time has expired.
 
64
         */
 
65
        void timout_Expired();
 
66
        
 
67
        /**
 
68
        A reference to the owner object.
 
69
        */
 
70
        EntityMoveAdjuster* mMoveAdjuster;
 
71
};
 
72
 
 
73
/**
 
74
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
75
@brief This class is responsible for adjusting moved entities to their correct place.
 
76
Basically, when an entity is moved the client sends the updates to the server, but it's not clear at that time whether the movement is allowed. This can only be seen by waiting to see whether the movement went through, i.e. if the entity was updated.
 
77
So what this class does, together with EntityMoveAdjustmentInstance, waiting a couple of milleseconds and then telling the entity that  was moved to synchronize with the server. If the movement didn't go through, this will lead to the entity "snapping" back to the original position. If it did go through nothing will happen.
 
78
*/
 
79
class EntityMoveAdjuster
 
80
{
 
81
friend class EntityMoveAdjustmentInstance;
 
82
public:
 
83
        /**
 
84
         *    Default ctor.
 
85
         * @param manager 
 
86
         * @return 
 
87
         */
 
88
        EntityMoveAdjuster(EntityMoveManager* manager);
 
89
private:
 
90
        typedef std::vector<EntityMoveAdjustmentInstance*> MoveAdjustmentInstanceStore;
 
91
        
 
92
        /**
 
93
        Holds all instances of EntityMoveAdjustmentInstance.
 
94
        */
 
95
        MoveAdjustmentInstanceStore mInstances;
 
96
        
 
97
        /**
 
98
         *    Removes the supplied instance from the list of instances.
 
99
         * @param  
 
100
         */
 
101
        void removeInstance(EntityMoveAdjustmentInstance*);
 
102
        
 
103
        /**
 
104
         *    When movement has finished, i.e. something has been moved, create an EntityMoveAdjustmentInstance which will update the entity at expiration.
 
105
         */
 
106
        void EntityMoveManager_FinishedMoving();
 
107
        
 
108
        /**
 
109
         *    When movement has been cancelled, there's no need to create any EntityMoveAdjustmentInstance, but we want to clean up.
 
110
         */
 
111
        void EntityMoveManager_CancelledMoving();
 
112
        
 
113
        /**
 
114
         *    When movement starts, register the entity that is being moved.
 
115
         * @param entity 
 
116
         */
 
117
        void EntityMoveManager_StartMoving(EmberEntity* entity);
 
118
        
 
119
        /**
 
120
        The entity that is being moved.
 
121
        */
 
122
        EmberEntity* mActiveEntity;
 
123
        
 
124
        /**
 
125
        A reference to the manager.
 
126
        */
 
127
        EntityMoveManager* mManager;
 
128
};
 
129
 
 
130
}
 
131
 
 
132
#endif