Split the sketch into a device-agnostic renderer core (RoomViewCore.h: RGB565 rasterizer, camera, world sim — no emulator dependencies) plus a thin emulator shell (keyboard pump + the 565-to-8888 presentation blit). Add fw/ as a self-contained PlatformIO project (own platformio.ini pointing at the shared boards/, lib/ and src/netdeck headers — per-env src_dir is not supported by PlatformIO, so NetDeck's top-level config stays untouched). fw/RoomViewHW.ino is the firmware twin: the core rasterizes directly into a TFT_eSprite's frameBuffer() (16-bit, PSRAM) and presents with the proven NetDeck startWrite/pushSprite/endWrite pattern. The loop free-runs and reports true throughput over USB serial every 2 s: fps + average render vs. push split. Verified: emulator render unchanged (smoke frame identical), pio RoomViewHW env builds clean for ESP32-S3 (346 KB flash), make netdeck dual build green.
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
/**
|
|
* RoomView — top-down "3D" flythrough of NetDeck's demo map.
|
|
*
|
|
* Target: T-Deck emulator (320x240, RGB565 device framebuffer).
|
|
*
|
|
* This file is only the emulator shell: keyboard pump, delta time, and
|
|
* the 565 -> 8888 presentation blit (the stand-in for the SPI push).
|
|
* The whole renderer lives in the device-agnostic RoomViewCore.h,
|
|
* shared 1:1 with the ESP32-S3 firmware build (fw/RoomViewHW.ino), so
|
|
* benchmark numbers measured on hardware describe exactly this code.
|
|
*
|
|
* Contract with the emulator host (src/main.cpp):
|
|
* - implement setup() — called once at launch
|
|
* - implement loop() — called once per frame (host paces at ~60 fps)
|
|
* - write pixels into emuGfx::fb[] (320x240, ABGR8888 uint32)
|
|
* - set emuGfx::dirty = true each frame you want presented
|
|
* - read keys from emu::keyboard (ASCII queue, filled from SDL events)
|
|
*
|
|
* Keys: a/d orbit speed, w/s zoom, r/f altitude, space pause, q/ESC quit.
|
|
*/
|
|
|
|
#include "shim.h"
|
|
#include "RoomViewCore.h"
|
|
|
|
extern uint32_t emuGfx::fb[320 * 240];
|
|
extern bool emuGfx::dirty;
|
|
extern std::deque<uint8_t> emu::keyboard;
|
|
|
|
// The "device" framebuffer the core renders into.
|
|
static uint16_t fb565[rvcore::W * rvcore::H];
|
|
|
|
void setup() {
|
|
rvcore::rvInit(fb565);
|
|
}
|
|
|
|
void loop() {
|
|
// --- keyboard pump ---
|
|
while (!emu::keyboard.empty()) {
|
|
uint8_t k = emu::keyboard.front();
|
|
emu::keyboard.pop_front();
|
|
rvcore::rvInput(k);
|
|
}
|
|
if (rvcore::rvQuitRequested()) emu::quitRequested = true;
|
|
|
|
// --- delta time: seconds since the previous frame ---
|
|
static unsigned long lastMs = 0;
|
|
unsigned long now = millis();
|
|
float dt = lastMs ? (now - lastMs) / 1000.0f : 1.0f / 60.0f;
|
|
lastMs = now;
|
|
if (dt > 0.1f) dt = 0.1f; // clamp after stalls (drag, breakpoint)
|
|
|
|
rvcore::rvFrame(dt, now);
|
|
|
|
// --- "SPI push": expand the 565 device buffer into the emulator's 8888 ---
|
|
// texture. On the T-Deck this step doesn't exist — the 565 buffer is
|
|
// what the panel receives. This is purely a desktop-presentation shim.
|
|
for (int i = 0; i < rvcore::W * rvcore::H; i++) {
|
|
uint16_t c = fb565[i];
|
|
uint32_t r5 = (c >> 11) & 31, g6 = (c >> 5) & 63, b5 = c & 31;
|
|
uint32_t r = (r5 << 3) | (r5 >> 2); // 5 -> 8 bit expansion
|
|
uint32_t g = (g6 << 2) | (g6 >> 4); // 6 -> 8 bit expansion
|
|
uint32_t b = (b5 << 3) | (b5 >> 2);
|
|
emuGfx::fb[i] = 0xFF000000u | (b << 16) | (g << 8) | r;
|
|
}
|
|
emuGfx::dirty = true;
|
|
}
|