Skip to content

Commit

Permalink
Fixed: Do not reload resources or parse DEDs when shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 16, 2012
1 parent 4033a77 commit 79f9c91
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 89 deletions.
117 changes: 64 additions & 53 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1174,14 +1174,19 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)
DD_ComposeMainWindowTitle(buf);
Sys_SetWindowTitle(windowIDX, buf);

Materials_Init();
FI_Init();
P_PtcInit();

if(!exchangeEntryPoints(Game_PluginId(game)))
if(!DD_IsShuttingDown())
{
Con_Message("Warning:DD_ChangeGame: Failed exchanging entrypoints with plugin %i, aborting.\n", (int)Game_PluginId(game));
return false;
// Re-initialize subsystems needed even when in ringzero.

Materials_Init();
FI_Init();
P_PtcInit(); /// @todo not needed in this mode.

if(!exchangeEntryPoints(Game_PluginId(game)))
{
Con_Message("Warning:DD_ChangeGame: Failed exchanging entrypoints with plugin %i, aborting.\n", (int)Game_PluginId(game));
return false;
}
}

// This is now the current game.
Expand All @@ -1190,63 +1195,69 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)
DD_ComposeMainWindowTitle(buf);
Sys_SetWindowTitle(windowIDX, buf);

if(!DD_IsNullGame(theGame))
{
// Tell the plugin it is being loaded.
void* loader = DD_FindEntryPoint(Game_PluginId(theGame), "DP_Load");
#ifdef _DEBUG
Con_Message("DD_ChangeGame2: Calling DP_Load (%p)\n", loader);
#endif
if(loader) ((pluginfunc_t)loader)();
}

/**
* The bulk of this we can do in busy mode unless we are already busy
* (which can happen if a fatal error occurs during game load and we must
* shutdown immediately; Sys_Shutdown will call back to load the special
* "null-game" game).
* If we aren't shutting down then we are either loading a game or switching
* to ringzero (the current game will have already been unloaded).
*/
if(!DD_IsShuttingDown())
{
const int busyMode = BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0);
ddgamechange_paramaters_t p;
BusyTask gameChangeTasks[] = {
// Phase 1: Initialization.
{ DD_BeginGameChangeWorker, &p, busyMode, "Loading game...", 200, 0.0f, 0.1f },
/**
* The bulk of this we can do in busy mode unless we are already busy
* (which can happen if a fatal error occurs during game load and we must
* shutdown immediately; Sys_Shutdown will call back to load the special
* "null-game" game).
*/
const int busyMode = BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0);
ddgamechange_paramaters_t p;
BusyTask gameChangeTasks[] = {
// Phase 1: Initialization.
{ DD_BeginGameChangeWorker, &p, busyMode, "Loading game...", 200, 0.0f, 0.1f },

// Phase 2: Loading "startup" resources.
{ DD_LoadGameStartupResourcesWorker, &p, busyMode, NULL, 200, 0.1f, 0.3f },
// Phase 2: Loading "startup" resources.
{ DD_LoadGameStartupResourcesWorker, &p, busyMode, NULL, 200, 0.1f, 0.3f },

// Phase 3: Loading "addon" resources.
{ DD_LoadAddonResourcesWorker, &p, busyMode, "Loading addons...", 200, 0.3f, 0.7f },
// Phase 3: Loading "addon" resources.
{ DD_LoadAddonResourcesWorker, &p, busyMode, "Loading addons...", 200, 0.3f, 0.7f },

// Phase 4: Game activation.
{ DD_ActivateGameWorker, &p, busyMode, "Starting game...", 200, 0.7f, 1.0f }
};
// Phase 4: Game activation.
{ DD_ActivateGameWorker, &p, busyMode, "Starting game...", 200, 0.7f, 1.0f }
};

p.initiatedBusyMode = !Con_IsBusy();
p.initiatedBusyMode = !Con_IsBusy();

/// \kludge Use more appropriate task names when unloading a game.
if(DD_IsNullGame(game))
{
gameChangeTasks[0].name = "Unloading game...";
gameChangeTasks[3].name = "Activating ringzero...";
}
// kludge end
if(!DD_IsNullGame(theGame))
{
// Tell the plugin it is being loaded.
/// @todo Must this be done in the main thread?
void* loader = DD_FindEntryPoint(Game_PluginId(theGame), "DP_Load");
#ifdef _DEBUG
Con_Message("DD_ChangeGame2: Calling DP_Load (%p)\n", loader);
#endif
if(loader) ((pluginfunc_t)loader)();
}

Con_BusyList(gameChangeTasks, sizeof(gameChangeTasks)/sizeof(gameChangeTasks[0]));
}
/// \kludge Use more appropriate task names when unloading a game or shutting down.
if(DD_IsNullGame(game))
{
gameChangeTasks[0].name = "Unloading game...";
gameChangeTasks[3].name = "Switching to ringzero...";
}
// kludge end

// Process any GL-related tasks we couldn't while Busy.
Rend_ParticleLoadExtraTextures();
Con_BusyList(gameChangeTasks, sizeof(gameChangeTasks)/sizeof(gameChangeTasks[0]));

if(!DD_IsNullGame(theGame))
{
printGameBanner(theGame);
}
else
{
// Lets play a nice title animation.
DD_StartTitle();
// Process any GL-related tasks we couldn't while Busy.
Rend_ParticleLoadExtraTextures();

if(!DD_IsNullGame(theGame))
{
printGameBanner(theGame);
}
else
{
// Lets play a nice title animation.
DD_StartTitle();
}
}

/**
Expand Down
91 changes: 55 additions & 36 deletions doomsday/engine/portable/src/fs_main.c
Expand Up @@ -550,48 +550,65 @@ static int unloadListFiles(FileList* list, boolean nonStartup)
return unloaded;
}

#if _DEBUG
static void logOrphanedFileIdentifiers(void)
{
fileidentifierid_t nullId;
uint i, orphanCount = 0;

memset(nullId, 0, sizeof nullId);

for(i = 0; i < fileIdentifiersCount; ++i)
{
fileidentifier_t* id = fileIdentifiers + i;
if(!memcmp(id->hash, &nullId, FILEIDENTIFIERID_T_LASTINDEX)) continue;

if(!orphanCount)
{
Con_Printf("Warning: Orphan file identifiers:\n");
}

Con_Printf(" %u - ", orphanCount);
F_PrintFileId(id->hash);
Con_Printf("\n");

orphanCount++;
}
}
#endif

int F_Reset(void)
{
int unloaded = 0;
if(inited)
{
if(!inited) return 0;

#if _DEBUG
// List all open files with their identifiers.
VERBOSE(
Con_Printf("Open files at reset:\n");
FileList_Print(openFiles);
Con_Printf("End\n") )
// List all open files with their identifiers.
VERBOSE(
Con_Printf("Open files at reset:\n");
FileList_Print(openFiles);
Con_Printf("End\n")
)
#endif

// Perform non-startup file unloading...
unloaded = unloadListFiles(loadedFiles, true/*non-startup*/);
// Perform non-startup file unloading...
unloaded = unloadListFiles(loadedFiles, true/*non-startup*/);

#if _DEBUG
// Sanity check: look for dangling identifiers.
{ uint i;
fileidentifierid_t nullId;
memset(nullId, 0, sizeof nullId);
for(i = 0; i < fileIdentifiersCount; ++i)
{
fileidentifier_t* id = fileIdentifiers + i;
if(!memcmp(id->hash, &nullId, FILEIDENTIFIERID_T_LASTINDEX)) continue;

Con_Printf("Warning: Dangling file identifier: ");
F_PrintFileId(id->hash);
Con_Printf("\n");
}}
// Sanity check: look for orphaned identifiers.
logOrphanedFileIdentifiers();
#endif

// Reset file IDs so previously seen files can be processed again.
/// \fixme this releases the ID of startup files too but given the
/// only startup file is doomsday.pk3 which we never attempt to load
/// again post engine startup, this isn't an immediate problem.
F_ResetFileIds();
// Reset file IDs so previously seen files can be processed again.
/// \fixme this releases the ID of startup files too but given the
/// only startup file is doomsday.pk3 which we never attempt to load
/// again post engine startup, this isn't an immediate problem.
F_ResetFileIds();

// Update the dir/WAD translations.
F_InitLumpDirectoryMappings();
F_InitVirtualDirectoryMappings();

// Update the dir/WAD translations.
F_InitLumpDirectoryMappings();
F_InitVirtualDirectoryMappings();
}
return unloaded;
}

Expand Down Expand Up @@ -1990,14 +2007,16 @@ void F_InitLumpDirectoryMappings(void)
static boolean inited = false;
size_t bufSize = 0;
uint8_t* buf = NULL;
lumpnum_t i;

if(inited)
{ // Free old paths, if any.
clearLDMappings();
}

if(DD_IsShuttingDown()) return;

// Add the contents of all DD_DIREC lumps.
{ lumpnum_t i;
for(i = 0; i < F_LumpCount(); ++i)
{
const LumpInfo* info;
Expand All @@ -2022,11 +2041,9 @@ void F_InitLumpDirectoryMappings(void)
F_ReadLumpSection(fsObject, lumpIdx, buf, 0, lumpLength);
buf[lumpLength] = 0;
parseLDMappingList((const char*)buf);
}}

if(NULL != buf)
free(buf);
}

if(buf) free(buf);
inited = true;
}

Expand Down Expand Up @@ -2134,6 +2151,8 @@ void F_InitVirtualDirectoryMappings(void)

clearVDMappings();

if(DD_IsShuttingDown()) return;

// Create virtual directory mappings by processing all -vdmap options.
for(i = 0; i < argC; ++i)
{
Expand Down

0 comments on commit 79f9c91

Please sign in to comment.