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/>.
23 #include "stdpch.h" // First include for pre-compiled headers.
25 #include "nel/3d/u_particle_system_instance.h"
26 #include "nel/pacs/u_global_position.h"
28 #include "fx_manager.h"
29 #include "time_client.h"
30 #include "pacs_client.h"
33 H_AUTO_DECL(RZ_FXManager
)
38 using namespace NLMISC
;
40 using namespace NLPACS
;
66 //-----------------------------------------------
69 //-----------------------------------------------
70 CFXManager::CFXManager()
72 H_AUTO_USE(RZ_FXManager
)
76 //-----------------------------------------------
79 //-----------------------------------------------
80 CFXManager::~CFXManager()
82 H_AUTO_USE(RZ_FXManager
)
87 //-----------------------------------------------
89 // create an FX that will be removed as soon as possible.
90 //-----------------------------------------------
91 NL3D::UParticleSystemInstance
CFXManager::instantFX(const std::string
&fxName
, float timeOut
/* = 0.f*/)
93 H_AUTO_USE(RZ_FXManager
)
98 NL3D::UParticleSystemInstance fx
;
99 fx
.cast (Scene
->createInstance(fxName
));
102 _FX2RemoveList
.push_back(CFX2Remove(fx
, timeOut
));
109 //-----------------------------------------------
111 //-----------------------------------------------
112 void CFXManager::addFX(NL3D::UParticleSystemInstance fx
, float timeOut
, bool testNoMoreParticles
/*= false*/)
114 H_AUTO_USE(RZ_FXManager
)
115 if (fx
.empty()) return;
116 _FX2RemoveList
.push_back(CFX2Remove(fx
, timeOut
, testNoMoreParticles
));
120 //-----------------------------------------------
122 //-----------------------------------------------
123 void CFXManager::fx2remove(NL3D::UParticleSystemInstance fx
, float timeOut
)
125 H_AUTO_USE(RZ_FXManager
)
128 _FX2RemoveList
.push_back(CFX2Remove(fx
, timeOut
));
133 //-----------------------------------------------
135 //-----------------------------------------------
136 void CFXManager::update()
138 H_AUTO_USE(RZ_FXManager
)
142 while (!_DeferredFXByDate
.empty())
145 if (T1
< (uint
)_DeferredFXByDate
.begin()->first
) break;
146 const CDeferredFX
&fx
= _DeferredFXByDate
.begin()->second
;
147 NL3D::UParticleSystemInstance fxInstance
= instantFX(fx
.FXName
, fx
.TimeOut
);
148 if (!fxInstance
.empty())
150 fxInstance
.setTransformMode(UTransform::DirectMatrix
);
151 fxInstance
.setMatrix(fx
.Matrix
);
152 UGlobalPosition gPos
;
153 GR
->retrievePosition(fx
.Matrix
.getPos());
154 UInstanceGroup
*clusterSystem
= getCluster(gPos
);
155 fxInstance
.setClusterSystem(clusterSystem
);
156 fxInstance
.forceInstanciate(); // accurate timing wanted
158 _DeferredFXByDate
.erase(_DeferredFXByDate
.begin());
163 nlassert(_NumFXToRemove
== _FX2RemoveList
.size());
165 // Try to remove Animation FXs still not removed.
166 std::list
<CFX2Remove
>::iterator itFx
= _FX2RemoveList
.begin();
167 while(itFx
!= _FX2RemoveList
.end())
170 // Backup the old iterator
171 std::list
<CFX2Remove
>::iterator itTmp
= itFx
;
172 // Iterator on the Next FX.
175 // If the FX is not present or valid -> remove the FX.
176 if(!itTmp
->Instance
.isSystemPresent() ||
177 !itTmp
->Instance
.isValid() ||
178 (itTmp
->TestNoMoreParticles
&& !itTmp
->Instance
.hasParticles())
182 Scene
->deleteInstance(itTmp
->Instance
);
183 // Remove from the list.
184 _FX2RemoveList
.erase(itTmp
);
188 if (itTmp
->TimeOut
!= 0.f
)
190 itTmp
->TimeOut
-= DT
;
191 if (itTmp
->TimeOut
< 0.f
)
194 Scene
->deleteInstance(itTmp
->Instance
);
195 // Remove from the list.
196 _FX2RemoveList
.erase(itTmp
);
203 //-----------------------------------------------
205 //-----------------------------------------------
206 void CFXManager::reset()
208 H_AUTO_USE(RZ_FXManager
)
209 // Remove Animation FXs still not removed.
210 std::list
<CFX2Remove
>::iterator itFx
= _FX2RemoveList
.begin();
211 while(itFx
!= _FX2RemoveList
.end())
215 Scene
->deleteInstance(itFx
->Instance
);
220 _FX2RemoveList
.clear();
221 _DeferredFXByDate
.clear();
225 //-----------------------------------------------
227 //-----------------------------------------------
228 void CFXManager::deferFX(const std::string
&fxName
, const NLMISC::CMatrix
&matrix
, float delayInSeconds
, float timeOut
/*=FX_MANAGER_DEFAULT_TIMEOUT*/)
233 fx
.TimeOut
= timeOut
;
234 _DeferredFXByDate
.insert(std::make_pair(T1
+ uint64(1000.f
* delayInSeconds
), fx
));