- Add -sUSE_FREETYPE=1 to Emscripten build flags
- Extend Font class with FT_Library, FT_Face, and FT_Stroker handles
- Rewrite FontAtlas to use FreeType with on-demand stroked glyph loading
- Text outlines now use FT_Stroker for vector-based stroking before
rasterization, eliminating gaps at corners with thick outlines
- Use glTexSubImage2D for incremental atlas updates (major perf fix)
- Disable canvas border in shell.html per Emscripten docs (alignment fix)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- src/shell.html: Custom HTML shell with crisp pixel CSS
(image-rendering: pixelated) and zoom prevention on canvas
- src/emscripten_pre.js: Patches browser quirks that cause crashes:
- Intercepts resize/scroll events to ensure e.detail is always 0
- Wraps window properties (innerWidth, outerWidth, etc.) to
always return integers, fixing browser zoom crashes
- CMakeLists.txt: Output as .html, include shell and pre-js files
The pre-JS fix addresses "attempt to write non-integer (undefined)
into integer heap" errors that occurred when users zoomed the browser
via Ctrl+scroll or browser menu.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements SFML-compatible text outlines using multi-pass rendering:
- Draws text 8 times at offset positions (N, NE, E, SE, S, SW, W, NW)
with outline color, then draws fill text on top
- Uses existing outlineThickness_ and outlineColor_ properties
- Refactored Text::draw() with helper lambda for code reuse
- Removed debug logging code
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The FontAtlas class was missing move semantics, causing the GPU texture
to be deleted immediately after creation. When FontAtlas was moved into
the cache with std::move(), the default move constructor copied textureId_,
then the original's destructor deleted the texture the cache was using.
Added:
- Move constructor that transfers ownership and clears source textureId_
- Move assignment operator with proper cleanup of existing resources
- Deleted copy operations since GPU textures can't be shared
Also cleaned up the text fragment shader to use proper alpha sampling.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
RenderTexture fix:
- Add flippedY_ flag to Texture class for tracking FBO textures
- RenderTexture marks its texture as Y-flipped
- Sprite::draw() flips V coordinates for flipped textures
- This should fix upside-down entities and grid content
Text debug:
- Log first glyph UV coordinates
- Log texture binding in drawTriangles for Text shader
- Warn if Text shader used without texture bound
Co-Authored-By: Claude <noreply@anthropic.com>
- Add Texture::setSize() method for RenderTexture to set its texture dimensions
- RenderTexture::create() now sets texture size (was 0,0 causing Sprite::draw to bail)
- Add debug output to FontAtlas::load showing glyph count and non-zero pixels
- Add debug output to Text::draw showing atlas texture ID and colors
These fixes should enable grid rendering (RenderTexture now has proper size).
Debug output will help diagnose why text shows as solid boxes instead of glyphs.
Co-Authored-By: Claude <noreply@anthropic.com>
Text rendering fix:
- Add ShaderType parameter to drawTriangles() to allow explicit shader selection
- Text::draw() now properly uses text shader (alpha-only sampling)
- Previously drawTriangles() always overrode to sprite shader
RenderTexture fix:
- Add pushRenderState/popRenderState to save/restore viewport and projection
- RenderTexture::clear() now sets viewport/projection to FBO dimensions
- RenderTexture::display() restores previous state
- This fixes grid rendering which uses RenderTexture for tile chunks
Co-Authored-By: Claude <noreply@anthropic.com>
- Sprite::draw(): Textured quad rendering with UV coordinates and color tint
- Text::draw(): Glyph rendering using FontAtlas cache, supports multi-line
- Text::getLocalBounds()/getGlobalBounds(): Calculate text dimensions
- VertexArray::draw(): Full primitive support (Triangles, TriangleFan,
TriangleStrip, Quads, Lines, LineStrip, Points)
- View::getTransform(): Proper camera transform using translate/rotate/scale
Frames and sprites now render in browser. Text shows glyph positions but
texture sampling needs debugging. Grid rendering not yet working.
Co-Authored-By: Claude <noreply@anthropic.com>
Shape rendering now works:
- Shape::draw() generates triangle vertices for fill and outline
- RectangleShape, CircleShape, ConvexShape provide getPointCount()/getPoint()
- Shapes render with correct fill color, outline color, and outline thickness
Transform class fully implemented:
- translate(), rotate(), scale() modify the 3x3 affine matrix
- transformPoint() applies transform to Vector2f
- operator* combines transforms
- getInverse() computes inverse transform
Transformable::getTransform() now computes proper transform from:
- position, rotation, scale, and origin
RenderStates now has transform, blendMode, shader members
Canvas sizing fixed for Emscripten:
- EM_ASM sets canvas size after SDL window creation
- SDL_GL_MakeCurrent called after canvas resize
Result: RectangleShape UI elements render in correct positions!
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Major milestone for issue #158 (Emscripten/WebAssembly build target):
- Python 3.14 successfully initializes and runs in WASM
- mcrfpy module loads and works correctly
- Game scripts execute with full level generation
- Entities (boulders, rats, cyclops, spawn points) placed correctly
Key changes:
- CMakeLists.txt: Add 2MB stack, Emscripten link options, preload files
- platform.h: Add WASM-specific implementations for executable paths
- HeadlessTypes.h: Make Texture/Font/Sound stubs return success
- CommandLineParser.cpp: Guard filesystem operations for WASM
- McRFPy_API.cpp: Add WASM path configuration, debug output
- game.py: Make 'code' module import optional (not available in WASM)
- wasm_stdlib/: Add minimal Python stdlib for WASM (~4MB)
Build with: emmake make (from build-emscripten/)
Test with: node mcrogueface.js
Next steps:
- Integrate VRSFML for actual WebGL rendering
- Create HTML page to host WASM build
- Test in actual browsers
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Major progress on Emscripten build:
- Built Python 3.14.2 for wasm32-emscripten using official Tools/wasm/emscripten
- Add EMSCRIPTEN detection with proper Python headers from cross-build
- Force MCRF_HEADLESS for Emscripten builds (no SFML yet)
- Link against libpython3.14.a (47MB WASM static lib)
Result: ALL 68 C++ source files compile successfully with emcc!
Only blocker remaining: libtcod needs WASM compilation
Build verified:
- Python LONG_BIT errors: FIXED (using wasm32-emscripten pyconfig.h)
- Source compilation: 100% success
- Link stage: fails on libtcod.so (next step)
Contributes to #158
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
First emcc build confirms Python headers are the blocker:
- HeadlessTypes.h stubs compile fine with Emscripten
- Game engine code compiles fine
- Python C API headers fail: LONG_BIT check, 48-bit shifts on 32-bit WASM
Options identified:
1. Pyodide - pre-built Python WASM (recommended)
2. CPython WASM - build ourselves (complex)
3. No-Python mode - test build without scripting (simplest for now)
Contributes to #158
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactors the main game loop to support both:
- Desktop: traditional blocking while(running) loop
- Browser: emscripten_set_main_loop_arg() callback (build-time conditional)
Changes:
- Add doFrame() method containing single-frame update logic
- Add isRunning() accessor for Emscripten callback
- run() now conditionally uses #ifdef __EMSCRIPTEN__ for loop selection
- Add emscriptenMainLoopCallback() static function
This is a prerequisite for Emscripten builds - browsers require
cooperative multitasking with callback-based frame updates.
Both normal and headless builds verified working.
Contributes to #158
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit enables McRogueFace to compile without SFML dependencies
when built with -DMCRF_HEADLESS, a prerequisite for Emscripten/WebAssembly
support.
Changes:
- Add src/platform/HeadlessTypes.h (~900 lines of SFML type stubs)
- Consolidate all SFML includes through src/Common.h (15 files fixed)
- Wrap ImGui-SFML with #ifndef MCRF_HEADLESS guards
- Disable debug console/explorer in headless builds
- Add comprehensive research document: docs/EMSCRIPTEN_RESEARCH.md
The headless build compiles successfully but uses stub implementations
that return failure/no-op. This proves the abstraction boundary is clean
and enables future work on alternative backends (VRSFML, Emscripten).
What still works in headless mode:
- Python interpreter and script execution
- libtcod integrations (pathfinding, FOV, noise, BSP, heightmaps)
- Timer system and scene management
- All game logic and data structures
Build commands:
Normal: make
Headless: cmake .. -DCMAKE_CXX_FLAGS="-DMCRF_HEADLESS" && make
Addresses #158
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When a Grid has a perspective entity set (typically the player), the API
now respects field-of-view by default. Only entities visible to the
perspective entity are returned in /scene responses.
Changes:
- serialize_grid() filters entities using grid.is_in_fov()
- Added ?omniscient=true query param to bypass FOV filtering
- Response includes perspective info with hidden_entities count
- Updated README with perspective documentation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements a general-purpose HTTP API that exposes McRogueFace games
to external clients (LLMs, accessibility tools, Twitch integrations,
testing harnesses).
API endpoints:
- GET /scene - Full scene graph with all UI elements
- GET /affordances - Interactive elements with semantic labels
- GET /screenshot - PNG screenshot (binary or base64)
- GET /metadata - Game metadata for LLM context
- GET /wait - Long-poll for state changes
- POST /input - Inject clicks, keys, or affordance clicks
Key features:
- Automatic affordance detection from Frame+Caption+on_click patterns
- Label extraction from caption text with fallback to element.name
- Thread-safe scene access via mcrfpy.lock()
- Fuzzy label matching for click_affordance
- Full input injection via mcrfpy.automation
Usage: from api import start_server; start_server(8765)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add convertDrawableToPython() and convertEntityToPython() helper functions
- Add animationValueToPython() to convert AnimationValue to Python objects
- Rewrite triggerCallback() to pass meaningful data:
- target: The animated Frame/Sprite/Grid/Entity/etc.
- property: String property name like "x", "opacity", "fill_color"
- final_value: float, int, tuple (for colors/vectors), or string
- Update test_animation_callback_simple.py for new signature
closes#229
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add ensureRenderTextureSize() helper that creates/resizes renderTexture to match game resolution
- Add renderTextureSize tracking member to detect when resize is needed
- Call helper in constructor and at start of render() to handle resolution changes
- Clamp maximum size to 4096x4096 (SFML texture limits)
- Only recreate texture when size actually changes (performance optimization)
closes#228
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Proof of concept for shader support on UIFrame:
- Add shader and shader_enabled members to UIFrame
- Add initializeTestShader() with hardcoded wave/glow fragment shader
- Add shader_enabled Python property for toggling
- Apply shader when drawing RenderTexture sprite
- Auto-update time uniform for animated effects
Also fixes position corruption when toggling RenderTexture usage:
- Standard rendering path now uses `position` as source of truth
- Prevents box position from staying at (0,0) after texture render
Test files:
- tests/shader_poc_test.py: Visual test of 6 render variants
- tests/shader_toggle_test.py: Regression test for position bug
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>