Commit graph

311 commits

Author SHA1 Message Date
f766e9efa2 Add y_plane parameter to screen_to_world(), closes #245
screen_to_world() previously only intersected the Y=0 plane.
Now accepts an optional y_plane parameter (default 0.0) for
intersecting arbitrary horizontal planes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 20:15:48 -05:00
d195c0e390 Add warning when RenderTexture creation fails, closes #227
Previously enableRenderTexture() silently failed. Now emits a
stderr warning with the requested dimensions, consistent with
the engine's logging pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 20:15:43 -05:00
2062e4e4ad Fix Entity3D.viewport returning None, closes #244
The root cause was PyViewport3DType being declared `static` in
Viewport3D.h, creating per-translation-unit copies. Entity3D.cpp's
copy was never passed through PyType_Ready, causing segfaults when
tp_alloc was called.

Changed `static` to `inline` (matching PyEntity3DType and
PyModel3DType patterns), and implemented get_viewport using the
standard type->tp_alloc pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 20:15:38 -05:00
b9a48a85b0 Version bump: 0.2.4-prerelease-7drl2026 (3ce7de6) -> 0.2.5-prerelease-7drl2026 2026-02-07 11:55:29 -05:00
3ce7de6134 Windows/WASM platform fixes 2026-02-07 11:54:01 -05:00
de7778b147 LDtk import support 2026-02-07 11:34:38 -05:00
322beeaf78 add __ne__ support to enum types for input 2026-02-06 21:43:52 -05:00
b093e087e1 Tiled XML/JSON import support 2026-02-06 21:43:03 -05:00
71cd2b9b41 3D / voxel unit tests 2026-02-06 16:15:07 -05:00
e12e80e511 add run banner to canvas in playground 2026-02-05 23:03:02 -05:00
de5616f3a4 voxel, animation, and pathfinding combined demo 2026-02-05 22:57:08 -05:00
992ea781cb Voxel functionality extension 2026-02-05 12:52:18 -05:00
3e6b6a5847 voxel example 2026-02-05 10:49:31 -05:00
7ebca63db3 emscripten build fixes 2026-02-05 00:29:40 -05:00
f2ccdff499 Frustum culling 2026-02-04 23:45:43 -05:00
7e8efe82ec 3D target demo 2026-02-04 23:41:37 -05:00
cc027a2517 rigging and animation 2026-02-04 23:19:03 -05:00
b85f225789 billboards 2026-02-04 20:47:51 -05:00
544c44ca31 glTF model loading 2026-02-04 19:35:48 -05:00
8636e766f8 fix: don't use SFML GL context management in SDL builds 2026-02-04 17:48:34 -05:00
f4c9db8436 3D entities 2026-02-04 17:45:12 -05:00
63008bdefd pathfinding on heightmap 2026-02-04 16:36:21 -05:00
e572269eac Terrain mesh, vertex color from heightmaps 2026-02-04 14:51:31 -05:00
9c29567349 Viewport scene explorer + object cache integration 2026-02-04 13:44:20 -05:00
e277663ba0 3D viewport, milestone 1 2026-02-04 13:33:14 -05:00
38156dd570 update playground's example program 2026-02-04 11:52:24 -05:00
d2ea64bc32 fix: animations modifying animations during callback is now safe 2026-02-04 10:25:59 -05:00
d8fec5fea0 DiscreteMap class - mask for operations or uint8 tile data 2026-02-03 20:36:42 -05:00
001cc6efd6 grid layer API modernization 2026-02-03 20:18:12 -05:00
b66b934d8f new build for emscripten details 2026-02-03 12:18:40 -05:00
045b625655 opacity + animation fixes 2026-02-03 12:18:21 -05:00
2fb29a102e Animation and Scene clean up functions. Playground build target 2026-02-01 21:17:29 -05:00
3b27401f29 Remove debugging output 2026-02-01 16:40:23 -05:00
69a59ad1e8 Version bump: 0.2.3-prerelease-7drl2026 (67aa413) -> 0.2.4-prerelease-7drl2026 2026-01-31 20:16:11 -05:00
67aa413a78 Replace stb_truetype with FreeType for proper text outline rendering 0.2.3-prerelease-7drl2026-emscripten
- 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>
2026-01-31 16:45:10 -05:00
1be2714240 Add Python REPL widget for WebGL build
Features:
- JSFiddle-style code editor panel alongside game canvas
- Run button (or Ctrl+Enter) executes Python code
- Reset button reloads game.py
- Tab key inserts 4 spaces for proper indentation
- Shows >>> prompt with code preview
- Displays repr of last expression (like Python REPL)
- Error highlighting in red, success in green
- Canvas focus handling with visual indicator

C++ exports (callable from JavaScript):
- run_python_string(code) - simple execution
- run_python_string_with_output(code) - captures stdout/stderr + expr repr
- reset_python_environment() - reloads game.py

JavaScript API available in console:
- runPython(code) - execute Python and get output
- resetGame() - reset to initial state
- FS.readFile/writeFile - access virtual filesystem

Also fixes canvas focus issues on page load.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 15:31:18 -05:00
bc7046180a Add Emscripten shell and pre-JS for browser compatibility
- 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>
2026-01-31 14:36:22 -05:00
1abec8f808 Add text outline support for SDL2/WebGL backend
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>
2026-01-31 14:01:50 -05:00
0811b76946 Fix FontAtlas texture deletion bug - text now renders in WebGL
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>
2026-01-31 13:54:48 -05:00
d89376901a Fix RenderTexture Y-flip and add text debug output
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>
2026-01-31 13:05:26 -05:00
50b63a8d06 Fix RenderTexture texture size + add text/font debug output
- 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>
2026-01-31 12:52:35 -05:00
e08f189d60 Fix Text shader and RenderTexture viewport for SDL2 backend
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>
2026-01-31 12:42:12 -05:00
be6fe23499 Implement Sprite, Text, and VertexArray draw() for SDL2 backend
- 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>
2026-01-31 12:38:03 -05:00
a702d3cab4 Implement Shape rendering and Transform math for SDL2 backend
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>
2026-01-31 11:58:42 -05:00
c5cc022aa2 Add SDL2+OpenGL ES 2 renderer backend for Emscripten/WebGL
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>
2026-01-31 11:13:15 -05:00
8c3128e29c WASM Python integration milestone - game.py runs in browser
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>
2026-01-31 05:15:11 -05:00
07fd12373d First successful Emscripten/WASM build for #158
Build produces mcrogueface.wasm (8.9MB) + mcrogueface.js (126KB):
- All 68 C++ source files compile with emcc
- Links Python 3.14 (wasm32-emscripten target)
- Links libtcod-headless (built for Emscripten)
- Uses Emscripten ports: zlib, bzip2, sqlite3
- Includes HACL crypto, expat, mpdec, ffi dependencies

CMakeLists.txt updates:
- Add HACL .o files (not included in libpython3.14.a)
- Add expat, mpdec, ffi static libraries from Python build
- Add libtcod WASM build with lodepng and utf8proc
- Add Emscripten port link options

libtcod-headless submodule updated with Emscripten build.

Next: Bundle Python stdlib into WASM filesystem.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 00:34:11 -05:00
3bd996f317 Add Emscripten Python 3.14 WASM integration to CMake
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>
2026-01-31 00:23:28 -05:00
5081a37c25 Document first Emscripten build attempt results
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>
2026-01-31 00:05:07 -05:00
8b6eb1e7ae Extract GameEngine::doFrame() for Emscripten callback support
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>
2026-01-30 23:51:35 -05:00