forked from metin-server/m2dev-client-src
effect decorators removed
This commit is contained in:
@@ -4,58 +4,7 @@
|
||||
|
||||
void CEffectElementBase::GetPosition(float fTime, D3DXVECTOR3 & rPosition)
|
||||
{
|
||||
if (m_TimeEventTablePosition.empty())
|
||||
{
|
||||
rPosition = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
return;
|
||||
}
|
||||
if (m_TimeEventTablePosition.size()==1)
|
||||
{
|
||||
rPosition = m_TimeEventTablePosition[0].m_vecPosition;
|
||||
return;
|
||||
}
|
||||
if (m_TimeEventTablePosition.front().m_fTime > fTime)
|
||||
{
|
||||
rPosition = m_TimeEventTablePosition.front().m_vecPosition;
|
||||
return;
|
||||
}
|
||||
if (m_TimeEventTablePosition.back().m_fTime < fTime)
|
||||
{
|
||||
rPosition = m_TimeEventTablePosition.back().m_vecPosition;
|
||||
return;
|
||||
}
|
||||
|
||||
typedef TTimeEventTablePosition::iterator iterator;
|
||||
iterator result = std::lower_bound( m_TimeEventTablePosition.begin(), m_TimeEventTablePosition.end(), fTime );
|
||||
|
||||
TEffectPosition & rEffectPosition = *result;
|
||||
iterator rPrev = result;
|
||||
if (m_TimeEventTablePosition.begin() != result)
|
||||
{
|
||||
rPrev = result-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rPosition = result->m_vecPosition;
|
||||
return;
|
||||
}
|
||||
TEffectPosition & rPrevEffectPosition = *rPrev;
|
||||
int iMovingType = rPrevEffectPosition.m_iMovingType;
|
||||
|
||||
if (MOVING_TYPE_DIRECT == iMovingType)
|
||||
{
|
||||
float Head = fabs(rEffectPosition.m_fTime - fTime) / fabs(rEffectPosition.m_fTime - rPrevEffectPosition.m_fTime);
|
||||
float Tail = 1.0f - fabs(rEffectPosition.m_fTime - fTime) / fabs(rEffectPosition.m_fTime - rPrevEffectPosition.m_fTime);
|
||||
rPosition = (rPrevEffectPosition.m_vecPosition*Head) + (rEffectPosition.m_vecPosition*Tail);
|
||||
}
|
||||
else if (MOVING_TYPE_BEZIER_CURVE == iMovingType)
|
||||
{
|
||||
float ft = (fTime - rPrevEffectPosition.m_fTime) / (rEffectPosition.m_fTime - rPrevEffectPosition.m_fTime);
|
||||
|
||||
rPosition = rPrevEffectPosition.m_vecPosition * (1.0f - ft) * (1.0f - ft) +
|
||||
(rPrevEffectPosition.m_vecPosition + rPrevEffectPosition.m_vecControlPoint) * (1.0f - ft) * ft * 2 +
|
||||
rEffectPosition.m_vecPosition * ft * ft;
|
||||
}
|
||||
rPosition = GetTimeEventBlendValue(fTime, m_TimeEventTablePosition);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,9 +71,9 @@ BOOL CEffectElementBase::LoadScript(CTextFileLoader & rTextFileLoader)
|
||||
|
||||
EffectPosition.m_iMovingType = MOVING_TYPE_BEZIER_CURVE;
|
||||
|
||||
EffectPosition.m_vecPosition.x = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_vecPosition.y = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_vecPosition.z = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.x = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.y = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.z = atof(pTokenVector->at(i++).c_str());
|
||||
|
||||
EffectPosition.m_vecControlPoint.x = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_vecControlPoint.y = atof(pTokenVector->at(i++).c_str());
|
||||
@@ -136,9 +85,9 @@ BOOL CEffectElementBase::LoadScript(CTextFileLoader & rTextFileLoader)
|
||||
|
||||
EffectPosition.m_iMovingType = MOVING_TYPE_DIRECT;
|
||||
|
||||
EffectPosition.m_vecPosition.x = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_vecPosition.y = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_vecPosition.z = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.x = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.y = atof(pTokenVector->at(i++).c_str());
|
||||
EffectPosition.m_Value.z = atof(pTokenVector->at(i++).c_str());
|
||||
|
||||
EffectPosition.m_vecControlPoint = D3DXVECTOR3(0.0f,0.0f,0.0f);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ void CEffectMeshInstance::OnRender()
|
||||
|
||||
float fAlpha = 1.0f;
|
||||
if (m_pMeshScript->GetTimeTableAlphaPointer(i, &TableAlpha) && !TableAlpha->empty())
|
||||
GetTimeEventBlendValue(m_fLocalTime,*TableAlpha, &fAlpha);
|
||||
fAlpha = GetTimeEventBlendValue(m_fLocalTime, *TableAlpha);
|
||||
|
||||
// Render //
|
||||
CEffectMesh::TEffectMeshData * pMeshData = pEffectMesh->GetMeshDataPointer(i);
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "EffectUpdateDecorator.h"
|
||||
#include "ParticleInstance.h"
|
||||
namespace NEffectUpdateDecorator
|
||||
{
|
||||
|
||||
CBaseDecorator* CAirResistanceDecorator::__Clone(CParticleInstance* pfi, CParticleInstance* pi)
|
||||
{
|
||||
pi->m_fAirResistance = pfi->m_fAirResistance;
|
||||
return new CAirResistanceDecorator;
|
||||
}
|
||||
|
||||
void CAirResistanceDecorator::__Excute(const CDecoratorData & d)
|
||||
{
|
||||
d.pInstance->m_v3Velocity *= 1.0f-d.pInstance->m_fAirResistance;
|
||||
}
|
||||
CBaseDecorator* CGravityDecorator::__Clone(CParticleInstance* pfi, CParticleInstance* pi)
|
||||
{
|
||||
pi->m_fGravity = pfi->m_fGravity;
|
||||
return new CGravityDecorator;
|
||||
}
|
||||
|
||||
void CGravityDecorator::__Excute(const CDecoratorData& d)
|
||||
{
|
||||
d.pInstance->m_v3Velocity.z -= d.pInstance->m_fGravity * d.fElapsedTime;
|
||||
}
|
||||
|
||||
CBaseDecorator* CRotationDecorator::__Clone(CParticleInstance* pfi, CParticleInstance* pi)
|
||||
{
|
||||
pi->m_fRotationSpeed = pfi->m_fRotationSpeed;
|
||||
return new CRotationDecorator;
|
||||
}
|
||||
|
||||
void CRotationDecorator::__Excute(const CDecoratorData& d)
|
||||
{
|
||||
d.pInstance->m_fRotation += d.pInstance->m_fRotationSpeed * d.fElapsedTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Type.h"
|
||||
#include "../eterbase/Random.h"
|
||||
#include "../eterlib/Pool.h"
|
||||
class CParticleInstance;
|
||||
|
||||
namespace NEffectUpdateDecorator
|
||||
{
|
||||
class CDecoratorData
|
||||
{
|
||||
public:
|
||||
float fTime;
|
||||
float fElapsedTime;
|
||||
CParticleInstance * pInstance;
|
||||
CDecoratorData(float fTime, float fElapsedTime, CParticleInstance * pInstance)
|
||||
: fTime(fTime), fElapsedTime(fElapsedTime), pInstance(pInstance)
|
||||
{}
|
||||
};
|
||||
class CBaseDecorator
|
||||
{
|
||||
friend class CParticleSystemData;
|
||||
public:
|
||||
CBaseDecorator() :m_NextDecorator(0), m_PrevDecorator(0) {}
|
||||
virtual ~CBaseDecorator(){}
|
||||
|
||||
void Excute(const CDecoratorData & d)
|
||||
{
|
||||
CBaseDecorator* pd = this;
|
||||
while(pd)
|
||||
{
|
||||
CBaseDecorator* pNextDecorator = pd->m_NextDecorator;
|
||||
pd->__Excute(d);
|
||||
pd = pNextDecorator;
|
||||
}
|
||||
}
|
||||
CBaseDecorator * AddChainFront(CBaseDecorator * pd)
|
||||
{
|
||||
pd->m_NextDecorator = this;
|
||||
m_PrevDecorator = pd;
|
||||
return pd;
|
||||
}
|
||||
void DeleteThis()
|
||||
{
|
||||
//return;
|
||||
if (m_NextDecorator)
|
||||
m_NextDecorator->DeleteThis();
|
||||
delete this;
|
||||
}
|
||||
CBaseDecorator * Clone(CParticleInstance* pFirstInstance, CParticleInstance* pInstance)
|
||||
{
|
||||
CBaseDecorator * pNewDecorator = __Clone(pFirstInstance, pInstance);
|
||||
CBaseDecorator * pSrc = this;
|
||||
CBaseDecorator * pDest = pNewDecorator;
|
||||
while (pSrc->m_NextDecorator)
|
||||
{
|
||||
pDest->m_NextDecorator = pSrc->m_NextDecorator->__Clone(pFirstInstance, pInstance);
|
||||
pDest->m_NextDecorator->m_PrevDecorator = pDest;
|
||||
|
||||
pSrc = pSrc->m_NextDecorator;
|
||||
pDest = pDest->m_NextDecorator;
|
||||
}
|
||||
return pNewDecorator;
|
||||
}
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData & d) = 0;
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pFirstInstance, CParticleInstance* pInstance) = 0;
|
||||
void RemoveMe()
|
||||
{
|
||||
m_PrevDecorator->m_NextDecorator = m_NextDecorator;
|
||||
m_NextDecorator->m_PrevDecorator=m_PrevDecorator;
|
||||
delete this;
|
||||
}
|
||||
CBaseDecorator * m_NextDecorator;
|
||||
CBaseDecorator * m_PrevDecorator;
|
||||
};
|
||||
|
||||
class CHeaderDecorator : public CBaseDecorator, public CPooledObject<CHeaderDecorator>
|
||||
{
|
||||
public:
|
||||
CHeaderDecorator() {}
|
||||
virtual ~CHeaderDecorator() {}
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData&) {}
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance*, CParticleInstance*) { return new CHeaderDecorator; }
|
||||
};
|
||||
|
||||
class CNullDecorator : public CBaseDecorator, public CPooledObject<CNullDecorator>
|
||||
{
|
||||
public:
|
||||
CNullDecorator(){}
|
||||
virtual ~CNullDecorator(){}
|
||||
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData & d) {}
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance*, CParticleInstance* ) { return new CNullDecorator; }
|
||||
};
|
||||
|
||||
template <class T> class CTimeEventDecorator : public CBaseDecorator, public CPooledObject<CTimeEventDecorator<T> >
|
||||
{
|
||||
public:
|
||||
typedef CTimeEvent<T> TTimeEventType;
|
||||
typedef std::vector<TTimeEventType> TTimeEventContainerType;
|
||||
CTimeEventDecorator(const TTimeEventContainerType& TimeEventContainer, T * pValue = 0)
|
||||
: it_start(TimeEventContainer.begin()),
|
||||
it_cur(TimeEventContainer.begin()),
|
||||
it_next(TimeEventContainer.begin()),
|
||||
it_end(TimeEventContainer.end()),
|
||||
pData(pValue)
|
||||
{
|
||||
if (it_start == it_end)
|
||||
*pValue = T();
|
||||
else
|
||||
++it_next;
|
||||
}
|
||||
virtual ~CTimeEventDecorator() {}
|
||||
|
||||
void SetData( T * pValue ) { pData = pValue; }
|
||||
|
||||
protected:
|
||||
//CTimeEventDecorator(CTimeEventDecorator<T>& ted, CParticleInstance * pFirstInstance, CParticleInstance * pInstance);
|
||||
CTimeEventDecorator(CTimeEventDecorator<T>& ted, CParticleInstance* pFirstInstance, CParticleInstance* pInstance)
|
||||
: it_start(ted.it_start),
|
||||
it_end(ted.it_end),
|
||||
it_cur(ted.it_cur),
|
||||
it_next(ted.it_next),
|
||||
pData((T*)( (unsigned char*)ted.pData - (DWORD)pFirstInstance + (DWORD)pInstance))
|
||||
{
|
||||
if (it_start == it_end)
|
||||
*pData = T();
|
||||
}
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pFirstInstance, CParticleInstance* pInstance) { return new CTimeEventDecorator(*this, pFirstInstance, pInstance); }
|
||||
virtual void __Excute(const CDecoratorData & d)
|
||||
{
|
||||
if (it_start==it_end)
|
||||
{
|
||||
RemoveMe();
|
||||
}
|
||||
else if (it_cur->m_fTime>d.fTime)
|
||||
{
|
||||
*pData = it_cur->m_Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (it_next!=it_end && it_next->m_fTime<=d.fTime)
|
||||
++it_cur, ++it_next;
|
||||
if (it_next == it_end)
|
||||
{
|
||||
// setting value
|
||||
*pData = it_cur->m_Value;
|
||||
|
||||
RemoveMe();
|
||||
}
|
||||
else
|
||||
{
|
||||
float length = it_next->m_fTime - it_cur->m_fTime;
|
||||
//*pData = it_cur->m_Value + (it_next->m_Value - it_cur->m_Value)*(d.fTime-it_cur->m_fTime)/length;
|
||||
*pData = it_cur->m_Value*(1-(d.fTime-it_cur->m_fTime)/length) ;
|
||||
*pData += it_next->m_Value * ((d.fTime-it_cur->m_fTime)/length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typename TTimeEventContainerType::const_iterator it_start;
|
||||
typename TTimeEventContainerType::const_iterator it_end;
|
||||
typename TTimeEventContainerType::const_iterator it_cur;
|
||||
typename TTimeEventContainerType::const_iterator it_next;
|
||||
T * pData;
|
||||
};
|
||||
|
||||
typedef CTimeEventDecorator<float> CScaleValueDecorator;
|
||||
typedef CTimeEventDecorator<float> CColorValueDecorator;
|
||||
typedef CTimeEventDecorator<DWORDCOLOR> CColorAllDecorator;
|
||||
typedef CTimeEventDecorator<float> CAirResistanceValueDecorator;
|
||||
typedef CTimeEventDecorator<float> CGravityValueDecorator;
|
||||
typedef CTimeEventDecorator<float> CRotationSpeedValueDecorator;
|
||||
|
||||
class CTextureAnimationCWDecorator : public CBaseDecorator, public CPooledObject<CTextureAnimationCWDecorator>
|
||||
{
|
||||
public:
|
||||
CTextureAnimationCWDecorator(float fFrameTime, DWORD n, BYTE * pIdx) :n(n),pIdx(pIdx),fFrameTime(fFrameTime),fLastFrameTime(fFrameTime){}
|
||||
virtual ~CTextureAnimationCWDecorator(){}
|
||||
protected:
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi) { return new CTextureAnimationCWDecorator(fFrameTime,n,(BYTE*)((unsigned char*)pi+((BYTE*)pIdx-(BYTE*)pfi))); }
|
||||
virtual void __Excute(const CDecoratorData & d)
|
||||
{
|
||||
fLastFrameTime -= d.fElapsedTime;
|
||||
while (fLastFrameTime<0.0f)
|
||||
{
|
||||
fLastFrameTime += fFrameTime;
|
||||
if (++(*pIdx) >= n)
|
||||
*pIdx = 0;
|
||||
}
|
||||
}
|
||||
DWORD n;
|
||||
float fLastFrameTime;
|
||||
float fFrameTime;
|
||||
BYTE* pIdx;
|
||||
|
||||
};
|
||||
class CTextureAnimationCCWDecorator : public CBaseDecorator, public CPooledObject<CTextureAnimationCCWDecorator>
|
||||
{
|
||||
public:
|
||||
CTextureAnimationCCWDecorator(float fFrameTime, BYTE n, BYTE * pIdx) :n(n),pIdx(pIdx),fFrameTime(fFrameTime),fLastFrameTime(fFrameTime){}
|
||||
virtual ~CTextureAnimationCCWDecorator(){}
|
||||
protected:
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi) { return new CTextureAnimationCCWDecorator(fFrameTime,n,(BYTE*)((unsigned char*)pi+((BYTE*)pIdx-(BYTE*)pfi))); }
|
||||
virtual void __Excute(const CDecoratorData & d)
|
||||
{
|
||||
fLastFrameTime -= d.fElapsedTime;
|
||||
while (fLastFrameTime<0.0f)
|
||||
{
|
||||
fLastFrameTime += fFrameTime;
|
||||
|
||||
if (--(*pIdx) >= n && n != 0) // Because variable is unsigned..
|
||||
*pIdx = BYTE(n - 1);
|
||||
}
|
||||
}
|
||||
BYTE n;
|
||||
float fLastFrameTime;
|
||||
float fFrameTime;
|
||||
BYTE* pIdx;
|
||||
|
||||
};
|
||||
class CTextureAnimationRandomDecorator : public CBaseDecorator, public CPooledObject<CTextureAnimationRandomDecorator>
|
||||
{
|
||||
public:
|
||||
CTextureAnimationRandomDecorator(float fFrameTime, BYTE n, BYTE * pIdx) :n(n),pIdx(pIdx),fFrameTime(fFrameTime),fLastFrameTime(fFrameTime){}
|
||||
virtual ~CTextureAnimationRandomDecorator(){}
|
||||
protected:
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi) { return new CTextureAnimationRandomDecorator(fFrameTime,n,(BYTE*)((unsigned char*)pi+((BYTE*)pIdx-(BYTE*)pfi))); }
|
||||
virtual void __Excute(const CDecoratorData & d)
|
||||
{
|
||||
fLastFrameTime -= d.fElapsedTime;
|
||||
if (fLastFrameTime<0.0f && n!=0)
|
||||
{
|
||||
*pIdx = (BYTE)random_range(0,n-1);
|
||||
}
|
||||
while (fLastFrameTime<0.0f)
|
||||
fLastFrameTime += fFrameTime;
|
||||
}
|
||||
BYTE n;
|
||||
float fLastFrameTime;
|
||||
float fFrameTime;
|
||||
BYTE* pIdx;
|
||||
|
||||
};
|
||||
|
||||
class CAirResistanceDecorator : public CBaseDecorator, public CPooledObject<CAirResistanceDecorator>
|
||||
{
|
||||
public:
|
||||
CAirResistanceDecorator(){}
|
||||
virtual ~CAirResistanceDecorator(){}
|
||||
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData & d);
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi);
|
||||
};
|
||||
|
||||
class CGravityDecorator : public CBaseDecorator, public CPooledObject<CGravityDecorator>
|
||||
{
|
||||
public:
|
||||
CGravityDecorator(){}
|
||||
virtual ~CGravityDecorator(){}
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData& d);
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi);
|
||||
};
|
||||
|
||||
class CRotationDecorator : public CBaseDecorator, public CPooledObject<CRotationDecorator>
|
||||
{
|
||||
public:
|
||||
CRotationDecorator(){}
|
||||
virtual ~CRotationDecorator()
|
||||
{
|
||||
}
|
||||
protected:
|
||||
virtual void __Excute(const CDecoratorData& d);
|
||||
virtual CBaseDecorator* __Clone(CParticleInstance* pfi, CParticleInstance* pi) ;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -14,55 +14,45 @@ BOOL CEmitterProperty::isEmitFromEdge()
|
||||
return m_bEmitFromEdgeFlag;
|
||||
}
|
||||
|
||||
void CEmitterProperty::GetEmittingSize(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingSize(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingSize, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingSize, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingSize);
|
||||
}
|
||||
void CEmitterProperty::GetEmittingAngularVelocity(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingAngularVelocity(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingAngularVelocity, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingAngularVelocity, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingAngularVelocity);
|
||||
}
|
||||
void CEmitterProperty::GetEmittingDirectionX(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingDirectionX(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingDirectionX, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionX, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionX);
|
||||
}
|
||||
void CEmitterProperty::GetEmittingDirectionY(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingDirectionY(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingDirectionY, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionY, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionY);
|
||||
}
|
||||
void CEmitterProperty::GetEmittingDirectionZ(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingDirectionZ(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingDirectionZ, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionZ, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingDirectionZ);
|
||||
}
|
||||
void CEmitterProperty::GetEmittingVelocity(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmittingVelocity(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmittingVelocity, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmittingVelocity, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmittingVelocity);
|
||||
}
|
||||
void CEmitterProperty::GetEmissionCountPerSecond(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetEmissionCountPerSecond(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventEmissionCountPerSecond, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventEmissionCountPerSecond, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventEmissionCountPerSecond);
|
||||
}
|
||||
void CEmitterProperty::GetParticleLifeTime(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetParticleLifeTime(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventLifeTime, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventLifeTime, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventLifeTime);
|
||||
}
|
||||
void CEmitterProperty::GetParticleSizeX(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetParticleSizeX(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventSizeX, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventSizeX, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventSizeX);
|
||||
}
|
||||
void CEmitterProperty::GetParticleSizeY(float fTime, float * pfValue)
|
||||
void CEmitterProperty::GetParticleSizeY(float fTime, float* pfValue)
|
||||
{
|
||||
//GetTimeEventBlendValue<TTimeEventTableFloat, float>(fTime, m_TimeEventSizeY, pfValue);
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventSizeY, pfValue);
|
||||
*pfValue = GetTimeEventBlendValue(fTime, m_TimeEventSizeY);
|
||||
}
|
||||
|
||||
void CEmitterProperty::Clear()
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
#include "ParticleInstance.h"
|
||||
#include "ParticleProperty.h"
|
||||
|
||||
#include "../eterBase/Random.h"
|
||||
#include "../eterLib/Camera.h"
|
||||
#include "../eterLib/StateManager.h"
|
||||
#include "EterBase/Random.h"
|
||||
#include "EterLib/Camera.h"
|
||||
#include "EterLib/StateManager.h"
|
||||
|
||||
CDynamicPool<CParticleInstance> CParticleInstance::ms_kPool;
|
||||
|
||||
using namespace NEffectUpdateDecorator;
|
||||
|
||||
void CParticleInstance::DestroySystem()
|
||||
{
|
||||
ms_kPool.Destroy();
|
||||
@@ -27,45 +25,12 @@ void CParticleInstance::DeleteThis()
|
||||
ms_kPool.Free(this);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//CDynamicPool<CRayParticleInstance> CRayParticleInstance::ms_kPool;
|
||||
|
||||
/*void CRayParticleInstance::DestroySystem()
|
||||
{
|
||||
ms_kPool.Destroy();
|
||||
}
|
||||
|
||||
CRayParticleInstance* CRayParticleInstance::New()
|
||||
{
|
||||
return ms_kPool.Alloc();
|
||||
}
|
||||
|
||||
void CRayParticleInstance::DeleteThis()
|
||||
{
|
||||
#ifdef RAY_TO_AFTERIMAGE
|
||||
m_PositionList.clear();
|
||||
#else
|
||||
m_bStart = false;
|
||||
#endif
|
||||
ms_kPool.Free(this);
|
||||
}
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float CParticleInstance::GetRadiusApproximation()
|
||||
{
|
||||
return m_v2HalfSize.y*m_v2Scale.y + m_v2HalfSize.x*m_v2Scale.x;
|
||||
}
|
||||
/*
|
||||
D3DXVECTOR3 CBaseParticleInstance::GetCenterApproximation()
|
||||
{
|
||||
return D3DXVECTOR3(
|
||||
m_v3Position.x + mc_pmatLocal._41,
|
||||
m_v3Position.y + mc_pmatLocal._42,
|
||||
m_v3Position.z + mc_pmatLocal._43
|
||||
);
|
||||
}*/
|
||||
|
||||
|
||||
BOOL CParticleInstance::Update(float fElapsedTime, float fAngle)
|
||||
@@ -76,7 +41,12 @@ BOOL CParticleInstance::Update(float fElapsedTime, float fAngle)
|
||||
|
||||
float fLifePercentage = (m_fLifeTime - m_fLastLifeTime) / m_fLifeTime;
|
||||
|
||||
m_pDecorator->Excute(CDecoratorData(fLifePercentage,fElapsedTime,this));
|
||||
UpdateRotation(fLifePercentage, fElapsedTime);
|
||||
UpdateTextureAnimation(fLifePercentage, fElapsedTime);
|
||||
UpdateScale(fLifePercentage, fElapsedTime);
|
||||
UpdateColor(fLifePercentage, fElapsedTime);
|
||||
UpdateGravity(fLifePercentage, fElapsedTime);
|
||||
UpdateAirResistance(fLifePercentage, fElapsedTime);
|
||||
|
||||
m_v3LastPosition = m_v3Position;
|
||||
m_v3Position += m_v3Velocity * fElapsedTime;
|
||||
@@ -121,6 +91,92 @@ BOOL CParticleInstance::Update(float fElapsedTime, float fAngle)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateRotation(float time, float elapsedTime)
|
||||
{
|
||||
if (m_rotationType == CParticleProperty::ROTATION_TYPE_NONE)
|
||||
return;
|
||||
|
||||
if (m_rotationType == CParticleProperty::ROTATION_TYPE_TIME_EVENT)
|
||||
m_fRotationSpeed = GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventRotation);
|
||||
|
||||
m_fRotation += m_fRotationSpeed * elapsedTime;
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateTextureAnimation(float time, float elapsedTime)
|
||||
{
|
||||
if (m_byTextureAnimationType == CParticleProperty::TEXTURE_ANIMATION_TYPE_NONE)
|
||||
return;
|
||||
|
||||
const float frameDelay = m_pParticleProperty->GetTextureAnimationFrameDelay();
|
||||
const DWORD frameCount = m_pParticleProperty->GetTextureAnimationFrameCount();
|
||||
|
||||
m_fFrameTime += elapsedTime;
|
||||
|
||||
const uint64_t elapsedFrames = static_cast<uint64_t>(m_fFrameTime / frameDelay);
|
||||
|
||||
if (0 == elapsedFrames)
|
||||
return;
|
||||
|
||||
m_fFrameTime -= elapsedFrames * frameDelay;
|
||||
|
||||
switch (m_byTextureAnimationType)
|
||||
{
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_CW:
|
||||
m_byFrameIndex += elapsedFrames;
|
||||
if (m_byFrameIndex >= frameCount)
|
||||
m_byFrameIndex = 0;
|
||||
break;
|
||||
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_CCW:
|
||||
m_byFrameIndex = std::min<uint8_t>(m_byFrameIndex - elapsedFrames, frameCount - 1);
|
||||
break;
|
||||
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_RANDOM_FRAME:
|
||||
if (frameCount != 0)
|
||||
m_byFrameIndex = random_range(0, frameCount - 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateScale(float time, float elapsedTime)
|
||||
{
|
||||
if (!m_pParticleProperty->m_TimeEventScaleX.empty())
|
||||
m_v2Scale.x = GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventScaleX);
|
||||
|
||||
if (!m_pParticleProperty->m_TimeEventScaleY.empty())
|
||||
m_v2Scale.y = GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventScaleY);
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateColor(float time, float elapsedTime)
|
||||
{
|
||||
if (m_pParticleProperty->m_TimeEventColor.empty())
|
||||
return;
|
||||
|
||||
m_dcColor = GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventColor);
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateGravity(float time, float elapsedTime)
|
||||
{
|
||||
if (m_pParticleProperty->m_TimeEventGravity.empty())
|
||||
return;
|
||||
|
||||
float fGravity;
|
||||
fGravity = GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventGravity);
|
||||
|
||||
m_v3Velocity.z -= fGravity * elapsedTime;
|
||||
}
|
||||
|
||||
void CParticleInstance::UpdateAirResistance(float time, float elapsedTime)
|
||||
{
|
||||
if (m_pParticleProperty->m_TimeEventAirResistance.empty())
|
||||
return;
|
||||
|
||||
m_v3Velocity *= 1.0f - GetTimeEventBlendValue(time, m_pParticleProperty->m_TimeEventAirResistance);
|
||||
}
|
||||
|
||||
void CParticleInstance::Transform(const D3DXMATRIX * c_matLocal)
|
||||
{
|
||||
#ifdef WORLD_EDITOR
|
||||
@@ -434,18 +490,11 @@ void CParticleInstance::Transform(const D3DXMATRIX * c_matLocal, const float c_f
|
||||
|
||||
void CParticleInstance::Destroy()
|
||||
{
|
||||
if (m_pDecorator)
|
||||
m_pDecorator->DeleteThis();
|
||||
|
||||
__Initialize();
|
||||
|
||||
}
|
||||
|
||||
void CParticleInstance::__Initialize()
|
||||
{
|
||||
//*
|
||||
m_pDecorator=NULL;
|
||||
|
||||
m_v3Position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
m_v3LastPosition = m_v3Position;
|
||||
m_v3Velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
@@ -458,6 +507,9 @@ void CParticleInstance::__Initialize()
|
||||
#endif
|
||||
|
||||
m_byFrameIndex = 0;
|
||||
m_rotationType = CParticleProperty::ROTATION_TYPE_NONE;
|
||||
m_fFrameTime = 0;
|
||||
|
||||
m_ParticleMesh[0].texCoord = D3DXVECTOR2(0.0f, 1.0f);
|
||||
m_ParticleMesh[1].texCoord = D3DXVECTOR2(0.0f, 0.0f);
|
||||
m_ParticleMesh[2].texCoord = D3DXVECTOR2(1.0f, 1.0f);
|
||||
@@ -474,43 +526,7 @@ CParticleInstance::~CParticleInstance()
|
||||
Destroy();
|
||||
}
|
||||
|
||||
/*CRayParticleInstance::CRayParticleInstance()
|
||||
{
|
||||
#ifdef RAY_TO_AFTERIMAGE
|
||||
int i;
|
||||
for(i=0;i<RAY_VERTEX_COUNT*2;i+=2)
|
||||
{
|
||||
m_ParticleMesh[i].texCoord = D3DXVECTOR2(i+0.0f, 1.0f);
|
||||
m_ParticleMesh[i+1].texCoord = D3DXVECTOR2(i+1.0f, 0.0f);
|
||||
}
|
||||
#else
|
||||
m_ParticleMesh[0].texCoord = D3DXVECTOR2(0.0f, 1.0f);
|
||||
m_ParticleMesh[1].texCoord = D3DXVECTOR2(0.0f, 0.0f);
|
||||
m_ParticleMesh[2].texCoord = D3DXVECTOR2(0.5f, 1.0f);
|
||||
m_ParticleMesh[3].texCoord = D3DXVECTOR2(0.5f, 0.0f);
|
||||
m_ParticleMesh[4].texCoord = D3DXVECTOR2(1.0f, 1.0f);
|
||||
m_ParticleMesh[5].texCoord = D3DXVECTOR2(1.0f, 0.0f);
|
||||
|
||||
m_bStart = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
CRayParticleInstance::~CRayParticleInstance()
|
||||
{
|
||||
}*/
|
||||
|
||||
|
||||
TPTVertex * CParticleInstance::GetParticleMeshPointer()
|
||||
{
|
||||
return m_ParticleMesh;
|
||||
}
|
||||
|
||||
/*TPTVertex * CRayParticleInstance::GetParticleMeshPointer()
|
||||
{
|
||||
return m_ParticleMesh;
|
||||
}
|
||||
|
||||
void CRayParticleInstance::Transform(const D3DXMATRIX * c_matLocal, const float c_fZRotation)
|
||||
{
|
||||
assert(false && "NOT_REACHED");
|
||||
}*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include "Type.h"
|
||||
#include "Eterlib/GrpBase.h"
|
||||
#include "EterLib/Pool.h"
|
||||
|
||||
#include "../eterlib/GrpBase.h"
|
||||
#include "../eterLib/Pool.h"
|
||||
#include "EffectUpdateDecorator.h"
|
||||
class CParticleProperty;
|
||||
class CEmitterProperty;
|
||||
|
||||
@@ -11,11 +11,6 @@ class CParticleInstance
|
||||
friend class CParticleSystemData;
|
||||
friend class CParticleSystemInstance;
|
||||
|
||||
friend class NEffectUpdateDecorator::CBaseDecorator;
|
||||
friend class NEffectUpdateDecorator::CAirResistanceDecorator;
|
||||
friend class NEffectUpdateDecorator::CGravityDecorator;
|
||||
friend class NEffectUpdateDecorator::CRotationDecorator;
|
||||
|
||||
public:
|
||||
CParticleInstance();
|
||||
~CParticleInstance();
|
||||
@@ -23,21 +18,16 @@ class CParticleInstance
|
||||
float GetRadiusApproximation();
|
||||
|
||||
BOOL Update(float fElapsedTime, float fAngle);
|
||||
//virtual void Transform(const D3DXMATRIX * c_matLocal, const float c_fZRotation)=0;
|
||||
//virtual void Transform(const D3DXMATRIX * c_matLocal = NULL)=0;
|
||||
|
||||
//virtual TPTVertex * GetParticleMeshPointer() = 0;
|
||||
|
||||
//__forceinline float GetLifePercentage()
|
||||
//{
|
||||
// return m_fLifePercentage;
|
||||
//return (m_fLifeTime - m_fLastLifeTime) / m_fLifeTime;
|
||||
//}
|
||||
|
||||
//virtual void DeleteThis() = 0;
|
||||
private:
|
||||
void UpdateRotation(float time, float elapsedTime);
|
||||
void UpdateTextureAnimation(float time, float elapsedTime);
|
||||
void UpdateScale(float time, float elapsedTime);
|
||||
void UpdateColor(float time, float elapsedTime);
|
||||
void UpdateGravity(float time, float elapsedTime);
|
||||
void UpdateAirResistance(float time, float elapsedTime);
|
||||
|
||||
protected:
|
||||
//float m_fLifePercentage;
|
||||
D3DXVECTOR3 m_v3StartPosition;
|
||||
|
||||
D3DXVECTOR3 m_v3Position;
|
||||
@@ -57,6 +47,7 @@ class CParticleInstance
|
||||
BYTE m_byTextureAnimationType;
|
||||
float m_fLastFrameTime;
|
||||
BYTE m_byFrameIndex;
|
||||
float m_fFrameTime;
|
||||
|
||||
float m_fLifeTime;
|
||||
float m_fLastLifeTime;
|
||||
@@ -64,11 +55,12 @@ class CParticleInstance
|
||||
CParticleProperty * m_pParticleProperty;
|
||||
CEmitterProperty * m_pEmitterProperty;
|
||||
|
||||
float m_fAirResistance;
|
||||
float m_fRotationSpeed;
|
||||
float m_fGravity;
|
||||
BYTE m_rotationType;
|
||||
|
||||
float m_fAirResistance;
|
||||
float m_fRotationSpeed;
|
||||
float m_fGravity;
|
||||
|
||||
NEffectUpdateDecorator::CBaseDecorator * m_pDecorator;
|
||||
public:
|
||||
static CParticleInstance* New();
|
||||
static void DestroySystem();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "StdAfx.h"
|
||||
#include "ParticleSystemData.h"
|
||||
#include "EffectUpdateDecorator.h"
|
||||
#include "ParticleInstance.h"
|
||||
|
||||
CDynamicPool<CParticleSystemData> CParticleSystemData::ms_kPool;
|
||||
@@ -252,10 +251,10 @@ BOOL CParticleSystemData::OnLoadScript(CTextFileLoader & rTextFileLoader)
|
||||
{
|
||||
float fTime = *it;
|
||||
float fR, fG, fB, fA;
|
||||
GetTimeEventBlendValue<float>(fTime, TimeEventR, &fR);
|
||||
GetTimeEventBlendValue<float>(fTime, TimeEventG, &fG);
|
||||
GetTimeEventBlendValue<float>(fTime, TimeEventB, &fB);
|
||||
GetTimeEventBlendValue<float>(fTime, TimeEventA, &fA);
|
||||
fR = GetTimeEventBlendValue(fTime, TimeEventR);
|
||||
fG = GetTimeEventBlendValue(fTime, TimeEventG);
|
||||
fB = GetTimeEventBlendValue(fTime, TimeEventB);
|
||||
fA = GetTimeEventBlendValue(fTime, TimeEventA);
|
||||
TTimeEventTypeColor t;
|
||||
t.m_fTime = fTime;
|
||||
D3DXCOLOR c;
|
||||
@@ -307,115 +306,6 @@ bool CParticleSystemData::OnIsData()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CParticleSystemData::BuildDecorator(CParticleInstance * pInstance)
|
||||
{
|
||||
using namespace NEffectUpdateDecorator;
|
||||
|
||||
pInstance->m_pDecorator = new CNullDecorator;
|
||||
|
||||
//////
|
||||
|
||||
if (m_ParticleProperty.m_TimeEventAirResistance.size()>1)
|
||||
{
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(new CAirResistanceDecorator);
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CAirResistanceValueDecorator(m_ParticleProperty.m_TimeEventAirResistance, &pInstance->m_fAirResistance)
|
||||
);
|
||||
}
|
||||
else if (m_ParticleProperty.m_TimeEventAirResistance.size()==1)
|
||||
{
|
||||
pInstance->m_fAirResistance = m_ParticleProperty.m_TimeEventAirResistance[0].m_Value;
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(new CAirResistanceDecorator);
|
||||
}
|
||||
|
||||
if (m_ParticleProperty.m_TimeEventGravity.size() > 1)
|
||||
{
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(new CGravityDecorator);
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CGravityValueDecorator(m_ParticleProperty.m_TimeEventGravity, &pInstance->m_fGravity)
|
||||
);
|
||||
}
|
||||
else if (m_ParticleProperty.m_TimeEventGravity.size() == 1)
|
||||
{
|
||||
pInstance->m_fGravity = m_ParticleProperty.m_TimeEventGravity[0].m_Value;
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(new CGravityDecorator);
|
||||
}
|
||||
#ifdef WORLD_EDITOR
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CColorValueDecorator(m_ParticleProperty.m_TimeEventColorRed, &pInstance->m_Color.r));
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CColorValueDecorator(m_ParticleProperty.m_TimeEventColorGreen, &pInstance->m_Color.g));
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CColorValueDecorator(m_ParticleProperty.m_TimeEventColorBlue, &pInstance->m_Color.b));
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CColorValueDecorator(m_ParticleProperty.m_TimeEventAlpha, &pInstance->m_Color.a));
|
||||
#else
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CColorAllDecorator(m_ParticleProperty.m_TimeEventColor, &pInstance->m_dcColor));
|
||||
#endif
|
||||
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CScaleValueDecorator(m_ParticleProperty.m_TimeEventScaleX, &pInstance->m_v2Scale.x));
|
||||
pInstance->m_pDecorator = pInstance->m_pDecorator->AddChainFront(
|
||||
new CScaleValueDecorator(m_ParticleProperty.m_TimeEventScaleY, &pInstance->m_v2Scale.y));
|
||||
|
||||
if (m_ParticleProperty.GetTextureAnimationFrameCount()>1 &&m_ParticleProperty.GetTextureAnimationFrameDelay()>1e-6)
|
||||
{
|
||||
switch (pInstance->m_byTextureAnimationType)
|
||||
{
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_CW:
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CTextureAnimationCWDecorator(m_ParticleProperty.GetTextureAnimationFrameDelay(), m_ParticleProperty.GetTextureAnimationFrameCount(), &pInstance->m_byFrameIndex));
|
||||
break;
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_CCW:
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CTextureAnimationCCWDecorator(m_ParticleProperty.GetTextureAnimationFrameDelay(), m_ParticleProperty.GetTextureAnimationFrameCount(), &pInstance->m_byFrameIndex));
|
||||
break;
|
||||
case CParticleProperty::TEXTURE_ANIMATION_TYPE_RANDOM_FRAME:
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CTextureAnimationRandomDecorator(m_ParticleProperty.GetTextureAnimationFrameDelay(), m_ParticleProperty.GetTextureAnimationFrameCount(), &pInstance->m_byFrameIndex));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BYTE byRotationType = m_ParticleProperty.m_byRotationType;
|
||||
|
||||
if (m_ParticleProperty.m_fRotationSpeed==0.0f && byRotationType!=CParticleProperty::ROTATION_TYPE_TIME_EVENT)
|
||||
{
|
||||
byRotationType = CParticleProperty::ROTATION_TYPE_NONE;
|
||||
}
|
||||
else if (byRotationType==CParticleProperty::ROTATION_TYPE_RANDOM_DIRECTION)
|
||||
{
|
||||
byRotationType = (random()&1)?CParticleProperty::ROTATION_TYPE_CW:CParticleProperty::ROTATION_TYPE_CCW;
|
||||
}
|
||||
|
||||
switch(byRotationType)
|
||||
{
|
||||
case CParticleProperty::ROTATION_TYPE_TIME_EVENT:
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CRotationDecorator());
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CRotationSpeedValueDecorator(m_ParticleProperty.m_TimeEventRotation,&pInstance->m_fRotationSpeed));
|
||||
break;
|
||||
|
||||
case CParticleProperty::ROTATION_TYPE_CW:
|
||||
pInstance->m_fRotationSpeed = m_ParticleProperty.m_fRotationSpeed;
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CRotationDecorator());
|
||||
break;
|
||||
|
||||
case CParticleProperty::ROTATION_TYPE_CCW:
|
||||
pInstance->m_fRotationSpeed = - m_ParticleProperty.m_fRotationSpeed;
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(
|
||||
new CRotationDecorator());
|
||||
break;
|
||||
}
|
||||
|
||||
/////
|
||||
|
||||
pInstance->m_pDecorator=pInstance->m_pDecorator->AddChainFront(new CHeaderDecorator);
|
||||
}
|
||||
|
||||
CParticleSystemData::CParticleSystemData()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class CParticleSystemData : public CEffectElementBase
|
||||
|
||||
void ChangeTexture(const char * c_szFileName);
|
||||
|
||||
void BuildDecorator(CParticleInstance * pInstance);
|
||||
protected:
|
||||
BOOL OnLoadScript(CTextFileLoader & rTextFileLoader);
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
CDynamicPool<CParticleSystemInstance> CParticleSystemInstance::ms_kPool;
|
||||
|
||||
using namespace NEffectUpdateDecorator;
|
||||
|
||||
void CParticleSystemInstance::DestroySystem()
|
||||
{
|
||||
ms_kPool.Destroy();
|
||||
@@ -88,8 +86,6 @@ void CParticleSystemInstance::CreateParticles(float fElapsedTime)
|
||||
|
||||
}
|
||||
|
||||
CParticleInstance * pFirstInstance = 0;
|
||||
|
||||
for (int i = 0; i < iCreatingCount; ++i)
|
||||
{
|
||||
CParticleInstance * pInstance;
|
||||
@@ -262,16 +258,6 @@ void CParticleSystemInstance::CreateParticles(float fElapsedTime)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!pFirstInstance)
|
||||
{
|
||||
m_pData->BuildDecorator(pInstance);
|
||||
pFirstInstance = pInstance;
|
||||
}
|
||||
else
|
||||
{
|
||||
pInstance->m_pDecorator = pFirstInstance->m_pDecorator->Clone(pFirstInstance,pInstance);
|
||||
}
|
||||
|
||||
m_ParticleInstanceListVector[pInstance->m_byFrameIndex].push_back(pInstance);
|
||||
m_dwCurrentEmissionCount++;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void CLightData::GetRange(float fTime, float& rRange)
|
||||
return;
|
||||
}
|
||||
|
||||
GetTimeEventBlendValue(fTime, m_TimeEventTableRange, &rRange);
|
||||
rRange = GetTimeEventBlendValue(fTime, m_TimeEventTableRange);
|
||||
rRange *= m_fMaxRange;
|
||||
if (rRange<0.0f)
|
||||
rRange = 0.0f;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <d3dx9math.h>
|
||||
|
||||
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
||||
#define GRAVITY D3DXVECTOR3(0.0f, 0.0f, -9.8f)
|
||||
@@ -88,41 +89,40 @@ enum EMovingType
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct SEffectPosition
|
||||
template <typename T>
|
||||
struct CTimeEvent
|
||||
{
|
||||
float m_fTime;
|
||||
|
||||
D3DXVECTOR3 m_vecPosition;
|
||||
|
||||
// For Bezier Curve
|
||||
int m_iMovingType;
|
||||
D3DXVECTOR3 m_vecControlPoint;
|
||||
|
||||
} TEffectPosition;
|
||||
|
||||
inline bool operator < (const SEffectPosition & lhs, const SEffectPosition & rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs.m_fTime;
|
||||
}
|
||||
inline bool operator < (const float & lhs, const SEffectPosition & rhs)
|
||||
{
|
||||
return lhs < rhs.m_fTime;
|
||||
}
|
||||
inline bool operator < (const SEffectPosition & lhs, const float & rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class CTimeEvent
|
||||
{
|
||||
public:
|
||||
CTimeEvent(){}
|
||||
~CTimeEvent(){}
|
||||
typedef T value_type;
|
||||
|
||||
float m_fTime;
|
||||
T m_Value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator<(const CTimeEvent<T>& lhs, const CTimeEvent<T>& rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs.m_fTime;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator<(const CTimeEvent<T>& lhs, const float& rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator<(const float& lhs, const CTimeEvent<T>& rhs)
|
||||
{
|
||||
return lhs < rhs.m_fTime;
|
||||
}
|
||||
|
||||
typedef struct SEffectPosition : public CTimeEvent<D3DXVECTOR3>
|
||||
{
|
||||
// For Bezier Curve
|
||||
int m_iMovingType;
|
||||
D3DXVECTOR3 m_vecControlPoint;
|
||||
} TEffectPosition;
|
||||
|
||||
#define AG_MASK 0xff00ff00
|
||||
#define RB_MASK 0x00ff00ff
|
||||
|
||||
@@ -135,7 +135,12 @@ struct DWORDCOLOR
|
||||
}
|
||||
DWORDCOLOR(const DWORDCOLOR& r)
|
||||
: m_dwColor(r.m_dwColor)
|
||||
{}
|
||||
{
|
||||
}
|
||||
DWORDCOLOR(DWORD dwColor)
|
||||
: m_dwColor(dwColor)
|
||||
{
|
||||
}
|
||||
|
||||
DWORDCOLOR& operator = (const DWORDCOLOR& r)
|
||||
{
|
||||
@@ -146,12 +151,9 @@ struct DWORDCOLOR
|
||||
DWORDCOLOR& operator *= (float f)
|
||||
{
|
||||
DWORD idx = DWORD(f * 256);
|
||||
m_dwColor =
|
||||
(((DWORD)(((m_dwColor & AG_MASK)>>8) * idx)) & AG_MASK)
|
||||
+((DWORD)(((m_dwColor & RB_MASK) * idx)>>8) & RB_MASK);
|
||||
//m_dwColor =
|
||||
// ((DWORD)((m_dwColor & AG_MASK) * f) & AG_MASK)
|
||||
// +((DWORD)((m_dwColor & RB_MASK) * f) & RB_MASK);
|
||||
m_dwColor =
|
||||
(((DWORD)(((m_dwColor & AG_MASK) >> 8) * idx)) & AG_MASK)
|
||||
+ ((DWORD)(((m_dwColor & RB_MASK) * idx) >> 8) & RB_MASK);
|
||||
return *this;
|
||||
}
|
||||
DWORDCOLOR& operator += (const DWORDCOLOR& r)
|
||||
@@ -159,11 +161,13 @@ struct DWORDCOLOR
|
||||
m_dwColor += r.m_dwColor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator DWORD()
|
||||
{
|
||||
return m_dwColor;
|
||||
}
|
||||
};
|
||||
|
||||
#undef AG_MASK
|
||||
#undef RB_MASK
|
||||
|
||||
@@ -181,24 +185,6 @@ inline DWORDCOLOR operator * (float f, DWORDCOLOR dc)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline bool operator < (const CTimeEvent<T> & lhs, const CTimeEvent<T> & rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs.m_fTime;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline bool operator < (const CTimeEvent<T> & lhs, const float & rhs)
|
||||
{
|
||||
return lhs.m_fTime < rhs;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline bool operator < (const float & lhs, const CTimeEvent<T> & rhs)
|
||||
{
|
||||
return lhs < rhs.m_fTime;
|
||||
}
|
||||
|
||||
typedef CTimeEvent<char> TTimeEventTypeCharacter;
|
||||
typedef CTimeEvent<short> TTimeEventTypeShort;
|
||||
typedef CTimeEvent<float> TTimeEventTypeFloat;
|
||||
@@ -219,57 +205,87 @@ typedef std::vector<TTimeEventTypeColor> TTimeEventTableColor;
|
||||
typedef std::vector<TTimeEventTypeVector2> TTimeEventTableVector2;
|
||||
typedef std::vector<TTimeEventTypeVector3> TTimeEventTableVector3;
|
||||
|
||||
template <typename T>
|
||||
T BlendSingleValue(float time,
|
||||
const CTimeEvent<T>& low,
|
||||
const CTimeEvent<T>& high)
|
||||
{
|
||||
const float timeDiff = high.m_fTime - low.m_fTime;
|
||||
const float perc = (time - low.m_fTime) / timeDiff;
|
||||
|
||||
// NOTE : TimeEventValue 함수들은 값을 넘겨 받지 말아야 하는 때도 있으므로
|
||||
// 값의 직접 리턴이 아닌 포인터 리턴으로 작성 했습니다. - [levites]
|
||||
const T valueDiff = high.m_Value - low.m_Value;
|
||||
return static_cast<T>(low.m_Value + perc * valueDiff);
|
||||
}
|
||||
|
||||
inline D3DXVECTOR3 BlendSingleValue(float time, const TEffectPosition& low, const TEffectPosition& high)
|
||||
{
|
||||
const float timeDiff = high.m_fTime - low.m_fTime;
|
||||
const float perc = (time - low.m_fTime) / timeDiff;
|
||||
|
||||
if (low.m_iMovingType == MOVING_TYPE_DIRECT)
|
||||
return low.m_Value + ((high.m_Value - low.m_Value) * perc);
|
||||
|
||||
if (low.m_iMovingType == MOVING_TYPE_BEZIER_CURVE)
|
||||
{
|
||||
const float invPerc = 1.0f - perc;
|
||||
|
||||
return low.m_Value * invPerc * invPerc +
|
||||
(low.m_Value + low.m_vecControlPoint) * invPerc * perc * 2.0f +
|
||||
high.m_Value * perc * perc;
|
||||
}
|
||||
|
||||
// Unknown moving type - impossible(?)
|
||||
return D3DXVECTOR3();
|
||||
}
|
||||
|
||||
inline DWORDCOLOR BlendSingleValue(float time, const TTimeEventTypeColor& low, const TTimeEventTypeColor& high)
|
||||
{
|
||||
const float timeDiff = high.m_fTime - low.m_fTime;
|
||||
const float perc = (time - low.m_fTime) / timeDiff;
|
||||
|
||||
return low.m_Value * (1.0f - perc) + high.m_Value * perc;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline void GetTimeEventBlendValue(float fElapsedTime, std::vector<CTimeEvent<T> >& rVector, T * pReturnValue)
|
||||
auto GetTimeEventBlendValue(float time,
|
||||
const std::vector<T>& vec) -> typename T::value_type
|
||||
{
|
||||
if (rVector.empty())
|
||||
{
|
||||
*pReturnValue = T();
|
||||
return;
|
||||
}
|
||||
if (vec.empty())
|
||||
return typename T::value_type();
|
||||
|
||||
if(rVector.begin()+1==rVector.end())
|
||||
{
|
||||
*pReturnValue = rVector.front().m_Value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fElapsedTime < rVector.front().m_fTime)
|
||||
{
|
||||
*pReturnValue = rVector.front().m_Value;
|
||||
return;
|
||||
}
|
||||
// Single element is easy...
|
||||
if (vec.begin() + 1 == vec.end())
|
||||
return vec.front().m_Value;
|
||||
|
||||
if (fElapsedTime > rVector.back().m_fTime)
|
||||
{
|
||||
*pReturnValue = rVector.back().m_Value;
|
||||
return;
|
||||
}
|
||||
// All elements are greater than |time| - pick the smallest
|
||||
if (time < vec.front().m_fTime)
|
||||
return vec.front().m_Value;
|
||||
|
||||
typedef typename std::vector<CTimeEvent<T> >::iterator iterator;
|
||||
// All elements are smaller than |time| - pick the greatest
|
||||
if (time > vec.back().m_fTime)
|
||||
return vec.back().m_Value;
|
||||
|
||||
std::pair<iterator, iterator> result = std::equal_range(rVector.begin(), rVector.end(), fElapsedTime);
|
||||
// The two checks above make sure that result doesn't contain vec.end()
|
||||
// (We could simply check for vec.end() ourself, but above code lets us
|
||||
// skip std::equal_range() altogether, making it faster.)
|
||||
auto result = std::equal_range(vec.begin(), vec.end(), time);
|
||||
|
||||
// We have one or more equal elements - pick the first
|
||||
if (result.first != result.second)
|
||||
*pReturnValue = result.first->m_Value;
|
||||
else
|
||||
{
|
||||
--result.first;
|
||||
float Head = (result.second->m_fTime - fElapsedTime) / (result.second->m_fTime - result.first->m_fTime);
|
||||
*pReturnValue = T((result.first->m_Value-result.second->m_Value)*Head+(result.second->m_Value));
|
||||
}
|
||||
return result.first->m_Value;
|
||||
|
||||
// We need first to point to an element smaller than |time|
|
||||
// (Note that decrementing first is safe here, we already accounted for
|
||||
// vec.begin() being greater-or-equal to |time|.)
|
||||
--result.first;
|
||||
return BlendSingleValue(time, *result.first, *result.second);
|
||||
}
|
||||
|
||||
extern BOOL GetTokenTimeEventFloat(CTextFileLoader & rTextFileLoader, const char * c_szKey, TTimeEventTableFloat * pTimeEventTableFloat);
|
||||
//extern void InsertItemTimeEventFloat(TTimeEventTableFloat * pTable, float fTime, float fValue);
|
||||
|
||||
template <typename T>
|
||||
void InsertItemTimeEvent(std::vector<CTimeEvent<T> > * pTable, float fTime, T fValue)
|
||||
void InsertItemTimeEvent(std::vector<CTimeEvent<T> >* pTable, float fTime, T fValue)
|
||||
{
|
||||
typedef std::vector<CTimeEvent<T> >::iterator iterator;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user