/** * rcore_emu.c — raylib platform layer for the FloorPlan3D emulator demo. * * Desktop counterpart of raylib-esp32's src/platform/rcore_esp32.c: provides * all symbols that rcore.c expects from a PLATFORM_CUSTOM backend, but * instead of pushing the RGB565 software-renderer buffer to an SPI panel it * hands it to the SDL host via emu_raylib_present() (implemented by the * sketch in C++, which converts 565→8888 into emuGfx::fb). * * Everything else mirrors rcore_esp32.c so the demo and the on-device build * exercise the same code paths (rlsw renderer, SwapScreenBuffer flow). */ #include "raylib_emu_config.h" #include "raylib.h" #include "rlgl.h" #include #include #include // --- Internal state -------------------------------------------------------- static int screen_width = 0; static int screen_height = 0; extern void *swGetColorBuffer(int *width, int *height); extern void *swSwapColorBuffer(int *width, int *height); // Provided by the sketch (C++): converts the RGB565 buffer into the // emulator's ABGR8888 framebuffer and marks it dirty. extern void emu_raylib_present(const unsigned short *rgb565, int w, int h); // Called by the sketch before InitWindow(), mirroring raylib_esp32_init() // (which tells the port layer the panel size on device). void emu_raylib_set_framebuffer(int w, int h) { screen_width = w; screen_height = h; } // --------------------------------------------------------------------------- // Window management stubs // --------------------------------------------------------------------------- bool WindowShouldClose(void) { return false; } void ToggleFullscreen(void) { TRACELOG(LOG_WARNING, "ToggleFullscreen() not available in the emulator"); } void ToggleBorderlessWindowed(void) { TRACELOG(LOG_WARNING, "ToggleBorderlessWindowed() not available in the emulator"); } void MaximizeWindow(void) { TRACELOG(LOG_WARNING, "MaximizeWindow() not available in the emulator"); } void MinimizeWindow(void) { TRACELOG(LOG_WARNING, "MinimizeWindow() not available in the emulator"); } void RestoreWindow(void) { TRACELOG(LOG_WARNING, "RestoreWindow() not available in the emulator"); } void SetWindowState(unsigned int flags) { (void)flags; } void ClearWindowState(unsigned int flags){ (void)flags; } void SetWindowIcon(Image image) { (void)image; } void SetWindowIcons(Image *imgs, int n) { (void)imgs; (void)n; } void SetWindowTitle(const char *title) { (void)title; } void SetWindowPosition(int x, int y) { (void)x; (void)y; } void SetWindowMonitor(int m) { (void)m; } void SetWindowMinSize(int w, int h) { (void)w; (void)h; } void SetWindowMaxSize(int w, int h) { (void)w; (void)h; } void SetWindowSize(int w, int h) { (void)w; (void)h; } void SetWindowOpacity(float o) { (void)o; } void SetWindowFocused(void) {} void *GetWindowHandle(void) { return NULL; } int GetCurrentMonitor(void) { return 0; } Vector2 GetMonitorPosition(int m) { (void)m; return (Vector2){0, 0}; } int GetMonitorWidth(int m) { (void)m; return screen_width; } int GetMonitorHeight(int m) { (void)m; return screen_height; } int GetMonitorPhysicalWidth(int m) { (void)m; return 0; } int GetMonitorPhysicalHeight(int m) { (void)m; return 0; } int GetMonitorRefreshRate(int m) { (void)m; return 60; } const char *GetMonitorName(int m) { (void)m; return "T-Deck emulator"; } Vector2 GetWindowPosition(void) { return (Vector2){0, 0}; } Vector2 GetWindowScaleDPI(void) { return (Vector2){1.0f, 1.0f}; } void SetClipboardText(const char *t) { (void)t; } const char *GetClipboardText(void) { return ""; } Image GetClipboardImage(void) { return (Image){0}; } // --------------------------------------------------------------------------- // Cursor stubs // --------------------------------------------------------------------------- void ShowCursor(void) {} void HideCursor(void) {} void EnableCursor(void) {} void DisableCursor(void) {} // --------------------------------------------------------------------------- // Input stubs (the sketch reads emu::keyboard directly instead) // --------------------------------------------------------------------------- int SetGamepadMappings(const char *m) { (void)m; return 0; } void SetMousePosition(int x, int y) { (void)x; (void)y; } void SetMouseCursor(int c) { (void)c; } const char *GetKeyName(int key) { (void)key; return ""; } void PollInputEvents(void) {} // --------------------------------------------------------------------------- // SwapScreenBuffer — hand the rendered frame to the SDL host // --------------------------------------------------------------------------- void SwapScreenBuffer(void) { int sw_w, sw_h; uint16_t *rendered = (uint16_t *)swSwapColorBuffer(&sw_w, &sw_h); if (!rendered || sw_w != screen_width || sw_h != screen_height) { TRACELOG(LOG_ERROR, "PLATFORM: Framebuffer mismatch"); return; } emu_raylib_present(rendered, sw_w, sw_h); } // --------------------------------------------------------------------------- // Timing // --------------------------------------------------------------------------- double GetTime(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000.0; } // --------------------------------------------------------------------------- // Misc // --------------------------------------------------------------------------- void OpenURL(const char *url) { if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL contains suspicious character"); } // --------------------------------------------------------------------------- // Platform init / close // --------------------------------------------------------------------------- int InitPlatform(void); bool InitGraphicsDevice(void); bool CreateWindowFramebuffer(int width, int height) { screen_width = width; screen_height = height; TRACELOG(LOG_INFO, "PLATFORM: Framebuffer %dx%d (RGB565, software renderer)", width, height); return true; } int InitPlatform(void) { if (screen_width == 0 || screen_height == 0) { // Mirrors the ESP32 port: display size must be known before InitWindow(). TRACELOG(LOG_ERROR, "PLATFORM: Framebuffer size unknown — call " "emu_raylib_set_framebuffer(w, h) before InitWindow()"); return -1; } CreateWindowFramebuffer(screen_width, screen_height); TRACELOG(LOG_INFO, "PLATFORM: Emulator initialized (%dx%d)", screen_width, screen_height); return 0; } void ClosePlatform(void) { TRACELOG(LOG_INFO, "PLATFORM: Emulator closed"); }