Skip to content

Commit

Permalink
Reinitialize states, sprites, and mobjinfo from full contents of backup
Browse files Browse the repository at this point in the history
Also changes a number of instances of iteration over DoomObjContainers to use iterators
  • Loading branch information
electricbrass committed Dec 17, 2024
1 parent 8aed205 commit 1565c72
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
18 changes: 9 additions & 9 deletions client/src/cl_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ void G_InitNew (const char *mapname)
{
if (wantFast)
{
for (i = 0; i < ::num_state_t_types(); i++)
for (const auto& it : states)
{
state_t* state = states[i];
state_t* state = it.second;
if (state->flags & STATEF_SKILL5FAST &&
(state->tics != 1 || demoplayback))
state->tics >>= 1; // don't change 1->0 since it causes cycles
}

for (i = 0; i < ::num_mobjinfo_types(); ++i)
for (const auto& it : mobjinfo)
{
mobjinfo_t* minfo = mobjinfo[i];
mobjinfo_t* minfo = it.second;
if (minfo->altspeed != NO_ALTSPEED)
{
int swap = minfo->speed;
Expand All @@ -260,16 +260,16 @@ void G_InitNew (const char *mapname)
}
else
{
for (i = 0; i < ::num_state_t_types(); i++)
for (const auto& it : states)
{
state_t* state = states[i];
state_t* state = it.second;
if (state->flags & STATEF_SKILL5FAST)
state->tics <<= 1; // don't change 1->0 since it causes cycles
}

for (i = 0; i < ::num_mobjinfo_types(); ++i)
for (const auto& it : mobjinfo)
{
mobjinfo_t* minfo = mobjinfo[i];
mobjinfo_t* minfo = it.second;
if (minfo->altspeed != NO_ALTSPEED)
{
int swap = minfo->altspeed;
Expand Down Expand Up @@ -301,7 +301,7 @@ void G_InitNew (const char *mapname)
viewactive = true;

D_SetupUserInfo();

level.mapname = mapname;

// [AM}] WDL stats (for testing purposes)
Expand Down
15 changes: 12 additions & 3 deletions common/d_dehacked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ typedef struct
DoomObjectContainer<mobjinfo_t> backupMobjInfo; // doom_mobjinfo
DoomObjectContainer<const char*> backupSprnames; // doom_sprnames
DoomObjectContainer<const char*> backupSoundMap; // doom_SoundMap
std::vector<sfxinfo_t> backupS_sfx;
weaponinfo_t backupWeaponInfo[NUMWEAPONS + 1];
int backupMaxAmmo[NUMAMMO];
int backupClipAmmo[NUMAMMO];
Expand Down Expand Up @@ -628,6 +629,7 @@ static void BackupData(void)
std::copy(clipammo, clipammo + ::NUMAMMO, doomBackup.backupClipAmmo);
std::copy(maxammo, maxammo + ::NUMAMMO, doomBackup.backupMaxAmmo);
doomBackup.backupDeh = deh;
doomBackup.backupS_sfx = S_sfx;

BackedUpData = true;
}
Expand All @@ -653,10 +655,16 @@ void D_UndoDehPatch()
}
M_Free(OrgSprNames);


sprnames.clear();
sprnames.reserve(doomBackup.backupSprnames.size());
for (const auto& sprname : doomBackup.backupSprnames)
{
sprnames.insert(sprname.second, sprname.first);
}
// unsafe usage of data() here but to keep a consistent API
D_Initialize_sprnames(doomBackup.backupSprnames.data(), ::NUMSPRITES, SPR_TROO);
D_Initialize_States(doomBackup.backupStates.data(), ::NUMSTATES);
D_Initialize_Mobjinfo(doomBackup.backupMobjInfo.data(), ::NUMMOBJTYPES);
D_Initialize_States(doomBackup.backupStates.data(), doomBackup.backupStates.size());
D_Initialize_Mobjinfo(doomBackup.backupMobjInfo.data(), doomBackup.backupMobjInfo.size());
D_Initialize_SoundMap(doomBackup.backupSoundMap.data(), ARRAY_LENGTH(doom_SoundMap));

extern bool isFast;
Expand All @@ -668,6 +676,7 @@ void D_UndoDehPatch()
std::copy(doomBackup.backupMaxAmmo, doomBackup.backupMaxAmmo + ::NUMAMMO, maxammo);

deh = doomBackup.backupDeh;
S_sfx = doomBackup.backupS_sfx;

BackedUpData = false;
}
Expand Down
2 changes: 1 addition & 1 deletion common/p_pspr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void P_SetPspritePtr(player_t* player, pspdef_t* psp, int32_t stnum)
break;
}

if (stnum >= ::num_state_t_types())
if (states.find(stnum) == states.end())
return;

psp->state = states[stnum];
Expand Down
38 changes: 21 additions & 17 deletions server/src/sv_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,38 +422,42 @@ void G_InitNew(const char *mapname)
{
if (wantFast)
{
for (i = 0; i < ::num_state_t_types(); i++)
for (const auto& it : states)
{
if (states[i]->flags & STATEF_SKILL5FAST &&
(states[i]->tics != 1 || demoplayback))
states[i]->tics >>= 1; // don't change 1->0 since it causes cycles
state_t* state = it.second;
if (state->flags & STATEF_SKILL5FAST &&
(state->tics != 1 || demoplayback))
state->tics >>= 1; // don't change 1->0 since it causes cycles
}

for (i = 0; i < ::num_mobjinfo_types(); ++i)
for (const auto& it : mobjinfo)
{
if (mobjinfo[i]->altspeed != NO_ALTSPEED)
mobjinfo_t* minfo = it.second;
if (minfo->altspeed != NO_ALTSPEED)
{
int swap = mobjinfo[i]->speed;
mobjinfo[i]->speed = mobjinfo[i]->altspeed;
mobjinfo[i]->altspeed = swap;
int swap = minfo->speed;
minfo->speed = minfo->altspeed;
minfo->altspeed = swap;
}
}
}
else
{
for (i = 0; i < ::num_state_t_types(); i++)
for (const auto& it : states)
{
if (states[i]->flags & STATEF_SKILL5FAST)
states[i]->tics <<= 1; // don't change 1->0 since it causes cycles
state_t* state = it.second;
if (state->flags & STATEF_SKILL5FAST)
state->tics <<= 1; // don't change 1->0 since it causes cycles
}

for (i = 0; i < ::num_mobjinfo_types(); ++i)
for (const auto& it : mobjinfo)
{
if (mobjinfo[i]->altspeed != NO_ALTSPEED)
mobjinfo_t* minfo = it.second;
if (minfo->altspeed != NO_ALTSPEED)
{
int swap = mobjinfo[i]->altspeed;
mobjinfo[i]->altspeed = mobjinfo[i]->speed;
mobjinfo[i]->speed = swap;
int swap = minfo->altspeed;
minfo->altspeed = minfo->speed;
minfo->speed = swap;
}
}
}
Expand Down

0 comments on commit 1565c72

Please sign in to comment.