1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
20 #include "effect_manager.h"
21 #include "effect_message.h"
24 using namespace NLMISC
;
25 using namespace NLNET
;
27 NL_INSTANCE_COUNTER_IMPL(TEffectVector
);
29 // init static members
30 TEntitiesEffectMap
CEffectManager::_Effects
;
31 vector
< CBasicEffect
> CEffectManager::_NewEffects
;
32 vector
< CBasicEffect
> CEffectManager::_RemovedEffects
;
33 set
< NLNET::TServiceId
> CEffectManager::_RegisteredServices
;
36 //--------------------------------------------------------------
37 // CEffectManager constructor
38 //--------------------------------------------------------------
39 CEffectManager::CEffectManager()
44 //--------------------------------------------------------------
45 // CEffectManager destructor
46 //--------------------------------------------------------------
47 CEffectManager::~CEffectManager()
53 //--------------------------------------------------------------
54 // CEffectManager::release
55 //--------------------------------------------------------------
56 void CEffectManager::release()
58 TEntitiesEffectMap::iterator it
= _Effects
.begin();
59 const TEntitiesEffectMap::iterator itEnd
= _Effects
.end();
61 for ( ; it
!= itEnd
; ++it
)
63 if ( (*it
).second
!= NULL
)
70 _RegisteredServices
.clear();
71 _RemovedEffects
.clear();
76 //--------------------------------------------------------------
77 // CEffectManager::update
78 //--------------------------------------------------------------
79 void CEffectManager::update()
81 H_AUTO(EffectManagerUpdate
);
83 if ( ! _RegisteredServices
.empty() )
85 CAddEffectsMessage addMsg
;
86 CRemoveEffectsMessage removeMsg
;
88 std::vector
< CBasicEffect
>::const_iterator itNew
= _NewEffects
.begin();
89 const std::vector
< CBasicEffect
>::const_iterator itNewEnd
= _NewEffects
.end();
90 for ( ; itNew
!= itNewEnd
; ++itNew
)
92 addMsg
.addEffect( *itNew
);
95 std::vector
< CBasicEffect
>::const_iterator itRemove
= _RemovedEffects
.begin();
96 const std::vector
< CBasicEffect
>::const_iterator itRemoveEnd
= _RemovedEffects
.end();
97 for ( ; itRemove
!= itRemoveEnd
; ++itRemove
)
99 removeMsg
.addEffect( *itRemove
);
102 set
< NLNET::TServiceId
>::const_iterator it
;
103 const set
< NLNET::TServiceId
>::const_iterator itEnd
= _RegisteredServices
.end();
104 for (it
= _RegisteredServices
.begin() ; it
!= itEnd
; ++it
)
106 if (!_NewEffects
.empty())
107 addMsg
.send( (*it
) );
109 if (!_RemovedEffects
.empty())
110 removeMsg
.send( (*it
) );
115 _RemovedEffects
.clear();