Skip to content

Commit

Permalink
Stabilize Classic DOOM Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
MadDeCoDeR committed Apr 3, 2024
1 parent 4665414 commit 909ab72
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 74 deletions.
1 change: 0 additions & 1 deletion doomclassic/doom/Precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ If you have questions concerning this license or the applicable additional terms
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <map>

#define ID_INLINE inline

Expand Down
2 changes: 1 addition & 1 deletion doomclassic/doom/d_udmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void ParseSector(std::vector<std::string> lines, int index) {
}
}
::g->sectors[index].thinglist = NULL;
::g->sectors[index].touching_thinglist = NULL;
//::g->sectors[index].touching_thinglist = NULL;
}

void ParseThing(std::vector<std::string> lines, int index) {
Expand Down
1 change: 1 addition & 0 deletions doomclassic/doom/doomlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ void DoomLib::Shutdown() {
CleanVector(glob->cpatch);
CleanVector(glob->visplanes);
CleanVector(glob->reverbs);
CleanVector(glob->sector_list);
for (size_t j = 0; j < glob->acts.size(); j++) {
CleanVector(glob->acts[j]);
}
Expand Down
15 changes: 7 additions & 8 deletions doomclassic/doom/g_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ qboolean G_DoLoadGame ()

::g->gameaction = ga_nothing;

M_ReadFile (::g->savename, &::g->savebuffer);
int savelength = M_ReadFile (::g->savename, &::g->savebuffer);

waitingForWipe = true;

Expand All @@ -1781,16 +1781,15 @@ qboolean G_DoLoadGame ()
memset (vcheck,0,sizeof(vcheck));
sprintf (vcheck,"version %i",VERSION);
//GK:Check if the save file uses mods
idStr tlab;
tlab = (char*)::g->save_p;
//strcpy(tlab, (char*)::g->save_p);
char* tlab = (char*)malloc(savelength);
strcpy(tlab, (const char*)::g->save_p);
if (tlab[11] != ' ') {
tlab[11] = '\0';
}
bool hm = false;
char clab[19];
std::vector<std::string>filelist;
if (strcmp (tlab, vcheck)) {
if (strcmp(tlab, vcheck)) {
//GK: Welp forgeting that was causing most of the problems with save files
int o = strlen(tlab) - 1;
while (tlab[o] != ',') {
Expand All @@ -1803,7 +1802,7 @@ qboolean G_DoLoadGame ()
bool ok = false;
if (!strcmp(clab, vcheck)) {
hm = true;
idStr fnames = tlab.SubStr(18);
idStr fnames = tlab + 18;
idStrList file = fnames.Split(",");
int sc = 0;
for (int j = 0; j < file.Num(); j++) {
Expand Down Expand Up @@ -1832,10 +1831,10 @@ qboolean G_DoLoadGame ()
tla += filelist[mf].c_str();
tla += ",";
}
::g->save_p += tla.Length();
::g->save_p += tla.Length() - 1;
}
else {
::g->save_p += tlab.Length();
::g->save_p += strlen(tlab);
}

::g->gameskill = (skill_t)*::g->save_p++;
Expand Down
31 changes: 16 additions & 15 deletions doomclassic/doom/hu_stuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,23 +565,24 @@ void HU_Ticker(void)
::g->message_on = false;
::g->message_nottobefuckedwith = false;
}

if ( ( m_inDemoMode.GetBool() == false && m_show_messages.GetBool() ) || ::g->message_dontfuckwithme)
{

// display message if necessary
if ((::g->plr->message && !::g->message_nottobefuckedwith)
|| (::g->plr->message && ::g->message_dontfuckwithme))
if (::g->plyr) {
if ((m_inDemoMode.GetBool() == false && m_show_messages.GetBool()) || ::g->message_dontfuckwithme)
{
HUlib_addMessageToSText(&::g->w_message, 0, ::g->plr->message);
::g->plr->message = 0;
::g->message_on = true;
::g->message_counter = HU_MSGTIMEOUT;
::g->message_nottobefuckedwith = ::g->message_dontfuckwithme;
::g->message_dontfuckwithme = 0;
}

} // else ::g->message_on = false;
// display message if necessary
if ((::g->plr->message && !::g->message_nottobefuckedwith)
|| (::g->plr->message && ::g->message_dontfuckwithme))
{
HUlib_addMessageToSText(&::g->w_message, 0, ::g->plr->message);
::g->plr->message = 0;
::g->message_on = true;
::g->message_counter = HU_MSGTIMEOUT;
::g->message_nottobefuckedwith = ::g->message_dontfuckwithme;
::g->message_dontfuckwithme = 0;
}

} // else ::g->message_on = false
}
}


Expand Down
2 changes: 2 additions & 0 deletions doomclassic/doom/p_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ extern int itemrespawntime[ITEMQUESIZE];
extern int iquehead;
extern int iquetail;

extern std::vector<msecnode_t*> sector_list;


void P_RespawnSpecials (void);

Expand Down
80 changes: 51 additions & 29 deletions doomclassic/doom/p_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,17 @@ msecnode_t* P_GetSecnode()
{
msecnode_t* node;

if (!::g->sector_list.empty())
if (::g->headsecind > 0)
{
node = ::g->sector_list.front();
#ifndef _DEBUG
::g->sector_list.pop_front();
#endif
node = ::g->sector_list[::g->headsecind - 1];
::g->sector_list[::g->headsecind - 1] = NULL;
::g->headsecind--;
if (::g->headsecind < 0) {
::g->headsecind = 0;
}
}
else
node = (msecnode_t*) DoomLib::Z_Malloc(sizeof(*node), PU_LEVEL_SHARED, NULL);
node = new msecnode_t();
return(node);
}
// phares 3/16/98
Expand All @@ -580,23 +582,34 @@ msecnode_t* P_GetSecnode()

void P_AddSecnode(sector_t* s, mobj_t* thing)
{
for (msecnode_t* node : ::g->sector_list) {
if (node->m_sector == s) // Already have a node for this sector?
for (int i = 0; i < ::g->headsecind; i++) {

if (::g->sector_list[i]->m_sector == s) // Already have a node for this sector?
{
node->m_thing = thing; // Yes. Setting m_thing says 'keep it'.
::g->sector_list[i]->m_thing = thing; // Yes. Setting m_thing says 'keep it'.
return;
}

}
msecnode_t* tnode = P_GetSecnode();
tnode->visited = 0;

tnode->m_sector = s; // sector
tnode->m_thing = thing; // mobj
s->touching_thinglist = tnode;
#ifdef _WIN32
::g->sector_list.push_front(tnode);
//s->touching_thinglist = tnode;
#if _ITERATOR_DEBUG_LEVEL < 2
if (::g->sector_list.size() == ::g->sector_list.capacity()) {
::g->sector_list.reserve(::g->sector_list.size() + 100);
}
//::g->specind = 0;
::g->sector_list.emplace_back(tnode);
#else
if (::g->sector_list.size() == ::g->sector_list.capacity()) {
::g->sector_list.resize(::g->sector_list.size() + 100);
}
::g->sector_list[::g->headsecind] = tnode;
#endif

::g->headsecind++;

//msecnode_t* node;

Expand Down Expand Up @@ -642,10 +655,12 @@ void P_AddSecnode(sector_t* s, mobj_t* thing)

void P_DelSecnode(msecnode_t* node)
{
if (node)
/*if (node)
{
DoomLib::Z_Free(node);
}
node->m_thing = NULL;
node->m_sector = NULL;
delete node;
}*/
} // phares 3/13/98

// Delete an entire sector list
Expand All @@ -654,11 +669,12 @@ void P_DelSeclist()

{
while(!::g->sector_list.empty()) {
msecnode_t* node = ::g->sector_list.front();

#ifndef _DEBUG
::g->sector_list.pop_front();
#endif
msecnode_t* node = ::g->sector_list[::g->headsecind - 1];
::g->sector_list[::g->headsecind - 1] = NULL;
::g->headsecind--;
if (::g->headsecind < 0) {
::g->headsecind = 0;
}
P_DelSecnode(node);
}
}
Expand Down Expand Up @@ -725,7 +741,9 @@ void P_CreateSecNodeList(mobj_t* thing, fixed_t x, fixed_t y)

for (msecnode_t* node : ::g->sector_list)
{
node->m_thing = NULL;
if (node != NULL) {
node->m_thing = NULL;
}
}

::g->tmthing = thing;
Expand Down Expand Up @@ -759,13 +777,17 @@ void P_CreateSecNodeList(mobj_t* thing, fixed_t x, fixed_t y)

for (msecnode_t* node : ::g->sector_list)
{
if (node->m_thing == NULL)
{
if (node == ::g->sector_list.front()) {
#ifndef _DEBUG
::g->sector_list.pop_front();
#endif
P_DelSecnode(node);
if (node != NULL) {
if (node->m_thing == NULL)
{
if (node == ::g->sector_list[::g->headsecind - 1]) {
::g->sector_list[::g->headsecind - 1] = NULL;
::g->headsecind--;
if (::g->headsecind < 0) {
::g->headsecind = 0;
}
P_DelSecnode(node);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomclassic/doom/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ P_SpawnMobj
mobj->height = info->height;
mobj->flags = info->flags;
mobj->health = info->spawnhealth;
mobj->touching_sectorlist = NULL; // NULL head of sector list // phares 3/13/98
//mobj->touching_sectorlist = NULL; // NULL head of sector list // phares 3/13/98

if (::g->gameskill != sk_nightmare)
mobj->reactiontime = info->reactiontime;
Expand Down
2 changes: 1 addition & 1 deletion doomclassic/doom/p_mobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ struct mobj_t
mobj_t* tracer;

// a linked list of sectors where this object appears
struct msecnode_s* touching_sectorlist; // phares 3/14/98
//struct msecnode_s* touching_sectorlist; // phares 3/14/98

};

Expand Down
2 changes: 1 addition & 1 deletion doomclassic/doom/p_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void P_LoadSectors (int lump)
ss->special = SHORT(ms->special);
ss->tag = SHORT(ms->tag);
ss->thinglist = NULL;
ss->touching_thinglist = NULL; // phares 3/14/98
//ss->touching_thinglist = NULL; // phares 3/14/98
//GK: Load the reverbs based on sector's index
ss->counter = i;
#if defined(_MSC_VER) && defined(USE_XAUDIO2)
Expand Down
18 changes: 10 additions & 8 deletions doomclassic/doom/p_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2139,14 +2139,16 @@ void T_Scroll(scroll_t *s)
::g->sectors[sec->heightsec].floorheight : MININT;

for (msecnode_t* node : ::g->sector_list) {
if (node->m_sector == sec) {
if (!((thing = node->m_thing)->flags & MF_NOCLIP) &&
(!(thing->z > height) || thing->z < waterheight))
{
// Move objects only if on floor or underwater,
// non-floating, and clipped.
thing->momx += dx;
thing->momy += dy;
if (node != NULL) {
if (node->m_sector == sec) {
if (!((thing = node->m_thing)->flags & MF_NOCLIP) &&
(!(thing->z > height) || thing->z < waterheight))
{
// Move objects only if on floor or underwater,
// non-floating, and clipped.
thing->momx += dx;
thing->momy += dy;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomclassic/doom/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ typedef struct

// list of mobjs that are at least partially in the sector
// thinglist is a subset of touching_thinglist
struct msecnode_s *touching_thinglist; // phares 3/14/98
//struct msecnode_s *touching_thinglist; // phares 3/14/98

int counter; //GK: keep the sector's index for reverb
} sector_t;
Expand Down
16 changes: 9 additions & 7 deletions doomclassic/doom/st_stuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,15 +1032,17 @@ void ST_Ticker (void)

::g->st_clock++;
::g->st_randomnumber = M_Random();
if (!in_photomode.GetBool()) {
if (::g->st_statusbaron) {
ST_updateWidgets();
}
else if (cl_HUD.GetBool()) {
ST_updateFullWidgets();
if (::g->plyr) {
if (!in_photomode.GetBool()) {
if (::g->st_statusbaron) {
ST_updateWidgets();
}
else if (cl_HUD.GetBool()) {
ST_updateFullWidgets();
}
}
::g->st_oldhealth = ::g->plyr->health;
}
::g->st_oldhealth = ::g->plyr->health;

}

Expand Down
3 changes: 2 additions & 1 deletion doomclassic/doom/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ int bombdamage;
qboolean crushchange;
qboolean nofit;
// Temporary holder for thing_sectorlist threads
std::deque<msecnode_t*> sector_list; // phares 3/16/98
std::vector<msecnode_t*> sector_list; // phares 3/16/98
size_t headsecind;
// p_map.vars end //
// p_maputl.vars begin //
fixed_t opentop;
Expand Down

0 comments on commit 909ab72

Please sign in to comment.