Boot: input grace period; persist high score + volume via NVS
- Ignore all input for ~1.2 s after power-up/reset (INPUT_GRACE_MS): the keyboard controller can emit stale bytes and pins can float, which used to start a game right after a restart. - High score + volume survive power cycles: Preferences (NVS, 'mc' namespace) loaded in setup(), saved on game over and on every volume key (U/V/M). arduino-esp32 commits NVS in end(), so savePrefs() does putUInt x2 + end() + begin() reopen. - SoundEngine::setVolume() restores a saved level (0 = stay muted, lastVol_ keeps unmute working). - Emulator: file-backed Preferences shim (mc-prefs.cfg, gitignored) so persistence is testable on the desktop.
This commit is contained in:
@@ -103,6 +103,15 @@ void SoundEngine::toggleMute()
|
||||
}
|
||||
}
|
||||
|
||||
// Restore a saved volume level (from NVS at boot); 0 keeps the device muted
|
||||
// while lastVol_ stays at its default so unmute still works.
|
||||
void SoundEngine::setVolume(uint8_t v)
|
||||
{
|
||||
if (v > VOL_MAX) v = VOL_MAX;
|
||||
vol_ = v;
|
||||
if (vol_ > 0) lastVol_ = vol_;
|
||||
}
|
||||
|
||||
// scaled peak amplitude for the current volume level
|
||||
static inline uint32_t scaledAmp(uint16_t amp, uint8_t vol)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user