feat: add safe game and app exit controls for 1.0.3
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "save_policy.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
using neslite::ExitSaveResult;
|
||||
for (int failure = 0; failure <= 3; ++failure) {
|
||||
std::vector<int> writes;
|
||||
bool closed = false;
|
||||
const auto result = neslite::commit_exit_saves(
|
||||
[&] { writes.push_back(1); return failure != 1; },
|
||||
[&] { writes.push_back(2); return failure != 2; },
|
||||
[&] { writes.push_back(3); closed = failure != 3; return closed; });
|
||||
const auto expected = failure == 0 ? ExitSaveResult::Committed :
|
||||
failure == 1 ? ExitSaveResult::BatteryFailed :
|
||||
failure == 2 ? ExitSaveResult::AutoStateFailed : ExitSaveResult::MarkerFailed;
|
||||
if (result != expected || closed != (failure == 0)) return 1;
|
||||
const std::vector<int> expected_writes = failure == 1 ? std::vector<int>{1} :
|
||||
failure == 2 ? std::vector<int>{1, 2} : std::vector<int>{1, 2, 3};
|
||||
if (writes != expected_writes) return 2;
|
||||
// Retrying after any failure must complete all writes before declaring the session closed.
|
||||
writes.clear();
|
||||
const auto retry = neslite::commit_exit_saves(
|
||||
[&] { writes.push_back(1); return true; },
|
||||
[&] { writes.push_back(2); return true; },
|
||||
[&] { writes.push_back(3); closed = true; return true; });
|
||||
if (retry != ExitSaveResult::Committed || !closed || writes != std::vector<int>{1, 2, 3}) return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user