Write out scores and prefs immediately upon change instead of when app exits, since Android doesn't really exit normally.

This commit is contained in:
elasota
2020-11-03 19:02:22 -05:00
parent 3b5f222d98
commit 43cfb7ea6b
7 changed files with 38 additions and 20 deletions

View File

@@ -99,6 +99,7 @@ void SortHighScores (void);
void ZeroHighScores (void); void ZeroHighScores (void);
void ZeroAllButHighestScore (void); void ZeroAllButHighestScore (void);
Boolean TestHighScore (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 WriteScoresToDisk (void);
Boolean ReadScoresFromDisk (void); Boolean ReadScoresFromDisk (void);

View File

@@ -55,5 +55,5 @@ extern long theScore;
extern short playOriginH, playOriginV; extern short playOriginH, playOriginV;
extern short thisRoomNumber, theMode, batteryTotal, bandsTotal; extern short thisRoomNumber, theMode, batteryTotal, bandsTotal;
extern short foilTotal, mortals, numMasterObjects, previousRoom; extern short foilTotal, mortals, numMasterObjects, previousRoom;
extern Boolean fileDirty, gameDirty, showFoil, doZooms, isPlayMusicGame; extern Boolean fileDirty, showFoil, doZooms, isPlayMusicGame;

View File

@@ -55,7 +55,7 @@ short lastHighScore;
Boolean keyStroke; Boolean keyStroke;
extern short splashOriginH, splashOriginV; extern short splashOriginH, splashOriginV;
extern Boolean quickerTransitions, resumedSavedGame; extern Boolean quickerTransitions, resumedSavedGame, houseIsReadOnly;
//============================================================== Functions //============================================================== Functions
@@ -402,7 +402,8 @@ Boolean TestHighScore (void)
thisHousePtr->highScores.timeStamps[kMaxScores - 1] = static_cast<uint32_t>(scoreTimestamp); thisHousePtr->highScores.timeStamps[kMaxScores - 1] = static_cast<uint32_t>(scoreTimestamp);
thisHousePtr->highScores.levels[kMaxScores - 1] = CountRoomsVisited(); thisHousePtr->highScores.levels[kMaxScores - 1] = CountRoomsVisited();
SortHighScores(); SortHighScores();
gameDirty = true;
WriteScores();
} }
if (placing != -1) if (placing != -1)
@@ -734,11 +735,20 @@ Boolean WriteScoresToDisk (void)
scoresStream->Close(); scoresStream->Close();
gameDirty = false;
return (true); return (true);
} }
void WriteScores (void)
{
if (houseIsReadOnly)
{
if (!WriteScoresToDisk())
YellowAlert(kYellowFailedWrite, 0);
}
else if (!WriteHouse(theMode == kEditMode))
YellowAlert(kYellowFailedWrite, 0);
}
//-------------------------------------------------------------- ReadScoresFromDisk //-------------------------------------------------------------- ReadScoresFromDisk
Boolean ReadScoresFromDisk (void) Boolean ReadScoresFromDisk (void)

View File

@@ -24,6 +24,7 @@
#define kGoToDialogID 1043 #define kGoToDialogID 1043
void WriteOutPrefs(void);
void UpdateGoToDialog (Dialog *); void UpdateGoToDialog (Dialog *);
int16_t GoToFilter (void *context, Dialog *dial, const TimeTaggedVOSEvent *evt); int16_t GoToFilter (void *context, Dialog *dial, const TimeTaggedVOSEvent *evt);
@@ -104,6 +105,8 @@ Boolean CreateNewHouse (void)
InitCursor(); InitCursor();
if (!OpenHouse()) if (!OpenHouse())
return (false); return (false);
WriteOutPrefs();
return (true); return (true);
} }

View File

@@ -39,7 +39,7 @@ Rect movieRect;
PortabilityLayer::IResourceArchive *houseResFork; PortabilityLayer::IResourceArchive *houseResFork;
short wasHouseVersion; short wasHouseVersion;
GpIOStream *houseStream; GpIOStream *houseStream;
Boolean houseOpen, fileDirty, gameDirty; Boolean houseOpen, fileDirty;
Boolean changeLockStateOfHouse, saveHouseLocked, houseIsReadOnly; Boolean changeLockStateOfHouse, saveHouseLocked, houseIsReadOnly;
Boolean hasMovie, tvInRoom; Boolean hasMovie, tvInRoom;
@@ -639,7 +639,6 @@ Boolean ReadHouse (void)
objActive = kNoObjectSelected; objActive = kNoObjectSelected;
ReflectCurrentRoom(true); ReflectCurrentRoom(true);
gameDirty = false;
fileDirty = false; fileDirty = false;
UpdateMenus(false); UpdateMenus(false);
@@ -724,7 +723,6 @@ Boolean WriteHouse (Boolean checkIt)
ReflectCurrentRoom(true); ReflectCurrentRoom(true);
} }
gameDirty = false;
fileDirty = false; fileDirty = false;
UpdateMenus(false); UpdateMenus(false);
return (true); return (true);
@@ -740,17 +738,7 @@ Boolean CloseHouse (void)
if (!houseOpen) if (!houseOpen)
return (true); return (true);
if (gameDirty) if (fileDirty)
{
if (houseIsReadOnly)
{
if (!WriteScoresToDisk())
YellowAlert(kYellowFailedWrite, 0);
}
else if (!WriteHouse(theMode == kEditMode))
YellowAlert(kYellowFailedWrite, 0);
}
else if (fileDirty)
{ {
#ifndef COMPILEDEMO #ifndef COMPILEDEMO
if (!QuerySaveChanges()) // false signifies user canceled if (!QuerySaveChanges()) // false signifies user canceled

View File

@@ -42,7 +42,7 @@
#define kGrayedOutDownArrow 1053 #define kGrayedOutDownArrow 1053
#define kMaxExtraHouses 8 #define kMaxExtraHouses 8
void WriteOutPrefs (void);
void UpdateLoadDialog (Dialog *); void UpdateLoadDialog (Dialog *);
void PageUpHouses (Dialog *); void PageUpHouses (Dialog *);
void PageDownHouses (Dialog *); void PageDownHouses (Dialog *);
@@ -343,6 +343,7 @@ void DoLoadHouse (void)
Dialog *theDial; Dialog *theDial;
short i, wasIndex, screenCount; short i, wasIndex, screenCount;
Boolean leaving, whoCares; Boolean leaving, whoCares;
bool houseNameDirty = false;
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance(); PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
@@ -411,7 +412,10 @@ void DoLoadHouse (void)
PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, PasStringCopy(theHousesSpecs[thisHouseIndex].m_name,
thisHouseName); thisHouseName);
if (OpenHouse()) if (OpenHouse())
{
whoCares = ReadHouse(); whoCares = ReadHouse();
houseNameDirty = true;
}
} }
leaving = true; leaving = true;
} }
@@ -449,7 +453,10 @@ void DoLoadHouse (void)
PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, PasStringCopy(theHousesSpecs[thisHouseIndex].m_name,
thisHouseName); thisHouseName);
if (OpenHouse()) if (OpenHouse())
{
whoCares = ReadHouse(); whoCares = ReadHouse();
houseNameDirty = true;
}
} }
leaving = true; leaving = true;
} }
@@ -483,7 +490,10 @@ void DoLoadHouse (void)
PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, PasStringCopy(theHousesSpecs[thisHouseIndex].m_name,
thisHouseName); thisHouseName);
if (OpenHouse()) if (OpenHouse())
{
whoCares = ReadHouse(); whoCares = ReadHouse();
houseNameDirty = true;
}
} }
leaving = true; leaving = true;
} }
@@ -501,6 +511,9 @@ void DoLoadHouse (void)
UpdateLoadDialog(theDial); UpdateLoadDialog(theDial);
} }
if (houseNameDirty)
WriteOutPrefs();
wm->SwapExclusiveWindow(exclWindow); // Pop exclusive window wm->SwapExclusiveWindow(exclWindow); // Pop exclusive window
theDial->Destroy(); theDial->Destroy();

View File

@@ -99,6 +99,7 @@ void FlashSettingsButton (DrawSurface *, short);
void UpdateSettingsMain (Dialog *); void UpdateSettingsMain (Dialog *);
int16_t PrefsFilter(void *context, Dialog *dialog, const TimeTaggedVOSEvent *evt); int16_t PrefsFilter(void *context, Dialog *dialog, const TimeTaggedVOSEvent *evt);
void BitchAboutChanges (void); void BitchAboutChanges (void);
void WriteOutPrefs (void);
Rect prefButton[4], controlRects[4]; Rect prefButton[4], controlRects[4];
@@ -1358,6 +1359,8 @@ void DoSettingsMain (void)
} }
PortabilityLayer::HostDisplayDriver::GetInstance()->SetUseICCProfile(isUseICCProfile); PortabilityLayer::HostDisplayDriver::GetInstance()->SetUseICCProfile(isUseICCProfile);
WriteOutPrefs();
} }
//-------------------------------------------------------------- BitchAboutChanges //-------------------------------------------------------------- BitchAboutChanges