sotn-lint support for drawFlags, and flags (#1593)

`sotn-lint` will now convert `flags` and `drawFlags` fields from
integers to enum values.

`sotn-lint` will no longer overwrite files that haven't changed, so
running `make format build` only has to rebuild files that are modified.

The logic from `DrawModeTransformer` has been pulled out into
`BitFlagLineTransformer` which will handle any type of bitmasked enum
type.
This commit is contained in:
Jonathan Hohle 2024-09-10 13:55:37 -07:00 committed by GitHub
parent b98747e213
commit 63a7c3bac9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
55 changed files with 752 additions and 262 deletions

View File

@ -78,21 +78,23 @@ typedef struct Prim {
#include "primitive.h"
#define DRAW_DEFAULT 0x00
#define DRAW_TRANSP 0x01 // make it semi transparent
#define DRAW_UNK02 0x02 // unknown
#define DRAW_COLORS 0x04 // use color blending
#define DRAW_HIDE 0x08 // do not render the primitive
#define DRAW_TPAGE 0x10 // use custom tpage
#define DRAW_TPAGE2 0x20 // use custom tpage
#define DRAW_UNK_40 0x40
#define DRAW_MENU 0x80 // render only if D_800973EC is set
#define DRAW_UNK_100 0x100 // unknown
#define DRAW_UNK_200 0x200 // unknown
#define DRAW_UNK_400 0x400 // unknown
#define DRAW_UNK_800 0x800 // unknown
#define DRAW_UNK_1000 0x1000 // unknown
#define DRAW_ABSPOS 0x2000 // use absolute coordinates with DRAW_MENU
typedef enum {
DRAW_DEFAULT = 0x00,
DRAW_TRANSP = 0x01, // make it semi transparent
DRAW_UNK02 = 0x02, // unknown
DRAW_COLORS = 0x04, // use color blending
DRAW_HIDE = 0x08, // do not render the primitive
DRAW_TPAGE = 0x10, // use custom tpage
DRAW_TPAGE2 = 0x20, // use custom tpage
DRAW_UNK_40 = 0x40,
DRAW_MENU = 0x80, // render only if D_800973EC is set
DRAW_UNK_100 = 0x100, // unknown
DRAW_UNK_200 = 0x200, // unknown
DRAW_UNK_400 = 0x400, // unknown
DRAW_UNK_800 = 0x800, // unknown
DRAW_UNK_1000 = 0x1000, // unknown
DRAW_ABSPOS = 0x2000, // use absolute coordinates with DRAW_MENU
} DrawMode;
#include "entity.h"
@ -238,48 +240,53 @@ extern u8 g_BmpCastleMap[0x20000];
#define ELEMENT_FIRE 0x8000
// Flags for entity->drawFlags
#define FLAG_DRAW_DEFAULT 0x00
#define FLAG_DRAW_ROTX 0x01
#define FLAG_DRAW_ROTY 0x02
#define FLAG_DRAW_ROTZ 0x04
#define FLAG_DRAW_UNK8 0x08
#define FLAG_DRAW_UNK10 0x10
#define FLAG_DRAW_UNK20 0x20
#define FLAG_DRAW_UNK40 0x40
#define FLAG_DRAW_UNK80 0x80
#define FLAG_DRAW_UNK100 0x100
typedef enum {
FLAG_DRAW_DEFAULT = 0x00,
FLAG_DRAW_ROTX = 0x01,
FLAG_DRAW_ROTY = 0x02,
FLAG_DRAW_ROTZ = 0x04,
FLAG_DRAW_UNK8 = 0x08,
FLAG_DRAW_UNK10 = 0x10,
FLAG_DRAW_UNK20 = 0x20,
FLAG_DRAW_UNK40 = 0x40,
FLAG_DRAW_UNK80 = 0x80,
FLAG_DRAW_UNK100 = 0x100,
} DrawFlag;
// Flags for entity->flags
#define FLAG_UNK_4 0x4
#define FLAG_UNK_10 0x10
// Signals that the entity should run its death routine
#define FLAG_DEAD 0x100
#define FLAG_UNK_200 0x200
#define FLAG_UNK_400 0x400
#define FLAG_UNK_800 0x800
#define FLAG_UNK_1000 0x1000
#define FLAG_UNK_2000 0x2000
#define FLAG_UNK_4000 0x4000
#define FLAG_UNK_8000 0x8000
#define FLAG_UNK_10000 0x10000
#define FLAG_UNK_20000 0x20000 // func_8011A9D8 will destroy if not set
#define FLAG_POS_PLAYER_LOCKED 0x40000
#define FLAG_UNK_80000 0x80000
#define FLAG_UNK_100000 0x100000
#define FLAG_UNK_400000 0x400000
// When an entity used AllocPrimitives and their primIndex set.
// At their destruction they need to free the prims with FreePrimitives.
#define FLAG_HAS_PRIMS 0x800000
#define FLAG_UNK_00200000 0x00200000
#define FLAG_NOT_AN_ENEMY 0x01000000
#define FLAG_UNK_02000000 0x02000000
#define FLAG_KEEP_ALIVE_OFFCAMERA 0x04000000
#define FLAG_POS_CAMERA_LOCKED 0x08000000
#define FLAG_UNK_10000000 0x10000000
#define FLAG_UNK_20000000 0x20000000
#define FLAG_DESTROY_IF_BARELY_OUT_OF_CAMERA 0x40000000
#define FLAG_DESTROY_IF_OUT_OF_CAMERA 0x80000000
typedef enum {
FLAG_UNK_10 = 0x10,
FLAG_UNK_20 = 0x20,
FLAG_UNK_40 = 0x40,
FLAG_UNK_80 = 0x80,
// Signals that the entity should run its death routine
FLAG_DEAD = 0x100,
FLAG_UNK_200 = 0x200,
FLAG_UNK_400 = 0x400,
FLAG_UNK_800 = 0x800,
FLAG_UNK_1000 = 0x1000,
FLAG_UNK_2000 = 0x2000,
FLAG_UNK_4000 = 0x4000,
FLAG_UNK_8000 = 0x8000,
FLAG_UNK_10000 = 0x10000,
FLAG_UNK_20000 = 0x20000, // func_8011A9D8 will destroy if not set
FLAG_POS_PLAYER_LOCKED = 0x40000,
FLAG_UNK_80000 = 0x80000,
FLAG_UNK_100000 = 0x100000,
FLAG_UNK_00200000 = 0x00200000,
FLAG_UNK_400000 = 0x400000,
// When an entity used AllocPrimitives and their primIndex set.
// At their destruction they need to free the prims with FreePrimitives.
FLAG_HAS_PRIMS = 0x800000,
FLAG_NOT_AN_ENEMY = 0x01000000,
FLAG_UNK_02000000 = 0x02000000,
FLAG_KEEP_ALIVE_OFFCAMERA = 0x04000000,
FLAG_POS_CAMERA_LOCKED = 0x08000000,
FLAG_UNK_10000000 = 0x10000000,
FLAG_UNK_20000000 = 0x20000000,
FLAG_DESTROY_IF_BARELY_OUT_OF_CAMERA = 0x40000000,
FLAG_DESTROY_IF_OUT_OF_CAMERA = 0x80000000,
} EntityFlag;
// document g_Player.unk0C
#define PLAYER_STATUS_BAT_FORM 0x00000001

View File

@ -212,7 +212,7 @@ void func_80109594() {
primIndex = AllocPrimitives(PRIM_TILE, 8);
prim = &g_PrimBuf[primIndex];
g_Entities[1].primIndex = primIndex;
g_Entities[1].flags |= 0x800000;
g_Entities[1].flags |= FLAG_HAS_PRIMS;
for (i = 0; i < 6; i++) {
prim->drawMode = DRAW_UNK_100 | DRAW_HIDE | DRAW_UNK02;
prim = prim->next;

View File

@ -488,7 +488,7 @@ void func_80113AAC(void) {
PLAYER.rotZ = 0x800;
PLAYER.rotPivotY = 2;
PLAYER.rotPivotX = 0;
PLAYER.drawFlags |= 4;
PLAYER.drawFlags |= FLAG_DRAW_ROTZ;
PLAYER.facingLeft = (PLAYER.facingLeft + 1) & 1;
SetPlayerAnim(0x2B);
} else {
@ -514,7 +514,7 @@ void func_80113AAC(void) {
break;
case 2:
PLAYER.drawFlags |= 4;
PLAYER.drawFlags |= FLAG_DRAW_ROTZ;
PLAYER.rotPivotX = 0;
PLAYER.rotPivotY = 2;
if (g_Player.unk4A >= 0x39) {
@ -958,7 +958,7 @@ void AlucardHandleDamage(DamageParam* damage, s16 arg1, s16 arg2) {
PLAYER.rotZ = 0x400;
PLAYER.rotPivotX = 0x10;
PLAYER.rotPivotY = 4;
PLAYER.drawFlags |= 4;
PLAYER.drawFlags |= FLAG_DRAW_ROTZ;
SetPlayerAnim(0x2C);
PLAYER.step_s = 0xE;
CreateEntFactoryFromEntity(g_CurrentEntity, FACTORY(31, 8), 0);
@ -997,9 +997,9 @@ void AlucardHandleDamage(DamageParam* damage, s16 arg1, s16 arg2) {
PLAYER.animFrameDuration = 0;
break;
case 14:
PLAYER.drawFlags |= 4;
PLAYER.drawFlags |= FLAG_DRAW_ROTZ;
if (g_Player.timers[8] <= 0) {
PLAYER.drawFlags &= ~4;
PLAYER.drawFlags &= ~FLAG_DRAW_ROTZ;
PLAYER.rotZ = 0x800;
PLAYER.velocityY = 0;
PLAYER.velocityX /= -2;

View File

@ -836,7 +836,7 @@ void EntityPlayerBlinkWhite(Entity* self) {
sp7c = D_8013AEBC[2];
sp7a = D_8013AEBC[3];
self->facingLeft = 0;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
goto block_748;
}
} else {

View File

@ -2209,7 +2209,8 @@ void UnknownEntId49(Entity* self) {
self->palette = PLAYER.palette;
self->facingLeft = PLAYER.facingLeft;
self->zPriority = PLAYER.zPriority;
self->flags = 0x04060000;
self->flags =
FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_POS_PLAYER_LOCKED | FLAG_UNK_20000;
self->step++;
}
self->drawFlags = PLAYER.drawFlags & FLAG_DRAW_UNK8;
@ -2287,7 +2288,8 @@ void func_80123B40(Entity* self) {
return;
}
self->flags = 0x0C830000;
self->flags = FLAG_POS_CAMERA_LOCKED | FLAG_KEEP_ALIVE_OFFCAMERA |
FLAG_HAS_PRIMS | FLAG_UNK_20000 | FLAG_UNK_10000;
self->velocityY = FIX(-3.0);
SetSpeedX(-0x1AAAA);
self->ext.et_80123B40.unk28 = 0x80;

View File

@ -1149,7 +1149,7 @@ void RicHandleDeadPrologue(void) {
if (D_801545AC != 0) {
D_801545AC--;
if ((D_801545AC) == 0) {
PLAYER.drawFlags = 0;
PLAYER.drawFlags = FLAG_DRAW_DEFAULT;
PLAYER.rotY = 0x100;
RicCreateEntFactoryFromEntity(
g_CurrentEntity, BP_MARIA_POWERS_APPLIED, 0);

View File

@ -1068,7 +1068,7 @@ void RicEntityMariaPowers(Entity* self) {
self->posX.val += self->velocityX;
self->posY.val += self->velocityY;
if (--self->ext.et_80162870.unk82 == 0) {
self->drawFlags = 3;
self->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotX = self->rotY = 0x100;
self->ext.et_80162870.unk82 = 0x10;
self->step++;

View File

@ -875,7 +875,7 @@ void RicEntityHitByIce(Entity* self) {
prim->b0 = prim->b1 = prim->b2 = prim->b3;
prim->g0 = prim->g1 = prim->g2 = prim->g3;
prim->drawMode |= DRAW_UNK02;
prim->drawMode &= ~0x300;
prim->drawMode &= ~(DRAW_UNK_200 | DRAW_UNK_100);
if (--prim->v0 == 0) {
prim->drawMode |= DRAW_HIDE;
}

View File

@ -442,7 +442,8 @@ void RicEntityWhip(Entity* self) {
self->zPriority = PLAYER.zPriority + 4;
self->posX.val = var_s3;
self->posY.val = var_s5;
self->flags = 0x04070000;
self->flags = FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_POS_PLAYER_LOCKED |
FLAG_UNK_20000 | FLAG_UNK_10000;
self->ext.whip.unk8C = 0x500;
self->ext.whip.unk7C.val = self->posX.val;
self->ext.whip.unk80.val = self->posY.val;
@ -450,7 +451,7 @@ void RicEntityWhip(Entity* self) {
self->ext.whip.unk9C = self->ext.whip.unk80.val;
self->primIndex = g_api.AllocPrimitives(PRIM_LINE_G2, 1);
if (self->primIndex != -1) {
self->flags |= 0x800000;
self->flags |= FLAG_HAS_PRIMS;
prim = &g_PrimBuf[self->primIndex];
prim->b0 = prim->g0 = prim->r0 = 0x7F;
prim->b1 = prim->g1 = prim->r1 = 0x1F;

View File

@ -539,7 +539,7 @@ void RicEntitySubwpnCross(Entity* self) {
self->facingLeft = PLAYER.facingLeft;
self->zPriority = PLAYER.zPriority;
RicSetSpeedX(FIX(3.5625));
self->drawFlags = 4;
self->drawFlags = FLAG_DRAW_ROTZ;
self->rotZ = 0xC00;
self->ext.crossBoomerang.subweaponId = PL_W_CROSS;
RicSetSubweaponParams(self);

View File

@ -1675,7 +1675,7 @@ void RicEntitySubwpnStopwatch(Entity* self) {
prim = &g_PrimBuf[self->primIndex];
self->flags &= ~FLAG_POS_PLAYER_LOCKED;
prim->priority = 0xC2;
prim->drawMode &= ~0x200;
prim->drawMode &= ~DRAW_UNK_200;
prim = prim->next;
prim->drawMode |= DRAW_HIDE;
prim = prim->next;

View File

@ -60,7 +60,7 @@ void EntityRoomForeground(Entity* entity) {
}
if (entity->params >= 5) {
entity->rotZ = 0x800;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
}
}
AnimateEntity(objInit->unk10, entity);

View File

@ -1192,13 +1192,13 @@ void EntityPinkBallProjectile(Entity* self) {
case 1:
self->rotX = self->rotY += 4;
if (self->rotX > 256) {
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
}
AnimateEntity(D_80180794, self);
entity = self->ext.succubus.real;
if (entity->ext.succubus.unk85 != 0) {
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step++;
}
if (entity->flags & FLAG_DEAD) {
@ -1257,7 +1257,7 @@ void EntitySuccubusWingSpike(Entity* self) {
self->animCurFrame = 0;
var_s0 = D_801807F0[self->params];
self->rotZ = var_s0;
self->drawFlags |= 1;
self->drawFlags |= FLAG_DRAW_ROTX;
self->rotX = 0x100;
CreateEntityFromEntity(E_SUCCUBUS_WING_SPIKE_TIP, self, &self[1]);
self[1].facingLeft = self->facingLeft;

View File

@ -11,7 +11,7 @@ void EntityExplosionSpawn(u16 arg0, u16 arg1) {
}
entity = g_CurrentEntity;
entity->drawFlags = 0;
entity->drawFlags = FLAG_DRAW_DEFAULT;
entity->entityId = E_EXPLOSION;
entity->pfnUpdate = (PfnEntityUpdate)EntityExplosion;
entity->params = arg0;

View File

@ -83,7 +83,7 @@ void EntityExplosionSpawn(u16 arg0, u16 arg1) {
}
entity = g_CurrentEntity;
entity->drawFlags = 0;
entity->drawFlags = FLAG_DRAW_DEFAULT;
entity->entityId = E_EXPLOSION;
entity->pfnUpdate = (PfnEntityUpdate)EntityExplosion;
entity->params = arg0;

View File

@ -291,7 +291,7 @@ void func_801966B0(u16* sensors) {
case 2:
g_CurrentEntity->unk6C += 2;
if (g_CurrentEntity->unk6C == 0xC0) {
g_CurrentEntity->drawFlags = 0;
g_CurrentEntity->drawFlags = FLAG_DRAW_DEFAULT;
g_CurrentEntity->drawMode = DRAW_DEFAULT;
g_CurrentEntity->hitEffect = g_CurrentEntity->palette;
g_CurrentEntity->step_s++;

View File

@ -746,7 +746,7 @@ void EntityCavernDoorLever(Entity* entity) {
InitializeEntity(D_80180B18);
entity->animCurFrame = 18;
entity->rotZ = -0x200;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
CreateEntityFromEntity(0x1E, entity, &entity[1]);
if (g_CastleFlags[0x30] != 0) {
entity->rotZ = 0;
@ -1431,7 +1431,7 @@ void EntityFallingRock2(Entity* self) {
self->animCurFrame = animFrame;
self->animCurFrame += 31;
self->zPriority = 0x9F;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
break;
case 1:
@ -1622,7 +1622,7 @@ void EntityFallingRock(Entity* self) {
self->animCurFrame = animFrame + 31;
self->rotY = 0x60;
self->rotX = 0x60;
self->drawFlags |= 7;
self->drawFlags |= FLAG_DRAW_ROTZ | FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
rnd = (Random() & 0x1F) + 16;
rndAngle = (Random() * 6) + 0x900;
self->velocityX = rnd * rcos(rndAngle);
@ -1876,7 +1876,7 @@ void EntityHeartRoomGoldDoor(Entity* self) {
newEntity->posX.i.hi += -8 + (Random() & 0xF);
newEntity->params = 0x10;
newEntity->rotX = newEntity->rotY = 192;
newEntity->drawFlags |= 3;
newEntity->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
}
}
}

View File

@ -345,7 +345,7 @@ void EntityDeath(Entity* self) {
self->rotZ -= 0x40;
if (self->rotZ == 0) {
SetStep(3);
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
}
x = (0x1000 - self->rotZ) * 0x1D;
@ -732,7 +732,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
case 3:
if (self->step_s == 0) {
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
switch (self->ext.wargpuff.unk88) {
case 1:
if (self->ext.wargpuff.unk89 >= 0x4) {
@ -785,7 +785,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
self->velocityY = FIX(-0.75);
self->facingLeft = rnd & 1;
self->rotX = 0xC0;
self->drawFlags |= 1;
self->drawFlags |= FLAG_DRAW_ROTX;
self->step_s++;
}
MoveEntity();

View File

@ -59,7 +59,7 @@ void EntityRoomForeground(Entity* entity) {
}
if (entity->params >= 5) {
entity->rotZ = 0x800;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
}
}
AnimateEntity(objInit->unk10, entity);
@ -81,7 +81,7 @@ void func_801CC5A4(Entity* entity, u8 count, u8 params, s32 xDist, s32 yDist,
newEnt->posY.i.hi = y;
newEnt->ext.generic.unk94 = D_80182A48[i];
newEnt->rotY = newEnt->rotX = D_80182A38[D_80182A48[i] + arg5];
newEnt->drawFlags = 3;
newEnt->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
newEnt->zPriority = entity->zPriority + 1;
}
}
@ -398,7 +398,7 @@ void func_801CF438(Entity* entity, u8 count, u8 params, s32 xDist, s32 yDist,
newEnt->posY.i.hi = y;
newEnt->ext.generic.unk94 = D_801832E8[i];
newEnt->rotY = newEnt->rotX = D_801832D8[D_801832E8[i] + arg5];
newEnt->drawFlags = 3;
newEnt->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
newEnt->zPriority = entity->zPriority + 1;
}
}

View File

@ -662,7 +662,7 @@ void EntityMerman2(Entity* self) {
if ((self->flags & FLAG_DEAD) && (self->step < MERMAN2_DYING)) {
PlaySfxPositional(0x71D);
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
if (self->flags & FLAG_HAS_PRIMS) {
g_api.FreePrimitives(self->primIndex);
self->flags &= ~FLAG_HAS_PRIMS;
@ -801,7 +801,7 @@ void EntityMerman2(Entity* self) {
newEntity->zPriority = self->zPriority;
}
self->rotZ = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
self->step_s++;
}
break;
@ -860,7 +860,10 @@ void EntityMerman2(Entity* self) {
g_api.FreePrimitives(self->primIndex);
self->hitboxHeight = 21;
self->flags &= ~FLAG_HAS_PRIMS;
self->drawFlags &= 0xFB;
self->drawFlags &=
FLAG_DRAW_UNK80 | FLAG_DRAW_UNK40 | FLAG_DRAW_UNK20 |
FLAG_DRAW_UNK10 | FLAG_DRAW_UNK8 | FLAG_DRAW_ROTY |
FLAG_DRAW_ROTX;
SetStep(MERMAN2_WALKING_TO_PLAYER);
}
} else {
@ -963,7 +966,7 @@ void EntityMerman2(Entity* self) {
}
self->ext.merman2.rotation = 1;
self->rotZ = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
if (self->facingLeft != 0) {
self->velocityX = FIX(-6);
} else {
@ -1032,7 +1035,10 @@ void EntityMerman2(Entity* self) {
self->rotZ += 0xC0;
if (self->rotZ > 0x1000) {
self->posY.i.hi -= 10;
self->drawFlags &= 0xFB;
self->drawFlags &=
FLAG_DRAW_UNK80 | FLAG_DRAW_UNK40 | FLAG_DRAW_UNK20 |
FLAG_DRAW_UNK10 | FLAG_DRAW_UNK8 | FLAG_DRAW_ROTY |
FLAG_DRAW_ROTX;
SetStep(MERMAN2_WALKING_TO_PLAYER);
}
if (func_801D2D40(0x1B)) {
@ -1074,7 +1080,7 @@ void EntityMerman2(Entity* self) {
prim = &g_PrimBuf[primIndex];
self->primIndex = primIndex;
self->ext.merman2.prim = prim;
self->flags |= 0x800000;
self->flags |= FLAG_HAS_PRIMS;
UnkPolyFunc2(prim);
prim->tpage = 0x12;
prim->clut = 0x292;
@ -1356,7 +1362,7 @@ void EntityFallingObject2(Entity* self) {
InitializeEntity(D_80180B48);
self->animCurFrame = 0;
self->hitboxState = 0;
self->flags |= 0x2000;
self->flags |= FLAG_UNK_2000;
self->zPriority += 4;
}
MoveEntity();
@ -1381,10 +1387,10 @@ void EntityUnkId3D(Entity* self) {
self->unk6C = 0xA0;
self->rotX = 0x100;
self->rotY = 0x1A0;
self->drawFlags |= 3;
self->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->ext.generic.unk84.S8.unk1 = 0x11;
self->ext.generic.unk84.S8.unk0 = self->params;
self->drawFlags |= 8;
self->drawFlags |= FLAG_DRAW_UNK8;
break;
case 1:
@ -1437,8 +1443,8 @@ void EntityLargeFallingObject(Entity* self) {
self->velocityY = FIX(0.0625);
self->palette = self->params + 0xE;
self->unk6C = 0x80;
self->drawFlags |= 8;
self->flags |= 0x2000;
self->drawFlags |= FLAG_DRAW_UNK8;
self->flags |= FLAG_UNK_2000;
return;
}
MoveEntity();

View File

@ -654,7 +654,7 @@ void EntityCavernDoorLever(Entity* entity) {
InitializeEntity(D_80180AA8);
entity->animCurFrame = 18;
entity->rotZ = -0x200;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
CreateEntityFromEntity(E_ID_1E, entity, &entity[1]);
if (g_CastleFlags[0x30] != 0) {
entity->rotZ = 0;
@ -1350,7 +1350,7 @@ void EntityFallingRock2(Entity* self) {
self->animCurFrame = animFrame;
self->animCurFrame += 31;
self->zPriority = 0x9F;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
break;
case 1:
@ -1539,7 +1539,7 @@ void EntityFallingRock(Entity* self) {
self->animCurFrame = animFrame + 31;
self->rotY = 0x60;
self->rotX = 0x60;
self->drawFlags |= 7;
self->drawFlags |= FLAG_DRAW_ROTZ | FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
rnd = (Random() & 0x1F) + 16;
rndAngle = (Random() * 6) + 0x900;
self->velocityX = rnd * rcos(rndAngle);
@ -1729,7 +1729,7 @@ void EntityHeartRoomGoldDoor(Entity* self) {
newEntity->posX.i.hi += -8 + (Random() & 15);
newEntity->params = 0x10;
newEntity->rotX = newEntity->rotY = 192;
newEntity->drawFlags |= 3;
newEntity->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
}
}
}

View File

@ -90,7 +90,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
case 3:
if (self->step_s == 0) {
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
switch (self->ext.wargpuff.unk88) {
case 1:
if (self->ext.wargpuff.unk89 >= 0x4) {
@ -143,7 +143,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
self->velocityY = FIX(-0.75);
self->facingLeft = rnd & 1;
self->rotX = 0xC0;
self->drawFlags |= 1;
self->drawFlags |= FLAG_DRAW_ROTX;
self->step_s++;
}
MoveEntity();

View File

@ -661,7 +661,7 @@ void EntityMerman2(Entity* self) {
if ((self->flags & FLAG_DEAD) && (self->step < MERMAN2_DYING)) {
PlaySfxPositional(0x71D);
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
if (self->flags & FLAG_HAS_PRIMS) {
g_api.FreePrimitives(self->primIndex);
self->flags &= ~FLAG_HAS_PRIMS;
@ -800,7 +800,7 @@ void EntityMerman2(Entity* self) {
newEntity->zPriority = self->zPriority;
}
self->rotZ = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
self->step_s++;
}
break;
@ -857,7 +857,10 @@ void EntityMerman2(Entity* self) {
g_api.FreePrimitives(self->primIndex);
self->hitboxHeight = 21;
self->flags &= ~FLAG_HAS_PRIMS;
self->drawFlags &= 0xFB;
self->drawFlags &=
FLAG_DRAW_UNK80 | FLAG_DRAW_UNK40 | FLAG_DRAW_UNK20 |
FLAG_DRAW_UNK10 | FLAG_DRAW_UNK8 | FLAG_DRAW_ROTY |
FLAG_DRAW_ROTX;
SetStep(MERMAN2_WALKING_TO_PLAYER);
}
} else {
@ -960,7 +963,7 @@ void EntityMerman2(Entity* self) {
}
self->ext.merman2.rotation = 1;
self->rotZ = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
if (self->facingLeft != 0) {
self->velocityX = FIX(-6);
} else {
@ -1029,7 +1032,10 @@ void EntityMerman2(Entity* self) {
self->rotZ += 0xC0;
if (self->rotZ > 0x1000) {
self->posY.i.hi -= 10;
self->drawFlags &= 0xFB;
self->drawFlags &=
FLAG_DRAW_UNK80 | FLAG_DRAW_UNK40 | FLAG_DRAW_UNK20 |
FLAG_DRAW_UNK10 | FLAG_DRAW_UNK8 | FLAG_DRAW_ROTY |
FLAG_DRAW_ROTX;
SetStep(MERMAN2_WALKING_TO_PLAYER);
}
if (func_801C6458(0x1B)) {
@ -1071,7 +1077,7 @@ void EntityMerman2(Entity* self) {
prim = &g_PrimBuf[primIndex];
self->primIndex = primIndex;
self->ext.merman2.prim = prim;
self->flags |= 0x800000;
self->flags |= FLAG_HAS_PRIMS;
UnkPolyFunc2(prim);
prim->tpage = 0x12;
prim->clut = 0x292;
@ -1376,10 +1382,10 @@ void func_801C7E18(Entity* self) {
self->unk6C = 0xA0;
self->rotX = 0x100;
self->rotY = 0x1A0;
self->drawFlags |= 3;
self->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->ext.generic.unk84.S8.unk1 = 0x11;
self->ext.generic.unk84.S8.unk0 = self->params;
self->drawFlags |= 8;
self->drawFlags |= FLAG_DRAW_UNK8;
break;
case 1:
@ -1431,7 +1437,7 @@ void EntityLargeFallingObject(Entity* self) {
self->velocityY = FIX(0.0625);
self->palette = self->params + 0xE;
self->unk6C = 0x80;
self->drawFlags |= 8;
self->drawFlags |= FLAG_DRAW_UNK8;
self->flags |= FLAG_UNK_2000;
return;
}

View File

@ -849,7 +849,7 @@ void EntityOwlKnight(Entity* self) {
if (!(self->ext.owl.unk80 & 4)) {
self->step_s++;
} else if (AnimateEntity(D_80182820) == 0) {
self->flags ^= FLAG_UNK_4;
self->flags ^= 0x4;
self->step_s++;
}
break;

View File

@ -373,7 +373,7 @@ void EntityGurkhaBodyParts(Entity* self) {
self->step = 0;
self->pfnUpdate = EntityExplosion;
self->params = 0;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
}
return;
}

View File

@ -13,7 +13,7 @@ void EntityHammerWeapon(Entity* self) {
InitializeEntity(D_80180B98);
self->hitboxWidth = 10;
self->hitboxHeight = 10;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
case 1:
angle = *(u16*)&self->ext.stub[0x20];
@ -522,7 +522,7 @@ void EntityGurkhaSword(Entity* self) {
InitializeEntity(D_80180BB0);
self->hitboxWidth = 8;
self->hitboxHeight = 8;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
break;
case 1:
@ -589,7 +589,7 @@ void EntityGurkhaSword(Entity* self) {
self->step = 0;
self->pfnUpdate = EntityExplosion;
self->params = 0;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
}
}
break;

View File

@ -541,7 +541,7 @@ void EntityBladeSword(Entity* self) {
InitializeEntity(D_80180BC8);
self->hitboxWidth = 6;
self->hitboxHeight = 6;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
primIndex = g_api.AllocPrimitives(PRIM_G4, 6);
if (primIndex == -1) {
self->ext.et_801D1BB8.prim = NULL;

View File

@ -18,7 +18,7 @@ void EntityRoomForeground(Entity* entity) {
}
if (entity->params >= 5) {
entity->rotZ = 0x800;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
}
}
AnimateEntity(objInit->unk10, entity);

View File

@ -722,7 +722,7 @@ void func_801B8CC0(Entity* self) {
void EntitySmallGaibonProjectile(Entity* self) {
if (self->flags & FLAG_DEAD) {
self->pfnUpdate = EntityExplosion;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step = 0;
self->entityId = 2;
self->params = 0;
@ -754,7 +754,7 @@ void EntityLargeGaibonProjectile(Entity* self) {
if (self->flags & FLAG_DEAD) {
self->pfnUpdate = EntityExplosion;
self->entityId = 2;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step = 0;
self->params = 1;
return;

View File

@ -1361,7 +1361,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
case 3:
if (self->step_s == 0) {
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
switch (self->ext.wargpuff.unk88) {
case 1:
if (self->ext.wargpuff.unk89 >= 0x4) {
@ -1414,7 +1414,7 @@ void EntityWargExplosionPuffOpaque(Entity* self) {
self->velocityY = FIX(-0.75);
self->facingLeft = rnd & 1;
self->rotX = 0xC0;
self->drawFlags |= 1;
self->drawFlags |= FLAG_DRAW_ROTX;
self->step_s++;
}
MoveEntity();

View File

@ -28,7 +28,9 @@ void EntityBloodSkeleton(Entity* self) {
InitializeEntity(D_80180C40);
self->facingLeft = (u32)Random() % 2;
self->animCurFrame = 1;
self->flags &= 0x1FFFFFFF;
self->flags &=
~(FLAG_DESTROY_IF_OUT_OF_CAMERA |
FLAG_DESTROY_IF_BARELY_OUT_OF_CAMERA | FLAG_UNK_20000000);
self->palette += self->params;
break;
@ -61,7 +63,7 @@ void EntityBloodSkeleton(Entity* self) {
case BLOOD_SKELETON_DISASSEMBLE:
if (AnimateEntity(D_80182638, self) == 0) {
self->ext.generic.unk80.modeS16.unk0 = 0xF0;
self->flags &= ~0x100;
self->flags &= ~FLAG_DEAD;
if (self->params != 0) {
self->ext.generic.unk80.modeS16.unk0 = 4;
}
@ -74,7 +76,7 @@ void EntityBloodSkeleton(Entity* self) {
case 0:
if (--self->ext.generic.unk80.modeS16.unk0 == 0) {
self->rotZ = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
PlaySfxPositional(NA_SE_EN_BLOOD_SKELETON_REASSEMBLES);
self->step_s++;
return;
@ -92,7 +94,7 @@ void EntityBloodSkeleton(Entity* self) {
}
if (self->ext.generic.unk80.modeS16.unk0 >= 9) {
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->rotZ = 0;
self->step_s++;
}

View File

@ -79,7 +79,7 @@ void EntitySpittleBone(Entity* self) {
FLAG_DESTROY_IF_OUT_OF_CAMERA;
newEntity->palette = 0x20D;
newEntity->animCurFrame = i + 0x3A;
newEntity->drawFlags |= 4;
newEntity->drawFlags |= FLAG_DRAW_ROTZ;
newEntity->rotZ = self->rotZ;
newEntity->step = 4;
newEntity->velocityX = D_80182504[i];
@ -126,7 +126,7 @@ void EntityRotateSpittlebone(Entity* self) {
switch (self->step) {
case 0:
InitializeEntity(g_EInitGeneric);
self->flags &= ~0x2200;
self->flags &= ~(FLAG_UNK_2000 | FLAG_UNK_200);
break;
case 1:

View File

@ -620,7 +620,7 @@ void func_801B69E8(Entity* self) {
void EntitySmallGaibonProjectile(Entity* self) {
if (self->flags & FLAG_DEAD) {
self->pfnUpdate = EntityExplosion;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step = 0;
self->entityId = 2;
self->params = 0;
@ -653,7 +653,7 @@ void EntityLargeGaibonProjectile(Entity* self) {
if (self->flags & FLAG_DEAD) {
self->pfnUpdate = EntityExplosion;
self->entityId = 2;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step = 0;
self->params = 1;
return;

View File

@ -472,7 +472,7 @@ void func_801B519C(void) {
prim = &g_PrimBuf[primBufIndex];
self->primIndex = primBufIndex;
self->ext.prim = prim;
self->flags |= 0x800000;
self->flags |= FLAG_HAS_PRIMS;
uvOfst = 0;
while (prim) {
v01 = 0x38 + uvOfst;

View File

@ -710,7 +710,7 @@ s32 func_801B79D4(Entity* entity) {
switch (entity->step) {
case 0:
if (func_801B76F0(D_8018BC54)) {
entity->flags |= 0x800000;
entity->flags |= FLAG_HAS_PRIMS;
entity->primIndex = (s32)g_Dialogue.prim[1];
++entity->step;
func_801B786C(0);

View File

@ -176,7 +176,7 @@ void EntitySecretStairs(Entity* self) {
break;
}
self->rotZ = -0x200;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
break;
case 1:
@ -189,7 +189,7 @@ void EntitySecretStairs(Entity* self) {
case 2:
self->rotZ += 0x10;
if (self->rotZ == 0) {
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step++;
}
break;

View File

@ -687,7 +687,7 @@ u32 func_801ABBBC(s32 step, Entity* dracula) {
if (dracula->unk6C >= 0x80U) {
step++;
dracula->unk6C = 0x80U;
dracula->drawFlags = 0;
dracula->drawFlags = FLAG_DRAW_DEFAULT;
}
break;
case 9:
@ -735,7 +735,7 @@ s32 func_801AC458(s16 arg0) {
case 2:
e = &g_CurrentEntity[1];
e->animCurFrame = 0;
e->drawFlags = 0;
e->drawFlags = FLAG_DRAW_DEFAULT;
e->step = 1;
ret = 0xFF;
break;

View File

@ -308,7 +308,7 @@ void EntityDracula(Entity* self) {
self->ext.dracula.unk94 = 0x40;
self->ext.dracula.unk98 = 0;
self->unk6C = 0x80;
self->drawFlags |= 8;
self->drawFlags |= FLAG_DRAW_UNK8;
prim->type = PRIM_G4;
prim->x0 = prim->x2 = self->posX.i.hi;
prim->x1 = prim->x3 = self->posX.i.hi;
@ -575,7 +575,7 @@ void EntityDraculaMeteorball(Entity* entity) {
case 0:
InitializeEntity(D_801805F8);
entity->hitboxState = 0;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
break;
case 1:
if (AnimateEntity(D_801809B0, entity) == 0) {
@ -668,7 +668,7 @@ void EntityDraculaGlass(Entity* entity) {
}
break;
case 2:
entity->drawFlags = 0;
entity->drawFlags = FLAG_DRAW_DEFAULT;
if (AnimateEntity(D_80180A40, entity) == 0) {
s32 i;
for (i = 0; i < 8; i++) {

View File

@ -142,7 +142,7 @@ void EntityDraculaFinalForm(Entity* self) {
self->animCurFrame = 1;
self->hitboxState = 3;
self->unk6C = 0x80;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
SetStep(2);
}
break;
@ -422,7 +422,8 @@ void EntityDraculaFinalForm(Entity* self) {
self->unk5A = 0x5E;
self->palette = 0x815F;
self->drawMode = DRAW_TPAGE2 | DRAW_TPAGE;
self->drawFlags = 0xB;
self->drawFlags =
FLAG_DRAW_UNK8 | FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->unk6C = 0x10;
self->rotY = 0x400;
self->rotX = 0x400;
@ -435,7 +436,7 @@ void EntityDraculaFinalForm(Entity* self) {
if (self->rotY < 0x100) {
self->animCurFrame = 0;
self->drawMode = DRAW_DEFAULT;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step_s++;
}
break;
@ -444,7 +445,7 @@ void EntityDraculaFinalForm(Entity* self) {
self->animCurFrame = 1;
self->unk5A = 0x50;
self->palette = 0x815F;
self->drawFlags = 8;
self->drawFlags = FLAG_DRAW_UNK8;
self->unk6C = 0;
self->drawMode = DRAW_TPAGE2 | DRAW_TPAGE;
self->step_s++;
@ -463,7 +464,7 @@ void EntityDraculaFinalForm(Entity* self) {
if (self->unk6C == 0) {
self->animCurFrame = 0;
self->drawMode = DRAW_DEFAULT;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->step_s++;
}
break;
@ -623,7 +624,7 @@ void EntityDraculaMegaFireball(Entity* self) {
angle = self->rotZ;
self->rotY = 0x80;
self->rotX = 0x80;
self->drawFlags |= 7;
self->drawFlags |= FLAG_DRAW_ROTZ | FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotZ = 0x1C0 - angle;
if (self->facingLeft != 0) {
self->velocityX = rcos(angle) * 0x60;

View File

@ -128,7 +128,7 @@ void func_801B57D0(u16 params) {
current = g_CurrentEntity;
g_CurrentEntity->entityId = E_EXPLOSION;
g_CurrentEntity->pfnUpdate = EntityExplosion;
g_CurrentEntity->drawFlags = 0;
g_CurrentEntity->drawFlags = FLAG_DRAW_DEFAULT;
current->params = params;
current->animCurFrame = 0;
g_CurrentEntity->step = 0;

View File

@ -62,7 +62,7 @@ void EntityRoomForeground(Entity* entity) {
}
if (entity->params >= 5) {
entity->rotZ = 0x800;
entity->drawFlags |= 4;
entity->drawFlags |= FLAG_DRAW_ROTZ;
}
}
AnimateEntity(objInit->unk10, entity);

View File

@ -348,7 +348,7 @@ static void func_ptr_80170008(Entity* self) {
self->hitboxHeight = 4;
}
if (self->ext.heavenSword.unk82 > 0x30) {
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
}
if (self->ext.heavenSword.unk82 == 0x34) {
g_api.PlaySfx(SFX_MAGIC_WEAPON_APPEAR_B);

View File

@ -88,7 +88,7 @@ void EntityWeaponAttack(Entity* self) {
self->ext.weapon.lifetime--;
if ((self->ext.weapon.lifetime) == 0) {
self->drawFlags = 3;
self->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotY = 256;
self->rotX = 256;
self->ext.weapon.lifetime = 14;

View File

@ -138,13 +138,13 @@ static void EntityWeaponAttack(Entity* self) {
case 4:
self->hitboxState = 0;
g_Player.unk48 = 0;
self->drawFlags |= 4;
self->drawFlags |= FLAG_DRAW_ROTZ;
self->posY.val += self->velocityY;
self->posX.val += self->velocityX;
self->velocityY += FIX(20.0 / 128);
self->rotZ = self->rotZ + 0x80;
if (--self->ext.weapon.lifetime < 16) {
self->drawFlags |= 0x80;
self->drawFlags |= FLAG_DRAW_UNK80;
}
if (--self->ext.weapon.lifetime == 0) {
DestroyEntity(self);
@ -177,7 +177,7 @@ s32 func_ptr_80170004(Entity* self) {
self->unk5A = self->ext.weapon.parent->unk5A;
self->ext.weapon.unk80 = self->ext.weapon.parent->ext.weapon.unk80;
self->animCurFrame = self->ext.weapon.parent->animCurFrame;
self->flags = 0x08000000;
self->flags = FLAG_POS_CAMERA_LOCKED;
self->drawFlags = FLAG_DRAW_UNK8 | FLAG_DRAW_UNK10;
self->unk6C = 0x80;
self->ext.weapon.unk7E = 0x14;
@ -234,7 +234,8 @@ static void EntityWeaponShieldSpell(Entity* self) {
self->ext.shield.unk7D = 0;
}
self->posY.i.hi -= 8;
self->flags = 0x04810000;
self->flags =
FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_HAS_PRIMS | FLAG_UNK_10000;
self->zPriority = PLAYER.zPriority - 2;
self->facingLeft = PLAYER.facingLeft;
self->animCurFrame = 0x3E;
@ -299,7 +300,7 @@ static void EntityWeaponShieldSpell(Entity* self) {
self->anim = D_CF000_8017AD24;
self->animFrameIdx = 0;
self->animFrameDuration = 0;
self->flags |= 0x100000;
self->flags |= FLAG_UNK_100000;
self->ext.weapon.unk80 = 0x20;
self->palette = self->ext.weapon.childPalette;
self->zPriority = 0x1B6;
@ -398,7 +399,7 @@ static void func_ptr_80170024(Entity* self) {
self->ext.weapon.childPalette = 0x110;
self->ext.shield.unk7D = 0;
}
self->flags |= 0x04800000;
self->flags |= FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_HAS_PRIMS;
self->ext.shield.unk9C = 0x40;
for (i = 0, prim = &g_PrimBuf[self->primIndex]; prim != NULL; i++,

View File

@ -127,7 +127,7 @@ s32 func_ptr_80170004(Entity* self) {
self->flags = FLAG_POS_CAMERA_LOCKED;
self->zPriority = self->ext.weapon.parent->zPriority - 2;
self->anim = D_11C000_8017A724;
self->drawFlags |= 3;
self->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotY = 0;
self->rotX = 0;
self->rotPivotY = 0x16;

View File

@ -329,7 +329,7 @@ s32 func_ptr_80170004(Entity* self) {
self->zPriority = self->ext.weapon.parent->zPriority - 2;
self->anim = D_123000_8017A4A4;
self->drawFlags |= 3;
self->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotX = self->rotY = 0;
self->step++;
break;

View File

@ -157,7 +157,7 @@ s32 func_ptr_80170004(Entity* self) {
self->flags = FLAG_POS_CAMERA_LOCKED;
self->zPriority = self->ext.weapon.parent->zPriority - 2;
self->anim = D_12A000_8017A604;
self->drawFlags |= 3;
self->drawFlags |= FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;
self->rotY = 0;
self->rotX = 0;
self->rotPivotY = 0x14;
@ -262,7 +262,7 @@ static void func_ptr_80170008(Entity* self) {
self->unk5A = 0;
self->animFrameDuration = 0;
self->animFrameIdx = 0;
self->drawFlags = 0;
self->drawFlags = FLAG_DRAW_DEFAULT;
self->velocityY = -FIX(0.5);
self->step++;
}

View File

@ -235,7 +235,7 @@ static void EntityWeaponAttack(Entity* self) {
prim->drawMode = DRAW_UNK_200 | DRAW_UNK_100 | DRAW_TPAGE2 |
DRAW_TPAGE | DRAW_COLORS | DRAW_TRANSP;
self->flags = 0x860000;
self->flags = FLAG_HAS_PRIMS | FLAG_POS_PLAYER_LOCKED | FLAG_UNK_20000;
temp = maskedParams & 0xFFFF;
if (!temp) {
SetWeaponProperties(self, 0);

View File

@ -105,6 +105,79 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
dependencies = [
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -115,6 +188,12 @@ dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "rayon"
version = "1.7.0"
@ -177,6 +256,8 @@ name = "sotn-lint"
version = "0.1.0"
dependencies = [
"lazy_static",
"num",
"once_cell",
"rayon",
"regex",
]

View File

@ -9,3 +9,5 @@ edition = "2021"
lazy_static = "1.4.0"
rayon = "1.7.0"
regex = "1.9.1"
num = "0.4.3"
once_cell = "1.19.0"

View File

@ -0,0 +1,139 @@
use std::cmp::Eq;
use std::cmp::Ord;
use std::fmt::Debug;
use std::mem::size_of;
use std::str::FromStr;
use std::vec::Vec;
use num::PrimInt;
use num::Unsigned;
use regex::Regex;
use crate::line_transformer::LineTransformer;
pub trait EnumValue: Unsigned + 'static + Sync + Eq + Ord + PrimInt + FromStr { }
impl EnumValue for u8 where <u8 as FromStr>::Err: Debug { }
impl EnumValue for u16 where <u16 as FromStr>::Err: Debug { }
impl EnumValue for u32 where <u32 as FromStr>::Err: Debug { }
impl EnumValue for u64 where <u64 as FromStr>::Err: Debug { }
// `BitFlagLineTransformer` supports transforminging fields of
// an enum type to a boolean combination of the enum flags
// of that type.
//
// This supports transforming lines in the following forms:
//
// * assignment:
// self->field = 35;
// self->field = 0x23;
// s.field = 0x23;
//
// * bitwise-OR assignment:
// self->field |= 524288;
// s.field |= 0x80000;
//
// * bitwise-AND assignment:
// self->field &= ~4;
// self->field &= 0xFFFB;
//
// If a constant contains bits which are not represented by
// enum values, no transformation will be made.
pub struct BitFlagLineTransformer<U: EnumValue> where <U as FromStr>::Err: Debug {
enum_values: Vec<&'static (U, &'static str)>,
regex: Regex,
default_value: &'static str,
safe_mask: U,
}
impl<U: EnumValue> BitFlagLineTransformer<U> where <U as FromStr>::Err: Debug {
pub fn new(field_name: &str, default_value: &'static str, enum_values: &Vec<&'static (U, &'static str)>) -> Self {
let mut _enum_values: Vec<&'static (U, &'static str)> = Vec::new();
_enum_values.extend_from_slice(&enum_values[..]);
_enum_values.sort_by(|(a, _), (b, _)| b.cmp(a));
let pattern = format!(r"([.>]{}\s*(?:[&|]?)=\s*)([~]?)((?:0x)?[A-Fa-f0-9]*)(?:;)", field_name.to_string());
let regex = Regex::new(&pattern).unwrap();
let safe_mask: U = enum_values.iter().fold(U::zero(), |mask, (bit, _)| mask | *bit);
Self {
enum_values: _enum_values,
regex: regex,
default_value: default_value,
safe_mask: safe_mask,
}
}
fn replace_enum(&self, captures: &regex::Captures) -> String {
if let Some(assignment) = captures.get(1).map(|m| m.as_str().to_string()) {
if let Some(field_value_string) = captures.get(3).map(|m| m.as_str().to_string()) {
let inverted = captures.get(2).map(|m| m.as_str()) == Some("~");
// if it starts with 0x, hex string, otherwise int
let mut field_value: U;
if field_value_string.starts_with("0x") {
if let Ok(v) = U::from_str_radix(field_value_string.strip_prefix("0x").unwrap(), 16) {
field_value = v;
} else {
return captures.get(0)
.map_or_else(|| "".to_string(), |m| m.as_str().to_string())
}
} else {
field_value = field_value_string.parse::<U>().unwrap();
}
if inverted {
field_value = !field_value;
}
let invert: String;
if field_value.count_ones() > ((size_of::<U>() as u32) * 8 / 2) {
invert = "~".to_string();
field_value = !field_value;
} else {
invert = "".to_string();
}
// there are bits present which are not enum values, so ignore
if !((field_value & !self.safe_mask).is_zero()) {
return captures
.get(0)
.map_or_else(|| "".to_string(), |m| m.as_str().to_string());
}
let mut rvalue: String;
if field_value.is_zero() {
rvalue = self.default_value.to_string();
} else {
// n.b.! there may be values missing from the enums which would
// result in an incorrect value being produced.
rvalue = self.enum_values.iter()
.map(|(mask, name)|
if !((*mask & field_value).is_zero()) {
Some(name)
} else {
None
})
.filter(|e| e.is_some())
.map(|e| *e.unwrap())
.collect::<Vec<&str>>()
.join(" | ");
if field_value.count_ones() > 1 &&
(invert == "~" || inverted) {
rvalue = format!("({})", rvalue);
}
}
return format!("{}{}{};", assignment.to_string(), invert, rvalue);
}
}
captures
.get(0)
.map_or_else(|| "".to_string(), |m| m.as_str().to_string())
}
}
impl<U: EnumValue> LineTransformer for BitFlagLineTransformer<U> where <U as FromStr>::Err: Debug {
fn transform_line(&self, line: &str) -> String where {
self.regex.replace_all(line, |captures: &regex::Captures| self.replace_enum(captures)).to_string()
}
}

View File

@ -0,0 +1,109 @@
use lazy_static::lazy_static;
use crate::line_transformer::LineTransformer;
use crate::bit_flag_line_transformer::BitFlagLineTransformer;
pub struct DrawFlagsTransformer {
transformer: BitFlagLineTransformer<u16>,
}
lazy_static! {
static ref DRAW_FLAGS: [(u16, &'static str); 9] = [
(1 << 0, "FLAG_DRAW_ROTX"),
(1 << 1, "FLAG_DRAW_ROTY"),
(1 << 2, "FLAG_DRAW_ROTZ"),
(1 << 3, "FLAG_DRAW_UNK8"),
(1 << 4, "FLAG_DRAW_UNK10"),
(1 << 5, "FLAG_DRAW_UNK20"),
(1 << 6, "FLAG_DRAW_UNK40"),
(1 << 7, "FLAG_DRAW_UNK80"),
(1 << 8, "FLAG_DRAW_UNK100"),
];
}
impl DrawFlagsTransformer {
pub fn new() -> Self {
Self {
transformer: BitFlagLineTransformer::<u16>::new(
"drawFlags", "FLAG_DRAW_DEFAULT", &DRAW_FLAGS.iter().collect()),
}
}
}
impl LineTransformer for DrawFlagsTransformer {
fn transform_line(&self, line: &str) -> String {
self.transformer.transform_line(line)
}
}
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
static FT: Lazy<DrawFlagsTransformer> = Lazy::new(|| DrawFlagsTransformer::new());
#[test]
fn test_draw_flags_hex() {
let input_line = "self->drawFlags = 0x3;";
let expected_line = "self->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_decimal() {
let input_line = "self->drawFlags = 3;";
let expected_line = "self->drawFlags = FLAG_DRAW_ROTY | FLAG_DRAW_ROTX;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_zero() {
let input_line = "self->drawFlags = 0;";
let expected_line = "self->drawFlags = FLAG_DRAW_DEFAULT;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_zero_hex() {
let input_line = "self->drawFlags = 0x0;";
let expected_line = "self->drawFlags = FLAG_DRAW_DEFAULT;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_flags() {
let input_line = "self->drawFlags = FLAG_DRAW_ROTX;";
let expected_line = "self->drawFlags = FLAG_DRAW_ROTX;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_set() {
let input_line = "self->drawFlags |= 0x80;";
let expected_line = "self->drawFlags |= FLAG_DRAW_UNK80;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_clear() {
let input_line = "PLAYER.drawFlags &= 0xFF7F;";
let expected_line = "PLAYER.drawFlags &= ~FLAG_DRAW_UNK80;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_flags_clear_many() {
let input_line = "self->drawFlags &= 0xFFFC;";
let expected_line = "self->drawFlags &= ~(FLAG_DRAW_ROTY | FLAG_DRAW_ROTX);";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
}

View File

@ -1,110 +1,58 @@
use regex::Regex;
use lazy_static::lazy_static;
use crate::line_transformer::LineTransformer;
use crate::bit_flag_line_transformer::BitFlagLineTransformer;
pub struct DrawModeTransformer;
impl LineTransformer for DrawModeTransformer {
fn transform_line(&self, line: &str) -> String {
transform_line_draw_mode(line)
}
pub struct DrawModeTransformer {
transformer: BitFlagLineTransformer<u16>,
}
lazy_static! {
static ref DRAW_MODES: [(u16, &'static str); 14] = {
let mut draw_modes = [
(1 << 0, "DRAW_TRANSP"),
(1 << 1, "DRAW_UNK02"),
(1 << 2, "DRAW_COLORS"),
(1 << 3, "DRAW_HIDE"),
(1 << 4, "DRAW_TPAGE"),
(1 << 5, "DRAW_TPAGE2"),
(1 << 6, "DRAW_UNK_40"),
(1 << 7, "DRAW_MENU"),
(1 << 8, "DRAW_UNK_100"),
(1 << 9, "DRAW_UNK_200"),
(1 << 10, "DRAW_UNK_400"),
(1 << 11, "DRAW_UNK_800"),
(1 << 12, "DRAW_UNK_1000"),
(1 << 13, "DRAW_ABSPOS"),
];
draw_modes.sort_by(|(a, _), (b, _)| b.cmp(a));
draw_modes
};
static ref REGEX: Regex = {
let pattern = r"([.>]drawMode\s*(?:[&|]?)=\s*)((?:0x)?[A-Fa-f0-9]*)(?:;)";
Regex::new(pattern).unwrap()
};
static ref DRAW_MODES: [(u16, &'static str); 14] = [
(1 << 0, "DRAW_TRANSP"),
(1 << 1, "DRAW_UNK02"),
(1 << 2, "DRAW_COLORS"),
(1 << 3, "DRAW_HIDE"),
(1 << 4, "DRAW_TPAGE"),
(1 << 5, "DRAW_TPAGE2"),
(1 << 6, "DRAW_UNK_40"),
(1 << 7, "DRAW_MENU"),
(1 << 8, "DRAW_UNK_100"),
(1 << 9, "DRAW_UNK_200"),
(1 << 10, "DRAW_UNK_400"),
(1 << 11, "DRAW_UNK_800"),
(1 << 12, "DRAW_UNK_1000"),
(1 << 13, "DRAW_ABSPOS"),
];
}
fn replace_enum(captures: &regex::Captures) -> String {
if let Some(assignment) = captures.get(1).map(|m| m.as_str().to_string()) {
if let Some(draw_mode) = captures.get(2).map(|m| m.as_str().to_string()) {
// if it starts with 0x, hex string, otherwise int
let mut draw_mode_value: u16;
if draw_mode.starts_with("0x") {
if let Ok(v) = u16::from_str_radix(draw_mode.strip_prefix("0x").unwrap(), 16) {
draw_mode_value = v;
} else {
return captures.get(0)
.map_or_else(|| "".to_string(), |m| m.as_str().to_string())
}
} else {
draw_mode_value = draw_mode.parse::<u16>().unwrap();
}
let invert: String;
if (draw_mode_value & 0x8000) != 0 {
invert = "~".to_string();
draw_mode_value = !draw_mode_value;
} else {
invert = "".to_string();
}
let mut rvalue: String;
if draw_mode_value == 0 {
rvalue = "DRAW_DEFAULT".to_string();
} else {
rvalue = DRAW_MODES.iter()
.map(|(mask, name)|
if (mask & draw_mode_value) != 0 {
Some(name)
} else {
None
})
.filter(|e| e.is_some())
.map(|e| *e.unwrap())
.collect::<Vec<&str>>()
.join(" | ");
if u16::count_ones(draw_mode_value) > 1 && invert == "~" {
rvalue = format!("({})", rvalue);
}
}
return format!("{}{}{};", assignment.to_string(), invert, rvalue);
impl DrawModeTransformer {
pub fn new() -> Self {
Self {
transformer: BitFlagLineTransformer::<u16>::new(
"drawMode", "DRAW_DEFAULT", &DRAW_MODES.iter().collect()),
}
}
captures
.get(0)
.map_or_else(|| "".to_string(), |m| m.as_str().to_string())
}
fn transform_line_draw_mode(line: &str) -> String {
REGEX.replace_all(line, |captures: &regex::Captures| replace_enum(captures)).to_string()
impl LineTransformer for DrawModeTransformer {
fn transform_line(&self, line: &str) -> String {
self.transformer.transform_line(line)
}
}
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
static DMT: Lazy<DrawModeTransformer> = Lazy::new(|| DrawModeTransformer::new());
#[test]
fn test_draw_mode_hex() {
let input_line = "self->drawMode = 0x30;";
let expected_line = "self->drawMode = DRAW_TPAGE2 | DRAW_TPAGE;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -112,7 +60,7 @@ mod tests {
fn test_draw_mode_decimal() {
let input_line = "self->drawMode = 32;";
let expected_line = "self->drawMode = DRAW_TPAGE2;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -120,7 +68,7 @@ mod tests {
fn test_draw_mode_zero() {
let input_line = "self->drawMode = 0;";
let expected_line = "self->drawMode = DRAW_DEFAULT;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -128,7 +76,7 @@ mod tests {
fn test_draw_mode_zero_hex() {
let input_line = "self->drawMode = 0x0;";
let expected_line = "self->drawMode = DRAW_DEFAULT;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -136,7 +84,7 @@ mod tests {
fn test_draw_mode_flags() {
let input_line = "self->drawMode = DRAW_TPAGE;";
let expected_line = "self->drawMode = DRAW_TPAGE;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -144,7 +92,7 @@ mod tests {
fn test_draw_mode_set() {
let input_line = "self->drawMode |= 0x80;";
let expected_line = "self->drawMode |= DRAW_MENU;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -152,7 +100,7 @@ mod tests {
fn test_draw_mode_clear() {
let input_line = "self->drawMode &= 0xFF7F;";
let expected_line = "self->drawMode &= ~DRAW_MENU;";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
@ -160,7 +108,16 @@ mod tests {
fn test_draw_mode_clear_many() {
let input_line = "self->drawMode &= 0xFFCF;";
let expected_line = "self->drawMode &= ~(DRAW_TPAGE2 | DRAW_TPAGE);";
let result = transform_line_draw_mode(input_line);
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_draw_mode_inverted_many() {
let input_line = "self->drawMode &= ~0x300;";
let expected_line = "self->drawMode &= ~(DRAW_UNK_200 | DRAW_UNK_100);";
let result = DMT.transform_line(input_line);
assert_eq!(result, expected_line)
}
}

View File

@ -0,0 +1,164 @@
use lazy_static::lazy_static;
use crate::line_transformer::LineTransformer;
use crate::bit_flag_line_transformer::BitFlagLineTransformer;
pub struct FlagsTransformer {
transformer: BitFlagLineTransformer<u32>,
}
lazy_static! {
static ref FLAGS: [(u32, &'static str); 28] = [
(1 << 4, "FLAG_UNK_10"),
(1 << 5, "FLAG_UNK_20"),
(1 << 6, "FLAG_UNK_40"),
(1 << 7, "FLAG_UNK_80"),
(1 << 8, "FLAG_DEAD"),
(1 << 9, "FLAG_UNK_200"),
(1 << 10, "FLAG_UNK_400"),
(1 << 11, "FLAG_UNK_800"),
(1 << 12, "FLAG_UNK_1000"),
(1 << 13, "FLAG_UNK_2000"),
(1 << 14, "FLAG_UNK_4000"),
(1 << 15, "FLAG_UNK_8000"),
(1 << 16, "FLAG_UNK_10000"),
(1 << 17, "FLAG_UNK_20000"),
(1 << 18, "FLAG_POS_PLAYER_LOCKED"),
(1 << 19, "FLAG_UNK_80000"),
(1 << 20, "FLAG_UNK_100000"),
(1 << 21, "FLAG_UNK_00200000"),
(1 << 22, "FLAG_UNK_400000"),
(1 << 23, "FLAG_HAS_PRIMS"),
(1 << 24, "FLAG_NOT_AN_ENEMY"),
(1 << 25, "FLAG_UNK_02000000"),
(1 << 26, "FLAG_KEEP_ALIVE_OFFCAMERA"),
(1 << 27, "FLAG_POS_CAMERA_LOCKED"),
(1 << 28, "FLAG_UNK_10000000"),
(1 << 29, "FLAG_UNK_20000000"),
(1 << 30, "FLAG_DESTROY_IF_BARELY_OUT_OF_CAMERA"),
(1 << 31, "FLAG_DESTROY_IF_OUT_OF_CAMERA"),
];
}
impl FlagsTransformer {
pub fn new() -> Self {
Self {
transformer: BitFlagLineTransformer::<u32>::new(
"flags", "0", &FLAGS.iter().collect()),
}
}
}
impl LineTransformer for FlagsTransformer {
fn transform_line(&self, line: &str) -> String {
if line.contains("g_BgLayers") ||
line.contains("g_Tilemap") {
return line.to_string();
}
self.transformer.transform_line(line)
}
}
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
static FT: Lazy<FlagsTransformer> = Lazy::new(|| FlagsTransformer::new());
#[test]
fn test_flags_hex() {
let input_line = "self->flags = 0x04070000;";
let expected_line = "self->flags = FLAG_KEEP_ALIVE_OFFCAMERA | FLAG_POS_PLAYER_LOCKED | FLAG_UNK_20000 | FLAG_UNK_10000;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_decimal() {
let input_line = "self->flags = 8781824;";
let expected_line = "self->flags = FLAG_HAS_PRIMS | FLAG_POS_PLAYER_LOCKED | FLAG_UNK_20000;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_zero() {
let input_line = "self->flags = 0;";
let expected_line = "self->flags = 0;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_zero_hex() {
let input_line = "self->flags = 0x0;";
let expected_line = "self->flags = 0;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_flags() {
let input_line = "self->flags = FLAG_HAS_PRIMS;";
let expected_line = "self->flags = FLAG_HAS_PRIMS;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_set() {
let input_line = "self->flags |= 0x2000;";
let expected_line = "self->flags |= FLAG_UNK_2000;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_clear() {
let input_line = "PLAYER.flags &= 0xFF7FFFFF;";
let expected_line = "PLAYER.flags &= ~FLAG_HAS_PRIMS;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_clear_many() {
let input_line = "self->flags &= 0xFF7FCFFF;";
let expected_line = "self->flags &= ~(FLAG_HAS_PRIMS | FLAG_UNK_2000 | FLAG_UNK_1000);";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_inverted_constant() {
let input_line = "self->flags &= ~256;";
let expected_line = "self->flags &= ~FLAG_DEAD;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_invalid_flags_ignored() {
let input_line = "self->flags = 0xf;";
let expected_line = "self->flags = 0xf;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_not_gb_layers_flags() {
let input_line = "g_BgLayers[0]->flags &= ~4;";
let expected_line = "g_BgLayers[0]->flags &= ~4;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
#[test]
fn test_flags_not_tilemap_flags() {
let input_line = "g_Tilemap->flags &= ~4;";
let expected_line = "g_Tilemap->flags &= ~4;";
let result = FT.transform_line(input_line);
assert_eq!(result, expected_line)
}
}

View File

@ -3,13 +3,18 @@ use std::io::{BufRead, BufReader, Write};
mod fixed;
mod line_transformer;
mod bit_flag_line_transformer;
mod relics;
mod drawmodes;
mod flags;
mod drawflags;
use crate::line_transformer::LineTransformer;
use line_transformer::LineTransformer;
use fixed::FixedTransformer;
use relics::RelicsTransformer;
use drawmodes::DrawModeTransformer;
use flags::FlagsTransformer;
use drawflags::DrawFlagsTransformer;
use rayon::prelude::*;
fn transform_file(file_path: &str, transformers: &Vec<Box<dyn LineTransformer>>) -> usize {
@ -30,13 +35,16 @@ fn transform_file(file_path: &str, transformers: &Vec<Box<dyn LineTransformer>>)
lines.push(line_str);
}
let mut file = File::create(file_path).expect("Unable to create file");
for (i, line) in lines.iter().enumerate() {
if lines[i] != original_lines[i] {
alterations += 1;
println!("{}: {} -> {}", i, original_lines[i], lines[i]);
if let Some(_) = original_lines.iter().zip(lines.iter()).position(|(a, b)| a != b) {
let mut file = File::create(file_path).expect("Unable to create file");
for (i, line) in lines.iter().enumerate() {
if lines[i] != original_lines[i] {
alterations += 1;
println!("{}: {} -> {}", i, original_lines[i], lines[i]);
}
writeln!(file, "{}", line).expect("Unable to write line to file");
}
writeln!(file, "{}", line).expect("Unable to write line to file");
}
alterations
@ -45,12 +53,16 @@ fn transform_file(file_path: &str, transformers: &Vec<Box<dyn LineTransformer>>)
fn process_directory(dir_path: &str) {
let fixed_transformer = FixedTransformer;
let relics_transformer = RelicsTransformer;
let draw_mode_transformer = DrawModeTransformer;
let draw_mode_transformer = DrawModeTransformer::new();
let flags_transformer = FlagsTransformer::new();
let draw_flags_transformer = DrawFlagsTransformer::new();
let transformers: Vec<Box<dyn LineTransformer>> = vec![
Box::new(fixed_transformer),
Box::new(relics_transformer),
Box::new(draw_mode_transformer),
Box::new(flags_transformer),
Box::new(draw_flags_transformer),
];
let entries = std::fs::read_dir(dir_path).expect("Unable to read directory");