Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / server_share / effect_manager.h
blobf654be44990d691f2cbbcd40bc1a3c17873f32a6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RY_EFFECT_MANAGER_H
20 #define RY_EFFECT_MANAGER_H
22 #include "nel/misc/types_nl.h"
24 #include "game_share/base_types.h"
25 #include "basic_effect.h"
27 class TEffectVector : public std::vector<CBasicEffect>
29 NL_INSTANCE_COUNTER_DECL(TEffectVector);
30 public:
33 //typedef std::vector< CBasicEffect > TEffectVector;
34 typedef std::map< TDataSetRow, TEffectVector* > TEntitiesEffectMap;
36 /**
37 * Singleton managing effects for EGS and AIS
38 * \author David Fleury
39 * \author Nevrax France
40 * \date 2003
42 class CEffectManager
44 public:
45 /// Constructor
46 CEffectManager();
48 /// Destructor
49 ~CEffectManager();
51 /// release method
52 static void release();
54 /// update method (should be called each tick)
55 static void update();
57 /// add a effect to given entity
58 inline static void addEffect( const TDataSetRow &entityRow, const CBasicEffect &effect )
60 TEntitiesEffectMap::iterator it = _Effects.find(entityRow);
61 if ( it != _Effects.end())
63 if ( (*it).second != NULL)
65 (*it).second->push_back(effect);
67 else
69 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow.getIndex() );
70 (*it).second = new TEffectVector();
71 if ( (*it).second)
72 (*it).second->push_back(effect);
75 else
77 // create new vector
78 TEffectVector *vector = new TEffectVector();
79 if (vector)
81 vector->push_back(effect);
82 _Effects.insert( std::make_pair(entityRow, vector) );
86 _NewEffects.push_back(effect);
89 /// add a vector of spells to given entity
90 inline static void addEffects( const TDataSetRow &entityRow, const std::vector<CBasicEffect> &spells )
92 TEntitiesEffectMap::iterator it = _Effects.find(entityRow);
93 if ( it != _Effects.end())
95 if ( (*it).second != NULL)
97 (*it).second->insert( (*it).second->end(), spells.begin(), spells.end() );
99 else
101 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow.getIndex() );
102 (*it).second = new TEffectVector();
103 if ( (*it).second)
104 (*it).second->insert( (*it).second->end(), spells.begin(), spells.end() );
107 else
109 // create new vector
110 TEffectVector *vector = new TEffectVector();
111 if (vector)
113 vector->insert( vector->end(), spells.begin(), spells.end() );
114 _Effects.insert( std::make_pair(entityRow, vector) );
118 _NewEffects.insert(_NewEffects.end(), spells.begin(), spells.end() );
121 /// remove a effect
122 inline static void removeEffect( const TDataSetRow &entityRow, uint32 effectId )
124 TEntitiesEffectMap::iterator it = _Effects.find(entityRow);
125 if ( it == _Effects.end())
127 return;
130 if ( (*it).second == NULL)
132 nlwarning("<CEffectManager::addEffect> NULL pointer instead of effect vector for entity RowId %u", entityRow.getIndex() );
133 return;
136 // parse vector
137 TEffectVector::iterator itEffect;
138 const TEffectVector::const_iterator itEnd = (*it).second->end();
139 for ( itEffect = (*it).second->begin() ; itEffect != itEnd ; ++itEffect)
141 if ( (*itEffect).effectId() == effectId )
143 _RemovedEffects.push_back(*itEffect);
144 (*it).second->erase(itEffect);
146 // if last effect, erase entry
147 if ((*it).second->empty())
149 delete (*it).second;
150 (*it).second = NULL;
151 _Effects.erase(it);
154 return;
159 /// remove an entity
160 inline void removeEntity( const TDataSetRow &entityRow )
162 TEntitiesEffectMap::iterator it = _Effects.find(entityRow);
163 if ( it != _Effects.end())
165 if ( (*it).second != NULL)
167 delete (*it).second;
168 (*it).second = NULL;
170 _Effects.erase(it);
174 /// register a service
175 inline void static registerService( NLNET::TServiceId serviceId )
177 _RegisteredServices.insert( serviceId );
180 /// unregister a service
181 inline void static unregisterService( NLNET::TServiceId serviceId )
183 _RegisteredServices.erase( serviceId );
186 private:
187 /// map entities to their active spells
188 static TEntitiesEffectMap _Effects;
190 /// the spells created since last update
191 static std::vector< CBasicEffect > _NewEffects;
193 /// the spells deleted since last update
194 static std::vector< CBasicEffect > _RemovedEffects;
196 /// list of services registered to new and removed spells/effects
197 static std::set<NLNET::TServiceId> _RegisteredServices;
202 #endif // RY_EFFECT_MANAGER_H
204 /* End of effect_manager.h */