Game code uses standard Python file I/O to mcrfpy.save_dir with no platform
branching. On WASM, builtins.open() is monkeypatched so writes to /save/
auto-sync IDBFS on close, making persistence transparent.
API: mcrfpy.save_dir (str), mcrfpy._sync_storage() (auto-called on WASM)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New workflow for game developers: run mcrf-init to create a project
directory with symlinks to a pre-built engine, then just write Python
scripts and assets. Games package for distribution (Linux/Windows/WASM)
without ever rebuilding the engine.
mcrf-init.sh creates:
- build/ with symlinked binary and libs, game content in assets/ + scripts/
- build-windows/ (if engine has a Windows build)
- Makefile with run, wasm, dist-linux, dist-windows, dist-wasm targets
- Starter game.py, .gitignore, pyrightconfig.json, VERSION file
CMakeLists.txt: WASM preload paths (assets, scripts) are now
configurable via MCRF_ASSETS_DIR / MCRF_SCRIPTS_DIR cache variables,
so game project Makefiles can point WASM builds at their own content
without modifying the engine.
Also adds pyrightconfig.json for the engine repo itself (IDE support
via stubs/).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Full screen "wasm-game" for viewport compatibility between desktop and
web interfaces. Viewport modes ("fit", "center", and "stretch") should
now work the same way under WASM/SDL and SFML. This should also enable
android or web-for-mobile aspect ratios to be supported more easily.
Replace no-op audio stubs in SDL2Types.h with real SDL2_mixer-backed
implementations of SoundBuffer, Sound, and Music. This enables audio
playback in the browser with zero changes to Python bindings.
- Add -sUSE_SDL_MIXER=2 to Emscripten compile/link flags (CMakeLists.txt)
- Initialize Mix_OpenAudio in SDL2Renderer::init(), Mix_CloseAudio in shutdown()
- SoundBuffer: Mix_LoadWAV/Mix_LoadWAV_RW with duration computation
- Sound: channel-based playback with Mix_ChannelFinished tracking
- Music: global channel streaming via Mix_LoadMUS/Mix_PlayMusic
- Volume conversion: SFML 0-100 scale to SDL_mixer 0-128 scale
Known limitations on web: Music.duration and Music.position getters
return 0 (SDL_mixer 2.0.2 lacks Mix_MusicDuration/Mix_GetMusicPosition).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 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>
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>
Integrates Dear ImGui for an in-game debug console that replaces the
blocking Python REPL. Press ~ (grave/tilde) to toggle the console.
Features:
- Python code execution without blocking the game loop
- Output capture with color coding (yellow=input, red=errors, gray=output)
- Expression results show repr() automatically
- Command history navigation with up/down arrows
- Word wrapping for long output lines
- Auto-scroll that doesn't fight manual scrolling
- mcrfpy.setDevConsole(bool) API to disable for shipping
Technical changes:
- Update imgui submodule to v1.89.9 (stable)
- Update imgui-sfml submodule to 2.6.x branch (SFML 2.x compatible)
- Add ImGui sources to CMakeLists.txt with OpenGL dependency
- Integrate ImGui lifecycle into GameEngine
- Add ImGuiConsole class for console overlay
closes#36, closes#65, closes#75🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace deprecated Python C API calls with modern PyConfig-based initialization:
- PySys_SetArgvEx() -> PyConfig.argv (deprecated since 3.11)
- Py_InspectFlag -> PyConfig.inspect (deprecated since 3.12)
Fix critical memory safety bugs discovered during migration:
- PyColor::from_arg() and PyVector::from_arg() now return new references
instead of borrowed references, preventing use-after-free when callers
call Py_DECREF on the result
- GameEngine::testTimers() now holds a local shared_ptr copy during
callback execution, preventing use-after-free when timer callbacks
call delTimer() on themselves
Fix double script execution bug with --exec flag:
- Scripts were running twice because GameEngine constructor executed them,
then main.cpp deleted and recreated the engine
- Now reuses existing engine and just sets auto_exit_after_exec flag
Update test syntax to use keyword arguments for Frame/Caption constructors.
Test results: 127/130 passing (97.7%)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
closes#72
ref #69 - this resolves the "UICollection" (not "UIEntityCollection", perhaps renamed since the issue opened) and "UIEntityCollection" portion. The Grid point based iterators were not updated.
**RPATH updates**
Will this RPATH setting allow McRogueFace to execute using its included "lib" subdirectory after being unzipped on a new computer?
The change from "./lib" to "$ORIGIN/./lib" improves portability. The $ORIGIN token is a special Linux/Unix convention that refers to the directory containing the executable itself. This makes the path relative to the executable's location rather than the current working directory, which means McRogueFace will correctly find its libraries in the lib subdirectory regardless of where it's run from after being unzipped on a new computer.
**New standard object initialization**
PyColor, PyVector
- Fixed all 15 PyTypeObject definitions to use proper designated initializer syntax
- Replaced PyType_GenericAlloc usage in PyColor.cpp and PyVector.cpp
- Updated PyObject_New usage in UIEntity.cpp
- All object creation now uses module-based type lookups instead of static references
- Created centralized utilities in PyObjectUtils.h
**RAII Wrappers**
automatic reference counting via C++ object lifecycle
- Created PyRAII.h with PyObjectRef and PyTypeRef classes
- These provide automatic reference counting management
- Updated PyColor::from_arg() to demonstrate RAII usage
- Prevents memory leaks and reference counting errors
**Python object base in type defs:**
`.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0}`
PyColor, PyTexture, PyVector, UICaption, UICollection, UIEntity, UIFrame, UIGrid
**convertDrawableToPython**
replace crazy macro to detect the correct Python type of a UIDrawable instance
- Removed the problematic macro from UIDrawable.h
- Created template-based functions in PyObjectUtils.h
- Updated UICollection.cpp to use local helper function
- The new approach is cleaner, more debuggable, and avoids static type references
**Iterator fixes**
tp_iter on UICollection, UIGrid, UIGridPoint, UISprite
UIGrid logic improved, standard
**List vs Vector usage analysis**
there are different use cases that weren't standardized:
- UICollection (for Frame children) uses std::vector<std::shared_ptr<UIDrawable>>
- UIEntityCollection (for Grid entities) uses std::list<std::shared_ptr<UIEntity>>
The rationale is currently connected to frequency of expected changes.
* A "UICollection" is likely either all visible or not; it's also likely to be created once and have a static set of contents. They should be contiguous in memory in hopes that this helps rendering speed.
* A "UIEntityCollection" is expected to be rendered as a subset within the visible rectangle of the UIGrid. Scrolling the grid or gameplay logic is likely to frequently create and destroy entities. In general I expect Entity collections to have a much higher common size than UICollections. For these reasons I've made them Lists in hopes that they never have to be reallocated or moved during a frame.
directories needed:
* build - for cmake output
* deps - stuff needed to compile McRogueface (headers)
libtcod -> ../modules/libtcod/src/libtcod
sfml -> ../modules/SFML/include/SFML
python -> ../modules/cpython/Include
* lib - stuff needed to link McRogueFace (shared objects); also required at runtime
libtcod -> `../modules/libtcod/buildsys/autotools/.libs/libtcod.so.1.0.24`
sfml -> `../modules/SFML/build/lib/*`
python -> `../modules/cpython/libpython3.12.so`; standard lib at ../modules/cpython/build/lib.linux-x86_64-3.12 & ../modules/cpython/Lib
You can get dependencies by:
- Build from source (i.e. all submodules)
- Go download them from each project's website
- install packages from your distro and symlink them to deps/lib directories