From 43cfb7ea6ba54a4c1339042eab90d96d21352f23 Mon Sep 17 00:00:00 2001 From: elasota Date: Tue, 3 Nov 2020 19:02:22 -0500 Subject: [PATCH] Write out scores and prefs immediately upon change instead of when app exits, since Android doesn't really exit normally. --- GpApp/GliderProtos.h | 1 + GpApp/GliderVars.h | 2 +- GpApp/HighScores.cpp | 18 ++++++++++++++---- GpApp/House.cpp | 3 +++ GpApp/HouseIO.cpp | 16 ++-------------- GpApp/SelectHouse.cpp | 15 ++++++++++++++- GpApp/Settings.cpp | 3 +++ 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/GpApp/GliderProtos.h b/GpApp/GliderProtos.h index e82ff01..915c372 100644 --- a/GpApp/GliderProtos.h +++ b/GpApp/GliderProtos.h @@ -99,6 +99,7 @@ void SortHighScores (void); void ZeroHighScores (void); void ZeroAllButHighestScore (void); Boolean TestHighScore (void); +void WriteScores (void); // Either saves the house or saves scores, depending on if it's read-only Boolean WriteScoresToDisk (void); Boolean ReadScoresFromDisk (void); diff --git a/GpApp/GliderVars.h b/GpApp/GliderVars.h index 25e8218..b6c8592 100644 --- a/GpApp/GliderVars.h +++ b/GpApp/GliderVars.h @@ -55,5 +55,5 @@ extern long theScore; extern short playOriginH, playOriginV; extern short thisRoomNumber, theMode, batteryTotal, bandsTotal; extern short foilTotal, mortals, numMasterObjects, previousRoom; -extern Boolean fileDirty, gameDirty, showFoil, doZooms, isPlayMusicGame; +extern Boolean fileDirty, showFoil, doZooms, isPlayMusicGame; diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp index b8f823b..e8f82b4 100644 --- a/GpApp/HighScores.cpp +++ b/GpApp/HighScores.cpp @@ -55,7 +55,7 @@ short lastHighScore; Boolean keyStroke; extern short splashOriginH, splashOriginV; -extern Boolean quickerTransitions, resumedSavedGame; +extern Boolean quickerTransitions, resumedSavedGame, houseIsReadOnly; //============================================================== Functions @@ -402,7 +402,8 @@ Boolean TestHighScore (void) thisHousePtr->highScores.timeStamps[kMaxScores - 1] = static_cast(scoreTimestamp); thisHousePtr->highScores.levels[kMaxScores - 1] = CountRoomsVisited(); SortHighScores(); - gameDirty = true; + + WriteScores(); } if (placing != -1) @@ -734,11 +735,20 @@ Boolean WriteScoresToDisk (void) scoresStream->Close(); - gameDirty = false; - return (true); } +void WriteScores (void) +{ + if (houseIsReadOnly) + { + if (!WriteScoresToDisk()) + YellowAlert(kYellowFailedWrite, 0); + } + else if (!WriteHouse(theMode == kEditMode)) + YellowAlert(kYellowFailedWrite, 0); +} + //-------------------------------------------------------------- ReadScoresFromDisk Boolean ReadScoresFromDisk (void) diff --git a/GpApp/House.cpp b/GpApp/House.cpp index b421904..c9296e3 100644 --- a/GpApp/House.cpp +++ b/GpApp/House.cpp @@ -24,6 +24,7 @@ #define kGoToDialogID 1043 +void WriteOutPrefs(void); void UpdateGoToDialog (Dialog *); int16_t GoToFilter (void *context, Dialog *dial, const TimeTaggedVOSEvent *evt); @@ -104,6 +105,8 @@ Boolean CreateNewHouse (void) InitCursor(); if (!OpenHouse()) return (false); + + WriteOutPrefs(); return (true); } diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index d9900be..41fb33a 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -39,7 +39,7 @@ Rect movieRect; PortabilityLayer::IResourceArchive *houseResFork; short wasHouseVersion; GpIOStream *houseStream; -Boolean houseOpen, fileDirty, gameDirty; +Boolean houseOpen, fileDirty; Boolean changeLockStateOfHouse, saveHouseLocked, houseIsReadOnly; Boolean hasMovie, tvInRoom; @@ -639,7 +639,6 @@ Boolean ReadHouse (void) objActive = kNoObjectSelected; ReflectCurrentRoom(true); - gameDirty = false; fileDirty = false; UpdateMenus(false); @@ -724,7 +723,6 @@ Boolean WriteHouse (Boolean checkIt) ReflectCurrentRoom(true); } - gameDirty = false; fileDirty = false; UpdateMenus(false); return (true); @@ -740,17 +738,7 @@ Boolean CloseHouse (void) if (!houseOpen) return (true); - if (gameDirty) - { - if (houseIsReadOnly) - { - if (!WriteScoresToDisk()) - YellowAlert(kYellowFailedWrite, 0); - } - else if (!WriteHouse(theMode == kEditMode)) - YellowAlert(kYellowFailedWrite, 0); - } - else if (fileDirty) + if (fileDirty) { #ifndef COMPILEDEMO if (!QuerySaveChanges()) // false signifies user canceled diff --git a/GpApp/SelectHouse.cpp b/GpApp/SelectHouse.cpp index 0e4af09..9a655a1 100644 --- a/GpApp/SelectHouse.cpp +++ b/GpApp/SelectHouse.cpp @@ -42,7 +42,7 @@ #define kGrayedOutDownArrow 1053 #define kMaxExtraHouses 8 - +void WriteOutPrefs (void); void UpdateLoadDialog (Dialog *); void PageUpHouses (Dialog *); void PageDownHouses (Dialog *); @@ -343,6 +343,7 @@ void DoLoadHouse (void) Dialog *theDial; short i, wasIndex, screenCount; Boolean leaving, whoCares; + bool houseNameDirty = false; PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance(); @@ -411,7 +412,10 @@ void DoLoadHouse (void) PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, thisHouseName); if (OpenHouse()) + { whoCares = ReadHouse(); + houseNameDirty = true; + } } leaving = true; } @@ -449,7 +453,10 @@ void DoLoadHouse (void) PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, thisHouseName); if (OpenHouse()) + { whoCares = ReadHouse(); + houseNameDirty = true; + } } leaving = true; } @@ -483,7 +490,10 @@ void DoLoadHouse (void) PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, thisHouseName); if (OpenHouse()) + { whoCares = ReadHouse(); + houseNameDirty = true; + } } leaving = true; } @@ -501,6 +511,9 @@ void DoLoadHouse (void) UpdateLoadDialog(theDial); } + if (houseNameDirty) + WriteOutPrefs(); + wm->SwapExclusiveWindow(exclWindow); // Pop exclusive window theDial->Destroy(); diff --git a/GpApp/Settings.cpp b/GpApp/Settings.cpp index 6e31f20..2b03ffd 100644 --- a/GpApp/Settings.cpp +++ b/GpApp/Settings.cpp @@ -99,6 +99,7 @@ void FlashSettingsButton (DrawSurface *, short); void UpdateSettingsMain (Dialog *); int16_t PrefsFilter(void *context, Dialog *dialog, const TimeTaggedVOSEvent *evt); void BitchAboutChanges (void); +void WriteOutPrefs (void); Rect prefButton[4], controlRects[4]; @@ -1358,6 +1359,8 @@ void DoSettingsMain (void) } PortabilityLayer::HostDisplayDriver::GetInstance()->SetUseICCProfile(isUseICCProfile); + + WriteOutPrefs(); } //-------------------------------------------------------------- BitchAboutChanges