Permalink
Browse files

- it works now so that I can start a level, go to the next one and qu…

…it the engine without crashing.

Judging from this there will be quite a few surprises with the memory management that still need fixing.
  • Loading branch information...
coelckers committed Jan 11, 2019
1 parent 70ee43a commit 99a3b09a68cda1f7d85dcb79085d69116b28153e
@@ -382,6 +382,8 @@ void DThinker::ChangeStatNum (int statnum)
{
FThinkerList *list;

Level = currentSession->Levelinfo[0]; // fixme later.

// This thinker should already be in a list; verify that.
assert(NextThinker != NULL && PrevThinker != NULL);

@@ -165,8 +165,7 @@ extern bool sendpause, sendsave, sendturn180, SendLand;

void *statcopy; // for statistics driver

static FGameSession session; // do not use directly. The pointer is more future proof.
FGameSession *currentSession = &session;
FGameSession *currentSession = nullptr;

//==========================================================================
//
@@ -1009,7 +1008,7 @@ void G_DoLoadLevel (const FString &nextlevel, int position, bool autosave, bool
{
auto levelinfo = FindLevelInfo(nextlevel);
TArray<level_info_t *> MapSet;

MapSet.Push(levelinfo);
//MapSet.Append(levelinfo->SubLevels);

@@ -1031,7 +1030,8 @@ void G_DoLoadLevel (const FString &nextlevel, int position, bool autosave, bool
lastposition = position;

StatusBar->DetachAllMessages ();
currentSession->Levelinfo.Clear(); // Delete all old levels.
currentSession->Levelinfo.DeleteAndClear();
GC::FullGC(); // really get rid of all the data we just deleted.

// Force 'teamplay' to 'true' if need be.
if (levelinfo->flags2 & LEVEL2_FORCETEAMPLAYON)
@@ -1838,9 +1838,7 @@ void G_UnSnapshotLevel (const TArray<FLevelLocals *> &levels, bool hubLoad)
auto snapshot = currentSession->Snapshots.CheckKey(Level->MapName);
if (snapshot == nullptr)
{
// should be handled by the caller when reading in the savegame.
I_Error("Bad list of levels passed to G_UnSnapshotLevel");
return;
continue;
}

if (Level->info->isValid())
@@ -317,7 +317,7 @@ struct FLevelLocals : public FLevelData
class FGameSession
{
public:
TArray<FLevelLocals *> Levelinfo;
TDeletingArray<FLevelLocals *> Levelinfo;

TMap<FName, FCompressedBuffer> Snapshots;
TMap<FName, TArray<acsdefered_t>> DeferredScripts;
@@ -2251,7 +2251,6 @@ static void ClearMapinfo()
AllSkills.Clear();
DefaultSkill = -1;
DeinitIntermissions();
currentSession->F1Pic = "";
}

//==========================================================================
@@ -61,7 +61,7 @@ class FDrawInfoList
public:
TDeletingArray<HWDrawInfo *> mList;

HWDrawInfo * GetNew(FLevelLocals *);
HWDrawInfo * GetNew();
void Release(HWDrawInfo *);
};

@@ -77,21 +77,22 @@ FDrawInfoList di_list;
//
//==========================================================================

HWDrawInfo *FDrawInfoList::GetNew(FLevelLocals *lev)
HWDrawInfo *FDrawInfoList::GetNew()
{
if (mList.Size() > 0)
{
HWDrawInfo *di;
mList.Pop(di);
return di;
}
return new HWDrawInfo(lev);
return new HWDrawInfo();
}

void FDrawInfoList::Release(HWDrawInfo * di)
{
di->DrawScene = nullptr;
di->ClearBuffers();
di->Level = nullptr;
mList.Push(di);
}

@@ -103,8 +104,9 @@ void FDrawInfoList::Release(HWDrawInfo * di)

HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
{
HWDrawInfo *di = di_list.GetNew(lev);
HWDrawInfo *di = di_list.GetNew();
if (parent) di->DrawScene = parent->DrawScene;
di->Level = lev;
di->StartScene(parentvp, uniforms);
return di;
}
@@ -193,16 +195,19 @@ void HWDrawInfo::ClearBuffers()
HandledSubsectors.Clear();
spriteindex = 0;

CurrentMapSections.Resize(Level->NumMapSections);
CurrentMapSections.Zero();
if (Level)
{
CurrentMapSections.Resize(Level->NumMapSections);
CurrentMapSections.Zero();

section_renderflags.Resize(Level->sections.allSections.Size());
ss_renderflags.Resize(Level->subsectors.Size());
no_renderflags.Resize(Level->subsectors.Size());
section_renderflags.Resize(Level->sections.allSections.Size());
ss_renderflags.Resize(Level->subsectors.Size());
no_renderflags.Resize(Level->subsectors.Size());

memset(&section_renderflags[0], 0, Level->sections.allSections.Size() * sizeof(section_renderflags[0]));
memset(&ss_renderflags[0], 0, Level->subsectors.Size() * sizeof(ss_renderflags[0]));
memset(&no_renderflags[0], 0, Level->nodes.Size() * sizeof(no_renderflags[0]));
memset(&section_renderflags[0], 0, Level->sections.allSections.Size() * sizeof(section_renderflags[0]));
memset(&ss_renderflags[0], 0, Level->subsectors.Size() * sizeof(ss_renderflags[0]));
memset(&no_renderflags[0], 0, Level->nodes.Size() * sizeof(no_renderflags[0]));
}

Decals[0].Clear();
Decals[1].Clear();
@@ -97,16 +97,6 @@ enum DrawListType

struct HWDrawInfo
{
HWDrawInfo(FLevelLocals *lev)
{
Level = lev;
}

virtual ~HWDrawInfo()
{
ClearBuffers();
}

struct wallseg
{
float x1, y1, z1, x2, y2, z2;
@@ -415,6 +415,7 @@ void P_Init ()
{
atterm (P_Shutdown);

currentSession = new FGameSession;
P_InitEffects (); // [RH]
P_InitTerrainTypes ();
P_InitKeyMessages ();
@@ -423,6 +424,8 @@ void P_Init ()

static void P_Shutdown ()
{
delete currentSession;
currentSession = nullptr;
DThinker::DestroyThinkersInList(STAT_STATIC);
P_FreeLevelData ();
// [ZZ] delete global event handlers
@@ -1767,7 +1767,8 @@ void S_StopSound (const FPolyObj *poly, int channel)

void S_StopAllChannels ()
{
ForAllLevels(SN_StopAllSequences);
if (currentSession)
ForAllLevels(SN_StopAllSequences);

FSoundChan *chan = Channels;
while (chan != NULL)

0 comments on commit 99a3b09

Please sign in to comment.