Skip to content

Commit c1445d3

Browse files
committed
Optimize multiple cases where return value (boolean) needs to be negated
1 parent 9361802 commit c1445d3

File tree

10 files changed

+113
-112
lines changed

10 files changed

+113
-112
lines changed

FASTDOOM/p_enemy.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,23 @@ byte P_CheckMeleeRange(mobj_t *actor)
155155
//
156156
// P_CheckMissileRange
157157
//
158-
byte P_CheckMissileRange(mobj_t *actor)
158+
byte P_NotCheckMissileRange(mobj_t *actor)
159159
{
160160
fixed_t dist;
161161

162162
if (!P_CheckSight(actor, actor->target))
163-
return 0;
163+
return 1;
164164

165165
if (actor->flags & MF_JUSTHIT)
166166
{
167167
// the target just hit the enemy,
168168
// so fight back!
169169
actor->flags &= ~MF_JUSTHIT;
170-
return 1;
170+
return 0;
171171
}
172172

173173
if (actor->reactiontime)
174-
return 0; // do not attack yet
174+
return 1; // do not attack yet
175175

176176
// OPTIMIZE: get this from a global checksight
177177
dist = P_AproxDistance(actor->x - actor->target->x, actor->y - actor->target->y) - 64 * FRACUNIT;
@@ -183,13 +183,13 @@ byte P_CheckMissileRange(mobj_t *actor)
183183

184184
if (actor->type == MT_VILE && dist > 14 * 64)
185185
{
186-
return 0; // too far away
186+
return 1; // too far away
187187
}
188188

189189
if (actor->type == MT_UNDEAD)
190190
{
191191
if (dist < 196)
192-
return 0; // close for fist attack
192+
return 1; // close for fist attack
193193
dist >>= 1;
194194
}
195195

@@ -201,7 +201,7 @@ byte P_CheckMissileRange(mobj_t *actor)
201201
if (actor->type == MT_CYBORG && dist > 160)
202202
dist = 160;
203203

204-
return P_Random >= dist;
204+
return P_Random < dist;
205205
}
206206

207207
//
@@ -214,7 +214,7 @@ byte P_CheckMissileRange(mobj_t *actor)
214214
extern line_t *spechit[MAXSPECIALCROSS];
215215
extern int numspechit;
216216

217-
byte P_Move(mobj_t *actor)
217+
byte P_NotMove(mobj_t *actor)
218218
{
219219
fixed_t tryx;
220220
fixed_t tryy;
@@ -223,8 +223,7 @@ byte P_Move(mobj_t *actor)
223223

224224
// warning: 'catch', 'throw', and 'try'
225225
// are all C++ reserved words
226-
byte good;
227-
226+
228227
fixed_t optSpeed;
229228

230229
switch (actor->movedir)
@@ -266,11 +265,13 @@ byte P_Move(mobj_t *actor)
266265
tryy = actor->y - optSpeed;
267266
break;
268267
case DI_NODIR:
269-
return 0;
268+
return 1;
270269
}
271270

272271
if (P_TryMove(actor, tryx, tryy))
273272
{
273+
byte good;
274+
274275
// open any specials
275276
if (actor->flags & MF_FLOAT && floatok)
276277
{
@@ -281,22 +282,22 @@ byte P_Move(mobj_t *actor)
281282
actor->z -= FLOATSPEED;
282283

283284
actor->flags |= MF_INFLOAT;
284-
return 1;
285+
return 0;
285286
}
286287

287288
if (!numspechit)
288-
return 0;
289+
return 1;
289290

290291
actor->movedir = DI_NODIR;
291-
good = 0;
292+
good = 1;
292293
while (numspechit--)
293294
{
294295
ld = spechit[numspechit];
295296
// if the special is not a door
296297
// that can be opened,
297298
// return false
298299
if (P_UseSpecialLine(actor, ld, 0))
299-
good = 1;
300+
good = 0;
300301
}
301302
return good;
302303
}
@@ -308,7 +309,7 @@ byte P_Move(mobj_t *actor)
308309
if (!(actor->flags & MF_FLOAT))
309310
actor->z = actor->floorz;
310311

311-
return 1;
312+
return 0;
312313
}
313314

314315
//
@@ -324,7 +325,7 @@ byte P_Move(mobj_t *actor)
324325
//
325326
byte P_TryWalk(mobj_t *actor)
326327
{
327-
if (!P_Move(actor))
328+
if (P_NotMove(actor))
328329
{
329330
return 0;
330331
}
@@ -618,7 +619,7 @@ void A_Look(mobj_t *actor)
618619
S_StartSound(actor, sound);
619620
}
620621

621-
P_SetMobjState(actor, actor->info->seestate);
622+
P_NotSetMobjState(actor, actor->info->seestate);
622623
}
623624

624625
//
@@ -661,7 +662,7 @@ void A_Chase(mobj_t *actor)
661662
if (P_LookForPlayersAllAround(actor))
662663
return; // got a new target
663664

664-
P_SetMobjState(actor, actor->info->spawnstate);
665+
P_NotSetMobjState(actor, actor->info->spawnstate);
665666
return;
666667
}
667668

@@ -680,7 +681,7 @@ void A_Chase(mobj_t *actor)
680681
if (actor->info->attacksound)
681682
S_StartSound(actor, actor->info->attacksound);
682683

683-
P_SetMobjState(actor, actor->info->meleestate);
684+
P_NotSetMobjState(actor, actor->info->meleestate);
684685
return;
685686
}
686687

@@ -690,10 +691,10 @@ void A_Chase(mobj_t *actor)
690691
if (gameskill < sk_nightmare && !fastparm && actor->movecount)
691692
goto nomissile;
692693

693-
if (!P_CheckMissileRange(actor))
694+
if (P_NotCheckMissileRange(actor))
694695
goto nomissile;
695696

696-
P_SetMobjState(actor, actor->info->missilestate);
697+
P_NotSetMobjState(actor, actor->info->missilestate);
697698
actor->flags |= MF_JUSTATTACKED;
698699
return;
699700
}
@@ -702,7 +703,7 @@ void A_Chase(mobj_t *actor)
702703
nomissile:
703704

704705
// chase towards player
705-
if (--actor->movecount < 0 || !P_Move(actor))
706+
if (--actor->movecount < 0 || P_NotMove(actor))
706707
{
707708
P_NewChaseDir(actor);
708709
}
@@ -810,7 +811,7 @@ void A_CPosRefire(mobj_t *actor)
810811
return;
811812

812813
if (!actor->target || actor->target->health <= 0 || !P_CheckSight(actor, actor->target))
813-
P_SetMobjState(actor, actor->info->seestate);
814+
P_NotSetMobjState(actor, actor->info->seestate);
814815
}
815816

816817
void A_SpidRefire(mobj_t *actor)
@@ -823,7 +824,7 @@ void A_SpidRefire(mobj_t *actor)
823824

824825
if (!actor->target || actor->target->health <= 0 || !P_CheckSight(actor, actor->target))
825826
{
826-
P_SetMobjState(actor, actor->info->seestate);
827+
P_NotSetMobjState(actor, actor->info->seestate);
827828
}
828829
}
829830

@@ -1072,10 +1073,10 @@ byte PIT_VileCheck(mobj_t *thing)
10721073
corpsehit = thing;
10731074
corpsehit->momx = corpsehit->momy = 0;
10741075
corpsehit->height <<= 2;
1075-
check = P_CheckPosition(corpsehit, corpsehit->x, corpsehit->y);
1076+
check = P_NotCheckPosition(corpsehit, corpsehit->x, corpsehit->y);
10761077
corpsehit->height >>= 2;
10771078

1078-
return !check;
1079+
return check;
10791080
}
10801081

10811082
//
@@ -1153,19 +1154,19 @@ void A_VileChase(mobj_t *actor)
11531154
// Call PIT_VileCheck to check
11541155
// whether object is a corpse
11551156
// that canbe raised.
1156-
if (!P_BlockThingsIterator(bx, by, PIT_VileCheck))
1157+
if (P_NotBlockThingsIterator(bx, by, PIT_VileCheck))
11571158
{
11581159
// got one!
11591160
temp = actor->target;
11601161
actor->target = corpsehit;
11611162
A_FaceTarget(actor);
11621163
actor->target = temp;
11631164

1164-
P_SetMobjState(actor, S_VILE_HEAL1);
1165+
P_NotSetMobjState(actor, S_VILE_HEAL1);
11651166
S_StartSound(corpsehit, sfx_slop);
11661167
info = corpsehit->info;
11671168

1168-
P_SetMobjState(corpsehit, info->raisestate);
1169+
P_NotSetMobjState(corpsehit, info->raisestate);
11691170
corpsehit->height <<= 2;
11701171
corpsehit->flags = info->flags;
11711172
corpsehit->health = info->spawnhealth;
@@ -1798,7 +1799,7 @@ void A_BrainScream(mobj_t *mo)
17981799
th = P_SpawnMobj(x, y, z, MT_ROCKET);
17991800
th->momz = P_Random * 512;
18001801

1801-
P_SetMobjState(th, S_BRAINEXPLODE1);
1802+
P_NotSetMobjState(th, S_BRAINEXPLODE1);
18021803

18031804
th->tics -= P_Random & 7;
18041805
if (th->tics < 1)
@@ -1821,7 +1822,7 @@ void A_BrainExplode(mobj_t *mo)
18211822
th = P_SpawnMobj(x, y, z, MT_ROCKET);
18221823
th->momz = P_Random * 512;
18231824

1824-
P_SetMobjState(th, S_BRAINEXPLODE1);
1825+
P_NotSetMobjState(th, S_BRAINEXPLODE1);
18251826

18261827
th->tics -= P_Random & 7;
18271828
if (th->tics < 1)
@@ -1913,7 +1914,7 @@ void A_SpawnFly(mobj_t *mo)
19131914

19141915
newmobj = P_SpawnMobj(targ->x, targ->y, targ->z, type);
19151916
if (P_LookForPlayersAllAround(newmobj))
1916-
P_SetMobjState(newmobj, newmobj->info->seestate);
1917+
P_NotSetMobjState(newmobj, newmobj->info->seestate);
19171918

19181919
// telefrag anything in this spot
19191920
P_TeleportMove(newmobj, newmobj->x, newmobj->y);

0 commit comments

Comments
 (0)