From b4d261de2fb07f5a6ff43360707ac815d7f35ef2 Mon Sep 17 00:00:00 2001 From: "wagic.jeck" Date: Wed, 23 Sep 2009 20:36:10 +0000 Subject: [PATCH] Jeck - Fix for set loading / unloading. * This is a little dirty, as it's loading the profile multiple times. The proper way to do it would be to add any line starting with "unlocked_" to an array for deferred loading. This would also allow us to write those lines back even without the associated set being loaded. The clean solution is on my todo-list now :) --- projects/mtg/src/GameApp.cpp | 5 ++++- projects/mtg/src/GameOptions.cpp | 9 ++------- projects/mtg/src/GameStateMenu.cpp | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 160b36049..bfdbc8575 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -72,7 +72,7 @@ void GameApp::Create() //Link this to our settings manager. options.theGame = this; - //Ensure that options are properly loaded before loading files. + //Ensure that options are partially loaded before loading files. options.reloadProfile(); //Test for Music files presence @@ -184,6 +184,9 @@ void GameApp::LoadGameStates() void GameApp::Destroy() { LOG("==Destroying GameApp=="); + //Save game options before we destroy everything. + options.save(); + for (int i=GAME_STATE_MENU;i<=MAX_STATE-1;i++) { if (mGameStates[i]){ diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index a6fd12ad1..287c3f36e 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -93,7 +93,7 @@ int Options::getID(string name){ //Is it an unlocked set? string setname = name.substr(strlen("unlocked_")); - if(MtgSets::SetsList){ + if(MtgSets::SetsList && MtgSets::SetsList->nb_items){ int unlocked = MtgSets::SetsList->find(setname); if(unlocked != -1) return Options::optionSet(unlocked); @@ -434,12 +434,7 @@ GameSettings::GameSettings() } GameSettings::~GameSettings(){ - if(globalOptions) - globalOptions->save(); - - if(profileOptions) - profileOptions->save(); - + //Destructor no longer saves, to prevent conflicts when MtgSets::SetsList == NULL SAFE_DELETE(globalOptions); SAFE_DELETE(profileOptions); SAFE_DELETE(themeOptions); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index f6210da1c..b90af3eda 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -324,8 +324,9 @@ void GameStateMenu::Update(float dt) }else{ currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE; } + //Reload list of unlocked sets, now that we know about the sets. - options.reloadProfile(); + options.reloadProfile(false); //List active profile and database size. PlayerData * playerdata = NEW PlayerData(mParent->collection);