SSE2: More alignment workarounds

--HG--
branch : sse2
hg/feature/sse2
kaetemi 11 years ago
parent ba2231f068
commit f8b6d81b25

@ -57,6 +57,7 @@ using NLMISC::CRefCount;
using NLMISC::CSmartPtr; using NLMISC::CSmartPtr;
using NLMISC::CRGBA; using NLMISC::CRGBA;
using NLMISC::CVector; using NLMISC::CVector;
using NLMISC::CVectorPacked;
using NLMISC::CMatrix; using NLMISC::CMatrix;
using NLMISC::CSynchronized; using NLMISC::CSynchronized;

@ -1244,7 +1244,7 @@ public:
static std::vector<uint> _ParticleToRemove; // used during the update step, contains the indices of the particles to remove static std::vector<uint> _ParticleToRemove; // used during the update step, contains the indices of the particles to remove
static std::vector<sint> _ParticleRemoveListIndex; // for each particle, -1 if it hasn't been removed, or else give the insertion number in _ParticleToRemove static std::vector<sint> _ParticleRemoveListIndex; // for each particle, -1 if it hasn't been removed, or else give the insertion number in _ParticleToRemove
static std::vector<uint> _CollidingParticles; // index of particle that collided static std::vector<uint> _CollidingParticles; // index of particle that collided
static std::vector<NLMISC::CVector> _SpawnPos; // spawn position of newly created particles static std::vector<NLMISC::CVectorPacked> _SpawnPos; // spawn position of newly created particles
public: public:
// current sim steps infos // current sim steps infos
static TAnimationTime EllapsedTime; static TAnimationTime EllapsedTime;

@ -563,7 +563,7 @@ void CPSAttrib<T>::swap(CPSAttrib<T> &other)
// here we give some definition for common types // here we give some definition for common types
typedef CPSAttrib<NLMISC::CVector> TPSAttribVector; typedef CPSAttrib<NLMISC::CVectorPacked> TPSAttribVector;
typedef CPSAttrib<NLMISC::CRGBA> TPSAttribRGBA; typedef CPSAttrib<NLMISC::CRGBA> TPSAttribRGBA;
typedef CPSAttrib<float> TPSAttribFloat; typedef CPSAttrib<float> TPSAttribFloat;
typedef CPSAttrib<uint32> TPSAttribUInt; typedef CPSAttrib<uint32> TPSAttribUInt;

@ -1190,10 +1190,10 @@ T CPSAttribMakerT<T, F>::get(CPSLocated *loc, uint32 index)
result= getInternal(loc->getInvMass()[index]); result= getInternal(loc->getInvMass()[index]);
break; break;
case CPSInputType::attrSpeed: case CPSInputType::attrSpeed:
result = getInternal(loc->getSpeed()[index].norm()); result = getInternal(NLMISC::CVector(loc->getSpeed()[index]).norm());
break; break;
case CPSInputType::attrPosition: case CPSInputType::attrPosition:
result = getInternal(loc->getPos()[index].norm()); result = getInternal(NLMISC::CVector(loc->getPos()[index]).norm());
break; break;
case CPSInputType::attrUniformRandom: case CPSInputType::attrUniformRandom:
{ {
@ -1210,7 +1210,7 @@ T CPSAttribMakerT<T, F>::get(CPSLocated *loc, uint32 index)
static NLMISC::CVector lodVect; static NLMISC::CVector lodVect;
float lodOffset; float lodOffset;
loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode()); loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode());
float r = fabsf(loc->getPos()[index] * lodVect + lodOffset); float r = fabsf(NLMISC::CVector(loc->getPos()[index]) * lodVect + lodOffset);
r = this->_NbCycles * r > MaxInputValue ? MaxInputValue : r; r = this->_NbCycles * r > MaxInputValue ? MaxInputValue : r;
if (_Clamp) if (_Clamp)
{ {
@ -1224,7 +1224,7 @@ T CPSAttribMakerT<T, F>::get(CPSLocated *loc, uint32 index)
static NLMISC::CVector lodVect; static NLMISC::CVector lodVect;
float lodOffset; float lodOffset;
loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode()); loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode());
float r = loc->getPos()[index] * lodVect + lodOffset; float r = NLMISC::CVector(loc->getPos()[index]) * lodVect + lodOffset;
r = this->_NbCycles * (r > MaxInputValue ? MaxInputValue : r * r); r = this->_NbCycles * (r > MaxInputValue ? MaxInputValue : r * r);
if (_Clamp) if (_Clamp)
@ -1240,7 +1240,7 @@ T CPSAttribMakerT<T, F>::get(CPSLocated *loc, uint32 index)
float lodOffset; float lodOffset;
loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode()); loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode());
float r = loc->getPos()[index] * lodVect + lodOffset; float r = NLMISC::CVector(loc->getPos()[index]) * lodVect + lodOffset;
if (r < 0) if (r < 0)
{ {
result = _F(MaxInputValue); result = _F(MaxInputValue);
@ -1260,7 +1260,7 @@ T CPSAttribMakerT<T, F>::get(CPSLocated *loc, uint32 index)
float lodOffset; float lodOffset;
loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode()); loc->getLODVect(lodVect, lodOffset, loc->getMatrixMode());
float r = loc->getPos()[index] * lodVect + lodOffset; float r = NLMISC::CVector(loc->getPos()[index]) * lodVect + lodOffset;
if (r < 0) if (r < 0)
{ {
result = _F(MaxInputValue); result = _F(MaxInputValue);

@ -48,7 +48,7 @@ namespace NL3D
template <class TBaseIter> template <class TBaseIter>
struct CVectNormIterator : CPSBaseIterator<TBaseIter> struct CVectNormIterator : CPSBaseIterator<TBaseIter>
{ {
GET_INLINE float get() const { return this->Iter.get().norm(); } GET_INLINE float get() const { return CVector(this->Iter.get()).norm(); }
CVectNormIterator(const TBaseIter &it) : CPSBaseIterator<TBaseIter>(it) {} CVectNormIterator(const TBaseIter &it) : CPSBaseIterator<TBaseIter>(it) {}
}; };
@ -76,7 +76,7 @@ namespace NL3D
template <class TBaseIter> template <class TBaseIter>
struct CDistIterator : CPSBaseIterator<TBaseIter> struct CDistIterator : CPSBaseIterator<TBaseIter>
{ {
NLMISC::CVector V; NLMISC::CVectorPacked V;
float Offset; float Offset;
CDistIterator(const TBaseIter &it) : CPSBaseIterator<TBaseIter>(it) {} CDistIterator(const TBaseIter &it) : CPSBaseIterator<TBaseIter>(it) {}
}; };
@ -89,7 +89,7 @@ namespace NL3D
GET_INLINE GET_INLINE
float get() const float get() const
{ {
const float r = fabsf(this->Iter.get() * this->V + this->Offset); const float r = fabsf(CVector(this->Iter.get()) * this->V + this->Offset);
return r > MaxInputValue ? MaxInputValue : r; return r > MaxInputValue ? MaxInputValue : r;
} }
CFDot3AddIterator(const TBaseIter &it) : CDistIterator<TBaseIter>(it) {} CFDot3AddIterator(const TBaseIter &it) : CDistIterator<TBaseIter>(it) {}
@ -101,7 +101,7 @@ namespace NL3D
{ {
float get() const float get() const
{ {
float r = this->Iter.get() * this->V + this->Offset; float r = CVector(this->Iter.get()) * this->V + this->Offset;
r *= r; r *= r;
return r > MaxInputValue ? MaxInputValue : r; return r > MaxInputValue ? MaxInputValue : r;
} }
@ -115,7 +115,7 @@ namespace NL3D
GET_INLINE GET_INLINE
float get() const float get() const
{ {
const float r = this->Iter.get() * this->V + this->Offset; const float r = CVector(this->Iter.get()) * this->V + this->Offset;
if (r < 0.f) return MaxInputValue; if (r < 0.f) return MaxInputValue;
return r > MaxInputValue ? MaxInputValue : r; return r > MaxInputValue ? MaxInputValue : r;
} }
@ -130,7 +130,7 @@ namespace NL3D
GET_INLINE GET_INLINE
float get() const float get() const
{ {
float r = this->Iter.get() * this->V + this->Offset; float r = CVector(this->Iter.get()) * this->V + this->Offset;
if (r < 0) return MaxInputValue; if (r < 0) return MaxInputValue;
r *= r; r *= r;
return r > MaxInputValue ? MaxInputValue : r; return r > MaxInputValue ? MaxInputValue : r;

@ -87,9 +87,9 @@ public:
* 'accumulate' set to false. * 'accumulate' set to false.
* NB : works only with integrable forces * NB : works only with integrable forces
*/ */
virtual void integrate(float /* date */, CPSLocated * /* src */, uint32 /* startIndex */, uint32 /* numObjects */, NLMISC::CVector * /* destPos */ = NULL, NLMISC::CVector * /* destSpeed */ = NULL, virtual void integrate(float /* date */, CPSLocated * /* src */, uint32 /* startIndex */, uint32 /* numObjects */, NLMISC::CVectorPacked * /* destPos */ = NULL, NLMISC::CVectorPacked * /* destSpeed */ = NULL,
bool /* accumulate */ = false, bool /* accumulate */ = false,
uint /* posStride */ = sizeof(NLMISC::CVector), uint /* speedStride */ = sizeof(NLMISC::CVector) uint /* posStride */ = sizeof(NLMISC::CVectorPacked), uint /* speedStride */ = sizeof(NLMISC::CVectorPacked)
) const ) const
{ {
nlassert(0); // not an integrable force nlassert(0); // not an integrable force
@ -325,7 +325,10 @@ template <class T> void CIsotropicForceT<T>::computeForces(CPSLocated &target)
for (; speedIt != endSpeedIt; ++speedIt, ++posIt, ++invMassIt) for (; speedIt != endSpeedIt; ++speedIt, ++posIt, ++invMassIt)
{ {
_F(*posIt, *speedIt, *invMassIt); const CVector posv = *posIt;
CVector speedv = *speedIt;
_F(posv, speedv, *invMassIt);
*speedIt = speedv;
} }
} }
} }
@ -770,7 +773,7 @@ protected:
virtual CPSLocated *getForceIntensityOwner(void) { return _Owner; } virtual CPSLocated *getForceIntensityOwner(void) { return _Owner; }
// the normal of the vortex // the normal of the vortex
CPSAttrib<NLMISC::CVector> _Normal; CPSAttrib<NLMISC::CVectorPacked> _Normal;
// radius of the vortex // radius of the vortex
TPSAttribFloat _Radius; TPSAttribFloat _Radius;

@ -134,10 +134,10 @@ namespace NL3D
/// Some typedefs /// Some typedefs
typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1; typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1;
typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorFloatStep1; typedef CAdvance1Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorFloatStep1;
typedef CAdvance1Iterator<TPSAttribVector::const_iterator, NLMISC::CVector> TIteratorVectStep1; typedef CAdvance1Iterator<TPSAttribVector::const_iterator, NLMISC::CVectorPacked> TIteratorVectStep1;
typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1616; typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, float> TIteratorFloatStep1616;
typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorTimeStep1616; typedef CAdvance1616Iterator<TPSAttribFloat::const_iterator, TAnimationTime> TIteratorTimeStep1616;
typedef CAdvance1616Iterator<TPSAttribVector::const_iterator, NLMISC::CVector> TIteratorVectStep1616; typedef CAdvance1616Iterator<TPSAttribVector::const_iterator, NLMISC::CVectorPacked> TIteratorVectStep1616;
} // NL3D } // NL3D

@ -220,6 +220,7 @@ public:
CScene *getScene(void); CScene *getScene(void);
/// shortcut to the same method of the owning particle system /// shortcut to the same method of the owning particle system
void getLODVect(NLMISC::CVectorPacked &v, float &offset, TPSMatrixMode matrixMode);
void getLODVect(NLMISC::CVector &v, float &offset, TPSMatrixMode matrixMode); void getLODVect(NLMISC::CVector &v, float &offset, TPSMatrixMode matrixMode);
@ -411,7 +412,7 @@ public:
void computeForces(); void computeForces();
// compute collisions // compute collisions
void computeCollisions(uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); void computeCollisions(uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
// get a conversion matrix between 2 matrix modes // get a conversion matrix between 2 matrix modes
static const NLMISC::CMatrix &getConversionMatrix(const CParticleSystem &ps, TPSMatrixMode to, TPSMatrixMode from); static const NLMISC::CMatrix &getConversionMatrix(const CParticleSystem &ps, TPSMatrixMode to, TPSMatrixMode from);

@ -28,6 +28,7 @@ namespace NLMISC
{ {
class CMatrix; class CMatrix;
class CVector; class CVector;
class CVectorPacked;
}; };
namespace NL3D namespace NL3D

@ -106,7 +106,7 @@ public:
/** Compute collisions for the given target. This will update the collisions infos. /** Compute collisions for the given target. This will update the collisions infos.
* The caller must provide pointer to arrays positions before and after time step. * The caller must provide pointer to arrays positions before and after time step.
*/ */
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) = 0; virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter) = 0;
protected: protected:
@ -141,7 +141,7 @@ protected:
class CPSZonePlane : public CPSZone, public IPSMover class CPSZonePlane : public CPSZone, public IPSMover
{ {
public: public:
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
virtual void show(); virtual void show();
@ -192,7 +192,7 @@ typedef CPSAttrib<CRadiusPair> TPSAttribRadiusPair;
class CPSZoneSphere : public CPSZone, public IPSMover class CPSZoneSphere : public CPSZone, public IPSMover
{ {
public: public:
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
virtual void show(); virtual void show();
@ -236,7 +236,7 @@ class CPSZoneSphere : public CPSZone, public IPSMover
class CPSZoneDisc : public CPSZone, public IPSMover class CPSZoneDisc : public CPSZone, public IPSMover
{ {
public: public:
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
virtual void show(); virtual void show();
CPSZoneDisc() CPSZoneDisc()
@ -283,7 +283,7 @@ class CPSZoneDisc : public CPSZone, public IPSMover
class CPSZoneCylinder : public CPSZone, public IPSMover class CPSZoneCylinder : public CPSZone, public IPSMover
{ {
public: public:
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
virtual void show(); virtual void show();
CPSZoneCylinder() CPSZoneCylinder()
@ -335,7 +335,7 @@ class CPSZoneCylinder : public CPSZone, public IPSMover
class CPSZoneRectangle : public CPSZone, public IPSMover class CPSZoneRectangle : public CPSZone, public IPSMover
{ {
public: public:
virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter); virtual void computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter);
virtual void show(); virtual void show();
CPSZoneRectangle() CPSZoneRectangle()

@ -47,6 +47,7 @@ namespace NL3D
using NLMISC::CVector; using NLMISC::CVector;
using NLMISC::CVectorPacked;
using NLMISC::CMatrix; using NLMISC::CMatrix;
using NLMISC::CRGBA; using NLMISC::CRGBA;
using NLMISC::CBitmap; using NLMISC::CBitmap;

@ -69,11 +69,11 @@ public: // Methods.
/// @name Object. /// @name Object.
//@{ //@{
/// Constructor which does nothing. /// Constructor which does nothing.
CVector() {} CVector() { if (((uintptr_t)(void *)(this) & 0xF) != 0) nlerror("Vector alignment error"); }
/// Constructor . /// Constructor .
CVector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} CVector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) { if (((uintptr_t)(void *)(this) & 0xF) != 0) nlerror("Vector alignment error"); }
/// Copy Constructor. /// Copy Constructor.
CVector(const CVector &v) : x(v.x), y(v.y), z(v.z) {} CVector(const CVector &v) : x(v.x), y(v.y), z(v.z) { if (((uintptr_t)(void *)(this) & 0xF) != 0) nlerror("Vector alignment error"); }
//@} //@}
/// @name Base Maths. /// @name Base Maths.
@ -181,6 +181,14 @@ public:
return *this; return *this;
} }
CVectorPacked &operator -= (const CVector &v)
{
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
operator CVector () const operator CVector () const
{ {
return CVector(x, y, z); return CVector(x, y, z);
@ -190,6 +198,16 @@ public:
{ {
f.serial(x,y,z); f.serial(x,y,z);
} }
CVector operator+(const CVector &v) const
{
return CVector(*this) + v;
}
CVector operator-(const CVector &v) const
{
return CVector(*this) - v;
}
}; };
// blend (faster version than the generic version found in algo.h) // blend (faster version than the generic version found in algo.h)
@ -214,9 +232,25 @@ inline CVector blend(const CVector &v0, const CVector &v1, float lambda)
} }
} }
namespace std {
inline void swap(NLMISC::CVectorPacked &v1, NLMISC::CVector &v2)
{
NLMISC::CVectorPacked temp = v2;
v2 = NLMISC::CVector(v1);
v1 = temp;
}
inline void swap(NLMISC::CVector &v1, NLMISC::CVectorPacked &v2)
{
NLMISC::CVectorPacked temp = v1;
v1 = NLMISC::CVector(v2);
v2 = temp;
}
}
#include "vector_inline.h" #include "vector_inline.h"

@ -64,7 +64,7 @@ float CParticleSystem::RealEllapsedTimeRatio = 1.f;
bool CParticleSystem::InsideSimLoop = false; bool CParticleSystem::InsideSimLoop = false;
bool CParticleSystem::InsideRemoveLoop = false; bool CParticleSystem::InsideRemoveLoop = false;
bool CParticleSystem::InsideNewElementsLoop = false;; bool CParticleSystem::InsideNewElementsLoop = false;;
std::vector<NLMISC::CVector> CParticleSystem::_SpawnPos; std::vector<NLMISC::CVectorPacked> CParticleSystem::_SpawnPos;

@ -2790,7 +2790,7 @@ void CPSEmitter::doEmitOnce(uint firstInstanceIndex)
CVector startPos; CVector startPos;
if (!_Owner->isParametricMotionEnabled()) if (!_Owner->isParametricMotionEnabled())
{ {
startPos = _Owner->getPos()[k] - _Owner->getSpeed()[k] * CParticleSystem::EllapsedTime; startPos = CVector(_Owner->getPos()[k]) - CVector(_Owner->getSpeed()[k]) * CParticleSystem::EllapsedTime;
} }
else else
{ {
@ -2823,7 +2823,7 @@ void CPSEmitter::doEmitOnce(uint firstInstanceIndex)
CVector startPos; CVector startPos;
if (!_Owner->isParametricMotionEnabled()) if (!_Owner->isParametricMotionEnabled())
{ {
startPos = _Owner->getPos()[k] - _Owner->getSpeed()[k] * CParticleSystem::EllapsedTime; startPos = CVector(_Owner->getPos()[k]) - CVector(_Owner->getSpeed()[k]) * CParticleSystem::EllapsedTime;
} }
else else
{ {

@ -65,7 +65,7 @@ public:
do do
{ {
// tmp unoptimized slow version // tmp unoptimized slow version
CVector normedSpeed = (*speedIt).normed(); CVector normedSpeed = CVector(*speedIt).normed();
float iProj = normedSpeed * I; float iProj = normedSpeed * I;
float kProj = normedSpeed * K; float kProj = normedSpeed * K;
dest->I = iProj * I + kProj * K; dest->I = iProj * I + kProj * K;

@ -862,8 +862,8 @@ void CPSCylindricVortex::computeForces(CPSLocated &target)
p *= 1.f / d; p *= 1.f / d;
// compute the speed vect that we should have (normalized) // compute the speed vect that we should have (normalized)
realTangentialSpeed = n ^ p; realTangentialSpeed = n ^ p;
tangentialSpeed = (*speedIt * realTangentialSpeed) * realTangentialSpeed; tangentialSpeed = (CVector(*speedIt) * realTangentialSpeed) * realTangentialSpeed;
radialSpeed = (p * *speedIt) * p; radialSpeed = (p * CVector(*speedIt)) * p;
// update radial speed; // update radial speed;
*speedIt -= _RadialViscosity * CParticleSystem::EllapsedTime * radialSpeed; *speedIt -= _RadialViscosity * CParticleSystem::EllapsedTime * radialSpeed;
// update tangential speed // update tangential speed
@ -981,7 +981,7 @@ void CPSMagneticForce::computeForces(CPSLocated &target)
TPSAttribFloat::const_iterator invMassIt = target.getInvMass().begin(); TPSAttribFloat::const_iterator invMassIt = target.getInvMass().begin();
for (; it != itend; ++it, ++invMassIt) for (; it != itend; ++it, ++invMassIt)
{ {
(*it) += intensity * *invMassIt * (*it ^ toAdd); (*it) += intensity * *invMassIt * (CVector(*it) ^ toAdd);
} }
} }
else else
@ -989,7 +989,7 @@ void CPSMagneticForce::computeForces(CPSLocated &target)
float i = intensity / target.getInitialMass(); float i = intensity / target.getInitialMass();
for (; it != itend; ++it) for (; it != itend; ++it)
{ {
(*it) += i * (*it ^ toAdd); (*it) += i * (CVector(*it) ^ toAdd);
} }
} }
} }

@ -502,6 +502,18 @@ bool CPSLocated::hasEmitters(void) const
return false; return false;
} }
/// ***************************************************************************************
void CPSLocated::getLODVect(NLMISC::CVectorPacked &v, float &offset, TPSMatrixMode matrixMode)
{
NL_PS_FUNC(CPSLocated_getLODVect)
nlassert(_Owner);
CHECK_PS_INTEGRITY
CVector temp;
_Owner->getLODVect(temp, offset, matrixMode);
v = temp;
CHECK_PS_INTEGRITY
}
/// *************************************************************************************** /// ***************************************************************************************
void CPSLocated::getLODVect(NLMISC::CVector &v, float &offset, TPSMatrixMode matrixMode) void CPSLocated::getLODVect(NLMISC::CVector &v, float &offset, TPSMatrixMode matrixMode)
{ {
@ -1866,7 +1878,7 @@ void CPSLocated::updateCollisions()
if (_Time[currCollision->Index] >= 1.f) if (_Time[currCollision->Index] >= 1.f)
{ {
// check whether particles died before the collision. If so, just continue (particle has already been inserted in the remove list), and cancel the collision // check whether particles died before the collision. If so, just continue (particle has already been inserted in the remove list), and cancel the collision
float timeToCollision = currCollision->Dist / _Speed[currCollision->Index].norm(); float timeToCollision = currCollision->Dist / CVector(_Speed[currCollision->Index]).norm();
if (_Time[currCollision->Index] / _TimeIncrement[currCollision->Index] - timeToCollision * CParticleSystem::RealEllapsedTimeRatio >= 1.f) if (_Time[currCollision->Index] / _TimeIncrement[currCollision->Index] - timeToCollision * CParticleSystem::RealEllapsedTimeRatio >= 1.f)
{ {
// says that collision did not occurs // says that collision did not occurs
@ -2196,12 +2208,12 @@ void CPSLocated::removeOldParticles()
if (_LifeScheme) if (_LifeScheme)
{ {
_Pos[*it] -= _Speed[*it] * ((_Time[*it] - 1.f) / _TimeIncrement[*it]) * ellapsedTimeRatio; _Pos[*it] -= CVector(_Speed[*it]) * ((_Time[*it] - 1.f) / _TimeIncrement[*it]) * ellapsedTimeRatio;
timeUntilNextSimStep = (_Time[*it] - 1.f) / _TimeIncrement[*it]; timeUntilNextSimStep = (_Time[*it] - 1.f) / _TimeIncrement[*it];
} }
else else
{ {
_Pos[*it] -= _Speed[*it] * ((_Time[*it] - 1.f) * _InitialLife) * ellapsedTimeRatio; _Pos[*it] -= CVector(_Speed[*it]) * ((_Time[*it] - 1.f) * _InitialLife) * ellapsedTimeRatio;
timeUntilNextSimStep = (_Time[*it] - 1.f) * _InitialLife; timeUntilNextSimStep = (_Time[*it] - 1.f) * _InitialLife;
} }
_Time[*it] = 0.9999f; _Time[*it] = 0.9999f;
@ -2255,7 +2267,7 @@ void CPSLocated::removeOldParticles()
{ {
// move position backward (compute its position at death) // move position backward (compute its position at death)
timeUntilNextSimStep = ((_Time[*it] - 1.f) / _TimeIncrement[*it]) * ellapsedTimeRatio; timeUntilNextSimStep = ((_Time[*it] - 1.f) / _TimeIncrement[*it]) * ellapsedTimeRatio;
_Pos[*it] -= _Speed[*it] * timeUntilNextSimStep; _Pos[*it] -= CVector(_Speed[*it]) * timeUntilNextSimStep;
// force time to 1 because emitter 'on death' may rely on the date of emitter to compute its attributes // force time to 1 because emitter 'on death' may rely on the date of emitter to compute its attributes
_Time[*it] = 0.9999f; _Time[*it] = 0.9999f;
@ -2283,7 +2295,7 @@ void CPSLocated::removeOldParticles()
{ {
// move position backward // move position backward
timeUntilNextSimStep = (_Time[*it] - 1.f) * _InitialLife * ellapsedTimeRatio; timeUntilNextSimStep = (_Time[*it] - 1.f) * _InitialLife * ellapsedTimeRatio;
_Pos[*it] -= _Speed[*it] * timeUntilNextSimStep; _Pos[*it] -= CVector(_Speed[*it]) * timeUntilNextSimStep;
// force time to 1 because emitter 'on death' may rely on the date of emitter to compute its attributes // force time to 1 because emitter 'on death' may rely on the date of emitter to compute its attributes
_Time[*it] = 0.9999f; _Time[*it] = 0.9999f;
} }
@ -3038,7 +3050,7 @@ void CPSLocated::setZBias(float value)
} }
/// *************************************************************************************** /// ***************************************************************************************
void CPSLocated::computeCollisions(uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSLocated::computeCollisions(uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSLocated_computeCollisions) NL_PS_FUNC(CPSLocated_computeCollisions)
for(TDtorObserversVect::iterator it = _DtorObserversVect.begin(); it != _DtorObserversVect.end(); ++it) for(TDtorObserversVect::iterator it = _DtorObserversVect.begin(); it != _DtorObserversVect.end(); ++it)

@ -130,7 +130,7 @@ void *CPSPlaneBasisFollowSpeed::make(CPSLocated *loc,
case XY: case XY:
while (numAttrib --) while (numAttrib --)
{ {
const CVector *speedVect = &(*(speedIt + (fpIndex >> 16))); const NLMISC::CVectorPacked *speedVect = &(*(speedIt + (fpIndex >> 16)));
float norm = sqrtf(speedVect->x * speedVect->x + speedVect->y * speedVect->y); float norm = sqrtf(speedVect->x * speedVect->x + speedVect->y * speedVect->y);
float invNorm = (norm != 0.f) ? 1.f / norm : 0.f; float invNorm = (norm != 0.f) ? 1.f / norm : 0.f;
CPlaneBasis &pb = *(CPlaneBasis *) ptDat; CPlaneBasis &pb = *(CPlaneBasis *) ptDat;
@ -143,7 +143,7 @@ void *CPSPlaneBasisFollowSpeed::make(CPSLocated *loc,
case XZ: case XZ:
while (numAttrib --) while (numAttrib --)
{ {
const CVector *speedVect = &(*(speedIt + (fpIndex >> 16))); const NLMISC::CVectorPacked *speedVect = &(*(speedIt + (fpIndex >> 16)));
float norm = sqrtf(speedVect->x * speedVect->x + speedVect->z * speedVect->z); float norm = sqrtf(speedVect->x * speedVect->x + speedVect->z * speedVect->z);
float invNorm = (norm != 0.f) ? 1.f / norm : 0.f; float invNorm = (norm != 0.f) ? 1.f / norm : 0.f;
CPlaneBasis &pb = *(CPlaneBasis *) ptDat; CPlaneBasis &pb = *(CPlaneBasis *) ptDat;
@ -156,7 +156,7 @@ void *CPSPlaneBasisFollowSpeed::make(CPSLocated *loc,
case YZ: case YZ:
while (numAttrib --) while (numAttrib --)
{ {
const CVector *speedVect = &(*(speedIt + (fpIndex >> 16))); const NLMISC::CVectorPacked *speedVect = &(*(speedIt + (fpIndex >> 16)));
float norm = sqrtf(speedVect->y * speedVect->y + speedVect->z * speedVect->z); float norm = sqrtf(speedVect->y * speedVect->y + speedVect->z * speedVect->z);
float invNorm = (norm != 0.f) ? 1.f / norm : 0.f; float invNorm = (norm != 0.f) ? 1.f / norm : 0.f;
CPlaneBasis &pb = *(CPlaneBasis *) ptDat; CPlaneBasis &pb = *(CPlaneBasis *) ptDat;

@ -160,10 +160,10 @@ public:
radVect = *ptCurrSize * (CPSUtil::getCos((sint32) currAngle) * ptCurrBasis->X + CPSUtil::getSin((sint32) currAngle) * ptCurrBasis->Y); radVect = *ptCurrSize * (CPSUtil::getCos((sint32) currAngle) * ptCurrBasis->X + CPSUtil::getSin((sint32) currAngle) * ptCurrBasis->Y);
innerVect = radiusRatio * radVect; innerVect = radiusRatio * radVect;
CHECK_VERTEX_BUFFER(*vb, currVertex); CHECK_VERTEX_BUFFER(*vb, currVertex);
* (CVectorPacked *) currVertex = *posIt + radVect; * (CVectorPacked *) currVertex = CVector(*posIt) + radVect;
currVertex += vSize; currVertex += vSize;
CHECK_VERTEX_BUFFER(*vb, currVertex); CHECK_VERTEX_BUFFER(*vb, currVertex);
* (CVectorPacked *) currVertex = *posIt + innerVect; * (CVectorPacked *) currVertex = CVector(*posIt) + innerVect;
currVertex += vSize; currVertex += vSize;
currAngle += angleStep; currAngle += angleStep;
} }

@ -148,8 +148,8 @@ void CPSSound::step(TPSProcessPass pass)
CPSAttrib<UPSSoundInstance *>::iterator it = _Sounds.begin(), CPSAttrib<UPSSoundInstance *>::iterator it = _Sounds.begin(),
endIt; endIt;
CPSAttrib<NLMISC::CVector>::const_iterator posIt = _Owner->getPos().begin(); CPSAttrib<NLMISC::CVectorPacked>::const_iterator posIt = _Owner->getPos().begin();
CPSAttrib<NLMISC::CVector>::const_iterator speedIt = _Owner->getSpeed().begin(); CPSAttrib<NLMISC::CVectorPacked>::const_iterator speedIt = _Owner->getSpeed().begin();
do do
{ {

@ -194,7 +194,7 @@ void CPSZonePlane::deleteElement(uint32 index)
} }
void CPSZonePlane::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSZonePlane::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSZonePlane_computeCollisions) NL_PS_FUNC(CPSZonePlane_computeCollisions)
MINI_TIMER(PSStatsZonePlane) MINI_TIMER(PSStatsZonePlane)
@ -213,9 +213,9 @@ void CPSZonePlane::computeCollisions(CPSLocated &target, uint firstInstanceIndex
NLMISC::CPlane p; NLMISC::CPlane p;
p.make(m.mulVector(*normalIt), m * (*planePosIt)); p.make(m.mulVector(*normalIt), m * (*planePosIt));
// deals with each particle // deals with each particle
const NLMISC::CVector *itPosBefore = posBefore + firstInstanceIndex; const NLMISC::CVectorPacked *itPosBefore = posBefore + firstInstanceIndex;
const NLMISC::CVector *itPosBeforeEnd = posBefore + target.getSize(); const NLMISC::CVectorPacked *itPosBeforeEnd = posBefore + target.getSize();
const NLMISC::CVector *itPosAfter = posAfter + firstInstanceIndex; const NLMISC::CVectorPacked *itPosAfter = posAfter + firstInstanceIndex;
while (itPosBefore != itPosBeforeEnd) while (itPosBefore != itPosBeforeEnd)
{ {
float posSide = p * *itPosBefore; float posSide = p * *itPosBefore;
@ -235,7 +235,7 @@ void CPSZonePlane::computeCollisions(CPSLocated &target, uint firstInstanceIndex
ci.Dist = startEnd.norm(); ci.Dist = startEnd.norm();
// we translate the particle from an epsilon so that it won't get hooked to the plane // we translate the particle from an epsilon so that it won't get hooked to the plane
ci.NewPos = *itPosBefore + startEnd + PSCollideEpsilon * p.getNormal(); ci.NewPos = *itPosBefore + startEnd + PSCollideEpsilon * p.getNormal();
const CVector &speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)]; const CVector speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)];
ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * p.getNormal()) * p.getNormal()); ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * p.getNormal()) * p.getNormal());
ci.CollisionZone = this; ci.CollisionZone = this;
CPSLocated::_Collisions[itPosBefore - posBefore].update(ci); CPSLocated::_Collisions[itPosBefore - posBefore].update(ci);
@ -290,7 +290,7 @@ void CPSZonePlane::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
// sphere implementation // // sphere implementation //
/////////////////////////// ///////////////////////////
void CPSZoneSphere::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSZoneSphere::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSZoneSphere_computeCollisions) NL_PS_FUNC(CPSZoneSphere_computeCollisions)
MINI_TIMER(PSStatsZoneSphere) MINI_TIMER(PSStatsZoneSphere)
@ -308,9 +308,9 @@ void CPSZoneSphere::computeCollisions(CPSLocated &target, uint firstInstanceInde
const CMatrix &m = CPSLocated::getConversionMatrix(&target, this->_Owner); const CMatrix &m = CPSLocated::getConversionMatrix(&target, this->_Owner);
CVector center = m * *spherePosIt; CVector center = m * *spherePosIt;
// deals with each particle // deals with each particle
const NLMISC::CVector *itPosBefore = posBefore + firstInstanceIndex; const NLMISC::CVectorPacked *itPosBefore = posBefore + firstInstanceIndex;
const NLMISC::CVector *itPosBeforeEnd = posBefore + target.getSize(); const NLMISC::CVectorPacked *itPosBeforeEnd = posBefore + target.getSize();
const NLMISC::CVector *itPosAfter = posAfter + firstInstanceIndex; const NLMISC::CVectorPacked *itPosAfter = posAfter + firstInstanceIndex;
while (itPosBefore != itPosBeforeEnd) while (itPosBefore != itPosBeforeEnd)
{ {
// check whether the located is going through the sphere // check whether the located is going through the sphere
@ -346,7 +346,7 @@ void CPSZoneSphere::computeCollisions(CPSLocated &target, uint firstInstanceInde
ci.Dist = startEnd.norm(); ci.Dist = startEnd.norm();
// we translate the particle from an epsilon so that it won't get hooked to the sphere // we translate the particle from an epsilon so that it won't get hooked to the sphere
ci.NewPos = pos + startEnd + PSCollideEpsilon * normal; ci.NewPos = pos + startEnd + PSCollideEpsilon * normal;
const CVector &speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)]; const CVector speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)];
ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * normal) * normal); ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * normal) * normal);
ci.CollisionZone = this; ci.CollisionZone = this;
CPSLocated::_Collisions[itPosBefore - posBefore].update(ci); CPSLocated::_Collisions[itPosBefore - posBefore].update(ci);
@ -450,7 +450,7 @@ void CPSZoneSphere::deleteElement(uint32 index)
//////////////////////////////// ////////////////////////////////
// CPSZoneDisc implementation // // CPSZoneDisc implementation //
//////////////////////////////// ////////////////////////////////
void CPSZoneDisc::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSZoneDisc::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSZoneDisc_computeCollisions) NL_PS_FUNC(CPSZoneDisc_computeCollisions)
MINI_TIMER(PSStatsZoneDisc) MINI_TIMER(PSStatsZoneDisc)
@ -477,9 +477,9 @@ void CPSZoneDisc::computeCollisions(CPSLocated &target, uint firstInstanceIndex,
const float epsilon = 0.5f * PSCollideEpsilon; const float epsilon = 0.5f * PSCollideEpsilon;
// deals with each particle // deals with each particle
const NLMISC::CVector *itPosBefore = posBefore + firstInstanceIndex; const NLMISC::CVectorPacked *itPosBefore = posBefore + firstInstanceIndex;
const NLMISC::CVector *itPosBeforeEnd = posBefore + target.getSize(); const NLMISC::CVectorPacked *itPosBeforeEnd = posBefore + target.getSize();
const NLMISC::CVector *itPosAfter = posAfter + firstInstanceIndex; const NLMISC::CVectorPacked *itPosAfter = posAfter + firstInstanceIndex;
while (itPosBefore != itPosBeforeEnd) while (itPosBefore != itPosBeforeEnd)
{ {
float posSide = p * *itPosBefore; float posSide = p * *itPosBefore;
@ -503,7 +503,7 @@ void CPSZoneDisc::computeCollisions(CPSLocated &target, uint firstInstanceIndex,
hitRadius2 = (ci.NewPos - center) * (ci.NewPos - center); hitRadius2 = (ci.NewPos - center) * (ci.NewPos - center);
if (hitRadius2 < radiusIt->R2) // check collision against disc if (hitRadius2 < radiusIt->R2) // check collision against disc
{ {
const CVector &speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)]; const CVector speed = target.getSpeed()[(uint32)(itPosBefore - posBefore)];
ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * p.getNormal()) * p.getNormal()); ci.NewSpeed = _BounceFactor * (speed - 2.0f * (speed * p.getNormal()) * p.getNormal());
ci.CollisionZone = this; ci.CollisionZone = this;
CPSLocated::_Collisions[itPosBefore - posBefore].update(ci); CPSLocated::_Collisions[itPosBefore - posBefore].update(ci);
@ -847,7 +847,7 @@ void CPSZoneCylinder::performMotion(TAnimationTime ellapsedTime)
*/ */
void CPSZoneCylinder::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSZoneCylinder::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSZoneCylinder_computeCollisions) NL_PS_FUNC(CPSZoneCylinder_computeCollisions)
MINI_TIMER(PSStatsZoneCylinder) MINI_TIMER(PSStatsZoneCylinder)
@ -873,9 +873,9 @@ void CPSZoneCylinder::computeCollisions(CPSLocated &target, uint firstInstanceIn
CVector destProjectedPos, destTPos; CVector destProjectedPos, destTPos;
// deals with each particle // deals with each particle
// deals with each particle // deals with each particle
const NLMISC::CVector *itPosBefore = posBefore + firstInstanceIndex; const NLMISC::CVectorPacked *itPosBefore = posBefore + firstInstanceIndex;
const NLMISC::CVector *itPosBeforeEnd = posBefore + target.getSize(); const NLMISC::CVectorPacked *itPosBeforeEnd = posBefore + target.getSize();
const NLMISC::CVector *itPosAfter = posAfter + firstInstanceIndex; const NLMISC::CVectorPacked *itPosAfter = posAfter + firstInstanceIndex;
while (itPosBefore != itPosBeforeEnd) while (itPosBefore != itPosBeforeEnd)
{ {
const CVector &pos = *itPosBefore; const CVector &pos = *itPosBefore;
@ -1123,7 +1123,7 @@ void CPSZoneCylinder::deleteElement(uint32 index)
// implementation of CPSZoneRectangle // // implementation of CPSZoneRectangle //
////////////////////////////////////////////// //////////////////////////////////////////////
void CPSZoneRectangle::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVector *posBefore, const NLMISC::CVector *posAfter) void CPSZoneRectangle::computeCollisions(CPSLocated &target, uint firstInstanceIndex, const NLMISC::CVectorPacked *posBefore, const NLMISC::CVectorPacked *posAfter)
{ {
NL_PS_FUNC(CPSZoneRectangle_computeCollisions) NL_PS_FUNC(CPSZoneRectangle_computeCollisions)
MINI_TIMER(PSStatsZoneRectangle) MINI_TIMER(PSStatsZoneRectangle)
@ -1149,9 +1149,9 @@ void CPSZoneRectangle::computeCollisions(CPSLocated &target, uint firstInstanceI
p.make(X ^ Y, center); p.make(X ^ Y, center);
// deals with each particle // deals with each particle
const float epsilon = 0.5f * PSCollideEpsilon; const float epsilon = 0.5f * PSCollideEpsilon;
const NLMISC::CVector *itPosBefore = posBefore + firstInstanceIndex; const NLMISC::CVectorPacked *itPosBefore = posBefore + firstInstanceIndex;
const NLMISC::CVector *itPosBeforeEnd = posBefore + target.getSize(); const NLMISC::CVectorPacked *itPosBeforeEnd = posBefore + target.getSize();
const NLMISC::CVector *itPosAfter = posAfter + firstInstanceIndex; const NLMISC::CVectorPacked *itPosAfter = posAfter + firstInstanceIndex;
while (itPosBefore != itPosBeforeEnd) while (itPosBefore != itPosBeforeEnd)
{ {
float posSide = p * *itPosBefore; float posSide = p * *itPosBefore;

Loading…
Cancel
Save