Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for wad command #3

Merged
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
1 change: 1 addition & 0 deletions client/src/d_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ void STACK_ARGS D_Shutdown()
// stop sound effects and music
S_Stop();
S_Deinit();
S_ClearSoundLumps();

// shutdown automap
AM_Stop();
Expand Down
2 changes: 0 additions & 2 deletions client/src/s_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,6 @@ void S_AddRandomSound(int owner, std::vector<int>& list)
// Parses all loaded SNDINFO lumps.
void S_ParseSndInfo()
{
S_ClearSoundLumps();

int lump = -1;
while ((lump = W_FindLump("SNDINFO", lump)) != -1)
{
Expand Down
68 changes: 29 additions & 39 deletions common/d_dehacked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,19 +532,6 @@ static BOOL HandleKey(const struct Key* keys, void* structure, const char* key,
return true;
}

/*
typedef struct
{
state_t backupStates[::NUMSTATES];
mobjinfo_t backupMobjInfo[::NUMMOBJTYPES];
weaponinfo_t backupWeaponInfo[NUMWEAPONS + 1];
const char** backupSprnames;
int backupMaxAmmo[NUMAMMO];
int backupClipAmmo[NUMAMMO];
DehInfo backupDeh;
} DoomBackup;
*/

typedef struct
{
DoomObjectContainer<state_t> backupStates; // boomstates
Expand Down Expand Up @@ -589,35 +576,35 @@ static void BackupData(void)
}

// states
doomBackup.backupStates.resize(::NUMSTATES);
doomBackup.backupStates.clear();
doomBackup.backupStates.reserve(states.size());
for (const std::pair<int32_t, state_t*> & it : states)
{
state_t state = *it.second;
doomBackup.backupStates.insert(state, it.first);
}

// mobjinfo
doomBackup.backupMobjInfo.resize(::NUMMOBJTYPES);
doomBackup.backupMobjInfo.clear();
doomBackup.backupMobjInfo.reserve(mobjinfo.size());
for (const std::pair<int32_t, mobjinfo_t*> & it : mobjinfo)
{
mobjinfo_t mobj = *it.second;
doomBackup.backupMobjInfo.insert(mobj, it.first);
}

// sprites
doomBackup.backupSprnames.resize(::NUMSPRITES);
doomBackup.backupSprnames.clear();
doomBackup.backupSprnames.reserve(sprnames.size());
for(const std::pair<int32_t, const char*> & it : sprnames)
{
const char* spr = strdup(it.second);
doomBackup.backupSprnames.insert(spr, it.first);
}

// sounds
doomBackup.backupSoundMap.resize(ARRAY_LENGTH(doom_SoundMap));
doomBackup.backupSoundMap.clear();
doomBackup.backupSoundMap.reserve(SoundMap.size());
for(const std::pair<int32_t, const char*> & it : SoundMap)
{
const char* sound = strdup(it.second);
Expand Down Expand Up @@ -653,11 +640,17 @@ 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_SoundMap(doomBackup.backupSoundMap.data(), ARRAY_LENGTH(doom_SoundMap));
D_Initialize_States(doomBackup.backupStates.data(), static_cast<int>(doomBackup.backupStates.size()));
D_Initialize_Mobjinfo(doomBackup.backupMobjInfo.data(), static_cast<int>(doomBackup.backupMobjInfo.size()));
D_Initialize_SoundMap(doomBackup.backupSoundMap.data(), static_cast<int>(doomBackup.backupSoundMap.size()));

extern bool isFast;
isFast = false;
Expand Down Expand Up @@ -2052,12 +2045,11 @@ static int PatchPointer(int ptrNum)
int i = atoi(Line2);

// [CMB]: dsdhacked allows infinite code pointers
// if (i >= ::num_state_t_types())
// is patchpointer supported at all for dsdhacked or does it only work for the original set of states, its deprecated in bex anyway
if (states.find(i) == states.end())
{
DPrintf("Pointer %d overruns array (max: %d wanted: %d)."
"\n",
ptrNum, ::num_state_t_types(), i);
DPrintf("Source frame %d not found while patching pointer %d.\n",
i, ptrNum);
}
else
{
Expand Down Expand Up @@ -2729,43 +2721,41 @@ static CodePtr null_bexptr = {"(NULL)", NULL, 0, {0, 0, 0, 0, 0, 0, 0, 0}};

void D_PostProcessDeh()
{
int i, j;
int i;
const CodePtr* bexptr_match;
int num_state_t_types = ::num_state_t_types();

// [CMB] TODO: using ptr here is just to go from front to back - iterator is BETTER but this works
state_t** statesptr = states.data();
for (i = 0; i < num_state_t_types; i++)
for (const auto& it : states)
{
state_t* state = it.second;
bexptr_match = &null_bexptr;

for (j = 1; CodePtrs[j].func != NULL; ++j)
for (i = 1; CodePtrs[i].func != NULL; ++i)
{
if (statesptr[i]->action == CodePtrs[j].func)
if (state->action == CodePtrs[i].func)
{
bexptr_match = &CodePtrs[j];
bexptr_match = &CodePtrs[i];
break;
}
}

// ensure states don't use more mbf21 args than their
// action pointer expects, for future-proofing's sake
for (j = MAXSTATEARGS - 1; j >= bexptr_match->argcount; j--)
for (i = MAXSTATEARGS - 1; i >= bexptr_match->argcount; i--)
{
if (statesptr[i]->args[j] != 0)
if (state->args[i] != 0)
{
I_Error("Action %s on state %d expects no more than %d nonzero args (%d "
"found). Check your DEHACKED.",
bexptr_match->name, i, bexptr_match->argcount, j + 1);
bexptr_match->name, state->statenum, bexptr_match->argcount, i + 1);
}
}

// replace unset fields with default values
for (; j >= 0; j--)
for (; i >= 0; i--)
{
if (statesptr[i]->args[j] == 0 && bexptr_match->default_args[j])
if (state->args[i] == 0 && bexptr_match->default_args[i])
{
statesptr[i]->args[j] = bexptr_match->default_args[j];
state->args[i] = bexptr_match->default_args[i];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/doom_obj_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "info.h" // doom object definitions - including enums with negative indices

/*
extern state_t odastates[]; //statenum_t
extern state_t odastates[]; //statenum_t
extern mobjinfo_t odathings[]; //mobjtype_t
extern const char* odasprnames[]; // spritenum_t

Expand Down Expand Up @@ -92,8 +92,8 @@
const_iterator find(IdxType idx) const;
bool contains(IdxType idx) const;

friend ObjType operator-(ObjType obj, DoomObjectContainerType& container);

Check warning on line 95 in common/doom_obj_container.h

View workflow job for this annotation

GitHub Actions / Build (SDL 2.0)

friend declaration ‘ObjType operator-(ObjType, DoomObjectContainer<ObjType, IdxType, InOrderContainer>::DoomObjectContainerType&)’ declares a non-template function [-Wnon-template-friend]
friend ObjType operator+(DoomObjectContainerType& container, WORD ofs);

Check warning on line 96 in common/doom_obj_container.h

View workflow job for this annotation

GitHub Actions / Build (SDL 2.0)

friend declaration ‘ObjType operator+(DoomObjectContainer<ObjType, IdxType, InOrderContainer>::DoomObjectContainerType&, WORD)’ declares a non-template function [-Wnon-template-friend]

private:
ResetObjType rf;
Expand Down Expand Up @@ -213,8 +213,8 @@
template <typename ObjType, typename IdxType, typename InOrderContainer>
void DoomObjectContainer<ObjType, IdxType, InOrderContainer>::clear()
{
this->container.erase(container.begin(), container.end());
this->lookup_table.erase(lookup_table.begin(), lookup_table.end());
this->container.clear();
this->lookup_table.clear();
}

// Allocation changes
Expand Down
37 changes: 29 additions & 8 deletions common/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static inline unsigned int __hash_cstring(const char* str)
unsigned int val = 0;
while (*str != 0)
val = val * 101 + *str++;
return val;
return val;
}

template <> struct hashfunc<char*>
Expand Down Expand Up @@ -273,7 +273,7 @@ class OHashTable
do {
mBucketNum++;
} while (mBucketNum < mHashTable->mSize && mHashTable->emptyBucket(mBucketNum));

if (mBucketNum >= mHashTable->mSize)
mBucketNum = IHTT::NOT_FOUND;
return *this;
Expand Down Expand Up @@ -379,7 +379,7 @@ class OHashTable
inline const_iterator end() const
{
return const_iterator(NOT_FOUND, this);
}
}

inline iterator find(const KT& key)
{
Expand Down Expand Up @@ -407,7 +407,7 @@ class OHashTable

std::pair<iterator, bool> insert(const HashPairType& hp)
{
unsigned int oldused = mUsed;
unsigned int oldused = mUsed;
IndexType bucketnum = insertElement(hp.first, hp.second);
return std::pair<iterator, bool>(iterator(bucketnum, this), mUsed > oldused);
}
Expand All @@ -424,7 +424,7 @@ class OHashTable

void erase(iterator it)
{
eraseBucket(it.mBucketNum);
eraseBucket(it.mBucketNum);
}

unsigned int erase(const KT& key)
Expand All @@ -440,9 +440,30 @@ class OHashTable
{
while (it1 != it2)
{
eraseBucket(it1.mBucketNum);
mElements[it1.mBucketNum].order = 0;
mElements[it1.mBucketNum].pair = HashPairType();
mUsed--;
++it1;
}
// Rehash all of the non-empty buckets that follow the erased buckets.
IndexType bucketnum = it2.mBucketNum & mSizeMask;
while (!emptyBucket(bucketnum))
{
const KT& key = mElements[bucketnum].pair.first;
unsigned int order = mElements[bucketnum].order;
mElements[bucketnum].order = 0;

IndexType new_bucketnum = findBucket(key);
mElements[new_bucketnum].order = order;

if (new_bucketnum != bucketnum)
{
mElements[new_bucketnum].pair = mElements[bucketnum].pair;
mElements[bucketnum].pair = HashPairType();
}

bucketnum = (bucketnum + 1) & mSizeMask;
}
}

private:
Expand Down Expand Up @@ -507,7 +528,7 @@ class OHashTable

inline IndexType findBucket(const KT& key) const
{
IndexType bucketnum = (mHashFunc(key) * 2654435761u) & mSizeMask;
IndexType bucketnum = (mHashFunc(key) * 2654435761u) & mSizeMask;

// [SL] NOTE: this can loop infinitely if there is no match and the table is full!
while (!emptyBucket(bucketnum) && mElements[bucketnum].pair.first != key)
Expand Down Expand Up @@ -560,7 +581,7 @@ class OHashTable
if (new_bucketnum != bucketnum)
{
mElements[new_bucketnum].pair = mElements[bucketnum].pair;
mElements[bucketnum].pair = HashPairType();
mElements[bucketnum].pair = HashPairType();
}

bucketnum = (bucketnum + 1) & mSizeMask;
Expand Down
8 changes: 4 additions & 4 deletions common/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,16 +3268,16 @@ BEGIN_COMMAND(cheat_mobjs)
const char* mobj_type = argv[1];
ptrdiff_t mobj_index = -1;

// [CMB] TODO: should we use an iterator here?
for (size_t i = 0; i < ::num_mobjinfo_types(); i++)
for (const auto& it : mobjinfo)
{
if (stricmp(::mobjinfo[i]->name, mobj_type) == 0)
if (stricmp(it.second->name, mobj_type) == 0)
{
mobj_index = i;
mobj_index = it.first;
break;
}
}

// TODO: index < 0 is valid now with dsdhacked
if (mobj_index < 0)
{
Printf("Unknown MT_* mobj type\n");
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
1 change: 1 addition & 0 deletions server/src/d_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void STACK_ARGS D_Shutdown()

// stop sound effects and music
S_Stop();
S_ClearSoundLumps();

DThinker::DestroyAllThinkers();

Expand Down
6 changes: 2 additions & 4 deletions server/src/s_sound.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Emacs style mode select -*- C++ -*-
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id$
Expand Down Expand Up @@ -258,7 +258,7 @@ int S_FindSound(const char *logicalname)

int S_FindSoundByLump(int lump)
{
if (lump != -1)
if (lump != -1)
{
for (unsigned i = 0; i < S_sfx.size(); i++)
if (S_sfx[i].lumpnum == lump)
Expand Down Expand Up @@ -341,8 +341,6 @@ void S_AddRandomSound(int owner, std::vector<int>& list)
// Parses all loaded SNDINFO lumps.
void S_ParseSndInfo()
{
S_ClearSoundLumps();

int lump = -1;
while ((lump = W_FindLump("SNDINFO", lump)) != -1)
{
Expand Down
Loading
Loading