How arthurcarrell/craycast works
1. This is a small SDL3/C raycasting application with two major runtime modes: a 3D-ish “World Mode” for movement and rendering, and a “Map Mode” for editing line geometry. The repository is organized around a lightweight game loop plus a separate map parser/saver pipeline.
2. The core application entrypoint is src/main.c, with src/state.c and src/state.h acting as the high-level mode/state coordinator. From the README and file layout, the state layer likely switches between title, world, and editor behavior rather than embedding that logic in one monolithic loop.
3. Platform and frame presentation are isolated in src/sdl.c, src/framebuf.c, and related headers. SDL3 is the only major external runtime dependency, so input polling, window creation, and presenting rendered pixels are probably centralized there instead of being spread through gameplay code.
4. Rendering is split into a software-style pipeline: src/raycast.c computes the view from the scene, src/framebuf.c manages the pixel buffer, src/textures.c holds image/texture data, and src/font.c supports text drawing. This suggests the engine draws into an internal buffer first and then hands that buffer to SDL for display.
5. World simulation is represented by src/world.c, src/actor.c, src/sector.c, and src/line.c. The presence of actor and sector indicates the scene is not just a flat list of walls; it is structured enough to support moving entities and region-based geometry, even if the README notes sectors/portals are still evolving.
6. Geometry appears to be line-centric. The README says Map Mode creates lines by clicking twice, and the line and sector modules likely define the map primitives used both for rendering boundaries and for collision/visibility tests. The sample .map files in maps/ are the main scene assets for this geometry layer.
7. Input handling is separated in src/input.c, which likely translates keyboard/mouse state into commands consumed by the current state. That matters architecturally because movement in World Mode and point placement in Map Mode are different consumers of the same low-level input stream.
8. Map editing is its own subsystem in src/editor.c. Based on the README, it provides interactive line creation and possibly persistence hooks, but it is distinct from the runtime renderer so that editing and play mode can share map data without sharing UI logic.
9. Persistence is handled by src/map_parser/parse.c and src/map_parser/save.c. This is a clear boundary: map files are not hardcoded into world logic, but loaded/saved through a dedicated parser layer. That makes .map files the main interchange format between the editor and the game runtime.
10. src/title.c suggests there is a startup or menu state before entering the main modes. Combined with state.c, this implies a small state machine architecture: title screen → world mode or map mode, with the current state determining which update/render path is active.
11. src/utils.c and the headers around the project likely contain shared math/helpers used across raycasting, map parsing, and rendering. In a repo like this, those utilities are important because they prevent geometry math and file parsing from being duplicated in multiple subsystems.
12. The asset structure is simple: textures/ holds visual resources, while maps/ holds example levels and test cases such as portals, loops, corridors, and infinite hallway scenarios. Those map names strongly suggest the engine is being exercised against tricky geometric cases, especially for the raycaster and future portal/sector work.
Main entry points: world.c World · state.c State · line.c Line · raycast.c Raycast
Components 19
Runtime
Application entry, state coordination, and mode switching
Presentation
SDL platform layer and software rendering pipeline
- SDL · Windowing, event loop integration, and presenting frames
src/sdl.c - Framebuf · Internal framebuffer for software rendering
src/framebuf.c - Raycast · Computes the 3D-ish view from world geometry
src/raycast.c - Textures · Texture and image data used by rendering
src/textures.c - Font · Bitmap text drawing for UI and debug output
src/font.c
Simulation
World, geometry, and movement logic
- World · World update, movement, and scene coordination
src/world.c - Actor · Moving entities and player-like actors
src/actor.c - Sector · Region-based spatial structure for the scene
src/sector.c - Line · Line-segment geometry used for walls and collisions
src/line.c - Utils · Common math and helper routines reused across subsystems
src/utils.c
Editing
Map authoring and persistence pipeline
Connections 24
- Main → State: runs · Main initializes and drives the active state
- State → Title: starts at · Initial menu/title flow before other modes
- State → World: enters · Switches into gameplay/world mode
- State → Editor: enters · Switches into map editing mode
- Input → State: feeds · Low-level input is consumed by the current mode
- SDL → Input: polls · SDL provides keyboard and mouse events
- SDL → Framebuf: presents · Final pixel buffer is displayed through SDL
- World → Raycast: renders via · World state is converted into a view by raycasting
- Raycast → Framebuf: draws into · Renderer outputs into the internal framebuffer
- Textures → Raycast: provides · Texture data is sampled during rendering
- Font → Framebuf: draws into · Text is composited into the framebuffer
- World → Actor: updates · World simulation advances actors and movement
- World → Sector: uses · World logic relies on region geometry
- World → Line: uses · Geometry and collision boundaries are line-centric
- Actor → Line: collides with · Actors interact with map lines
- Sector → Line: bounded by · Sectors are defined from line geometry
- Editor → Line: creates · Map mode builds line geometry interactively
- Editor → Save: writes · Edited geometry is persisted through the save pipeline
- Parse → Line: builds · Parser turns map files into line geometry
- Parse → Sector: builds · Parser reconstructs sector structure when present
- Save → Maps: stores · Saved maps land in the scene asset directory
- Parse → Maps: loads · Runtime and editor consume .map scene files
- World → Utils: shares helpers · Shared math and helper routines support simulation
- Raycast → Utils: shares helpers · Rendering math uses common utilities