Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / fx_manager.cpp
blobb24f7eb4ec11f155c1cf121d7b9186dc1a2461ea
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/>.
20 /////////////
21 // INCLUDE //
22 /////////////
23 #include "stdpch.h" // First include for pre-compiled headers.
24 // 3D
25 #include "nel/3d/u_particle_system_instance.h"
26 #include "nel/pacs/u_global_position.h"
27 // Client
28 #include "fx_manager.h"
29 #include "time_client.h"
30 #include "pacs_client.h"
33 H_AUTO_DECL(RZ_FXManager)
35 ///////////
36 // USING //
37 ///////////
38 using namespace NLMISC;
39 using namespace NL3D;
40 using namespace NLPACS;
41 using namespace std;
45 ////////////
46 // EXTERN //
47 ////////////
48 extern UScene *Scene;
51 /////////////
52 // GLOBALS //
53 /////////////
54 // FX manager.
55 CFXManager FXMngr;
58 /////////////
59 // MEMBERS //
60 /////////////
63 /////////////
64 // METHODS //
65 /////////////
66 //-----------------------------------------------
67 // CFXManager :
68 // Constructor.
69 //-----------------------------------------------
70 CFXManager::CFXManager()
72 H_AUTO_USE(RZ_FXManager)
73 _NumFXToRemove = 0;
74 }// CFXManager //
76 //-----------------------------------------------
77 // CFXManager :
78 // Destructor.
79 //-----------------------------------------------
80 CFXManager::~CFXManager()
82 H_AUTO_USE(RZ_FXManager)
83 reset();
84 }// CFXManager //
87 //-----------------------------------------------
88 // instantFX :
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)
94 // Check FX Name.
95 if(fxName.empty())
96 return 0;
98 NL3D::UParticleSystemInstance fx;
99 fx.cast (Scene->createInstance(fxName));
100 if(!fx.empty())
102 _FX2RemoveList.push_back(CFX2Remove(fx, timeOut));
103 ++_NumFXToRemove;
105 return fx;
106 }// instantFX //
109 //-----------------------------------------------
110 // addFX :
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));
117 ++_NumFXToRemove;
118 }// addFX //
120 //-----------------------------------------------
121 // fx2remove :
122 //-----------------------------------------------
123 void CFXManager::fx2remove(NL3D::UParticleSystemInstance fx, float timeOut)
125 H_AUTO_USE(RZ_FXManager)
126 if(!fx.empty())
128 _FX2RemoveList.push_back(CFX2Remove(fx, timeOut));
129 ++_NumFXToRemove;
131 }// fx2remove //
133 //-----------------------------------------------
134 // update :
135 //-----------------------------------------------
136 void CFXManager::update()
138 H_AUTO_USE(RZ_FXManager)
140 // deferred fx
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());
162 #ifdef NL_DEBUG
163 nlassert(_NumFXToRemove == _FX2RemoveList.size());
164 #endif
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.
173 itFx++;
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())
181 // Delete the FX.
182 Scene->deleteInstance(itTmp->Instance);
183 // Remove from the list.
184 _FX2RemoveList.erase(itTmp);
185 -- _NumFXToRemove;
187 else
188 if (itTmp->TimeOut != 0.f)
190 itTmp->TimeOut -= DT;
191 if (itTmp->TimeOut < 0.f)
193 // Delete the FX.
194 Scene->deleteInstance(itTmp->Instance);
195 // Remove from the list.
196 _FX2RemoveList.erase(itTmp);
197 -- _NumFXToRemove;
201 }// update //
203 //-----------------------------------------------
204 // reset :
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())
213 // Delete the FX.
214 if(Scene)
215 Scene->deleteInstance(itFx->Instance);
216 // Next FX
217 itFx++;
219 // clear FX list
220 _FX2RemoveList.clear();
221 _DeferredFXByDate.clear();
222 _NumFXToRemove = 0;
225 //-----------------------------------------------
226 // deferedFX :
227 //-----------------------------------------------
228 void CFXManager::deferFX(const std::string &fxName, const NLMISC::CMatrix &matrix, float delayInSeconds, float timeOut /*=FX_MANAGER_DEFAULT_TIMEOUT*/)
230 CDeferredFX fx;
231 fx.FXName = fxName;
232 fx.Matrix = matrix;
233 fx.TimeOut = timeOut;
234 _DeferredFXByDate.insert(std::make_pair(T1 + uint64(1000.f * delayInSeconds), fx));