Skip to content

Commit

Permalink
Fix several broken conversions from C4Fixed->bool->int (#1904)
Browse files Browse the repository at this point in the history
This is why non-explicit operator bool is bad.
  • Loading branch information
isilkor committed Apr 19, 2017
1 parent fc1a7a5 commit 81e49fe
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/landscape/C4Particles.cpp
Expand Up @@ -499,7 +499,7 @@ float C4ParticleValueProvider::Wind(C4Particle *forParticle)

float C4ParticleValueProvider::Gravity(C4Particle *forParticle)
{
return startValue + (speedFactor * ::Landscape.GetGravity());
return startValue + (speedFactor * fixtof(::Landscape.GetGravity()));
}

void C4ParticleValueProvider::SetType(C4ParticleValueProviderID what)
Expand Down
3 changes: 2 additions & 1 deletion src/landscape/C4SolidMask.cpp
Expand Up @@ -411,7 +411,8 @@ C4SolidMask::C4SolidMask(C4Object *pForObject) : pForObject(pForObject)
// zero fields
MaskPut=false;
MaskPutRotation=0;
MaskRemovalX=MaskRemovalY=Fix0;
MaskRemovalX = Fix0;
MaskRemovalY = 0;
ppAttachingObjects=nullptr;
iAttachingObjectsCount=iAttachingObjectsCapacity=0;
MaskMaterial=MCVehic;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/C4Real.h
Expand Up @@ -123,7 +123,7 @@ class C4Fixed
inline C4Fixed &operator = (int32_t x) { return *this = C4Fixed(x); }

// test value
inline operator bool () const { return !! val; }
explicit operator bool () const { return val != 0; }
inline bool operator ! () const { return ! val; }

// arithmetic operations
Expand Down
2 changes: 1 addition & 1 deletion src/object/C4FindObject.cpp
Expand Up @@ -1027,7 +1027,7 @@ int32_t C4SortObjectRandom::CompareGetValue(C4Object *pFor)

int32_t C4SortObjectSpeed::CompareGetValue(C4Object *pFor)
{
return pFor->xdir*pFor->xdir + pFor->ydir*pFor->ydir;
return fixtoi(pFor->xdir*pFor->xdir + pFor->ydir*pFor->ydir);
}

int32_t C4SortObjectMass::CompareGetValue(C4Object *pFor)
Expand Down
2 changes: 1 addition & 1 deletion src/object/C4Object.cpp
Expand Up @@ -3529,7 +3529,7 @@ void C4Object::ExecAction()
else if (Action.t_attach & CNAT_Top && Shape.Attach(smpx,smpy,CNAT_Top)) fAttachOK = true;
if (!fAttachOK)
{ ObjectComStopDig(this); return; }
iPhaseAdvance=40*limit;
iPhaseAdvance=fixtoi(itofix(40)*limit);

if (xdir < 0) SetDir(DIR_Left); else if (xdir > 0) SetDir(DIR_Right);
Action.t_attach=CNAT_None;
Expand Down
2 changes: 1 addition & 1 deletion src/object/C4Shape.cpp
Expand Up @@ -44,7 +44,7 @@ void C4Shape::Rotate(C4Real Angle, bool bUpdateVertices)
int32_t i = 0;
if (Config.General.DebugRec)
{
rc.x=x; rc.y=y; rc.wdt=Wdt; rc.hgt=Hgt; rc.r=Angle;
rc.x=x; rc.y=y; rc.wdt=Wdt; rc.hgt=Hgt; rc.r=fixtoi(Angle);
for (; i<4; ++i)
{ rc.VtxX[i]=VtxX[i]; rc.VtxY[i]=VtxY[i]; }
AddDbgRec(RCT_RotVtx1, &rc, sizeof(rc));
Expand Down

0 comments on commit 81e49fe

Please sign in to comment.