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 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);

View File

@@ -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;

View File

@@ -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<uint32_t>(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)

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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