src/:
src/grim/— Engine/platform layer (raylib wrapper, assets, rendering helpers)src/crimson/— Game layer (modes, simulation, UI, persistence, data tables)
grim.dll vs crimsonland.exe boundary while staying idiomatic for Python.
Design Principles
Import Rule:
grim must not import crimson. The game layer can import engine helpers, but not vice versa.grimshould not importcrimsoncrimsoncan importgrimhelpers- Keep raylib calls confined to
grimas much as practical - Prefer small moves that preserve working entrypoints
- No compatibility re-exports or stubs when moving modules
Grim Module (Engine Layer)
Location:src/grim/
Core Subsystems
| Module | Purpose | Key Files |
|---|---|---|
| Window/Loop | Window init, main loop, FPS, view protocol | app.py, view.py |
| Assets | PAQ/JAZ decoders, texture cache | paq.py, jaz.py, assets.py |
| Input | Keyboard/mouse/gamepad wrapper | input.py |
| Rendering | Terrain renderer, geometry helpers | terrain_render.py, geom.py, color.py |
| Audio | Music/SFX playback | audio.py, music.py, sfx.py, sfx_map.py |
| Config | crimson.cfg persistence | config.py |
| Console | Debug console overlay | console.py |
| Fonts | Font loaders and text rendering | fonts/small.py, fonts/grim_mono.py |
| Math | Geometry primitives | math.py, geom.py |
| Random | RNG wrapper | rand.py |
Example: Terrain Rendering
src/grim/terrain_render.py
Crimson Module (Game Layer)
Location:src/crimson/
Core Subsystems
| Module | Purpose | Key Files |
|---|---|---|
| CLI | Command-line interface | cli/root.py, cli/replay.py |
| Game Flow | State machine, boot sequence | game/__init__.py, demo.py |
| Modes | Gameplay mode implementations | modes/survival_mode.py, modes/rush_mode.py, etc. |
| Simulation | Deterministic world state | sim/world_state.py, sim/step_pipeline.py |
| Gameplay | Player update, weapon handling | gameplay.py, weapon_runtime.py |
| Creatures | AI, animations, spawning | creatures/ai.py, creatures/runtime.py |
| Projectiles | Projectile pools and updates | projectiles/runtime.py, projectiles/types.py |
| Bonuses | Pickup logic and effects | bonuses/apply.py, bonuses/pool.py |
| Perks | Perk runtime architecture | perks/runtime/manifest.py, perks/impl/* |
| Quests | Quest builders (tiers 1-5) | quests/tier1.py, quests/runtime.py |
| Tutorial | Tutorial stage progression | tutorial/stages.py, tutorial/hints.py |
| Typ-o | Typing mechanics | typo/target_matching.py |
| Networking | Rollback netplay, lockstep | net/rollback.py, net/lan_lockstep.py |
| Replay | Deterministic replay system | replay/codec.py, replay/recorder.py |
| UI | HUD, menus, panels | ui/hud.py, frontend/menu.py |
| Persistence | Save files, high scores | persistence/save_status.py |
| Audio Routing | Gameplay audio events | audio_router.py, weapon_sfx.py |
| Data Tables | Weapons, perks, creatures | weapons.py, perks/ids.py |
Example: Game Mode Structure
src/crimson/modes/survival_mode.py
Module Organization
Simulation Layer
The deterministic simulation core lives insrc/crimson/sim/:
Perks Architecture
Perks are split into three layers (see Perks Module):Prefix Map (Decompile → Rewrite)
Original binary prefix clusters map to rewrite packages:| Original Prefix | Rewrite Package |
|---|---|
grim_* | grim.* (graphics/input/audio/assets) |
resource_*, buffer_reader_* | grim.paq, grim.assets |
console_* | grim.console |
ui_*, hud_* | crimson.ui.* |
quest_*, survival_*, rush_* | crimson.modes.* |
player_*, creature_*, projectile_* | crimson.sim.*, crimson.gameplay |
weapon_*, perk_* | crimson.weapons, crimson.perks.* |
bonus_*, effect_*, fx_* | crimson.bonuses.*, crimson.effects |
highscore_* | crimson.persistence.* |
File Locations
Key entry points and their locations:Game Entry Points
Game Entry Points
src/crimson/cli/root.py— Main CLI (crimsoncommand)src/crimson/game/__init__.py— Game flow state machinesrc/crimson/demo.py— Demo/attract mode
Simulation Core
Simulation Core
src/crimson/sim/world_state.py— World step logicsrc/crimson/sim/step_pipeline.py— Deterministic pipelinesrc/crimson/sim/sessions.py— Mode session adapters
Rendering
Rendering
src/grim/terrain_render.py— Terrain renderingsrc/crimson/render/world/— World sprite renderingsrc/crimson/ui/hud.py— HUD overlay
Assets
Assets
src/grim/paq.py— PAQ archive readersrc/grim/jaz.py— JAZ texture decodersrc/grim/assets.py— Texture cache
Import Boundaries
The project usesimport-linter to enforce architectural boundaries:
Next Steps
Game Loop
Understand the frame pipeline
Deterministic Pipeline
Learn about the step contract
Crimson Module
Dive into game logic
Grim Module
Explore the engine layer