- Yay! We now seem to be free of memory leaks! The next step will be to

merge a lot of these static destructor-only structs into regular
  functions added to the exit chain with atterm so that they can be called
  in a deterministic order and not whatever order the linker decides to put
  them in. (Interestingly, the amount of memory used when repeatedly
  executing the same map command at the console varies up and down, but it
  now stays relatively stable rather than increasing unbounded.)
- Fixed: The list of resolutions in the video modes menu was not freed
  at exit.
- Fixed: mus_playing.name was not freed at exit.
- Fixed: SN_StopAllSequences() should be called at the start of
  P_FreeLevelData(), not just before the call to P_SetupLevel() in
  G_DoLoadLevel(), so it can run even at exit. And C_FullConsole() can
  call P_FreeLevelData() to free more memory too.
- Fixed: StatusBar was not freed at exit.
- Fixed: spritesorter was not freed at exit.
- Fixed: Bad things happened if FString's data pool was destroyed before
  all C_RemoveTabCommand() calls were made.
- Added an overload for FArchive << FString.
- Fixed: The players' log text was not freed at exit.
- Fixed: Bot information was not freed at exit.
- Fixed: doomcom was not freed at exit. But since it's always created,
  there's no reason why it needs to be allocated from the heap. My guess
  is that in the DOS days, the external packet driver was responsible for
  allocating doomcom and passed its location with the -net parameter.
- Fixed: FBlockNodes were not freed at exit.
- Fixed: Openings were not freed at exit.
- Fixed: Drawsegs were not freed at exit.
- Fixed: Vissprites were not freed at exit.
- Fixed: Console command history was not freed at exit.
- Fixed: Visplanes were not freed at exit.
- Fixed: Call P_FreeLevelData() at exit.
- Fixed: Channel, SoundCurve, and PlayList in s_sound.cpp were not freed at
  exit.
- Fixed: Sound sequences were not freed at exit.
- Fixed: DSeqNode::Serialize() did not resize the m_SequenceChoices array
  when loading.


SVN r106 (trunk)
This commit is contained in:
Randy Heit 2006-05-11 04:00:58 +00:00
parent 0069ca4072
commit a0c88a9b31
22 changed files with 432 additions and 199 deletions

View file

@ -1,4 +1,41 @@
May 10, 2006 May 10, 2006
- Yay! We now seem to be free of memory leaks! The next step will be to
merge a lot of these static destructor-only structs into regular
functions added to the exit chain with atterm so that they can be called
in a deterministic order and not whatever order the linker decides to put
them in. (Interestingly, the amount of memory used when repeatedly
executing the same map command at the console varies up and down, but it
now stays relatively stable rather than increasing unbounded.)
- Fixed: The list of resolutions in the video modes menu was not freed
at exit.
- Fixed: mus_playing.name was not freed at exit.
- Fixed: SN_StopAllSequences() should be called at the start of
P_FreeLevelData(), not just before the call to P_SetupLevel() in
G_DoLoadLevel(), so it can run even at exit. And C_FullConsole() can
call P_FreeLevelData() to free more memory too.
- Fixed: StatusBar was not freed at exit.
- Fixed: spritesorter was not freed at exit.
- Fixed: Bad things happened if FString's data pool was destroyed before
all C_RemoveTabCommand() calls were made.
- Added an overload for FArchive << FString.
- Fixed: The players' log text was not freed at exit.
- Fixed: Bot information was not freed at exit.
- Fixed: doomcom was not freed at exit. But since it's always created,
there's no reason why it needs to be allocated from the heap. My guess
is that in the DOS days, the external packet driver was responsible for
allocating doomcom and passed its location with the -net parameter.
- Fixed: FBlockNodes were not freed at exit.
- Fixed: Openings were not freed at exit.
- Fixed: Drawsegs were not freed at exit.
- Fixed: Vissprites were not freed at exit.
- Fixed: Console command history was not freed at exit.
- Fixed: Visplanes were not freed at exit.
- Fixed: Call P_FreeLevelData() at exit.
- Fixed: Channel, SoundCurve, and PlayList in s_sound.cpp were not freed at
exit.
- Fixed: Sound sequences were not freed at exit.
- Fixed: DSeqNode::Serialize() did not resize the m_SequenceChoices array
when loading.
- Fixed mvlineasm1 and mvlineasm4 so that they can be used with textures - Fixed mvlineasm1 and mvlineasm4 so that they can be used with textures
taller than 256 pixels. There was a very slight performance hit for this, taller than 256 pixels. There was a very slight performance hit for this,
but I was able to tweak mvlineasm4 to make it approximately as fast as but I was able to tweak mvlineasm4 to make it approximately as fast as

View file

@ -78,6 +78,8 @@ class DCajunMaster : public DObject
DECLARE_CLASS (DCajunMaster, DObject) DECLARE_CLASS (DCajunMaster, DObject)
HAS_OBJECT_POINTERS HAS_OBJECT_POINTERS
public: public:
~DCajunMaster();
void ClearPlayer (int playernum, bool keepTeam); void ClearPlayer (int playernum, bool keepTeam);
//(B_Game.c) //(B_Game.c)

View file

@ -90,6 +90,10 @@ static bool waitingforspawn[MAXPLAYERS];
void G_DoReborn (int playernum, bool freshbot); void G_DoReborn (int playernum, bool freshbot);
DCajunMaster::~DCajunMaster()
{
ForgetBots();
}
//This function is called every tick (from g_game.c), //This function is called every tick (from g_game.c),
//send bots into thinking (+more). //send bots into thinking (+more).

View file

@ -34,6 +34,7 @@
#include "m_alloc.h" #include "m_alloc.h"
#include "templates.h" #include "templates.h"
#include "p_setup.h"
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -132,6 +133,21 @@ static byte CmdLine[260];
static struct History *HistHead = NULL, *HistTail = NULL, *HistPos = NULL; static struct History *HistHead = NULL, *HistTail = NULL, *HistPos = NULL;
static int HistSize; static int HistSize;
static struct HistoryFree
{
~HistoryFree()
{
History *hist = HistTail;
while (hist != NULL)
{
History *next = hist->Newer;
free (hist);
hist = next;
}
}
} HistoryFree_er;
CVAR (Float, con_notifytime, 3.f, CVAR_ARCHIVE) CVAR (Float, con_notifytime, 3.f, CVAR_ARCHIVE)
CVAR (Bool, con_centernotify, false, CVAR_ARCHIVE) CVAR (Bool, con_centernotify, false, CVAR_ARCHIVE)
@ -1151,7 +1167,7 @@ void C_FullConsole ()
gamestate = GS_FULLCONSOLE; gamestate = GS_FULLCONSOLE;
level.music = NULL; level.music = NULL;
S_Start (); S_Start ();
SN_StopAllSequences (); P_FreeLevelData ();
V_SetBlend (0,0,0,0); V_SetBlend (0,0,0,0);
} }
else else
@ -1716,7 +1732,7 @@ void C_MidPrintBold (const char *msg)
struct TabData struct TabData
{ {
int UseCount; int UseCount;
FString Name; FName TabName;
TabData() TabData()
: UseCount(0) : UseCount(0)
@ -1724,12 +1740,12 @@ struct TabData
} }
TabData(const char *name) TabData(const char *name)
: UseCount(1), Name(name) : UseCount(1), TabName(name)
{ {
} }
TabData(const TabData &other) TabData(const TabData &other)
: UseCount(other.UseCount), Name(other.Name) : UseCount(other.UseCount), TabName(other.TabName)
{ {
} }
}; };
@ -1741,11 +1757,18 @@ static int TabSize; // Size of tab string
static BOOL FindTabCommand (const char *name, int *stoppos, int len) static BOOL FindTabCommand (const char *name, int *stoppos, int len)
{ {
int i, cval = 1; FName aname(name);
unsigned int i;
int cval = 1;
for (i = 0; i < TabCommands.Size(); i++) for (i = 0; i < TabCommands.Size(); i++)
{ {
cval = strnicmp (TabCommands[i].Name, name, len); if (TabCommands[i].TabName == aname)
{
*stoppos = i;
return true;
}
cval = strnicmp (TabCommands[i].TabName.GetChars(), name, len);
if (cval >= 0) if (cval >= 0)
break; break;
} }
@ -1772,19 +1795,28 @@ void C_AddTabCommand (const char *name)
void C_RemoveTabCommand (const char *name) void C_RemoveTabCommand (const char *name)
{ {
int pos; FName aname(name, true);
if (FindTabCommand (name, &pos, INT_MAX)) if (aname == NAME_None)
{ {
if (--TabCommands[pos].UseCount == 0) return;
}
for (unsigned int i = 0; i < TabCommands.Size(); ++i)
{
if (TabCommands[i].TabName == aname)
{ {
TabCommands.Delete(pos); if (--TabCommands[i].UseCount == 0)
{
TabCommands.Delete(i);
}
break;
} }
} }
} }
static int FindDiffPoint (const char *str1, const char *str2) static int FindDiffPoint (FName name1, const char *str2)
{ {
const char *str1 = name1.GetChars();
int i; int i;
for (i = 0; tolower(str1[i]) == tolower(str2[i]); i++) for (i = 0; tolower(str1[i]) == tolower(str2[i]); i++)
@ -1845,7 +1877,7 @@ static void C_TabComplete (bool goForward)
{ // Find the last matching tab, then go one past it. { // Find the last matching tab, then go one past it.
while (++TabPos < TabCommands.Size()) while (++TabPos < TabCommands.Size())
{ {
if (FindDiffPoint (TabCommands[TabPos].Name, (char *)(CmdLine + TabStart)) < TabSize) if (FindDiffPoint (TabCommands[TabPos].TabName, (char *)(CmdLine + TabStart)) < TabSize)
{ {
break; break;
} }
@ -1866,7 +1898,7 @@ static void C_TabComplete (bool goForward)
} }
else else
{ {
diffpoint = FindDiffPoint (TabCommands[TabPos].Name, (char *)(CmdLine + TabStart)); diffpoint = FindDiffPoint (TabCommands[TabPos].TabName, (char *)(CmdLine + TabStart));
if (diffpoint < TabSize) if (diffpoint < TabSize)
{ {
@ -1876,7 +1908,7 @@ static void C_TabComplete (bool goForward)
} }
else else
{ {
strcpy ((char *)(CmdLine + TabStart), TabCommands[TabPos].Name); strcpy ((char *)(CmdLine + TabStart), TabCommands[TabPos].TabName.GetChars());
CmdLine[0] = CmdLine[1] = (BYTE)strlen ((char *)(CmdLine + 2)) + 1; CmdLine[0] = CmdLine[1] = (BYTE)strlen ((char *)(CmdLine + 2)) + 1;
CmdLine[CmdLine[0] + 1] = ' '; CmdLine[CmdLine[0] + 1] = ' ';
} }
@ -1896,7 +1928,7 @@ static bool C_TabCompleteList ()
for (i = TabPos; i < TabCommands.Size(); ++i) for (i = TabPos; i < TabCommands.Size(); ++i)
{ {
if (FindDiffPoint (TabCommands[i].Name, (char *)(CmdLine + TabStart)) < TabSize) if (FindDiffPoint (TabCommands[i].TabName, (char *)(CmdLine + TabStart)) < TabSize)
{ {
break; break;
} }
@ -1907,14 +1939,14 @@ static bool C_TabCompleteList ()
// This keeps track of the longest common prefix for all the possible // This keeps track of the longest common prefix for all the possible
// completions, so we can fill in part of the command for the user if // completions, so we can fill in part of the command for the user if
// the longest common prefix is longer than what the user already typed. // the longest common prefix is longer than what the user already typed.
int diffpt = FindDiffPoint (TabCommands[i-1].Name, TabCommands[i].Name); int diffpt = FindDiffPoint (TabCommands[i-1].TabName, TabCommands[i].TabName.GetChars());
if (diffpt < commonsize) if (diffpt < commonsize)
{ {
commonsize = diffpt; commonsize = diffpt;
} }
} }
nummatches++; nummatches++;
maxwidth = MAX (maxwidth, strlen (TabCommands[i].Name)); maxwidth = MAX (maxwidth, strlen (TabCommands[i].TabName.GetChars()));
} }
} }
if (nummatches > 1) if (nummatches > 1)
@ -1924,7 +1956,7 @@ static bool C_TabCompleteList ()
Printf (TEXTCOLOR_BLUE "Completions for %s:\n", CmdLine+2); Printf (TEXTCOLOR_BLUE "Completions for %s:\n", CmdLine+2);
for (i = TabPos; nummatches > 0; ++i, --nummatches) for (i = TabPos; nummatches > 0; ++i, --nummatches)
{ {
Printf ("%-*s", int(maxwidth), TabCommands[i].Name.GetChars()); Printf ("%-*s", int(maxwidth), TabCommands[i].TabName.GetChars());
x += maxwidth; x += maxwidth;
if (x > ConCols - maxwidth) if (x > ConCols - maxwidth)
{ {
@ -1940,7 +1972,7 @@ static bool C_TabCompleteList ()
if (TabSize != commonsize) if (TabSize != commonsize)
{ {
TabSize = commonsize; TabSize = commonsize;
strncpy ((char *)CmdLine + TabStart, TabCommands[TabPos].Name, commonsize); strncpy ((char *)CmdLine + TabStart, TabCommands[TabPos].TabName.GetChars(), commonsize);
CmdLine[0] = TabStart + commonsize - 2; CmdLine[0] = TabStart + commonsize - 2;
CmdLine[1] = CmdLine[0]; CmdLine[1] = CmdLine[0];
} }

View file

@ -93,8 +93,8 @@ extern FString savegamefile;
extern short consistancy[MAXPLAYERS][BACKUPTICS]; extern short consistancy[MAXPLAYERS][BACKUPTICS];
doomcom_t* doomcom; doomcom_t doomcom;
#define netbuffer (doomcom->data) #define netbuffer (doomcom.data)
enum { NET_PeerToPeer, NET_PacketServer }; enum { NET_PeerToPeer, NET_PacketServer };
BYTE NetMode = NET_PeerToPeer; BYTE NetMode = NET_PeerToPeer;
@ -327,7 +327,7 @@ int NetbufferSize ()
{ {
if (netbuffer[0] & (NCMD_EXIT | NCMD_SETUP)) if (netbuffer[0] & (NCMD_EXIT | NCMD_SETUP))
{ {
return doomcom->datalength; return doomcom.datalength;
} }
int k = 2, count, numtics; int k = 2, count, numtics;
@ -335,7 +335,7 @@ int NetbufferSize ()
if (netbuffer[0] & NCMD_RETRANSMIT) if (netbuffer[0] & NCMD_RETRANSMIT)
k++; k++;
if (NetMode == NET_PacketServer && doomcom->remotenode == nodeforplayer[Net_Arbitrator]) if (NetMode == NET_PacketServer && doomcom.remotenode == nodeforplayer[Net_Arbitrator])
k++; k++;
numtics = netbuffer[0] & NCMD_XTICS; numtics = netbuffer[0] & NCMD_XTICS;
@ -360,7 +360,7 @@ int NetbufferSize ()
} }
// Need at least 3 bytes per tic per player // Need at least 3 bytes per tic per player
if (doomcom->datalength < k + 3 * count * numtics) if (doomcom.datalength < k + 3 * count * numtics)
{ {
return k + 3 * count * numtics; return k + 3 * count * numtics;
} }
@ -449,7 +449,7 @@ void HSendPacket (int node, int len)
fprintf (debugfile, "%c%2x", i==k?'|':' ', ((byte *)netbuffer)[i]); fprintf (debugfile, "%c%2x", i==k?'|':' ', ((byte *)netbuffer)[i]);
} }
fprintf (debugfile, " [[ "); fprintf (debugfile, " [[ ");
for (i = 0; i < doomcom->numnodes; ++i) for (i = 0; i < doomcom.numnodes; ++i)
{ {
if (nodeingame[i]) if (nodeingame[i])
{ {
@ -485,9 +485,9 @@ void HSendPacket (int node, int len)
} }
#endif #endif
doomcom->command = CMD_SEND; doomcom.command = CMD_SEND;
doomcom->remotenode = node; doomcom.remotenode = node;
doomcom->datalength = len; doomcom.datalength = len;
I_NetCmd (); I_NetCmd ();
} }
@ -501,7 +501,7 @@ BOOL HGetPacket (void)
if (reboundpacket) if (reboundpacket)
{ {
memcpy (netbuffer, reboundstore, reboundpacket); memcpy (netbuffer, reboundstore, reboundpacket);
doomcom->remotenode = 0; doomcom.remotenode = 0;
reboundpacket = 0; reboundpacket = 0;
return true; return true;
} }
@ -512,10 +512,10 @@ BOOL HGetPacket (void)
if (demoplayback) if (demoplayback)
return false; return false;
doomcom->command = CMD_GET; doomcom.command = CMD_GET;
I_NetCmd (); I_NetCmd ();
if (doomcom->remotenode == -1) if (doomcom.remotenode == -1)
return false; return false;
if (debugfile) if (debugfile)
@ -524,15 +524,15 @@ BOOL HGetPacket (void)
if (netbuffer[0] & NCMD_SETUP) if (netbuffer[0] & NCMD_SETUP)
{ {
fprintf (debugfile,"%i/%i get %i = SETUP [%3i]", gametic, maketic, doomcom->remotenode, doomcom->datalength); fprintf (debugfile,"%i/%i get %i = SETUP [%3i]", gametic, maketic, doomcom.remotenode, doomcom.datalength);
for (i = 0; i < doomcom->datalength; i++) for (i = 0; i < doomcom.datalength; i++)
fprintf (debugfile, " %2x", ((byte *)netbuffer)[i]); fprintf (debugfile, " %2x", ((byte *)netbuffer)[i]);
fprintf (debugfile, "\n"); fprintf (debugfile, "\n");
} }
else if (netbuffer[0] & NCMD_EXIT) else if (netbuffer[0] & NCMD_EXIT)
{ {
fprintf (debugfile,"%i/%i get %i = EXIT [%3i]", gametic, maketic, doomcom->remotenode, doomcom->datalength); fprintf (debugfile,"%i/%i get %i = EXIT [%3i]", gametic, maketic, doomcom.remotenode, doomcom.datalength);
for (i = 0; i < doomcom->datalength; i++) for (i = 0; i < doomcom.datalength; i++)
fprintf (debugfile, " %2x", ((byte *)netbuffer)[i]); fprintf (debugfile, " %2x", ((byte *)netbuffer)[i]);
fprintf (debugfile, "\n"); fprintf (debugfile, "\n");
} }
@ -540,7 +540,7 @@ BOOL HGetPacket (void)
k = 2; k = 2;
if (NetMode == NET_PacketServer && if (NetMode == NET_PacketServer &&
doomcom->remotenode == nodeforplayer[Net_Arbitrator]) doomcom.remotenode == nodeforplayer[Net_Arbitrator])
{ {
k++; k++;
} }
@ -556,25 +556,25 @@ BOOL HGetPacket (void)
fprintf (debugfile,"%i/%i get %i = (%i + %i, R %i) [%3i]", fprintf (debugfile,"%i/%i get %i = (%i + %i, R %i) [%3i]",
gametic, maketic, gametic, maketic,
doomcom->remotenode, doomcom.remotenode,
ExpandTics(netbuffer[1]), ExpandTics(netbuffer[1]),
numtics, realretrans, doomcom->datalength); numtics, realretrans, doomcom.datalength);
for (i = 0; i < doomcom->datalength; i++) for (i = 0; i < doomcom.datalength; i++)
fprintf (debugfile, "%c%2x", i==k?'|':' ', ((byte *)netbuffer)[i]); fprintf (debugfile, "%c%2x", i==k?'|':' ', ((byte *)netbuffer)[i]);
if (numtics) if (numtics)
fprintf (debugfile, " <<%4x>>\n", fprintf (debugfile, " <<%4x>>\n",
consistancy[playerfornode[doomcom->remotenode]][nettics[doomcom->remotenode]%BACKUPTICS] & 0xFFFF); consistancy[playerfornode[doomcom.remotenode]][nettics[doomcom.remotenode]%BACKUPTICS] & 0xFFFF);
else else
fprintf (debugfile, "\n"); fprintf (debugfile, "\n");
} }
} }
if (doomcom->datalength != NetbufferSize ()) if (doomcom.datalength != NetbufferSize ())
{ {
if (debugfile) if (debugfile)
fprintf (debugfile,"---bad packet length %i (calculated %i)\n", fprintf (debugfile,"---bad packet length %i (calculated %i)\n",
doomcom->datalength, NetbufferSize()); doomcom.datalength, NetbufferSize());
return false; return false;
} }
@ -585,14 +585,14 @@ void PlayerIsGone (int netnode, int netconsole)
{ {
int i; int i;
for (i = netnode + 1; i < doomcom->numnodes; ++i) for (i = netnode + 1; i < doomcom.numnodes; ++i)
{ {
if (nodeingame[i]) if (nodeingame[i])
break; break;
} }
if (i == doomcom->numnodes) if (i == doomcom.numnodes)
{ {
doomcom->numnodes = netnode; doomcom.numnodes = netnode;
} }
nodeingame[netnode] = false; nodeingame[netnode] = false;
@ -690,12 +690,12 @@ void GetPackets (void)
{ {
// This player apparantly doesn't realise the game has started // This player apparantly doesn't realise the game has started
netbuffer[0] = NCMD_SETUP+3; netbuffer[0] = NCMD_SETUP+3;
HSendPacket (doomcom->remotenode, 1); HSendPacket (doomcom.remotenode, 1);
} }
continue; // extra setup packet continue; // extra setup packet
} }
netnode = doomcom->remotenode; netnode = doomcom.remotenode;
netconsole = playerfornode[netnode] & ~PL_DRONE; netconsole = playerfornode[netnode] & ~PL_DRONE;
// [RH] Get "ping" times // [RH] Get "ping" times
@ -1065,7 +1065,7 @@ void NetUpdate (void)
// and it also added the player being sent the packet to the count. // and it also added the player being sent the packet to the count.
count -= 2; count -= 2;
for (j = 0; j < doomcom->numnodes; ++j) for (j = 0; j < doomcom.numnodes; ++j)
{ {
if (nodejustleft[j]) if (nodejustleft[j])
{ {
@ -1087,7 +1087,7 @@ void NetUpdate (void)
} }
} }
for (i = 0; i < doomcom->numnodes; i++) for (i = 0; i < doomcom.numnodes; i++)
{ {
BYTE playerbytes[MAXPLAYERS]; BYTE playerbytes[MAXPLAYERS];
@ -1120,7 +1120,7 @@ void NetUpdate (void)
consoleplayer == Net_Arbitrator && consoleplayer == Net_Arbitrator &&
i != 0) i != 0)
{ {
for (j = 1; j < doomcom->numnodes; ++j) for (j = 1; j < doomcom.numnodes; ++j)
{ {
if (nodeingame[j] && nettics[j] < lowtic && j != i) if (nodeingame[j] && nettics[j] < lowtic && j != i)
{ {
@ -1134,7 +1134,7 @@ void NetUpdate (void)
if (numtics > BACKUPTICS) if (numtics > BACKUPTICS)
I_Error ("NetUpdate: Node %d missed too many tics", i); I_Error ("NetUpdate: Node %d missed too many tics", i);
resendto[i] = MAX (0, lowtic - doomcom->extratics); resendto[i] = MAX (0, lowtic - doomcom.extratics);
if (numtics == 0 && resendOnly && !remoteresend[i] && nettics[i]) if (numtics == 0 && resendOnly && !remoteresend[i] && nettics[i])
{ {
@ -1161,7 +1161,7 @@ void NetUpdate (void)
{ {
netbuffer[0] |= NCMD_QUITTERS; netbuffer[0] |= NCMD_QUITTERS;
netbuffer[k++] = quitcount; netbuffer[k++] = quitcount;
for (int l = 0; l < doomcom->numnodes; ++l) for (int l = 0; l < doomcom.numnodes; ++l)
{ {
if (nodejustleft[l]) if (nodejustleft[l])
{ {
@ -1339,7 +1339,7 @@ void D_ArbitrateNetStart (void)
bool allset = false; bool allset = false;
// Return right away if we're just playing with ourselves. // Return right away if we're just playing with ourselves.
if (doomcom->numnodes == 1) if (doomcom.numnodes == 1)
return; return;
autostart = true; autostart = true;
@ -1355,7 +1355,7 @@ void D_ArbitrateNetStart (void)
nodeforplayer[consoleplayer] = 0; nodeforplayer[consoleplayer] = 0;
if (consoleplayer == Net_Arbitrator) if (consoleplayer == Net_Arbitrator)
{ {
for (i = 1; i < doomcom->numnodes; ++i) for (i = 1; i < doomcom.numnodes; ++i)
{ {
playerfornode[i] = i; playerfornode[i] = i;
nodeforplayer[i] = i; nodeforplayer[i] = i;
@ -1365,7 +1365,7 @@ void D_ArbitrateNetStart (void)
{ {
playerfornode[1] = 0; playerfornode[1] = 0;
nodeforplayer[0] = 1; nodeforplayer[0] = 1;
for (i = 1; i < doomcom->numnodes; ++i) for (i = 1; i < doomcom.numnodes; ++i)
{ {
if (i < consoleplayer) if (i < consoleplayer)
{ {
@ -1399,14 +1399,14 @@ void D_ArbitrateNetStart (void)
I_FatalError ("The game was aborted\n"); I_FatalError ("The game was aborted\n");
} }
if (doomcom->remotenode == 0) if (doomcom.remotenode == 0)
{ {
continue; continue;
} }
if (netbuffer[0] == NCMD_SETUP || netbuffer[0] == NCMD_SETUP+1) // got user info if (netbuffer[0] == NCMD_SETUP || netbuffer[0] == NCMD_SETUP+1) // got user info
{ {
node = (netbuffer[0] == NCMD_SETUP) ? doomcom->remotenode node = (netbuffer[0] == NCMD_SETUP) ? doomcom.remotenode
: nodeforplayer[netbuffer[1]]; : nodeforplayer[netbuffer[1]];
playersdetected[node] = playersdetected[node] =
@ -1442,8 +1442,8 @@ void D_ArbitrateNetStart (void)
{ {
gotsetup[0] = 0x80; gotsetup[0] = 0x80;
ticdup = doomcom->ticdup = netbuffer[1]; ticdup = doomcom.ticdup = netbuffer[1];
doomcom->extratics = netbuffer[2]; doomcom.extratics = netbuffer[2];
NetMode = netbuffer[3]; NetMode = netbuffer[3];
stream = &netbuffer[4]; stream = &netbuffer[4];
@ -1462,11 +1462,11 @@ void D_ArbitrateNetStart (void)
// If everybody already knows everything, it's time to go // If everybody already knows everything, it's time to go
if (consoleplayer == Net_Arbitrator) if (consoleplayer == Net_Arbitrator)
{ {
for (i = 0; i < doomcom->numnodes; ++i) for (i = 0; i < doomcom.numnodes; ++i)
if (playersdetected[i] != DWORD(1 << doomcom->numnodes) - 1 || !gotsetup[i]) if (playersdetected[i] != DWORD(1 << doomcom.numnodes) - 1 || !gotsetup[i])
break; break;
if (i == doomcom->numnodes) if (i == doomcom.numnodes)
break; break;
} }
@ -1489,9 +1489,9 @@ void D_ArbitrateNetStart (void)
{ // Send user info for all nodes { // Send user info for all nodes
netbuffer[0] = NCMD_SETUP+1; netbuffer[0] = NCMD_SETUP+1;
netbuffer[2] = NETGAMEVERSION; netbuffer[2] = NETGAMEVERSION;
for (i = 1; i < doomcom->numnodes; ++i) for (i = 1; i < doomcom.numnodes; ++i)
{ {
for (j = 0; j < doomcom->numnodes; ++j) for (j = 0; j < doomcom.numnodes; ++j)
{ {
// Send info about player j to player i? // Send info about player j to player i?
if (i != j && (playersdetected[0] & (1<<j)) && if (i != j && (playersdetected[0] & (1<<j)) &&
@ -1510,8 +1510,8 @@ void D_ArbitrateNetStart (void)
if (consoleplayer == Net_Arbitrator) if (consoleplayer == Net_Arbitrator)
{ {
netbuffer[0] = NCMD_SETUP+2; netbuffer[0] = NCMD_SETUP+2;
netbuffer[1] = doomcom->ticdup; netbuffer[1] = doomcom.ticdup;
netbuffer[2] = doomcom->extratics; netbuffer[2] = doomcom.extratics;
netbuffer[3] = NetMode; netbuffer[3] = NetMode;
stream = &netbuffer[4]; stream = &netbuffer[4];
WriteString (startmap, &stream); WriteString (startmap, &stream);
@ -1530,7 +1530,7 @@ void D_ArbitrateNetStart (void)
if (debugfile) if (debugfile)
{ {
for (i = 0; i < doomcom->numnodes; ++i) for (i = 0; i < doomcom.numnodes; ++i)
{ {
fprintf (debugfile, "player %d is on node %d\n", i, nodeforplayer[i]); fprintf (debugfile, "player %d is on node %d\n", i, nodeforplayer[i]);
} }
@ -1552,7 +1552,7 @@ static void SendSetup (DWORD playersdetected[MAXNETNODES], BYTE gotsetup[MAXNETN
} }
else else
{ {
for (int i = 1; i < doomcom->numnodes; ++i) for (int i = 1; i < doomcom.numnodes; ++i)
{ {
if (!gotsetup[i] || netbuffer[0] == NCMD_SETUP+3) if (!gotsetup[i] || netbuffer[0] == NCMD_SETUP+3)
{ {
@ -1583,10 +1583,10 @@ void D_CheckNetGame (void)
// I_InitNetwork sets doomcom and netgame // I_InitNetwork sets doomcom and netgame
I_InitNetwork (); I_InitNetwork ();
if (doomcom->id != DOOMCOM_ID) if (doomcom.id != DOOMCOM_ID)
I_FatalError ("Doomcom buffer invalid!"); I_FatalError ("Doomcom buffer invalid!");
consoleplayer = doomcom->consoleplayer; consoleplayer = doomcom.consoleplayer;
v = Args.CheckValue ("-netmode"); v = Args.CheckValue ("-netmode");
if (v != NULL) if (v != NULL)
@ -1612,15 +1612,15 @@ void D_CheckNetGame (void)
} }
// read values out of doomcom // read values out of doomcom
ticdup = doomcom->ticdup; ticdup = doomcom.ticdup;
for (i = 0; i < doomcom->numplayers; i++) for (i = 0; i < doomcom.numplayers; i++)
playeringame[i] = true; playeringame[i] = true;
for (i = 0; i < doomcom->numnodes; i++) for (i = 0; i < doomcom.numnodes; i++)
nodeingame[i] = true; nodeingame[i] = true;
Printf ("player %i of %i (%i nodes)\n", Printf ("player %i of %i (%i nodes)\n",
consoleplayer+1, doomcom->numplayers, doomcom->numnodes); consoleplayer+1, doomcom.numplayers, doomcom.numnodes);
} }
@ -1663,7 +1663,7 @@ void STACK_ARGS D_QuitNetGame (void)
} }
else else
{ {
for (j = 1; j < doomcom->numnodes; j++) for (j = 1; j < doomcom.numnodes; j++)
if (nodeingame[j]) if (nodeingame[j])
HSendPacket (j, k); HSendPacket (j, k);
} }
@ -1709,7 +1709,7 @@ void TryRunTics (void)
lowtic = INT_MAX; lowtic = INT_MAX;
numplaying = 0; numplaying = 0;
for (i = 0; i < doomcom->numnodes; i++) for (i = 0; i < doomcom.numnodes; i++)
{ {
if (nodeingame[i]) if (nodeingame[i])
{ {
@ -1806,7 +1806,7 @@ void TryRunTics (void)
NetUpdate (); NetUpdate ();
lowtic = INT_MAX; lowtic = INT_MAX;
for (i = 0; i < doomcom->numnodes; i++) for (i = 0; i < doomcom.numnodes; i++)
if (nodeingame[i] && nettics[i] < lowtic) if (nodeingame[i] && nettics[i] < lowtic)
lowtic = nettics[i]; lowtic = nettics[i];

View file

@ -276,7 +276,7 @@ public:
float BlendB; float BlendB;
float BlendA; float BlendA;
char *LogText; // [RH] Log for Strife FString LogText; // [RH] Log for Strife
fixed_t GetDeltaViewHeight() const fixed_t GetDeltaViewHeight() const

View file

@ -254,7 +254,7 @@ extern int skyflatnum;
// This is the interface to the packet driver, a separate program // This is the interface to the packet driver, a separate program
// in DOS, but just an abstraction here. // in DOS, but just an abstraction here.
extern doomcom_t* doomcom; extern doomcom_t doomcom;
extern struct ticcmd_t localcmds[LOCALCMDTICS]; extern struct ticcmd_t localcmds[LOCALCMDTICS];

View file

@ -43,6 +43,7 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <zlib.h> #include <zlib.h>
#include <malloc.h>
#include "doomtype.h" #include "doomtype.h"
#include "farchive.h" #include "farchive.h"
@ -830,6 +831,32 @@ FArchive &FArchive::operator<< (char *&str)
return *this; return *this;
} }
FArchive &FArchive::operator<< (FString &str)
{
if (m_Storing)
{
WriteString (str.GetChars());
}
else
{
DWORD size = ReadCount();
if (size == 0)
{
str = "";
}
else
{
char *str2 = (char *)alloca(size*sizeof(char));
size--;
Read (str2, size);
str2[size] = 0;
str = str2;
}
}
return *this;
}
FArchive &FArchive::operator<< (BYTE &c) FArchive &FArchive::operator<< (BYTE &c)
{ {
if (m_Storing) if (m_Storing)

View file

@ -179,6 +179,7 @@ virtual void Read (void *mem, unsigned int len);
FArchive& operator<< (double &d); FArchive& operator<< (double &d);
FArchive& operator<< (char *&str); FArchive& operator<< (char *&str);
FArchive& operator<< (FName &n); FArchive& operator<< (FName &n);
FArchive& operator<< (FString &str);
FArchive& SerializePointer (void *ptrbase, BYTE **ptr, DWORD elemSize); FArchive& SerializePointer (void *ptrbase, BYTE **ptr, DWORD elemSize);
FArchive& SerializeObject (DObject *&object, PClass *type); FArchive& SerializeObject (DObject *&object, PClass *type);
FArchive& WriteObject (DObject *obj); FArchive& WriteObject (DObject *obj);

View file

@ -1769,7 +1769,6 @@ void G_DoLoadLevel (int position, bool autosave)
players[i].fragcount = 0; players[i].fragcount = 0;
} }
SN_StopAllSequences ();
P_SetupLevel (level.mapname, position); P_SetupLevel (level.mapname, position);
// [RH] Start lightning, if MAPINFO tells us to // [RH] Start lightning, if MAPINFO tells us to

View file

@ -797,6 +797,7 @@ extern int DisplayBits;
int testingmode; // Holds time to revert to old mode int testingmode; // Holds time to revert to old mode
int OldWidth, OldHeight, OldBits; int OldWidth, OldHeight, OldBits;
void M_FreeModesList ();
static void BuildModesList (int hiwidth, int hiheight, int hi_id); static void BuildModesList (int hiwidth, int hiheight, int hi_id);
static BOOL GetSelectedSize (int line, int *width, int *height); static BOOL GetSelectedSize (int line, int *width, int *height);
static void SetModesMenu (int w, int h, int bits); static void SetModesMenu (int w, int h, int bits);
@ -823,6 +824,7 @@ static struct DepthNameKiller
Depths[i].name = NULL; Depths[i].name = NULL;
} }
} }
M_FreeModesList();
} }
} KillTheDepthValues; } KillTheDepthValues;
@ -2743,7 +2745,7 @@ static void BuildModesList (int hiwidth, int hiheight, int hi_bits)
{ {
if (*str) if (*str)
{ {
free (*str); delete[] *str;
*str = NULL; *str = NULL;
} }
} }
@ -2756,6 +2758,29 @@ void M_RefreshModesList ()
BuildModesList (SCREENWIDTH, SCREENHEIGHT, DisplayBits); BuildModesList (SCREENWIDTH, SCREENHEIGHT, DisplayBits);
} }
void M_FreeModesList ()
{
for (int i = VM_RESSTART; ModesItems[i].type == screenres; ++i)
{
for (int c = 0; c < 3; ++c)
{
char **str;
switch (c)
{
default: str = &ModesItems[i].b.res1; break;
case 1: str = &ModesItems[i].c.res2; break;
case 2: str = &ModesItems[i].d.res3; break;
}
if (str != NULL)
{
delete[] *str;
*str = NULL;
}
}
}
}
static BOOL GetSelectedSize (int line, int *width, int *height) static BOOL GetSelectedSize (int line, int *width, int *height)
{ {
if (ModesItems[line].type != screenres) if (ModesItems[line].type != screenres)

View file

@ -4240,22 +4240,6 @@ bool P_ChangeSector (sector_t *sector, int crunch, int amt, int floorOrCeil)
msecnode_t *headsecnode = NULL; msecnode_t *headsecnode = NULL;
struct SecnodeKiller
{
~SecnodeKiller()
{
msecnode_t *node = headsecnode;
while (node != NULL)
{
msecnode_t *next = node->m_snext;
free (node);
node = next;
}
headsecnode = NULL;
}
} KillTheSecnodes;
//============================================================================= //=============================================================================
// //
// P_GetSecnode // P_GetSecnode

View file

@ -55,6 +55,8 @@
#include "gi.h" #include "gi.h"
#include "p_conversation.h" #include "p_conversation.h"
#include "a_keys.h" #include "a_keys.h"
#include "s_sndseq.h"
#include "sbar.h"
extern void P_SpawnMapThing (mapthing2_t *mthing, int position); extern void P_SpawnMapThing (mapthing2_t *mthing, int position);
extern bool P_LoadBuildMap (BYTE *mapdata, size_t len, mapthing2_t **things, int *numthings); extern bool P_LoadBuildMap (BYTE *mapdata, size_t len, mapthing2_t **things, int *numthings);
@ -2790,6 +2792,7 @@ extern polyblock_t **PolyBlockMap;
void P_FreeLevelData () void P_FreeLevelData ()
{ {
SN_StopAllSequences ();
DThinker::DestroyAllThinkers (); DThinker::DestroyAllThinkers ();
level.total_monsters = level.total_items = level.total_secrets = level.total_monsters = level.total_items = level.total_secrets =
level.killed_monsters = level.found_items = level.found_secrets = level.killed_monsters = level.found_items = level.found_secrets =
@ -2904,10 +2907,50 @@ void P_FreeLevelData ()
if (zones != NULL) if (zones != NULL)
{ {
delete[] zones; delete[] zones;
zones = NULL;
} }
P_FreeStrifeConversations (); P_FreeStrifeConversations ();
} }
extern msecnode_t *headsecnode;
static struct AutoFreeLevelData
{
~AutoFreeLevelData()
{
P_FreeLevelData();
// Blocknodes and msecnodes should be freed now, when we
// can be sure they are all easily located in their
// free lists.
{
FBlockNode *node = FBlockNode::FreeBlocks;
while (node != NULL)
{
FBlockNode *next = node->NextBlock;
delete node;
node = next;
}
}
{
msecnode_t *node = headsecnode;
while (node != NULL)
{
msecnode_t *next = node->m_snext;
free (node);
node = next;
}
headsecnode = NULL;
}
if (StatusBar != NULL)
{
delete StatusBar;
StatusBar = NULL;
}
}
} LevelDataFree_er;
// //
// P_SetupLevel // P_SetupLevel
// //

View file

@ -32,6 +32,8 @@
// of single-player start spots should be spawned in the level. // of single-player start spots should be spawned in the level.
void P_SetupLevel (char *mapname, int position); void P_SetupLevel (char *mapname, int position);
void P_FreeLevelData();
// Called by startup code. // Called by startup code.
void P_Init (void); void P_Init (void);

View file

@ -124,7 +124,7 @@ void player_s::SetLogNumber (int num)
void player_s::SetLogText (const char *text) void player_s::SetLogText (const char *text)
{ {
ReplaceString (&LogText, text); LogText = text;
} }
IMPLEMENT_ABSTRACT_ACTOR (APlayerPawn) IMPLEMENT_ABSTRACT_ACTOR (APlayerPawn)

View file

@ -83,6 +83,18 @@ drawseg_t *drawsegs;
drawseg_t* firstdrawseg; drawseg_t* firstdrawseg;
drawseg_t* ds_p; drawseg_t* ds_p;
static struct DrawSegFree
{
~DrawSegFree()
{
if (drawsegs != NULL)
{
free (drawsegs);
drawsegs = NULL;
}
}
} FreeDrawSegs;
size_t FirstInterestingDrawseg; size_t FirstInterestingDrawseg;
TArray<size_t> InterestingDrawsegs; TArray<size_t> InterestingDrawsegs;

View file

@ -72,6 +72,20 @@ static visplane_t *visplanes[MAXVISPLANES+1]; // killough
static visplane_t *freetail; // killough static visplane_t *freetail; // killough
static visplane_t **freehead = &freetail; // killough static visplane_t **freehead = &freetail; // killough
static struct VisPlaneFree
{
~VisPlaneFree()
{
R_ClearPlanes(false);
for (visplane_t *pl = freetail; pl != NULL; )
{
visplane_t *next = pl->next;
free (pl);
pl = next;
}
}
} VisPlaneFree_er;
visplane_t *floorplane; visplane_t *floorplane;
visplane_t *ceilingplane; visplane_t *ceilingplane;
@ -99,6 +113,17 @@ size_t maxopenings;
short *openings; short *openings;
ptrdiff_t lastopening; ptrdiff_t lastopening;
static struct OpeningsFree
{
~OpeningsFree()
{
if (openings != NULL)
{
free (openings);
openings = NULL;
}
}
} FreeOpenings;
// //
// Clip values are the solid pixel bounding the range. // Clip values are the solid pixel bounding the range.

View file

@ -678,6 +678,18 @@ vissprite_t **vissprite_p;
vissprite_t **lastvissprite; vissprite_t **lastvissprite;
int newvissprite; int newvissprite;
static struct VisSpriteDeleter
{
~VisSpriteDeleter()
{
for (int i = 0; i < MaxVisSprites; ++i)
{
delete vissprites[i];
}
free (vissprites);
}
} DeleteTheVisSprites;
static void R_CreateSkinTranslation (const char *palname) static void R_CreateSkinTranslation (const char *palname)
{ {
FMemLump lump = Wads.ReadLump (palname); FMemLump lump = Wads.ReadLump (palname);
@ -832,7 +844,6 @@ vissprite_t *R_NewVisSprite (void)
return *(vissprite_p-1); return *(vissprite_p-1);
} }
// //
// R_DrawMaskedColumn // R_DrawMaskedColumn
// Used for sprites and masked mid textures. // Used for sprites and masked mid textures.
@ -1555,8 +1566,18 @@ static vissprite_t **spritesorter;
static int spritesortersize = 0; static int spritesortersize = 0;
static int vsprcount; static int vsprcount;
static drawseg_t **drawsegsorter; static struct SpriteSorterFree
static int drawsegsortersize = 0; {
~SpriteSorterFree()
{
if (spritesorter != NULL)
{
delete[] spritesorter;
spritesortersize = 0;
spritesorter = NULL;
}
}
} SpriteSorterFree_er;
// Sort vissprites by depth, far to near // Sort vissprites by depth, far to near
static int STACK_ARGS sv_compare (const void *arg1, const void *arg2) static int STACK_ARGS sv_compare (const void *arg1, const void *arg2)
@ -1569,6 +1590,9 @@ static int STACK_ARGS sv_compare (const void *arg1, const void *arg2)
} }
#if 0 #if 0
static drawseg_t **drawsegsorter;
static int drawsegsortersize = 0;
// Sort vissprites by leftmost column, left to right // Sort vissprites by leftmost column, left to right
static int STACK_ARGS sv_comparex (const void *arg1, const void *arg2) static int STACK_ARGS sv_comparex (const void *arg1, const void *arg2)
{ {

View file

@ -146,6 +146,18 @@ private:
sector_t *m_Sector; sector_t *m_Sector;
}; };
// When destroyed, destroy the sound sequences too.
struct FSoundSequencePtrArray : public TArray<FSoundSequence *>
{
~FSoundSequencePtrArray()
{
for (unsigned int i = 0; i < Size(); ++i)
{
free ((*this)[i]);
}
}
};
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void AssignTranslations (int seq, seqtype_t type); static void AssignTranslations (int seq, seqtype_t type);
@ -157,7 +169,7 @@ static bool TwiddleSeqNum (int &sequence, seqtype_t type);
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // PUBLIC DATA DEFINITIONS -------------------------------------------------
TArray<FSoundSequence *> Sequences; FSoundSequencePtrArray Sequences;
int ActiveSequences; int ActiveSequences;
DSeqNode *DSeqNode::SequenceListHead; DSeqNode *DSeqNode::SequenceListHead;
@ -298,6 +310,7 @@ void DSeqNode::Serialize (FArchive &arc)
ChangeData (seqOffset, delayTics - TIME_REFERENCE, volume, id); ChangeData (seqOffset, delayTics - TIME_REFERENCE, volume, id);
numchoices = arc.ReadCount(); numchoices = arc.ReadCount();
m_SequenceChoices.Resize(numchoices);
for (i = 0; i < numchoices; ++i) for (i = 0; i < numchoices; ++i)
{ {
arc << seqName; arc << seqName;

View file

@ -116,7 +116,7 @@ typedef struct
struct MusPlayingInfo struct MusPlayingInfo
{ {
char *name; FString name;
void *handle; void *handle;
int baseorder; int baseorder;
bool loop; bool loop;
@ -144,7 +144,7 @@ int MAX_SND_DIST;
static channel_t *Channel; // the set of channels available static channel_t *Channel; // the set of channels available
static BOOL mus_paused; // whether songs are paused static BOOL mus_paused; // whether songs are paused
static MusPlayingInfo mus_playing; // music currently being played static MusPlayingInfo mus_playing; // music currently being played
static char *LastSong; // last music that was played static FString LastSong; // last music that was played
static byte *SoundCurve; static byte *SoundCurve;
static int nextcleanup; static int nextcleanup;
static FPlayList *PlayList; static FPlayList *PlayList;
@ -167,6 +167,29 @@ CVAR (Bool, snd_flipstereo, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
static struct FreeSoundData
{
~FreeSoundData()
{
if (Channel != NULL)
{
delete[] Channel;
Channel = NULL;
numChannels = 0;
}
if (SoundCurve != NULL)
{
delete[] SoundCurve;
SoundCurve = NULL;
}
if (PlayList != NULL)
{
delete PlayList;
PlayList = NULL;
}
}
} SoundDataFree_er;
//========================================================================== //==========================================================================
// //
// P_AproxDistance2 // P_AproxDistance2
@ -1430,7 +1453,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
return false; return false;
} }
if (mus_playing.name && stricmp (mus_playing.name, musicname) == 0) if (!mus_playing.name.IsEmpty() && stricmp (mus_playing.name, musicname) == 0)
{ {
if (order != mus_playing.baseorder) if (order != mus_playing.baseorder)
{ {
@ -1451,10 +1474,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
id = strtoul (more+1, NULL, 16); id = strtoul (more+1, NULL, 16);
} }
S_StopMusic (true); S_StopMusic (true);
if (mus_playing.name)
{
delete[] mus_playing.name;
}
mus_playing.handle = I_RegisterCDSong (track, id); mus_playing.handle = I_RegisterCDSong (track, id);
} }
else else
@ -1498,15 +1517,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
S_StopMusic (true); S_StopMusic (true);
// load & register it // load & register it
// Note by Graf Zahl: S_StopMusic NULLs this variable so there's nothing to delete anymore!
/*
if (mus_playing.name)
{
delete[] mus_playing.name;
}
*/
if (offset!=-1) if (offset!=-1)
{ {
mus_playing.handle = I_RegisterSong (lumpnum != -1 ? mus_playing.handle = I_RegisterSong (lumpnum != -1 ?
@ -1525,7 +1535,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
if (mus_playing.handle != 0) if (mus_playing.handle != 0)
{ // play it { // play it
mus_playing.name = copystring (musicname); mus_playing.name = musicname;
I_PlaySong (mus_playing.handle, looping, S_GetMusicVolume (musicname)); I_PlaySong (mus_playing.handle, looping, S_GetMusicVolume (musicname));
mus_playing.baseorder = mus_playing.baseorder =
(I_SetSongPosition (mus_playing.handle, order) ? order : 0); (I_SetSongPosition (mus_playing.handle, order) ? order : 0);
@ -1543,11 +1553,10 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
void S_RestartMusic () void S_RestartMusic ()
{ {
if (LastSong != NULL) if (!LastSong.IsEmpty())
{ {
S_ChangeMusic (LastSong, mus_playing.baseorder, mus_playing.loop, true); S_ChangeMusic (LastSong, mus_playing.baseorder, mus_playing.loop, true);
delete[] LastSong; LastSong = "";
LastSong = NULL;
} }
} }
@ -1583,7 +1592,7 @@ int S_GetMusic (char **name)
void S_StopMusic (bool force) void S_StopMusic (bool force)
{ {
// [RH] Don't stop if a playlist is active. // [RH] Don't stop if a playlist is active.
if ((force || PlayList == NULL) && mus_playing.name) if ((force || PlayList == NULL) && !mus_playing.name.IsEmpty())
{ {
if (mus_paused) if (mus_paused)
I_ResumeSong(mus_playing.handle); I_ResumeSong(mus_playing.handle);
@ -1591,13 +1600,8 @@ void S_StopMusic (bool force)
I_StopSong(mus_playing.handle); I_StopSong(mus_playing.handle);
I_UnRegisterSong(mus_playing.handle); I_UnRegisterSong(mus_playing.handle);
if (LastSong)
{
delete[] LastSong;
}
LastSong = mus_playing.name; LastSong = mus_playing.name;
mus_playing.name = NULL; mus_playing.name = "";
mus_playing.handle = 0; mus_playing.handle = 0;
} }
} }

View file

@ -170,12 +170,12 @@ int FindNode (sockaddr_in *address)
int i; int i;
// find remote node number // find remote node number
for (i = 0; i<doomcom->numnodes; i++) for (i = 0; i<doomcom.numnodes; i++)
if (address->sin_addr.s_addr == sendaddress[i].sin_addr.s_addr if (address->sin_addr.s_addr == sendaddress[i].sin_addr.s_addr
&& address->sin_port == sendaddress[i].sin_port) && address->sin_port == sendaddress[i].sin_port)
break; break;
if (i == doomcom->numnodes) if (i == doomcom.numnodes)
{ {
// packet is not from one of the players (new game broadcast?) // packet is not from one of the players (new game broadcast?)
i = -1; i = -1;
@ -191,9 +191,9 @@ void PacketSend (void)
int c; int c;
//printf ("sending %i\n",gametic); //printf ("sending %i\n",gametic);
c = sendto (mysocket , (const char*)doomcom->data, doomcom->datalength c = sendto (mysocket , (const char*)doomcom.data, doomcom.datalength
,0,(sockaddr *)&sendaddress[doomcom->remotenode] ,0,(sockaddr *)&sendaddress[doomcom.remotenode]
,sizeof(sendaddress[doomcom->remotenode])); ,sizeof(sendaddress[doomcom.remotenode]));
// if (c == -1) // if (c == -1)
// I_Error ("SendPacket error: %s",strerror(errno)); // I_Error ("SendPacket error: %s",strerror(errno));
@ -211,7 +211,7 @@ void PacketGet (void)
int node; int node;
fromlen = sizeof(fromaddress); fromlen = sizeof(fromaddress);
c = recvfrom (mysocket, (char*)doomcom->data, MAX_MSGLEN, 0 c = recvfrom (mysocket, (char*)doomcom.data, MAX_MSGLEN, 0
, (sockaddr *)&fromaddress, &fromlen); , (sockaddr *)&fromaddress, &fromlen);
node = FindNode (&fromaddress); node = FindNode (&fromaddress);
@ -225,7 +225,7 @@ void PacketGet (void)
Printf (PRINT_BOLD, "The connection from %s was dropped\n", Printf (PRINT_BOLD, "The connection from %s was dropped\n",
players[sendplayer[node]].userinfo.netname); players[sendplayer[node]].userinfo.netname);
doomcom->data[0] = 0x80; // NCMD_EXIT doomcom.data[0] = 0x80; // NCMD_EXIT
c = 1; c = 1;
} }
else if (err != WSAEWOULDBLOCK) else if (err != WSAEWOULDBLOCK)
@ -234,13 +234,13 @@ void PacketGet (void)
} }
else else
{ {
doomcom->remotenode = -1; // no packet doomcom.remotenode = -1; // no packet
return; return;
} }
} }
doomcom->remotenode = node; doomcom.remotenode = node;
doomcom->datalength = (short)c; doomcom.datalength = (short)c;
} }
sockaddr_in *PreGet (void *buffer, int bufferlen, bool noabort) sockaddr_in *PreGet (void *buffer, int bufferlen, bool noabort)
@ -307,7 +307,7 @@ void BuildAddress (sockaddr_in *address, char *name)
if (!isnamed) if (!isnamed)
{ {
address->sin_addr.s_addr = inet_addr (name); address->sin_addr.s_addr = inet_addr (name);
Printf ("Node number %d address %s\n", doomcom->numnodes, name); Printf ("Node number %d address %s\n", doomcom.numnodes, name);
} }
else else
{ {
@ -316,7 +316,7 @@ void BuildAddress (sockaddr_in *address, char *name)
I_FatalError ("gethostbyname: couldn't find %s\n%s", name, neterror()); I_FatalError ("gethostbyname: couldn't find %s\n%s", name, neterror());
address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0];
Printf ("Node number %d hostname %s\n", Printf ("Node number %d hostname %s\n",
doomcom->numnodes, hostentry->h_name); doomcom.numnodes, hostentry->h_name);
} }
if (portpart) if (portpart)
@ -368,34 +368,34 @@ void WaitForPlayers (int i)
StartNetwork (false); StartNetwork (false);
// parse player number and host list // parse player number and host list
doomcom->consoleplayer = (short)(Args.GetArg (i+1)[0]-'1'); doomcom.consoleplayer = (short)(Args.GetArg (i+1)[0]-'1');
Printf ("Console player number: %d\n", doomcom->consoleplayer); Printf ("Console player number: %d\n", doomcom.consoleplayer);
doomcom->numnodes = 1; // this node for sure doomcom.numnodes = 1; // this node for sure
i++; i++;
while (++i < Args.NumArgs() && Args.GetArg (i)[0] != '-' && Args.GetArg (i)[0] != '+') while (++i < Args.NumArgs() && Args.GetArg (i)[0] != '-' && Args.GetArg (i)[0] != '+')
{ {
BuildAddress (&sendaddress[doomcom->numnodes], Args.GetArg (i)); BuildAddress (&sendaddress[doomcom.numnodes], Args.GetArg (i));
doomcom->numnodes++; doomcom.numnodes++;
} }
Printf ("Total players: %d\n", doomcom->numnodes); Printf ("Total players: %d\n", doomcom.numnodes);
doomcom->id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes; doomcom.numplayers = doomcom.numnodes;
} }
void STACK_ARGS SendAbort (void) void STACK_ARGS SendAbort (void)
{ {
BYTE dis[2] = { PRE_FAKE, PRE_DISCONNECT }; BYTE dis[2] = { PRE_FAKE, PRE_DISCONNECT };
while (--doomcom->numnodes > 0) while (--doomcom.numnodes > 0)
{ {
PreSend (dis, 2, &sendaddress[doomcom->numnodes]); PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom->numnodes]); PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom->numnodes]); PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
PreSend (dis, 2, &sendaddress[doomcom->numnodes]); PreSend (dis, 2, &sendaddress[doomcom.numnodes]);
} }
} }
@ -417,9 +417,9 @@ void HostGame (int i)
{ // Special case: Only 1 player, so don't bother starting the network { // Special case: Only 1 player, so don't bother starting the network
netgame = false; netgame = false;
multiplayer = true; multiplayer = true;
doomcom->id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes = 1; doomcom.numplayers = doomcom.numnodes = 1;
doomcom->consoleplayer = 0; doomcom.consoleplayer = 0;
return; return;
} }
@ -427,18 +427,18 @@ void HostGame (int i)
// [JC] - this computer is starting the game, therefore it should // [JC] - this computer is starting the game, therefore it should
// be the Net Arbitrator. // be the Net Arbitrator.
doomcom->consoleplayer = 0; doomcom.consoleplayer = 0;
Printf ("Console player number: %d\n", doomcom->consoleplayer); Printf ("Console player number: %d\n", doomcom.consoleplayer);
doomcom->numnodes = 1; doomcom.numnodes = 1;
Printf ("Waiting for players...\n"); Printf ("Waiting for players...\n");
atterm (SendAbort); atterm (SendAbort);
// Wait for numplayers-1 different connections // Wait for numplayers-1 different connections
while (doomcom->numnodes < numplayers) while (doomcom.numnodes < numplayers)
{ {
while (doomcom->numnodes < numplayers) while (doomcom.numnodes < numplayers)
{ {
if (CheckAbort ()) if (CheckAbort ())
{ {
@ -458,7 +458,7 @@ void HostGame (int i)
node = FindNode (from); node = FindNode (from);
if (node == -1) if (node == -1)
{ {
node = doomcom->numnodes++; node = doomcom.numnodes++;
sendaddress[node] = *from; sendaddress[node] = *from;
} }
Printf ("Got connect from node %d\n", node); Printf ("Got connect from node %d\n", node);
@ -472,8 +472,8 @@ void HostGame (int i)
if (node >= 0) if (node >= 0)
{ {
Printf ("Got disconnect from node %d\n", node); Printf ("Got disconnect from node %d\n", node);
doomcom->numnodes--; doomcom.numnodes--;
while (node < doomcom->numnodes) while (node < doomcom.numnodes)
{ {
sendaddress[node] = sendaddress[node+1]; sendaddress[node] = sendaddress[node+1];
node++; node++;
@ -494,8 +494,8 @@ void HostGame (int i)
node = FindNode (from); node = FindNode (from);
if (node >= 0) if (node >= 0)
{ {
doomcom->numnodes--; doomcom.numnodes--;
while (node < doomcom->numnodes) while (node < doomcom.numnodes)
{ {
sendaddress[node] = sendaddress[node+1]; sendaddress[node] = sendaddress[node+1];
node++; node++;
@ -510,18 +510,18 @@ void HostGame (int i)
ackcount = 0; ackcount = 0;
memset (gotack, 0, sizeof(gotack)); memset (gotack, 0, sizeof(gotack));
Printf ("Sending all here\n"); Printf ("Sending all here\n");
while (ackcount < doomcom->numnodes - 1) while (ackcount < doomcom.numnodes - 1)
{ {
packet.fake = PRE_FAKE; packet.fake = PRE_FAKE;
packet.message = PRE_ALLHERE; packet.message = PRE_ALLHERE;
packet.numnodes = doomcom->numnodes - 2; packet.numnodes = doomcom.numnodes - 2;
for (node = 1; node < doomcom->numnodes; node++) for (node = 1; node < doomcom.numnodes; node++)
{ {
int machine, spot = 0; int machine, spot = 0;
if (!gotack[node]) if (!gotack[node])
{ {
for (spot = 0, machine = 1; machine < doomcom->numnodes; machine++) for (spot = 0, machine = 1; machine < doomcom.numnodes; machine++)
{ {
if (node != machine) if (node != machine)
{ {
@ -567,7 +567,7 @@ void HostGame (int i)
Printf ("Go\n"); Printf ("Go\n");
packet.fake = PRE_FAKE; packet.fake = PRE_FAKE;
packet.message = PRE_GO; packet.message = PRE_GO;
for (node = 1; node < doomcom->numnodes; node++) for (node = 1; node < doomcom.numnodes; node++)
{ {
for (int i = 8; i != 0; --i) for (int i = 8; i != 0; --i)
{ {
@ -575,13 +575,13 @@ void HostGame (int i)
} }
} }
Printf ("Total players: %d\n", doomcom->numnodes); Printf ("Total players: %d\n", doomcom.numnodes);
doomcom->id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes; doomcom.numplayers = doomcom.numnodes;
// On the host, each player's number is the same as its node number // On the host, each player's number is the same as its node number
for (i = 0; i < doomcom->numnodes; ++i) for (i = 0; i < doomcom.numnodes; ++i)
{ {
sendplayer[i] = i; sendplayer[i] = i;
} }
@ -614,9 +614,9 @@ void SendToHost (BYTE message, BYTE ackmess, bool abortable)
{ {
waiting = false; waiting = false;
doomcom->consoleplayer = packet.consolenum; doomcom.consoleplayer = packet.consolenum;
sendplayer[0] = packet.consolenum; sendplayer[0] = packet.consolenum;
Printf ("Console player number: %d\n", doomcom->consoleplayer); Printf ("Console player number: %d\n", doomcom.consoleplayer);
} }
} }
} }
@ -644,7 +644,7 @@ void JoinGame (int i)
// Wait for everyone else to connect // Wait for everyone else to connect
waiting = true; waiting = true;
//doomcom->numnodes = 2; //doomcom.numnodes = 2;
atterm (SendAbort); atterm (SendAbort);
while (waiting) while (waiting)
@ -665,12 +665,12 @@ void JoinGame (int i)
switch (packet.message) switch (packet.message)
{ {
case PRE_ALLHERE: case PRE_ALLHERE:
if (doomcom->numnodes == 0) if (doomcom.numnodes == 0)
{ {
int node; int node;
packet.numnodes = packet.numnodes; packet.numnodes = packet.numnodes;
doomcom->numnodes = packet.numnodes + 2; doomcom.numnodes = packet.numnodes + 2;
for (node = 0; node < packet.numnodes; node++) for (node = 0; node < packet.numnodes; node++)
{ {
sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address; sendaddress[node+2].sin_addr.s_addr = packet.machines[node].address;
@ -702,10 +702,10 @@ void JoinGame (int i)
popterm (); popterm ();
Printf ("Total players: %d\n", doomcom->numnodes); Printf ("Total players: %d\n", doomcom.numnodes);
doomcom->id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes; doomcom.numplayers = doomcom.numnodes;
} }
// //
@ -716,24 +716,23 @@ void I_InitNetwork (void)
int i; int i;
char *v; char *v;
doomcom = new doomcom_t; memset (&doomcom, 0, sizeof(doomcom));
memset (doomcom, 0, sizeof(*doomcom));
// set up for network // set up for network
v = Args.CheckValue ("-dup"); v = Args.CheckValue ("-dup");
if (v) if (v)
{ {
doomcom->ticdup = clamp (atoi (v), 1, MAXTICDUP); doomcom.ticdup = clamp (atoi (v), 1, MAXTICDUP);
} }
else else
{ {
doomcom->ticdup = 1; doomcom.ticdup = 1;
} }
if (Args.CheckParm ("-extratic")) if (Args.CheckParm ("-extratic"))
doomcom->extratics = 1; doomcom.extratics = 1;
else else
doomcom->extratics = 0; doomcom.extratics = 0;
v = Args.CheckValue ("-port"); v = Args.CheckValue ("-port");
if (v) if (v)
@ -758,9 +757,9 @@ void I_InitNetwork (void)
// single player game // single player game
netgame = false; netgame = false;
multiplayer = false; multiplayer = false;
doomcom->id = DOOMCOM_ID; doomcom.id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes = 1; doomcom.numplayers = doomcom.numnodes = 1;
doomcom->consoleplayer = 0; doomcom.consoleplayer = 0;
return; return;
} }
} }
@ -768,16 +767,16 @@ void I_InitNetwork (void)
void I_NetCmd (void) void I_NetCmd (void)
{ {
if (doomcom->command == CMD_SEND) if (doomcom.command == CMD_SEND)
{ {
netsend (); netsend ();
} }
else if (doomcom->command == CMD_GET) else if (doomcom.command == CMD_GET)
{ {
netget (); netget ();
} }
else else
I_Error ("Bad net cmd: %i\n",doomcom->command); I_Error ("Bad net cmd: %i\n",doomcom.command);
} }
#ifdef __WIN32__ #ifdef __WIN32__

View file

@ -200,7 +200,7 @@ FString::Pool::~Pool ()
if (str->Owner != NULL) if (str->Owner != NULL)
{ {
FString *owner = str->Owner; FString *owner = str->Owner;
assert (owner->Chars == (char *)str + sizeof(StringHeader)); // assert (owner->Chars == (char *)str + sizeof(StringHeader));
Free ((char *)str + sizeof(StringHeader)); Free ((char *)str + sizeof(StringHeader));
owner->Chars = ""; owner->Chars = "";
} }
@ -307,7 +307,7 @@ void FString::Pool::Free (char *chars)
{ {
if (str->Owner != NULL) if (str->Owner != NULL)
{ {
assert (str->Owner->Chars == (char *)str + sizeof(StringHeader)); // assert (str->Owner->Chars == (char *)str + sizeof(StringHeader));
str = (StringHeader *)((char *)str + RoundLen(str->Len)); str = (StringHeader *)((char *)str + RoundLen(str->Len));
} }
else else
@ -335,7 +335,7 @@ void FString::Pool::Free (char *chars)
{ {
if (str->Owner != NULL) if (str->Owner != NULL)
{ {
assert (str->Owner->Chars == (char *)str + sizeof(StringHeader)); // assert (str->Owner->Chars == (char *)str + sizeof(StringHeader));
str = (StringHeader *)((char *)str + RoundLen(str->Len)); str = (StringHeader *)((char *)str + RoundLen(str->Len));
} }
else else