Implements Phase 1 of renderer abstraction plan: - SDL2Types.h: SFML-compatible type stubs in sf:: namespace - SDL2Renderer.h/cpp: OpenGL ES 2 rendering implementation - EmscriptenStubs.cpp: Stubs for missing POSIX functions (wait3, wait4, wcsftime) Build system changes: - Add MCRF_SDL2 compile-time backend selection - Add Emscripten SDL2 link options (-sUSE_SDL=2, -sFULL_ES2=1) - Fix LONG_BIT mismatch for Emscripten in pyport.h Code changes for SDL2/headless compatibility: - Guard ImGui includes with !MCRF_HEADLESS && !MCRF_SDL2 - Defer GL shader initialization until after context creation Current status: Python runs in browser, rendering WIP (canvas sizing issues) Build commands: emcmake cmake -DMCRF_SDL2=ON -B build-emscripten emmake make -C build-emscripten Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
# pragma once
|
|
|
|
// =============================================================================
|
|
// Platform Selection
|
|
// =============================================================================
|
|
// Define MCRF_HEADLESS to build without SFML graphics/audio dependencies.
|
|
// This enables headless operation for servers, CI, and Emscripten builds.
|
|
//
|
|
// Build with: cmake -DMCRF_HEADLESS=ON ..
|
|
// =============================================================================
|
|
|
|
#ifdef MCRF_HEADLESS
|
|
// Use headless type stubs instead of SFML (no graphics, for CI/testing)
|
|
#include "platform/HeadlessTypes.h"
|
|
#define MCRF_GRAPHICS_BACKEND "headless"
|
|
#elif defined(MCRF_SDL2)
|
|
// Use SDL2 + OpenGL ES 2 backend (for Emscripten/WebGL, Android, cross-platform)
|
|
#include "platform/SDL2Types.h"
|
|
#define MCRF_GRAPHICS_BACKEND "sdl2"
|
|
#else
|
|
// Use SFML for graphics and audio (default desktop build)
|
|
#include <SFML/Graphics.hpp>
|
|
#include <SFML/Audio.hpp>
|
|
#define MCRF_GRAPHICS_BACKEND "sfml"
|
|
#endif
|
|
|
|
// Maximum dimension for grids, layers, and heightmaps (8192x8192 = 256MB of float data)
|
|
// Prevents integer overflow in size calculations and limits memory allocation
|
|
constexpr int GRID_MAX = 8192;
|
|
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <algorithm>
|
|
|
|
// wstring<->string conversion
|
|
#include <locale>
|
|
#include <codecvt>
|
|
#include <filesystem>
|
|
|