[colobot] 89/145: Fixed CParticle::CheckChannel "errors"
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 99a831a03be068dd0c40ee3a7ca162cdcfb5e85d
Author: krzys-h <krzys_h at interia.pl>
Date: Sat May 28 00:26:56 2016 +0200
Fixed CParticle::CheckChannel "errors"
Not really errors, but I fixed them anyway
---
src/graphics/engine/particle.cpp | 56 +++++++++++++++++++---------------------
src/graphics/engine/particle.h | 13 ++++++----
src/object/old_object.cpp | 6 +++--
src/object/old_object.h | 6 ++---
4 files changed, 42 insertions(+), 39 deletions(-)
diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp
index e9aa0ab..2642b74 100644
--- a/src/graphics/engine/particle.cpp
+++ b/src/graphics/engine/particle.cpp
@@ -581,7 +581,7 @@ int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim
if (!m_track[i].used) // free?
{
int rank = channel;
- if (!CheckChannel(rank)) return -1;
+ GetRankFromChannel(rank);
m_particle[rank].trackRank = i;
m_track[i].used = true;
@@ -636,27 +636,26 @@ void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2,
-/** Adapts the channel so it can be used as an offset in m_particle */
-bool CParticle::CheckChannel(int &channel)
+void CParticle::GetRankFromChannel(int &channel)
{
int uniqueStamp = (channel>>16)&0xffff;
channel &= 0xffff;
- if (channel < 0) return false;
- if (channel >= MAXPARTICULE*MAXPARTITYPE) return false;
+ assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE);
- if (!m_particle[channel].used)
- {
- GetLogger()->Error("CParticle::CheckChannel used=false !\n");
- return false;
- }
+ if (!m_particle[channel].used) assert(!!"Tried to access invalid particle channel (used=false) !\n");
+ if (m_particle[channel].uniqueStamp != uniqueStamp) assert(!!"Tried to access invalid particle channel (uniqueStamp changed) !\n");
+}
- if (m_particle[channel].uniqueStamp != uniqueStamp)
- {
- GetLogger()->Error("CParticle::CheckChannel uniqueStamp !\n");
- return false;
- }
+bool CParticle::ParticleExists(int channel)
+{
+ int uniqueStamp = (channel>>16)&0xffff;
+ channel &= 0xffff;
+ assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE);
+
+ if (!m_particle[channel].used) return false;
+ if (m_particle[channel].uniqueStamp != uniqueStamp) return false;
return true;
}
@@ -685,7 +684,7 @@ void CParticle::DeleteParticle(ParticleType type)
void CParticle::DeleteParticle(int channel)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
if (m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet] > 0 )
m_totalInterface[channel/MAXPARTICULE][m_particle[channel].sheet]--;
@@ -699,50 +698,50 @@ void CParticle::DeleteParticle(int channel)
void CParticle::SetObjectLink(int channel, CObject *object)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].objLink = object;
}
void CParticle::SetObjectFather(int channel, CObject *object)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].objFather = object;
}
void CParticle::SetPosition(int channel, Math::Vector pos)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].pos = pos;
}
void CParticle::SetDimension(int channel, Math::Point dim)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].dim = dim;
}
void CParticle::SetZoom(int channel, float zoom)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].zoom = zoom;
}
void CParticle::SetAngle(int channel, float angle)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].angle = angle;
}
void CParticle::SetIntensity(int channel, float intensity)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].intensity = intensity;
}
void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom,
float angle, float intensity)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].pos = pos;
m_particle[channel].dim = dim;
m_particle[channel].zoom = zoom;
@@ -752,17 +751,16 @@ void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float z
void CParticle::SetPhase(int channel, ParticlePhase phase, float duration)
{
- if (!CheckChannel(channel)) return;
+ GetRankFromChannel(channel);
m_particle[channel].phase = phase;
m_particle[channel].duration = duration;
m_particle[channel].phaseTime = m_particle[channel].time;
}
-bool CParticle::GetPosition(int channel, Math::Vector &pos)
+Math::Vector CParticle::GetPosition(int channel)
{
- if (!CheckChannel(channel)) return false;
- pos = m_particle[channel].pos;
- return true;
+ GetRankFromChannel(channel);
+ return m_particle[channel].pos;
}
void CParticle::SetFrameUpdate(int sheet, bool update)
diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h
index 5279009..55ef7ba 100644
--- a/src/graphics/engine/particle.h
+++ b/src/graphics/engine/particle.h
@@ -162,9 +162,9 @@ enum ParticlePhase
struct Particle
{
- bool used = false; // TRUE -> particle used
+ bool used = false; //!< true if this channel is used, false if not
bool ray = false; // TRUE -> ray with goal
- unsigned short uniqueStamp = 0; // unique mark
+ unsigned short uniqueStamp = 0; //!< unique marker added to particle channel ID to make sure this is still the same particle
short sheet = 0; // sheet (0..n)
ParticleType type = {}; // type PARTI*
ParticlePhase phase = {}; // phase PARPH*
@@ -279,7 +279,7 @@ public:
void SetPhase(int channel, ParticlePhase phase, float duration);
//! Returns the position of the particle
- bool GetPosition(int channel, Math::Vector &pos);
+ Math::Vector GetPosition(int channel);
//! Returns the color if you're in the fog or black if you're not
Color GetFogColor(Math::Vector pos);
@@ -291,11 +291,14 @@ public:
//! Draws all the particles
void DrawParticle(int sheet);
+ //! Checks if given particle channel still exists
+ bool ParticleExists(int channel);
+
protected:
//! Removes a particle of given rank
void DeleteRank(int rank);
- //! Check a channel number
- bool CheckChannel(int &channel);
+ //! Adapts the channel so it can be used as an offset in m_particle
+ void GetRankFromChannel(int &channel);
//! Draws a triangular particle
void DrawParticleTriangle(int i);
//! Draw a normal particle
diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp
index cfc2e11..7c2682d 100644
--- a/src/object/old_object.cpp
+++ b/src/object/old_object.cpp
@@ -2187,15 +2187,17 @@ void COldObject::PartiFrame(float rTime)
channel = m_objectPart[i].masterParti;
if ( channel == -1 ) continue;
- if ( !m_particle->GetPosition(channel, pos) )
+ if ( !m_particle->ParticleExists(channel) )
{
m_objectPart[i].masterParti = -1; // particle no longer exists!
continue;
}
+ pos = m_particle->GetPosition(channel);
+
SetPartPosition(i, pos);
- // Each song spins differently.
+ // Each part rotates differently
switch( i%5 )
{
case 0: factor = Math::Vector( 0.5f, 0.3f, 0.6f); break;
diff --git a/src/object/old_object.h b/src/object/old_object.h
index 44a49e2..5ba5c7e 100644
--- a/src/object/old_object.h
+++ b/src/object/old_object.h
@@ -55,9 +55,9 @@ const int OBJECTMAXPART = 40;
struct ObjectPart
{
bool bUsed = false;
- int object = -1; // number of the object in CEngine
- int parentPart = -1; // number of father part
- int masterParti = -1; // master canal of the particle
+ int object = -1; //!< identifier of the object in Gfx::CEngine
+ int parentPart = -1; //!< identifier of parent part
+ int masterParti = -1; //!< particle channel this part is connected to after explosion
Math::Vector position;
Math::Vector angle;
Math::Vector zoom;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list