No description
Find a file
John McCardle 257e52327b Fix #219: Add threading support with mcrfpy.lock() context manager
Enables background Python threads to safely modify UI objects by
synchronizing with the render loop at frame boundaries.

Implementation:
- FrameLock class provides mutex/condvar synchronization
- GIL released during window.display() allowing background threads to run
- Safe window opens between frames for synchronized UI updates
- mcrfpy.lock() context manager blocks until safe window, then executes
- Main thread detection: lock() is a no-op when called from callbacks
  or script initialization (already synchronized)

Usage:
    import threading
    import mcrfpy

    def background_worker():
        with mcrfpy.lock():  # Blocks until safe
            player.x = new_x  # Safe to modify UI

    threading.Thread(target=background_worker).start()

The lock works transparently from any context - background threads get
actual synchronization, main thread calls (callbacks, init) get no-op.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 23:37:49 -05:00
assets asset cleanup 2026-01-08 22:52:34 -05:00
cmake/toolchains mingw toolchain and final fixes for Windows. Closes #162 2026-01-08 21:16:27 -05:00
deps/platform mingw toolchain and final fixes for Windows. Closes #162 2026-01-08 21:16:27 -05:00
docs Cookbook: draft docs 2026-01-13 19:42:37 -05:00
explanation Add headless-automation.md explanation document 2026-01-14 03:04:48 +00:00
modules Sync heightmap API with libtcod/libtcod #175 convolution feature branch 2026-01-19 21:49:31 -05:00
src Fix #219: Add threading support with mcrfpy.lock() context manager 2026-01-19 23:37:49 -05:00
stubs using custom libtcod-headless 2.2.2 feature branch: fixes to convolution, gradient method 2026-01-19 14:10:07 -05:00
tests Add input validation and fix Entity repr 2026-01-16 19:18:27 -05:00
tools distribution packaging 2026-01-09 12:00:59 -05:00
.gitignore distribution packaging 2026-01-09 12:00:59 -05:00
.gitmodules feat: Replace libtcod with libtcod-headless fork (closes #134) 2025-11-26 11:22:48 -05:00
build.sh Squashed commit of the following: [alpha_streamline_1] 2025-07-05 18:56:02 -04:00
BUILD_FROM_SOURCE.md docs: Add comprehensive build documentation 2025-11-26 11:28:10 -05:00
build_windows.bat hotfix: Windows build attempt 2025-07-09 23:33:09 -04:00
build_windows_cmake.bat Squashed commit of the following: [alpha_presentable] 2025-07-15 21:30:49 -04:00
CLAUDE.md distribution packaging 2026-01-09 12:00:59 -05:00
CMakeLists.txt libtcod as SYSTEM include, to ignore deprecations 2026-01-11 20:44:46 -05:00
compile_commands.json Squashed commit of the following: [interpreter_mode] 2025-07-05 17:23:09 -04:00
forgejo-mcp.linux.amd64 version bump for forgejo-mcp binary 2025-11-03 10:59:22 -05:00
LICENSE.md Refactor: Python 3.12, build libtcod & SFML from source. Cmake build. Directory cleanup 2024-02-24 22:48:39 -05:00
README.md Update old format scene/timer examples 2026-01-05 11:42:22 -05:00
ROADMAP.md feat: auto-exit in --headless --exec mode when script completes 2025-10-30 22:52:52 -04:00

McRogueFace

Blame my wife for the name

A Python-powered 2D game engine for creating roguelike games, built with C++ and SFML.

  • Core roguelike logic from libtcod: field of view, pathfinding
  • Animate sprites with multiple frames. Smooth transitions for positions, sizes, zoom, and camera
  • Simple GUI element system allows keyboard and mouse input, composition
  • No compilation or installation necessary. The runtime is a full Python environment; "Zip And Ship"

 Image

Pre-Alpha Release Demo: my 7DRL 2025 entry "Crypt of Sokoban" - a prototype with buttons, boulders, enemies, and items.

Quick Start

Download:

  • The entire McRogueFace visual framework:
    • Sprite: an image file or one sprite from a shared sprite sheet
    • Caption: load a font, display text
    • Frame: A rectangle; put other things on it to move or manage GUIs as modules
    • Grid: A 2D array of tiles with zoom + position control
    • Entity: Lives on a Grid, displays a sprite, and can have a perspective or move along a path
    • Animation: Change any property on any of the above over time
# Clone and build
git clone <wherever you found this repo>
cd McRogueFace
make

# Run the example game
cd build
./mcrogueface

Building from Source

For most users, pre-built releases are available. If you need to build from source:

Quick Build (with pre-built dependencies)

Download build_deps.tar.gz from the releases page, then:

git clone <repository-url> McRogueFace
cd McRogueFace
tar -xzf /path/to/build_deps.tar.gz
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Full Build (compiling all dependencies)

git clone --recursive <repository-url> McRogueFace
cd McRogueFace
# See BUILD_FROM_SOURCE.md for complete instructions

BUILD_FROM_SOURCE.md - Complete build guide including:

  • System dependency installation
  • Compiling SFML, Python, and libtcod-headless from source
  • Creating build_deps archives for distribution
  • Troubleshooting common build issues

System Requirements

  • Linux: Debian/Ubuntu tested; other distros should work
  • Windows: Supported (see build guide for details)
  • macOS: Untested

Example: Creating a Simple Scene

import mcrfpy

# Create a new scene
intro = mcrfpy.Scene("intro")

# Add a text caption
caption = mcrfpy.Caption((50, 50), "Welcome to McRogueFace!")
caption.size = 48 
caption.fill_color = (255, 255, 255)

# Add to scene
intro.children.append(caption)

# Switch to the scene
intro.activate()

Documentation

📚 Developer Documentation

For comprehensive documentation about systems, architecture, and development workflows:

Project Wiki

Key wiki pages:

📖 Development Guides

In the repository root:

Build Requirements

  • C++17 compiler (GCC 7+ or Clang 5+)
  • CMake 3.14+
  • Python 3.12+
  • SFML 2.6
  • Linux or Windows (macOS untested)

Project Structure

McRogueFace/
├── assets/        # Sprites, fonts, audio
├── build/         # Build output directory: zip + ship
│   ├─ (*)assets/  # (copied location of assets) 
│   ├─ (*)scripts/ # (copied location of src/scripts)
│   └─ lib/        # SFML, TCOD libraries,  Python + standard library / modules
├── deps/          # Python, SFML, and libtcod imports can be tossed in here to build
│   └─ platform/   # windows, linux subdirectories for OS-specific cpython config
├── docs/          # generated HTML, markdown docs
│   └─ stubs/      # .pyi files for editor integration
├── modules/       # git submodules, to build all of McRogueFace's dependencies from source
├── src/           # C++ engine source
│   └─ scripts/    # Python game scripts (copied during build)
└── tests/         # Automated test suite
└── tools/         # For the McRogueFace ecosystem: docs generation

If you are building McRogueFace to implement game logic or scene configuration in C++, you'll have to compile the project.

If you are writing a game in Python using McRogueFace, you only need to rename and zip/distribute the build directory.

Philosophy

  • C++ every frame, Python every tick: All rendering data is handled in C++. Structure your UI and program animations in Python, and they are rendered without Python. All game logic can be written in Python.
  • No Compiling Required; Zip And Ship: Implement your game objects with Python, zip up McRogueFace with your "game.py" to ship
  • Built-in Roguelike Support: Dungeon generation, pathfinding, and field-of-view via libtcod
  • Hands-Off Testing: PyAutoGUI-inspired event generation framework. All McRogueFace interactions can be performed headlessly via script: for software testing or AI integration
  • Interactive Development: Python REPL integration for live game debugging. Use mcrogueface like a Python interpreter

Contributing

PRs will be considered! Please include explicit mention that your contribution is your own work and released under the MIT license in the pull request.

Issue Tracking

The project uses Gitea Issues for task tracking and bug reports. Issues are organized with labels:

  • System labels (grid, animation, python-binding, etc.) - identify which codebase area
  • Priority labels (tier1-active, tier2-foundation, tier3-future) - development timeline
  • Type labels (Major Feature, Minor Feature, Bugfix, etc.) - effort and scope

See the Issue Roadmap on the wiki for organized view of all open tasks.

License

This project is licensed under the MIT License - see LICENSE file for details.

Acknowledgments

  • Developed for 7-Day Roguelike 2023, 2024, 2025 - here's to many more
  • Built with SFML, libtcod, and Python
  • Inspired by David Churchill's COMP4300 game engine lectures