Skip to content

Commit

Permalink
Fixed|libcommon: Fully reinitialize the game SaveSlots when changing …
Browse files Browse the repository at this point in the history
…game

The game plugin might not be unloaded when the game is changed, so we
need to fully reinitialize the save slots each time.
  • Loading branch information
danij-deng committed Mar 10, 2014
1 parent 7421fac commit c7f6397
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -213,7 +213,7 @@ mobj_t *bodyQueue[BODYQUEUESIZE];
int bodyQueueSlot;
#endif

static SaveSlots sslots;
static SaveSlots *sslots;

// vars used with game status cvars
int gsvEpisode;
Expand Down Expand Up @@ -480,7 +480,8 @@ gameaction_t G_GameAction()

static void initSaveSlots()
{
DENG2_ASSERT(sslots.slotCount() == 0);
delete sslots;
sslots = new SaveSlots;

// Declare the native game state reader.
de::game::SavedSessionRepository &saveRepo = G_SavedSessionRepository();
Expand All @@ -495,12 +496,12 @@ static void initSaveSlots()
};
for(int i = 0; i < NUMSAVESLOTS; ++i)
{
sslots.addSlot(de::String::number(i), true, de::String(SAVEGAMENAME "%1").arg(i),
gameMenuSaveSlotWidgetIds[i]);
sslots->addSlot(de::String::number(i), true, de::String(SAVEGAMENAME "%1").arg(i),
gameMenuSaveSlotWidgetIds[i]);
}
sslots.addSlot("auto", false, de::String(SAVEGAMENAME "%1").arg(AUTO_SLOT));
sslots->addSlot("auto", false, de::String(SAVEGAMENAME "%1").arg(AUTO_SLOT));
#if __JHEXEN__
sslots.addSlot("base", false, de::String(SAVEGAMENAME "%1").arg(BASE_SLOT));
sslots->addSlot("base", false, de::String(SAVEGAMENAME "%1").arg(BASE_SLOT));
#endif
}

Expand All @@ -510,31 +511,31 @@ static void initSaveSlots()
*/
void G_CommonPreInit()
{
int i, j;

DENG_ASSERT(gameMapUri == 0);
gameMapUri = Uri_New();
if(!gameMapUri)
{
gameMapUri = Uri_New();
}
Uri_Clear(gameMapUri);
quitInProgress = false;
verbose = CommandLine_Exists("-verbose");

// Register hooks.
Plug_AddHook(HOOK_DEMO_STOP, Hook_DemoStop);

// Setup the players.
for(i = 0; i < MAXPLAYERS; ++i)
for(int i = 0; i < MAXPLAYERS; ++i)
{
player_t* pl = players + i;
player_t *pl = players + i;

pl->plr = DD_GetPlayer(i);
pl->plr->extraData = (void*) &players[i];

/// \todo Only necessary because the engine does not yet unload game
/// plugins when they are not in use; thus a game change may leave
/// these pointers dangling.
for(j = 0; j < NUMPSPRITES; ++j)
/// @todo Only necessary because the engine does not yet unload game plugins when they
/// are not in use; thus a game change may leave these pointers dangling.
for(int k = 0; k < NUMPSPRITES; ++k)
{
pl->pSprites[j].state = NULL;
pl->plr->pSprites[j].statePtr = NULL;
pl->pSprites[k].state = NULL;
pl->plr->pSprites[k].statePtr = NULL;
}
}

Expand Down Expand Up @@ -976,7 +977,8 @@ void R_InitHud()

SaveSlots &G_SaveSlots()
{
return sslots;
DENG2_ASSERT(sslots != 0);
return *sslots;
}

de::game::SavedSessionRepository &G_SavedSessionRepository()
Expand Down Expand Up @@ -1071,6 +1073,7 @@ void G_CommonShutdown()
ST_Shutdown();
GUI_Shutdown();

delete sslots; sslots = 0;
Uri_Delete(gameMapUri); gameMapUri = 0;
}

Expand Down

0 comments on commit c7f6397

Please sign in to comment.