Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / u_particle_system_instance.cpp
blobea5794b199ad0eb48a108ca858ddfe2d16f7c5e2
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
17 #include "std3d.h"
19 #include "nel/3d/u_particle_system_instance.h"
20 #include "nel/3d/particle_system.h"
21 #include "nel/3d/particle_system_shape.h"
22 #include "nel/3d/ps_emitter.h"
23 #include "nel/3d/particle_system_model.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NL3D {
32 // ***************************************************************************
33 bool UParticleSystemInstance::isSystemPresent(void) const
35 if (!_Object) return false; // the system is not even valid
36 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
37 return object->getPS() != NULL;
40 // ***************************************************************************
41 bool UParticleSystemInstance::getSystemBBox(NLMISC::CAABBox &bbox)
43 if (!_Object) return false;
44 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
45 if (!object->getPS()) return false;
46 object->getPS()->computeBBox(bbox);
47 return true;
51 // ***************************************************************************
52 void UParticleSystemInstance::setUserColor(NLMISC::CRGBA userColor)
54 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
55 object->setUserColor(userColor);
58 // ***************************************************************************
59 NLMISC::CRGBA UParticleSystemInstance::getUserColor() const
61 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
62 return object->getUserColor();
65 // ***************************************************************************
66 void UParticleSystemInstance::setUserParam(uint index, float value)
68 if (index >= MaxPSUserParam)
70 nlwarning("invalid user param index");
71 return;
73 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
74 // object->getPS()->setUserParam(index, value);
75 IAnimatedValue *av = object->getValue(CParticleSystemModel::PSParam0 + index);
76 NLMISC::safe_cast<CAnimatedValueFloat *>(av)->Value = value;
77 object->touch(CParticleSystemModel::PSParam0 + index, CParticleSystemModel::OwnerBit);
80 // ***************************************************************************
81 float UParticleSystemInstance::getUserParam(uint index) const
83 if (index >= MaxPSUserParam)
85 nlwarning("invalid user param index");
86 return 0.f;
88 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object) ;
89 //return object->getPS()->getUserParam(index) ;
90 IAnimatedValue *av = object->getValue(CParticleSystemModel::PSParam0 + index);
91 return NLMISC::safe_cast<CAnimatedValueFloat *>(av)->Value;
94 // ***************************************************************************
95 static inline uint32 IDToLittleEndian(uint32 input)
97 #ifdef NL_LITTLE_ENDIAN
98 return input;
99 #else
100 return ((input & (0xff<<24))>>24)
101 | ((input & (0xff<<16))>>8)
102 | ((input & (0xff<<8))<<8)
103 | ((input & 0xff)<<24);
104 #endif
107 // ***************************************************************************
108 bool UParticleSystemInstance::emit(uint32 anId, uint quantity)
110 const uint32 id = IDToLittleEndian(anId);
111 nlassert(isSystemPresent());
112 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
113 uint numLb = ps->getNumLocatedBindableByExternID(id);
114 if (numLb == 0) return false; // INVALID ID !!
115 for (uint k = 0; k < numLb; ++k)
117 CPSLocatedBindable *lb = ps->getLocatedBindableByExternID(id, k);
118 if (lb->getType() == PSEmitter)
120 CPSEmitter *e = NLMISC::safe_cast<CPSEmitter *>(lb);
121 nlassert(e->getOwner());
122 uint nbInstances = e->getOwner()->getSize();
123 for (uint l = 0; l < nbInstances; ++l)
125 e->singleEmit(l, quantity);
129 return true;
134 // ***************************************************************************
135 bool UParticleSystemInstance::removeByID(uint32 anId)
137 const uint32 id = IDToLittleEndian(anId);
138 if (!isSystemPresent()) return false;
139 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
140 uint numLb = ps->getNumLocatedBindableByExternID(id);
141 if (numLb == 0) return false; // INVALID ID !!
142 for (uint k = 0; k < numLb; ++k)
144 CPSLocatedBindable *lb = ps->getLocatedBindableByExternID(id, k);
145 CPSLocated *owner = lb->getOwner();
146 nlassert(owner);
147 uint nbInstances = owner->getSize();
148 for (uint l = 0; l < nbInstances; ++l)
150 owner->deleteElement(0);
153 return true;
156 // ***************************************************************************
157 uint UParticleSystemInstance::getNumID() const
159 if (!isSystemPresent()) return 0;
160 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
161 return ps->getNumID();
164 // ***************************************************************************
165 uint32 UParticleSystemInstance::getID(uint index) const
167 if (!isSystemPresent()) return 0;
168 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
169 return ps->getID(index);
172 // ***************************************************************************
173 bool UParticleSystemInstance::getIDs(std::vector<uint32> &dest) const
175 if (!isSystemPresent()) return false;
176 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
177 ps->getIDs(dest);
178 return true;
181 // ***************************************************************************
182 bool UParticleSystemInstance::setActive(uint32 anId, bool active)
184 const uint32 id = IDToLittleEndian(anId);
185 if (!isSystemPresent()) return false;
186 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
187 uint numLb = ps->getNumLocatedBindableByExternID(id);
188 if (numLb == 0) return false; // INVALID ID !!
189 for (uint k = 0; k < numLb; ++k)
191 CPSLocatedBindable *lb = ps->getLocatedBindableByExternID(id, k);
192 lb->setActive(active);
194 return true;
197 // ***************************************************************************
198 void UParticleSystemInstance::activateEmitters(bool active)
200 (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->activateEmitters(active);
203 // ***************************************************************************
204 bool UParticleSystemInstance::hasActiveEmitters() const
206 return (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->hasActiveEmitters();
209 // ***************************************************************************
210 bool UParticleSystemInstance::hasParticles() const
212 if (!isSystemPresent()) return false;
213 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
214 return ps->hasParticles();
217 // ***************************************************************************
218 bool UParticleSystemInstance::hasEmmiters() const
220 if (!isSystemPresent()) return false;
221 CParticleSystem *ps = (NLMISC::safe_cast<CParticleSystemModel *>(_Object))->getPS();
222 return ps->hasEmitters();
224 // ***************************************************************************
225 bool UParticleSystemInstance::isShared() const
227 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
228 if(object->Shape)
230 return NLMISC::safe_cast<CParticleSystemShape *>((IShape *) object->Shape)->isShared();
232 return false;
235 // ***************************************************************************
236 void UParticleSystemInstance::setGlobalUserParamValue(const std::string &name, float value)
238 if (name.empty())
240 nlwarning("invalid name");
241 return;
243 CParticleSystem::setGlobalValue(name, value);
246 // ***************************************************************************
247 float UParticleSystemInstance::getGlobalUserParamValue(const std::string &name)
249 if (name.empty())
251 nlwarning("invalid name");
252 return 0.f;
254 return CParticleSystem::getGlobalValue(name);
257 // ***************************************************************************
258 void UParticleSystemInstance::setGlobalVectorValue(const std::string &name,const NLMISC::CVector &v)
260 if (name.empty())
262 nlwarning("invalid name");
264 CParticleSystem::setGlobalVectorValue(name, v);
267 // ***************************************************************************
268 void UParticleSystemInstance::forceDisplayBBox(bool on)
270 CParticleSystem::forceDisplayBBox(on);
274 // ***************************************************************************
275 NLMISC::CVector UParticleSystemInstance::getGlobalVectorValue(const std::string &name)
277 if (name.empty())
279 nlwarning("invalid name");
280 return NLMISC::CVector::Null;
282 else return CParticleSystem::getGlobalVectorValue(name);
285 // ***************************************************************************
286 void UParticleSystemInstance::bypassGlobalUserParamValue(uint userParamIndex, bool byPass /*=true*/)
288 if (userParamIndex >= MaxPSUserParam)
290 nlwarning("invalid user param index");
291 return;
293 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
294 object->bypassGlobalUserParamValue(userParamIndex, byPass);
297 // ***************************************************************************
298 bool UParticleSystemInstance::isGlobalUserParamValueBypassed(uint userParamIndex) const
300 if (userParamIndex >= MaxPSUserParam)
302 nlwarning("invalid user param index");
303 return 0.f;
305 return isGlobalUserParamValueBypassed(userParamIndex);
308 // ***************************************************************************
309 void UParticleSystemInstance::setUserMatrix(const NLMISC::CMatrix &userMat)
311 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
312 object->setUserMatrix(userMat);
315 // ***************************************************************************
316 void UParticleSystemInstance::forceSetUserMatrix(const NLMISC::CMatrix &userMat)
318 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
319 object->forceSetUserMatrix(userMat);
323 // ***************************************************************************
324 void UParticleSystemInstance::forceInstanciate()
326 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
327 object->forceInstanciate();
330 // ***************************************************************************
331 void UParticleSystemInstance::setZBias(float value)
333 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
334 object->setZBias(value);
337 // ***************************************************************************
339 void UParticleSystemInstance::cast(UInstance object)
341 attach(dynamic_cast<CParticleSystemModel*> (object.getObjectPtr()));
344 // ***************************************************************************
345 bool UParticleSystemInstance::isValid() const
347 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
348 return !object->isInvalid();
351 // ***************************************************************************
352 void UParticleSystemInstance::stopSound()
354 if (!_Object) return;
355 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
356 object->stopSound();
359 // ***************************************************************************
360 void UParticleSystemInstance::reactivateSound()
362 if (!_Object) return;
363 CParticleSystemModel *object = NLMISC::safe_cast<CParticleSystemModel *>(_Object);
364 object->reactivateSound();
368 // ***************************************************************************
370 } // NL3D