Revert CParticle::CheckChannel changes
I misinterpreted this as being a bug, while actually it seems to be an explicit CParticle design choice (maybe not the best one, but whatever). We DO need better docs for some old code like this :/
Fixes #806
This reverts commit 99a831a03b
.
dev-new-models
parent
dc415c3d2a
commit
3472ec6613
|
@ -581,7 +581,7 @@ int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim
|
||||||
if (!m_track[i].used) // free?
|
if (!m_track[i].used) // free?
|
||||||
{
|
{
|
||||||
int rank = channel;
|
int rank = channel;
|
||||||
GetRankFromChannel(rank);
|
if (!CheckChannel(rank)) return -1;
|
||||||
m_particle[rank].trackRank = i;
|
m_particle[rank].trackRank = i;
|
||||||
|
|
||||||
m_track[i].used = true;
|
m_track[i].used = true;
|
||||||
|
@ -636,27 +636,28 @@ void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CParticle::GetRankFromChannel(int &channel)
|
/** Adapts the channel so it can be used as an offset in m_particle */
|
||||||
|
bool CParticle::CheckChannel(int &channel)
|
||||||
{
|
{
|
||||||
int uniqueStamp = (channel>>16)&0xffff;
|
int uniqueStamp = (channel>>16)&0xffff;
|
||||||
channel &= 0xffff;
|
channel &= 0xffff;
|
||||||
|
|
||||||
if (channel < 0 || channel >= MAXPARTICULE*MAXPARTITYPE) throw std::runtime_error("Tried to access invalid particle channel (invalid ID)");
|
if (channel < 0) return false;
|
||||||
if (!m_particle[channel].used) throw std::runtime_error("Tried to access invalid particle channel (used=false)");
|
if (channel >= MAXPARTICULE*MAXPARTITYPE) return false;
|
||||||
if (m_particle[channel].uniqueStamp != uniqueStamp) throw std::runtime_error("Tried to access invalid particle channel (uniqueStamp changed)");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CParticle::ParticleExists(int channel)
|
if (!m_particle[channel].used)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GetRankFromChannel(channel);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (const std::runtime_error& e)
|
|
||||||
{
|
{
|
||||||
|
GetLogger()->Trace("Particle %d:%d doesn't exist anymore (used=false)\n", channel, uniqueStamp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_particle[channel].uniqueStamp != uniqueStamp)
|
||||||
|
{
|
||||||
|
GetLogger()->Trace("Particle %d:%d doesn't exist anymore (uniqueStamp changed)\n", channel, uniqueStamp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::DeleteRank(int rank)
|
void CParticle::DeleteRank(int rank)
|
||||||
|
@ -684,7 +685,7 @@ void CParticle::DeleteParticle(ParticleType type)
|
||||||
|
|
||||||
void CParticle::DeleteParticle(int channel)
|
void CParticle::DeleteParticle(int channel)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
|
|
||||||
if (m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet] > 0 )
|
if (m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet] > 0 )
|
||||||
m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet]--;
|
m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet]--;
|
||||||
|
@ -698,50 +699,50 @@ void CParticle::DeleteParticle(int channel)
|
||||||
|
|
||||||
void CParticle::SetObjectLink(int channel, CObject *object)
|
void CParticle::SetObjectLink(int channel, CObject *object)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].objLink = object;
|
m_particle[channel].objLink = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetObjectFather(int channel, CObject *object)
|
void CParticle::SetObjectFather(int channel, CObject *object)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].objFather = object;
|
m_particle[channel].objFather = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetPosition(int channel, Math::Vector pos)
|
void CParticle::SetPosition(int channel, Math::Vector pos)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].pos = pos;
|
m_particle[channel].pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetDimension(int channel, Math::Point dim)
|
void CParticle::SetDimension(int channel, Math::Point dim)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].dim = dim;
|
m_particle[channel].dim = dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetZoom(int channel, float zoom)
|
void CParticle::SetZoom(int channel, float zoom)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].zoom = zoom;
|
m_particle[channel].zoom = zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetAngle(int channel, float angle)
|
void CParticle::SetAngle(int channel, float angle)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].angle = angle;
|
m_particle[channel].angle = angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetIntensity(int channel, float intensity)
|
void CParticle::SetIntensity(int channel, float intensity)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].intensity = intensity;
|
m_particle[channel].intensity = intensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom,
|
void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom,
|
||||||
float angle, float intensity)
|
float angle, float intensity)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].pos = pos;
|
m_particle[channel].pos = pos;
|
||||||
m_particle[channel].dim = dim;
|
m_particle[channel].dim = dim;
|
||||||
m_particle[channel].zoom = zoom;
|
m_particle[channel].zoom = zoom;
|
||||||
|
@ -751,16 +752,17 @@ void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float z
|
||||||
|
|
||||||
void CParticle::SetPhase(int channel, ParticlePhase phase, float duration)
|
void CParticle::SetPhase(int channel, ParticlePhase phase, float duration)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return;
|
||||||
m_particle[channel].phase = phase;
|
m_particle[channel].phase = phase;
|
||||||
m_particle[channel].duration = duration;
|
m_particle[channel].duration = duration;
|
||||||
m_particle[channel].phaseTime = m_particle[channel].time;
|
m_particle[channel].phaseTime = m_particle[channel].time;
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Vector CParticle::GetPosition(int channel)
|
bool CParticle::GetPosition(int channel, Math::Vector &pos)
|
||||||
{
|
{
|
||||||
GetRankFromChannel(channel);
|
if (!CheckChannel(channel)) return false;
|
||||||
return m_particle[channel].pos;
|
pos = m_particle[channel].pos;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CParticle::SetFrameUpdate(int sheet, bool update)
|
void CParticle::SetFrameUpdate(int sheet, bool update)
|
||||||
|
|
|
@ -162,9 +162,9 @@ enum ParticlePhase
|
||||||
|
|
||||||
struct Particle
|
struct Particle
|
||||||
{
|
{
|
||||||
bool used = false; //!< true if this channel is used, false if not
|
bool used = false; // TRUE -> particle used
|
||||||
bool ray = false; // TRUE -> ray with goal
|
bool ray = false; // TRUE -> ray with goal
|
||||||
unsigned short uniqueStamp = 0; //!< unique marker added to particle channel ID to make sure this is still the same particle
|
unsigned short uniqueStamp = 0; // unique mark
|
||||||
short sheet = 0; // sheet (0..n)
|
short sheet = 0; // sheet (0..n)
|
||||||
ParticleType type = {}; // type PARTI*
|
ParticleType type = {}; // type PARTI*
|
||||||
ParticlePhase phase = {}; // phase PARPH*
|
ParticlePhase phase = {}; // phase PARPH*
|
||||||
|
@ -279,7 +279,7 @@ public:
|
||||||
void SetPhase(int channel, ParticlePhase phase, float duration);
|
void SetPhase(int channel, ParticlePhase phase, float duration);
|
||||||
|
|
||||||
//! Returns the position of the particle
|
//! Returns the position of the particle
|
||||||
Math::Vector GetPosition(int channel);
|
bool GetPosition(int channel, Math::Vector &pos);
|
||||||
|
|
||||||
//! Returns the color if you're in the fog or black if you're not
|
//! Returns the color if you're in the fog or black if you're not
|
||||||
Color GetFogColor(Math::Vector pos);
|
Color GetFogColor(Math::Vector pos);
|
||||||
|
@ -291,18 +291,15 @@ public:
|
||||||
//! Draws all the particles
|
//! Draws all the particles
|
||||||
void DrawParticle(int sheet);
|
void DrawParticle(int sheet);
|
||||||
|
|
||||||
//! Checks if given particle channel still exists
|
|
||||||
bool ParticleExists(int channel);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Removes a particle of given rank
|
//! Removes a particle of given rank
|
||||||
void DeleteRank(int rank);
|
void DeleteRank(int rank);
|
||||||
/**
|
/**
|
||||||
* \brief Adapts the channel so it can be used as an offset in m_particle
|
* \brief Adapts the channel so it can be used as an offset in m_particle
|
||||||
* \param channel Channel number to process, will be modified to be index of particle in m_particle
|
* \param channel Channel number to process, will be modified to be index of particle in m_particle
|
||||||
* \throw std::runtime_error if this particle does not exist any more
|
* \return true if success, false if particle doesn't exist anymore
|
||||||
**/
|
**/
|
||||||
void GetRankFromChannel(int &channel);
|
bool CheckChannel(int &channel);
|
||||||
//! Draws a triangular particle
|
//! Draws a triangular particle
|
||||||
void DrawParticleTriangle(int i);
|
void DrawParticleTriangle(int i);
|
||||||
//! Draw a normal particle
|
//! Draw a normal particle
|
||||||
|
|
|
@ -2185,17 +2185,15 @@ void COldObject::PartiFrame(float rTime)
|
||||||
channel = m_objectPart[i].masterParti;
|
channel = m_objectPart[i].masterParti;
|
||||||
if ( channel == -1 ) continue;
|
if ( channel == -1 ) continue;
|
||||||
|
|
||||||
if ( !m_particle->ParticleExists(channel) )
|
if ( !m_particle->GetPosition(channel, pos) )
|
||||||
{
|
{
|
||||||
m_objectPart[i].masterParti = -1; // particle no longer exists!
|
m_objectPart[i].masterParti = -1; // particle no longer exists!
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = m_particle->GetPosition(channel);
|
|
||||||
|
|
||||||
SetPartPosition(i, pos);
|
SetPartPosition(i, pos);
|
||||||
|
|
||||||
// Each part rotates differently
|
// Each song spins differently.
|
||||||
switch( i%5 )
|
switch( i%5 )
|
||||||
{
|
{
|
||||||
case 0: factor = Math::Vector( 0.5f, 0.3f, 0.6f); break;
|
case 0: factor = Math::Vector( 0.5f, 0.3f, 0.6f); break;
|
||||||
|
|
|
@ -55,9 +55,9 @@ const int OBJECTMAXPART = 40;
|
||||||
struct ObjectPart
|
struct ObjectPart
|
||||||
{
|
{
|
||||||
bool bUsed = false;
|
bool bUsed = false;
|
||||||
int object = -1; //!< identifier of the object in Gfx::CEngine
|
int object = -1; // number of the object in CEngine
|
||||||
int parentPart = -1; //!< identifier of parent part
|
int parentPart = -1; // number of father part
|
||||||
int masterParti = -1; //!< particle channel this part is connected to after explosion
|
int masterParti = -1; // master canal of the particle
|
||||||
Math::Vector position;
|
Math::Vector position;
|
||||||
Math::Vector angle;
|
Math::Vector angle;
|
||||||
Math::Vector zoom;
|
Math::Vector zoom;
|
||||||
|
|
Loading…
Reference in New Issue