Skip to content
Permalink
Browse files

Fix several broken conversions from C4Fixed->bool->int (#1904)

This is why non-explicit operator bool is bad.
  • Loading branch information...
isilkor committed Apr 19, 2017
1 parent fc1a7a5 commit 81e49fe0f583798464a14085b106c266bfb12f35
@@ -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)
@@ -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;
@@ -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
@@ -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)
@@ -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;
@@ -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));

0 comments on commit 81e49fe

Please sign in to comment.
You can’t perform that action at this time.