victor.pl
FREN
← All projects

Frame 010 · engineC++

MyGM

Data-driven 2D game engine: games are described in JSON instead of being hard-coded. Entity factory, event bus, spatial-hashing collisions, animation, audio and a code generator.

View the repository on GitLab (opens in a new tab)

README.md

C++ SFML License

A lightweight, data-driven 2D game engine built with C++17 and SFML 2. MyGm focuses on modularity, extensibility, and rapid game development through JSON-driven content and code generation.


🚀 Overview

MyGm separates engine code (src/engine/) from game code (src/game/), allowing most gameplay elements to be configured in JSON without modifying the engine itself.

The engine is built around a generic Factory with automatic type registration, a component system attached to every object, an EventBus for decoupled communication, and reusable JSON templates.

logo


✨ Features

  • 📦 Data-driven architecture: engine configuration, levels and menus are JSON files
  • 🏗️ Factory with automatic type registration (REGISTER_TYPE)
  • 🧩 Component system with JSON-based instantiation
  • ⚡ EventBus with publish/subscribe, priorities and immediate/queued execution
  • 🎮 World (game objects, physics, culling) and MenuManager (UI menus) containers
  • 🎥 Cameras as components: follow modes, bounds, zoom, rotation, viewports (split screen, minimap)
  • 🔗 Hierarchy: objects attached to others (weapons, shadows, panel content), nested children in JSON
  • 📑 Reusable JSON templates (template_path), keys in snake_case or camelCase
  • 💾 World and menu (de)serialization (save/load at runtime)
  • 🧱 Spatial hashing for collision queries and for the culling of large worlds
  • 💥 Collisions (swept AABB) with callbacks and bounces, triggers, gravity and friction on a fixed timestep
  • 🎞️ Sprite sources (shapes, textures, animations) with sprite batching, Animator (idle / run / jump states, flip)
  • 🖼️ UI widgets: text (typewriter effect), buttons, gauges, toggles, sliders, screen fades, textured or colored
  • 🕹️ Gameplay components: health, damage, zones and pickups, timers, spawners, counters: a simple game in JSON only
  • 🔊 Sound effects and music with master/category/local volumes
  • 🛜 Authoritative client/server networking (TCP, CBOR or JSON frames, rooms, client-side prediction)
  • 🛠️ Debug visualization (colliders, triggers, movement vectors, grid chunks, UI hitboxes, FPS)
  • 🤖 Artisan code generator
  • 🧪 Unit tests (Catch2), sanitizers and coverage in CI

📦 Example

Game objects are described in JSON instead of being hardcoded into the engine. This is an entry of the entities array of a level file:

{
    "type": "GameObject",
    "layer": "FOREGROUND",
    "collision": "collider",
    "is_gravity": true,
    "args": {
        "x": 0, "y": 0,
        "w": 32, "h": 32,
        "components": [
            {
                "type": "SpriteManager",
                "args": {
                    "sprites": [
                        {
                            "name": "idle",
                            "type": "AnimationSource",
                            "args": {
                                "file_path": "game/assets/player/idle.png",
                                "time_per_frame": 0.1,
                                "nb_sprites": 7,
                                "loop": true,
                                "rect": {
                                    "x": 0,
                                    "y": 0,
                                    "width": 32,
                                    "height": 32
                                }
                            }
                        }
                    ],
                    "current": "idle",
                    "follow": true,
                    "auto_sizing": true
                }
            }
        ]
    }
}

New content can be created and configured this way without recompiling. New behaviors are written as C++ components (see USAGE).


📚 Documentation

The documentation is split into focused guides.

🏗️ Engine Architecture

Internal design of the engine: project layout, runtime loop, subsystems, factory, event system and UML diagrams.

➡️ ARCHITECTURE

⚙️ Tools

Build system (builder), Artisan code generator, Doxygen documentation and UML generation.

➡️ TOOLS

🎮 Usage Guide

Dependency installation, configuration files, adding game content, templates and debugging tools.

➡️ USAGE

🛜 Networking

Client/server architecture, rooms, player assignment, messages and configuration.

➡️ NETWORK

🤖 AI agents

Technical reference written for AI coding agents (also useful for humans).

➡️ docs/ai/README_FOR_AI.md


🛠️ Quick Start

Install the required dependencies (Debian / Ubuntu):

sudo apt update
sudo apt install git g++ cmake ninja-build ccache libsfml-dev python3

Clone the repository:

git clone https://gitlab.com/altair908/mygm.git
cd mygm/src

Build and run (always from src/, all runtime paths are relative to it):

python3 builder
./app

To contribute, also install clang-format 18.1.8 (same version as the CI) to format the code with python3 builder format:

sudo apt install pipx
pipx install clang-format==18.1.8   # provides clang-format and git-clang-format
pipx ensurepath                     # then open a new terminal

For other platforms, IDE configuration, and advanced build commands, see USAGE and TOOLS.


🤖 Development Tools

Builder

A Python wrapper around CMake (Ninja generator).

python3 builder            # build (Release on the first configure)
python3 builder debug      # rebuild with debug symbols
python3 builder test       # build and run the unit tests
python3 builder release    # package a ready-to-run game into release/
python3 builder clean      # remove game objects and the app executable
python3 builder uml        # generate UML diagrams
python3 builder format     # format the C++ code (clang-format 18.1.8); format check: only check
python3 builder help       # list every command

Artisan

Generates boilerplate for new content.

./artisan make:Component player/playerController      # C++ component (.hpp/.cpp/test/template)
./artisan make:GameObject player/hero -c SpriteManager  # JSON template of a GameObject
./artisan make:UiObject ui/health_bar                   # JSON template of a UiObject
  • make:Component creates the header, the source (with REGISTER_TYPE), a Catch2 test and a *.default.json template under game/.
  • make:GameObject / make:UiObject only create a JSON template under game/assets/templates/, pre-filled with the default templates of the requested components.

See TOOLS for more information.


📖 Project Documentation


🚧 Project Status

This project is under active development.

Planned features and milestones are documented in ROADMAP, while completed work is tracked in CHANGELOG.


🤝 Contributing

Contributions are welcome, whether you want to fix bugs, improve documentation, optimize the engine, implement new features or add tests.

Please read CONTRIBUTING before opening a Merge Request.


📄 License

This project is licensed under the MIT License.

See LICENSE for details.