How thecherno/sparky works
Project Type and Purpose
• Sparky is a C++‐based, cross‐platform high‐performance game engine.
• It includes:
• Sparky-core: the engine runtime (subsystems: windowing, input, graphics, audio, VFS, entity-component, math, debug).
• Demo apps:
– Sandbox (native C++)
– SandboxCS (C#/.NET)
• SparkyCLI: a console‐mode tool for experiments or asset inspection.
• Tools/SPMBuild: a standalone content‐packaging utility.
• Dependencies: physics (Box2D), image loading (FreeImage), font (FreeType), audio (Gorilla-audio/OpenAL, libogg, libvorbis), OpenGL/DirectX loaders (GLEW), etc.
A. Applications (Sandbox, SandboxCS, SparkyCLI)
B. Engine Core Library (Sparky-core)
C. Third-Party Libraries & Asset Pipeline
D. Platform Abstraction & OS/Hardware
Main Components & Their Relationships
• Applications
– Depend on Sparky-core API.
– Provide entry point, game logic, test scenes, UI.
• Sparky-core Subsystems (each as a distinct block):
1. System & Platform: windowing (Window), file I/O (VFS), memory, threading, timers.
2. Input: keyboard/mouse events → EventDispatcher/EventListeners.
3. Graphics:
– API Abstraction Layer (Context, Buffer, Texture, Framebuffer…)
– Renderer (ForwardRenderer, DeferredRenderer, GBuffer, RenderCommand)
– Shader Management (ShaderFactory, ShaderManager)
– UI & Debug over‐lays (DebugRenderer, UI widgets)
4. Audio: SoundManager → Gorilla-audio/OpenAL → codecs (libogg/libvorbis).
5. Entity-Component System: Scene, Entity, Components (Transform, Mesh, Sprite…).
6. Math & Utilities: vectors/matrices, AABB, file utilities, image loaders.
• Third-Party & Asset Pipeline
– Images/fonts: FreeImage, FreeType
– Physics: Box2D (optional integration)
– Audio codecs: libogg, libvorbis
– Model loaders: OBJModel, PBR materials
– Tools: SPMBuild for packaging .spm scenes & assets
• Platform Backends (selected at compile/run):
– OpenGL (sp/platform/opengl + GLEW)
– DirectX (sp/platform/directx)
– POSIX/Win32 glue for window, input, file system
Data Flows & Interactions
• Application → calls Engine Core to initialize subsystems
• Engine Core → Platform layer to create window/context & dispatch OS events
• Input events → Engine Core → Entity/Component or App layer via EventDispatcher
• Graphics: Scene data → Renderer → Graphics API → GPU
• Audio: Sound requests → SoundManager → OpenAL → Audio hardware
• Asset loading: VFS → FreeImage/FreeType → memory → engine resources
• Packaging tool: SPMBuild reads raw assets → writes runtime package (.spm)
Architectural Patterns & Principles
• Layered architecture: clear separation of application, engine, third-party, and platform layers.
• Facade: high-level Sparky API hides platform/third-party details.
• ECS pattern: decouples data (components) from behavior (systems).
• Strategy pattern: pluggable platform backends (OpenGL vs. DirectX).
• Resource‐manager singletons for textures, shaders, sounds.