Skip to content

Commit

Permalink
SW: eliminated StateStart
Browse files Browse the repository at this point in the history
This was only used in two places, one now uses the texture replacement feature and the other, only used for a multiplayer item,
got a code-based solution.
  • Loading branch information
coelckers committed Nov 13, 2023
1 parent 215d929 commit cb947a2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 46 deletions.
18 changes: 3 additions & 15 deletions source/games/sw/src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,25 +472,14 @@ void WarpCopySprite(tspriteArray& tsprites)

void DoStarView(tspritetype* tsp, DSWActor* tActor, double viewz)
{
extern FState s_Star[], s_StarDown[];
extern FState s_StarStuck[], s_StarDownStuck[];
double zdiff = viewz - tsp->pos.Z;

if (abs(zdiff) > 24)
{
if (tActor->user.__legacyState.StateStart == s_StarStuck)
tsp->setspritetexture(picFromState(&s_StarDownStuck[tActor->user.State - s_StarStuck]));
else
tsp->setspritetexture(picFromState(&s_StarDown[tActor->user.State - s_Star]));

if (zdiff > 0)
tsp->cstat |= (CSTAT_SPRITE_YFLIP);
}
else
{
if (zdiff > 0)
tsp->cstat |= (CSTAT_SPRITE_YFLIP);
tsp->setspritetexture(GetTextureReplacement(tsp->spritetexture(), NAME_StarView));
}
if (zdiff > 0)
tsp->cstat |= (CSTAT_SPRITE_YFLIP);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -1061,7 +1050,6 @@ void PreDrawStackedWater(void)
// analyzesprites() needs to draw the image
actorNew->user.State = itActor2->user.State;
actorNew->user.__legacyState.Rot = itActor2->user.__legacyState.Rot;
actorNew->user.__legacyState.StateStart = itActor2->user.__legacyState.StateStart;
actorNew->user.__legacyState.StateEnd = itActor2->user.__legacyState.StateEnd;
actorNew->user.Flags = itActor2->user.Flags;
actorNew->user.Flags2 = itActor2->user.Flags2;
Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ struct USER
struct LegacyState
{
FState* Rot;
FState* StateStart;
FState* StateEnd;
FState* StateFallOverride; // a bit kludgy - override std fall state
ACTOR_ACTION_SET* ActorActionSet;
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/namelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ x(CARD_LOCKED, 1852)
x(CARD_UNLOCKED, 1853)
x(BREAK_LIGHT, 443)
x(BREAK_MUSHROOM, 666)
x(STAR1, 2049)
x(STAR1, 2049) // this is not a texture - just a spawn ID!
x(CRACK, 80)
x(BLADE4, 5011)
x(FFIRE1, 3143)
Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ void UpdatePlayerUnderSprite(DSWPlayer* pp)

act_under->user.State = act_over->user.State;
act_under->user.__legacyState.Rot = act_over->user.__legacyState.Rot;
act_under->user.__legacyState.StateStart = act_over->user.__legacyState.StateStart;
act_under->spr.setspritetexture(act_over->spr.spritetexture());
}

Expand Down
2 changes: 0 additions & 2 deletions source/games/sw/src/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,11 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
// The default serializer cannot handle the statically defined states so call these functons explicitly.
_Serialize(arc, "State", w.State, &def->State);
_Serialize(arc, "Rot", w.__legacyState.Rot, &def->__legacyState.Rot);
_Serialize(arc, "StateStart", w.__legacyState.StateStart, &def->__legacyState.StateStart);
_Serialize(arc, "StateEnd", w.__legacyState.StateEnd, &def->__legacyState.StateEnd);
_Serialize(arc, "StateFallOverride", w.__legacyState.StateFallOverride, &def->__legacyState.StateFallOverride);
/*
("State", w.State, def->State)
("Rot", w.__legacyState.Rot, def->__legacyState.Rot)
("StateStart", w.__legacyState.StateStart, def->__legacyState.StateStart)
("StateEnd", w.__legacyState.StateEnd, def->__legacyState.StateEnd)
("StateFallOverride", w.__legacyState.StateFallOverride, def->__legacyState.StateFallOverride)
*/
Expand Down
57 changes: 31 additions & 26 deletions source/games/sw/src/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ void ChangeState(DSWActor* actor, FState* statep)
return;

actor->user.Tics = 0;
actor->user.State = actor->user.__legacyState.StateStart = statep;
actor->spr.cstat2 |= CSTAT2_SPRITE_NOANIMATE; // just in case
}

Expand Down Expand Up @@ -761,8 +760,6 @@ void SpawnUser(DSWActor* actor, short id, FState* state)
PRODUCTION_ASSERT(actor->hasU());

// be careful State can be nullptr
actor->user.State = actor->user.__legacyState.StateStart = state;

change_actor_stat(actor, actor->spr.statnum);

actor->user.ID = id;
Expand Down Expand Up @@ -4202,7 +4199,6 @@ int NewStateGroup(DSWActor* actor, FState* StateGroup)
return 0;

actor->user.__legacyState.Rot = StateGroup;
actor->user.State = actor->user.__legacyState.StateStart = StateGroup;

actor->user.Tics = 0;

Expand Down Expand Up @@ -4682,6 +4678,18 @@ int DoKey(DSWActor* actor)
//
//---------------------------------------------------------------------------

static FState* LookForFrame(FState* start, int frame)
{
auto state = start;
// try to do this as hack-free as possible, but make no assumptions about the state organization.
while (state && state->NextState == state + 1 && state->sprite == start->sprite)
{
if (state->Frame == frame) return state;
state++;
}
return start;
}

int DoCoin(DSWActor* actor)
{
int offset;
Expand All @@ -4696,26 +4704,34 @@ int DoCoin(DSWActor* actor)

if (actor->user.WaitTics < 10*120)
{
if (actor->user.__legacyState.StateStart != s_GreenCoin)
if (actor->spr.inittype == 1)
{
offset = int(actor->user.State - actor->user.__legacyState.StateStart);
ChangeState(actor, s_GreenCoin);
actor->user.State = actor->user.__legacyState.StateStart + offset;
actor->spr.inittype = 2;
ChangeState(actor, LookForFrame(s_GreenCoin, actor->user.State->Frame));
}
}
else if (actor->user.WaitTics < 20*120)
{
if (actor->user.__legacyState.StateStart != s_YellowCoin)
if (actor->spr.inittype == 0)
{
offset = int(actor->user.State - actor->user.__legacyState.StateStart);
ChangeState(actor, s_YellowCoin);
actor->user.State = actor->user.__legacyState.StateStart + offset;
actor->spr.inittype = 1;
ChangeState(actor, LookForFrame(s_YellowCoin, actor->user.State->Frame));
}
}

return 0;
}


void SpawnCoin(DSWActor* actor)
{
auto actorNew = SpawnActor(STAT_ITEM, Red_COIN, s_RedCoin, actor->sector(), actor->spr.pos, nullAngle);

actorNew->spr.inittype = 0;
actorNew->spr.shade = -20;
actorNew->user.WaitTics = actor->user.WaitTics - 12;

}
//---------------------------------------------------------------------------
//
//
Expand Down Expand Up @@ -4746,11 +4762,8 @@ int KillGet(DSWActor* actor)
if (!gNet.SpawnMarkers || actor->spr.hitag == TAG_NORESPAWN_FLAG) // No coin if it's a special flag
break;

auto actorNew = SpawnActor(STAT_ITEM, Red_COIN, s_RedCoin, actor->sector(), actor->spr.pos, nullAngle);

actorNew->spr.shade = -20;
actorNew->user.WaitTics = actor->user.WaitTics - 12;

SpawnCoin(actor);
break;
}
return 0;
Expand Down Expand Up @@ -4794,11 +4807,7 @@ int KillGetAmmo(DSWActor* actor)
if (!gNet.SpawnMarkers)
break;

auto actorNew = SpawnActor(STAT_ITEM, Red_COIN, s_RedCoin, actor->sector(), actor->spr.pos, nullAngle);

actorNew->spr.shade = -20;
actorNew->user.WaitTics = actor->user.WaitTics - 12;

SpawnCoin(actor);
break;
}
return 0;
Expand Down Expand Up @@ -4850,11 +4859,7 @@ int KillGetWeapon(DSWActor* actor)
if (!gNet.SpawnMarkers)
break;

auto actorNew = SpawnActor(STAT_ITEM, Red_COIN, s_RedCoin, actor->sector(), actor->spr.pos, nullAngle);

actorNew->spr.shade = -20;
actorNew->user.WaitTics = actor->user.WaitTics - 12;

SpawnCoin(actor);
break;
}
return 0;
Expand Down
8 changes: 8 additions & 0 deletions wadsrc/static/filter/shadowwarrior/rmapinfo.texflags
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ texturereplace shotgun2
SHOTGUN_RELOAD1 = SHOTGUN2_RELOAD1
SHOTGUN_RELOAD2 = SHOTGUN2_RELOAD2
}

texturereplace StarView
{
"STAR@A1" = "STAR_DOWN@A1"
"STAR@B1" = "STAR_DOWN@B1"
"STAR@C1" = "STAR_DOWN@C1"
"STAR@D1" = "STAR_DOWN@D1"
}

0 comments on commit cb947a2

Please sign in to comment.