How feresr/super-mario-bros works
Project Type & Purpose
• This is a native (and wasm‐ported) 2D game written in C++ using SDL2.
• It employs an Entity-Component-System (ECS) architecture, with multiple “scenes” (Intro, Game, Editor).
File Structure
• Top-level build: CMakeLists.txt, cmake/*.cmake, vendor/ (SDL2 find-modules).
• Core include/ and src/ directories: ECS core, Components, Systems, Scenes, Game entry point, Asset managers.
• assets/: audio files, map layouts.
• maplayout/: level data.
README Insights
• Confirms no external engine, pure C++ & SDL2.
• Highlights ECS inspired by redxdev/ECS.
• Mentions three scenes and multiple systems (physics, render, sound, etc.).
Main Components
a. Game Application (Main.cpp → Game.cpp)
• Initializes SDL2 subsystems (video, audio, input).
• Loads assets via TextureManager & SoundManager.
• Creates ECS world (EntityManager, ComponentStorage, SystemManager).
• SceneManager controlling IntroScene, GameScene, EditorScene.
b. ECS Core
• EntityManager: tracks entity IDs.
• Component Storage: arrays/maps keyed by entity.
• SystemManager: iterates over systems each frame.
c. Systems (Update Loop)
• Input System → generates events/commands.
• PhysicsSystem → updates positions, collisions via AABB.
• PlayerSystem, EnemySystem, FlagSystem → game logic.
• MapSystem → tile loading & streaming from maplayout/.
• AnimationSystem → sprite frame updates.
• SoundSystem → triggers sounds via SoundManager.
• ScoreSystem → updates score UI.
• CallbackSystem, EditorSystem → hooks & editor-specific logic.
d. Scenes
• IntroScene → splash screen.
• GameScene → actual gameplay loop.
• EditorScene → level editor UI and interactions.
e. Asset Managers
• TextureManager: loads and caches SDL_Textures from disk.
• SoundManager: loads and plays WAV/MIDI via SDL_mixer.
f. External Libraries
• SDL2 (window, input), SDL2_image, SDL2_mixer, SDL2_ttf.
g. Data Stores
• assets/music/*.wav
• assets/world1-1 map files
• maplayout/ custom level definitions
Relationships & Data Flow
• Startup: Main → Game.Init → SDL_Init → AssetManagers load → ECS registered → SceneManager loads initial scene.
• Game Loop (each frame):
1. Poll SDL events → InputSystem → update component state
2. Update all Systems in sequence (Physics → AI → Map → Animation → Score → Sound)
4. SceneManager may swap Scenes on signals
• Asset Access: Systems request TextureManager/SoundManager for resources.
• Scene ↔ ECS: Scenes configure which Systems are active, spawn Entities with Components.
Architectural Patterns & Principles
• ECS decouples data (Components) from behavior (Systems).
• Scene-based state management (finite state machine for screens).
• Resource caching via manager singletons.
• Modular CMake build for cross-platform and wasm.
Final Checklist
• All components identified above included and labeled.
• Optionally, annotate with file paths (e.g., Systems correspond to include/systems/*.h & src/systems/*.cpp).