Skip to content

Commit

Permalink
- adapt sprite rotation code to proper states.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed May 29, 2023
1 parent 80a0f62 commit 1445fb9
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 112 deletions.
4 changes: 1 addition & 3 deletions source/games/sw/src/actor.cpp
Expand Up @@ -181,7 +181,7 @@ int DoActorDie(DSWActor* actor, DSWActor* weapActor, int meansofdeath)
DoActorBeginJump(actor);
}

actor->user.__legacyState.RotNum = 0;


actor->clearActionFunc();
if (!sw_ninjahack)
Expand Down Expand Up @@ -957,8 +957,6 @@ int DoFall(DSWActor* actor)
void DSWActor::ChangeStateEnd()
{
ChangeState(this, user.__legacyState.StateEnd);
user.__legacyState.RotNum = 0;

}

Personality* DSWActor::getPersonality()
Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/coolie.cpp
Expand Up @@ -303,7 +303,6 @@ void EnemyDefaults(DSWActor* actor, ACTOR_ACTION_SET* action, PERSONALITY* perso

actor->user.spal = actor->spr.pal;

actor->user.__legacyState.RotNum = 5;
actor->clipdist = 16;

actor->user.zclip = 48;
Expand Down
85 changes: 25 additions & 60 deletions source/games/sw/src/draw.cpp
Expand Up @@ -98,8 +98,7 @@ void ShadeSprite(tspritetype* tsp)
//
//
//---------------------------------------------------------------------------

int GetRotation(tspriteArray& tsprites, int tSpriteNum, const DVector2& view)
int SetActorRotation(tspriteArray& tsprites, int tSpriteNum, const DVector2& viewpos)
{
static const uint8_t RotTable8[] = {0, 7, 6, 5, 4, 3, 2, 1};
static const uint8_t RotTable5[] = {0, 1, 2, 3, 4, 3, 2, 1};
Expand All @@ -108,16 +107,33 @@ int GetRotation(tspriteArray& tsprites, int tSpriteNum, const DVector2& view)
tspritetype* tsp = tsprites.get(tSpriteNum);
auto ownerActor = static_cast<DSWActor*>(tsp->ownerActor);

if (!ownerActor->hasU() || ownerActor->user.__legacyState.RotNum == 0)
if (!ownerActor->hasU())
return 0;

unsigned sprite = ownerActor->user.__legacyState.State->Sprite;
unsigned frame = ownerActor->user.__legacyState.State->Frame - 'A';

if (SpriteDefs.Size() <= sprite) return 0;
auto spdef = &SpriteDefs[sprite];
if (SpriteFrames.Size() <= spdef->numframes) return 0;
auto spframe = &SpriteFrames[spdef->spriteframes + frame];
if (spframe->RotMode == 0) return 0;
if (spframe->RotMode == 1)
{
tsp->setspritetexture(spframe->Texture[0]);
return 0;
}

if (spframe->RotMode != 5 && spframe->RotMode != 8) return 0;


// Get which of the 8 angles of the sprite to draw (0-7)
// rotation ranges from 0-7
DAngle angle2 = (tsp->pos - view).Angle();
DAngle angle2 = (tsp->pos - viewpos).Angle();
rotation = (tsp->Angles.Yaw + DAngle180 + DAngle22_5 * 0.5 - angle2).Buildang() & 2047;
rotation = (rotation >> 8) & 7;

if (ownerActor->user.__legacyState.RotNum == 5)
if (spframe->RotMode == 5)
{
if ((ownerActor->user.Flags & SPR_XFLIP_TOGGLE))
{
Expand Down Expand Up @@ -153,60 +169,11 @@ int GetRotation(tspriteArray& tsprites, int tSpriteNum, const DVector2& view)
ID == SAILORGIRL_R0)
tsp->cstat &= ~(CSTAT_SPRITE_XFLIP); // clear x-flipping bit

return RotTable5[rotation];
}

return RotTable8[rotation];

}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

/*
!AIC - At draw time this is called for actor rotation. GetRotation() is more
complex than needs to be in part because importing of actor rotations and x-flip
directions was not standardized.
*/

int SetActorRotation(tspriteArray& tsprites, int tSpriteNum, const DVector2& viewpos)
{
tspritetype* tsp = tsprites.get(tSpriteNum);
auto ownerActor = static_cast<DSWActor*>(tsp->ownerActor);
int StateOffset, Rotation;

if (!ownerActor->hasU()) return 0;
// don't modify ANY tu vars - back them up!
STATE* State = ownerActor->user.__legacyState.State;
STATE* StateStart = ownerActor->user.__legacyState.StateStart;

if (ownerActor->user.__legacyState.RotNum == 0)
tsp->setspritetexture(spframe->Texture[RotTable5[rotation]]);
return 0;
}

// Get the offset into the State animation
StateOffset = int(State - StateStart);

// Get the rotation angle
Rotation = GetRotation(tsprites, tSpriteNum, viewpos);

ASSERT(Rotation < 5);

// Reset the State animation start based on the Rotation
StateStart = ownerActor->user.__legacyState.Rot[Rotation];

// Set the sprites state
State = StateStart + StateOffset;

// set the picnum here - may be redundant, but we just changed states and
// thats a big deal
//tsp->p icnum = State->Pic;

tsp->setspritetexture(spframe->Texture[RotTable8[rotation]]);
return 0;
}

Expand Down Expand Up @@ -702,8 +669,7 @@ static void analyzesprites(tspriteArray& tsprites, const DVector3& viewpos, doub
}

// rotation
if (tActor->user.__legacyState.RotNum > 0)
SetActorRotation(tsprites, tSpriteNum, viewpos.XY());
SetActorRotation(tsprites, tSpriteNum, viewpos.XY());

if (tActor->user.motion_blur_num)
{
Expand Down Expand Up @@ -1099,7 +1065,6 @@ void PreDrawStackedWater(void)
actorNew->user.__legacyState.StateEnd = itActor2->user.__legacyState.StateEnd;
actorNew->user.Flags = itActor2->user.Flags;
actorNew->user.Flags2 = itActor2->user.Flags2;
actorNew->user.__legacyState.RotNum = itActor2->user.__legacyState.RotNum;
actorNew->user.ID = itActor2->user.ID;

actorNew->user.PlayerP = itActor2->user.PlayerP;
Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/jsector.cpp
Expand Up @@ -180,7 +180,6 @@ void JS_SpriteSetup(void)
{
SpawnUser(itActor, 0, nullptr);

itActor->user.__legacyState.RotNum = 0;
itActor->user.WaitTics = itActor->spr.lotag * 120;

itActor->user.ActorActionFunc = AF(GenerateDrips);
Expand Down
24 changes: 12 additions & 12 deletions source/games/sw/src/miscactr.cpp
Expand Up @@ -124,7 +124,7 @@ int SetupToiletGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &ToiletGirlAttrib;
actor->user.__legacyState.StateEnd = s_ToiletGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.5, 0.5);
actor->vel.X = 0;
Expand Down Expand Up @@ -371,7 +371,7 @@ int SetupWashGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &WashGirlAttrib;
actor->user.__legacyState.StateEnd = s_WashGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.4374, 0.375);
actor->vel.X = 0;
Expand Down Expand Up @@ -595,7 +595,7 @@ int SetupTrashCan(DSWActor* actor)
actor->user.__legacyState.Attrib = &TrashCanAttrib;
actor->user.__legacyState.StateEnd = s_TrashCanStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;



actor->spr.scale = DVector2(0.71875, 0.65625);
Expand Down Expand Up @@ -704,7 +704,7 @@ int SetupPachinkoLight(DSWActor* actor)
actor->user.__legacyState.Attrib = &PachinkoLightAttrib;
actor->user.__legacyState.StateEnd = s_PachinkoLightStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;

actor->user.ID = PACHINKOLIGHT_R0;

actor->vel.X = 0;
Expand Down Expand Up @@ -806,7 +806,7 @@ int SetupPachinko1(DSWActor* actor)
actor->user.__legacyState.Attrib = &Pachinko1Attrib;
actor->user.__legacyState.StateEnd = s_Pachinko1Stand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;

actor->user.ID = PACHINKO1;

actor->vel.Z = 0;
Expand Down Expand Up @@ -976,7 +976,7 @@ int SetupPachinko2(DSWActor* actor)
actor->user.__legacyState.Attrib = &Pachinko2Attrib;
actor->user.__legacyState.StateEnd = s_Pachinko2Stand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;

actor->user.ID = PACHINKO2;

actor->vel.Z = 0;
Expand Down Expand Up @@ -1058,7 +1058,7 @@ int SetupPachinko3(DSWActor* actor)
actor->user.__legacyState.Attrib = &Pachinko3Attrib;
actor->user.__legacyState.StateEnd = s_Pachinko3Stand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;

actor->user.ID = PACHINKO3;

actor->vel.Z = 0;
Expand Down Expand Up @@ -1141,7 +1141,7 @@ int SetupPachinko4(DSWActor* actor)
actor->user.__legacyState.Attrib = &Pachinko4Attrib;
actor->user.__legacyState.StateEnd = s_Pachinko4Stand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;

actor->user.ID = PACHINKO4;

actor->vel.Z = 0;
Expand Down Expand Up @@ -1247,7 +1247,7 @@ int SetupCarGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &CarGirlAttrib;
actor->user.__legacyState.StateEnd = s_CarGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.453125, 0.390625);
actor->vel.X = 0;
Expand Down Expand Up @@ -1473,7 +1473,7 @@ int SetupMechanicGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &MechanicGirlAttrib;
actor->user.__legacyState.StateEnd = s_MechanicGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.421875, 0.40625);
actor->vel.X = 0;
Expand Down Expand Up @@ -1698,7 +1698,7 @@ int SetupSailorGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &SailorGirlAttrib;
actor->user.__legacyState.StateEnd = s_SailorGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.4375, 0.40625);
actor->vel.X = 0;
Expand Down Expand Up @@ -1920,7 +1920,7 @@ int SetupPruneGirl(DSWActor* actor)
actor->user.__legacyState.Attrib = &PruneGirlAttrib;
actor->user.__legacyState.StateEnd = s_PruneGirlStand;
actor->user.__legacyState.Rot = 0;
actor->user.__legacyState.RotNum = 0;


actor->spr.scale = DVector2(0.515625, 0.4375);
actor->vel.X = 0;
Expand Down
8 changes: 3 additions & 5 deletions source/games/sw/src/ninja.cpp
Expand Up @@ -1247,7 +1247,7 @@ int DoNinjaHariKari(DSWActor* actor)
actor->user.Flags |= (SPR_DEAD);
actor->user.Flags &= ~(SPR_FALLING | SPR_JUMPING);
actor->user.floor_dist = (40);
actor->user.__legacyState.RotNum = 0;

actor->clearActionFunc();

actor->spr.extra |= (SPRX_BREAKABLE);
Expand Down Expand Up @@ -1282,7 +1282,7 @@ int DoNinjaGrabThroat(DSWActor* actor)
actor->user.Flags |= (SPR_DEAD);
actor->user.Flags &= ~(SPR_FALLING | SPR_JUMPING);
actor->user.floor_dist = (40);
actor->user.__legacyState.RotNum = 0;

actor->clearActionFunc();

actor->spr.extra |= (SPRX_BREAKABLE);
Expand Down Expand Up @@ -1718,8 +1718,6 @@ void InitPlayerSprite(PLAYER* pp, const DVector3& spawnpos, const DAngle startan
actor->user.__legacyState.Rot = sg_NinjaRun;
actor->user.__legacyState.ActorActionSet = &PlayerNinjaActionSet;

actor->user.__legacyState.RotNum = 5;

actor->user.Radius = 400;
actor->user.PlayerP = pp;
//actor->user.Health = pp->MaxHealth;
Expand Down Expand Up @@ -1785,7 +1783,7 @@ void SpawnPlayerUnderSprite(PLAYER* pp)
actor->spr.extra |= (SPRX_PLAYER_OR_ENEMY);

actor->user.__legacyState.Rot = sg_NinjaRun;
actor->user.__legacyState.RotNum = plActor->user.__legacyState.RotNum;
actor->user.__legacyState.State = plActor->user.__legacyState.State;
NewStateGroup(pp->PlayerUnderActor, plActor->user.__legacyState.Rot);

actor->user.Radius = plActor->user.Radius;
Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/save.cpp
Expand Up @@ -751,7 +751,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
("flags", w.Flags, def->Flags)
("flags2", w.Flags2, def->Flags2)
("Tics", w.Tics, def->Tics)
("RotNum", w.__legacyState.RotNum, def->__legacyState.RotNum)
("ID", w.ID, def->ID)
("Health", w.Health, def->Health)
("MaxHealth", w.MaxHealth, def->MaxHealth)
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/skull.cpp
Expand Up @@ -286,7 +286,7 @@ int DoSkullBeginDeath(DSWActor* actor)
}

actor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN);
actor->user.__legacyState.RotNum = 0;

actor->user.Tics = 0;
actor->user.ID = SKULL_R0;
actor->user.Radius = DamageData[DMG_SKULL_EXP].radius; //*DamageRadiusSkull;
Expand Down Expand Up @@ -644,7 +644,7 @@ int DoBettyBeginDeath(DSWActor* actor)
}

actor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN);
actor->user.__legacyState.RotNum = 0;

actor->user.Tics = 0;
actor->user.ID = BETTY_R0;
actor->user.Radius = DamageData[DMG_SKULL_EXP].radius; //*DamageRadiusBetty;
Expand Down
4 changes: 1 addition & 3 deletions source/games/sw/src/track.cpp
Expand Up @@ -801,8 +801,6 @@ void SectorObjectSetupBounds(SECTOR_OBJECT* sop)
if (!itActor->hasU())
SpawnUser(itActor, 0, nullptr);

itActor->user.__legacyState.RotNum = 0;

itActor->backuppos();
itActor->user.oz = itActor->opos.Z;

Expand Down Expand Up @@ -3124,7 +3122,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
break;

case TRACK_ACTOR_DEATH1:
if (actor->hasState(NAME_Death2))
if (actor->hasState(NAME_Death1))
{
actor->user.WaitTics = 4 * 120;
actor->setStateGroup(NAME_Death1);
Expand Down

0 comments on commit 1445fb9

Please sign in to comment.