Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to the **ArcadeMatrix (ESP32)** firmware, WebUI, and tooling

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.3.9] - 2026-12-02

### Fixed
- **Zero Retained `FighterEngine` Memory Between Fights, Across Rotation & During FrontendSync (`ESP32` & `ESP32-S3` — `ADR-0004`)**:
- **Eliminated `Clock + Fighters -> GIFs` Rotation Lock-Up & FrontendSync PNG Starvation on `esp32dev`**: `OverlayManager` now destroys `FighterEngine` completely via `Core0LifecycleDispatcher` after each fight (`0 B` retained during the inter-fight cooldown), across every rotation slot switch, deactivation, and FrontendSync preemption (`0 B` retained heap/PSRAM when inactive on both `esp32dev` and `ESP32-S3`), and `RotationManager::switchToModule()` / `evictAllActiveEnginesForMemory()` synchronously wait for Core 0 reclamation *before* evaluating HUB75 DMA depth or allocating `AnimatedGIF` (`22.6 KB` contiguous).
- **Strictly Rotation-Scoped Overlays, SMP-Safe Worker Handshake & Live Heap Admission Gate**: Removed `FighterEngine` activation from FrontendSync (`MQTT` / `MARQUEE`), moved `FighterEngine::loadRoster()` and post-fight `freeFighter()` off Core 1 onto Core 0 (`FgtLoader` / `Core0Lifecycle`), added a single-notify `signalLoaderStopOnce()` handshake, made `s_lastInstance` atomic, preserved `idle_fighter_interval` across ephemeral evictions in a rollover-safe `4 B` `.bss` timestamp, and gated `OverlayManager` instantiation on live free internal SRAM / PSRAM headroom.
- **Decoder-First `GifEngine::activate()` & Safe `8-bit` PNG Heap Floor**: `GifEngine::activate()` now allocates `AnimatedGIF` (`22.6 KB`) before spawning `gif_preload` (`4 KB` stack on `!hasPsram`), and `GifEngine::refineDynamicRequirements()` reserves a `~30 KB` total SRAM floor so `128x32` stays at `8-bit` with zero DMA teardowns while constrained geometries step down cleanly instead of starving `LitePngDecoder` or LwIP TCP RX.
- **Restored `< 45 ms` Live Intermediate Marquee Logos During `100 ms/step` Wheel Navigation on `esp32dev` (`FrontendSyncEngine`)**:
- Eliminated the redundant `35 ms` Tier-2 network settle delay on local-SD `!hasPsram` targets, tightened non-PSRAM Tier-1 burst coalescing to `15 ms`, reduced `SyncShowcaseWkr` wake polling to `2 ms` slices, and added stripped `title` stems to `binarySearchCatalogForGameJob()` (`O(log N)` exact lookup for Console titles).
- **M.U.G.E.N Extractor Palette Fidelity & Non-Body Helper Filtering (`tools/mugen_extractor/mugen_extractor.py`)**:
- Decoded reversed Elecbyte `.act` palette tables (`255..0` index convention), chained `SFFv1` shared palettes across sprite groups so character colors never corrupt on secondary frames, and filtered detached helper/projectile sprites when computing character bounding boxes.

## [4.3.8] - 2026-12-01

### Fixed
Expand Down
13 changes: 6 additions & 7 deletions docs/adr/0004-overlay-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ In early firmware iterations, the M.U.G.E.N `FighterEngine` was treated as a sel
- `DisplayArbiter`: Selects the primary display source (e.g. `MQTT` > `VISUALIZER` > `MARQUEE` > `GIF` > `ROTATION`).
- `EngineRegistry`: Contains only primary selectable display sources (`clock`, `date`, `weather`, `gifs`, `crypto`, `stock`, `audiovisualizer`, `decibelMeter`, `temp`, `message`, `google_cast`, `spotify`, `system_info`, `music_player`, `dashboard`, `gnews`, `marquee`, `mqttdata`).
- `OverlayManager`: Manages transverse overlays (`FighterEngine`).
2. **User-Driven Per-Rotation Configuration:**
- Overlays are enabled per rotation slot via `"overlays": { "fighter": true }` (migrated from legacy `"fighter_overlay"`).
- Combined with global master switch: `isActive = global_enabled && rotation_entry.overlays.fighter`.
- Zero engine-specific exceptions: `GIF + Fighter` is completely supported.
2. **User-Driven Per-Rotation Configuration & Engine Gating:**
- Overlays are enabled per rotation slot via `"overlays": { "fighter": true }` (migrated from legacy `"fighter_overlay"`), combined with the global master switch: `isActive = global_enabled && rotation_entry.overlays.fighter`.
- Full-frame media engines (`GifEngine`, `allowsOverlay() == false`) and non-rotation priority sessions (`FrontendSync` `MQTT` / `MARQUEE` / `GIF` / `INGAME_SHOWCASE`, `VISUALIZER`, `WEBUI_SYNC`) suppress overlays completely.
3. **Additive Invariant:**
- Overlays compose additively over existing framebuffers and must never call `matrix.clear()`.
4. **Heap Preservation on ESP32:**
- `OverlayManager` lazily instantiates `FighterEngine` on first demand and preserves the instance in heap across rotation cycles.
4. **Zero Retained Memory When Inactive or Between Fights (ESP32 & ESP32-S3):**
- `OverlayManager` instantiates `FighterEngine` strictly on demand after the active rotation engine is admitted, cooldown has elapsed, and heap headroom is verified, and destroys the entire `FighterEngine` instance via `Core0LifecycleDispatcher` after each fight (holding `0 B` during inter-fight cooldown), across every rotation slot switch, deactivation, or FrontendSync preemption — reclaiming 100% of worker stacks, rosters, and sprite buffers before the incoming engine evaluates pipeline depth or allocates decoders.

## Consequences
- Clean, extensible layering architecture where overlays are independent of primary engine types.
- Zero visual flicker through additive compositing.
- Zero heap fragmentation on ESP32.
- Zero residual overlay SRAM or PSRAM footprint during `GifEngine` playlists and `FrontendSync` marquee sessions.
2 changes: 1 addition & 1 deletion src/api/WebUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const size_t WebUI_html_len = 147298;
const char WebUI_html_etag[] = "57c256b84c692a71";
const uint8_t WebUI_html[] PROGMEM = {
0x1f, 0x8b, 0x08, 0x00, 0x53, 0x1d, 0x0f, 0x6b, 0x02, 0xff, 0xec, 0xbd,
0x1f, 0x8b, 0x08, 0x00, 0x9f, 0x54, 0x10, 0x6b, 0x02, 0xff, 0xec, 0xbd,
0x6b, 0x77, 0x23, 0xdb, 0x75, 0x20, 0xf6, 0x5d, 0xbf, 0xe2, 0x08, 0x37,
0xba, 0x04, 0x2c, 0x00, 0x04, 0xc0, 0x47, 0xb3, 0xc1, 0x4b, 0xca, 0x6c,
0xb2, 0x5f, 0x56, 0xb3, 0x9b, 0x6e, 0xb2, 0x75, 0xad, 0xf1, 0x78, 0x41,
Expand Down
6 changes: 3 additions & 3 deletions src/core/BuildInfo.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#ifndef FIRMWARE_VERSION
#define FIRMWARE_VERSION "4.3.7"
#define FIRMWARE_VERSION "4.3.9-beta1-dev"
#endif
#ifndef BUILD_GIT_COMMIT
#define BUILD_GIT_COMMIT "0b702a1"
#define BUILD_GIT_COMMIT "f965e94"
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP "2026-12-01 19:17:20 UTC"
#define BUILD_TIMESTAMP "2026-12-02 17:23:44 UTC"
#endif
1 change: 1 addition & 0 deletions src/core/Core0Lifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Core0LifecycleDispatcher {

size_t getQuarantineCount() const { return _quarantineCount; }
bool hasPending() const { return _activeRetirements.load(std::memory_order_acquire) > 0 || !_retireQueue.isEmpty(); }
bool hasWorkerTask() const { return _lifecycleTaskHandle != nullptr; }

private:
Core0LifecycleDispatcher() = default;
Expand Down
31 changes: 20 additions & 11 deletions src/core/DisplayRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ void DisplayRuntime::purgeRotationPreemptionEntries() {
}
}

void DisplayRuntime::evictOverlaysForMemory() {
if (m_overlayManager) {
m_overlayManager->evictForMemory();
}
}

void DisplayRuntime::transitionSession(const DisplayDecision& decision) { // PHASE 1: Resolve target engine
IEngine* targetEngine = resolveEngine(decision.engineHandle, decision.sourceId);

Expand Down Expand Up @@ -294,6 +300,7 @@ void DisplayRuntime::transitionSession(const DisplayDecision& decision) { //
if (oldEngine && !sameEngine) {
oldEngine->pause();
}
evictOverlaysForMemory();
if (m_rotationManager && m_rotationManager->getActiveEngineCount() > 0) {
m_rotationManager->evictAllActiveEnginesForMemory();
}
Expand Down Expand Up @@ -332,6 +339,9 @@ void DisplayRuntime::transitionSession(const DisplayDecision& decision) { //
// CASE 4: REPLACE
const bool isInternalRotationSwitch = (decision.sourceId == DisplaySourceId::ROTATION && m_session.sourceId == DisplaySourceId::ROTATION);

if (decision.sourceId != DisplaySourceId::ROTATION) {
evictOverlaysForMemory();
}
if (evictManagedRotation) {
m_rotationManager->evictAllActiveEnginesForMemory();
oldEngine = nullptr;
Expand Down Expand Up @@ -436,19 +446,18 @@ FrameRenderResult DisplayRuntime::render(const DisplayDecision& decision, AppEng
result.nextDueInMs = activeEngine->nextFrameDueInMs();
}

// Render Overlays (Fighter etc.) if enabled by decision and active rotation slot
if (m_overlayManager && decision.allowsOverlay && (!activeEngine || activeEngine->allowsOverlay())) {
OverlayConfig activeOverlayConfig;
if (decision.sourceId == DisplaySourceId::ROTATION && m_rotationManager) {
activeOverlayConfig = m_rotationManager->getCurrentOverlays();
} else if (decision.sourceId == DisplaySourceId::MQTT || decision.sourceId == DisplaySourceId::MARQUEE) {
activeOverlayConfig.fighter = FighterOverride::Enabled;
}
m_overlayManager->configure(activeOverlayConfig);
// Transverse overlays (FighterEngine) are strictly scoped to ROTATION slots whose primary
// engine permits overlays (never active on FrontendSync MQTT/MARQUEE/GIF or GifEngine playlists).
if (m_overlayManager &&
decision.sourceId == DisplaySourceId::ROTATION &&
m_rotationManager != nullptr &&
decision.allowsOverlay &&
(!activeEngine || activeEngine->allowsOverlay())) {
m_overlayManager->configure(m_rotationManager->getCurrentOverlays());
m_overlayManager->update();
m_overlayManager->render();
// An active overlay draws over the engine's frame; a dirty-pixel engine must repaint under it.
if (m_overlayManager->isActive()) matrixEngine.markExternalDraw();
// An active combat pass draws over the engine's frame; a dirty-pixel engine must repaint under it.
if (m_overlayManager->isRenderingCombat()) matrixEngine.markExternalDraw();
} else if (m_overlayManager) {
m_overlayManager->deactivate();
}
Expand Down
1 change: 1 addition & 0 deletions src/core/DisplayRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class DisplayRuntime {
*/
void purgeEngineReferences(IEngine* engine, const char* instanceId);
void purgeRotationPreemptionEntries();
void evictOverlaysForMemory();

/**
* @brief Reset the Adafruit_GFX text state (font, size, wrap) shared through the panel object.
Expand Down
Loading
Loading