How iercann/enari-engine works
Main Components
• Game Engine Core – Representing the heart of the project (see files like src/Game.ts). This is where the game loop and central orchestration happen.
• Input Management – Found in src/Input (InputManager.ts, KeyBinding.ts), handling user inputs (WASD, mouse clicks, etc.).
• Controllers – In src/Controller (CarController.ts, PlayerController.ts, and generic Controller.ts) which process game object behaviors based on input and game state.
• Core Domain Objects – Under src/Core, containing classes such as Actor, GameObject, Pawn, Player, and various utility math classes (Vector, Quaternion, etc.) that represent game entities and support their behaviors.
• Physics Engine – Located in src/Physics, including colliders (Cube, Sphere, Ground, Trimesh) and physics integration with Ammo.js. This module is responsible for collision detection and physical simulations.
• Rendering & Visualization – Consisting of various submodules under src/View:
• Mesh and Asset Loading (files in src/View/Mesh and related Draco decoding support)
• Renderer Components (in src/View/Renderer: different renderers like CubeRenderer, GroundRenderer, FPSRenderer, ThirdPersonRenderer, etc.)
• Camera Management (src/View/CameraManager with FPS and TPS camera implementations)
• Lighting and Shader management (src/View/Shader, SceneLighting, SkyLight, etc.)
• Particle systems (src/View/Particle/ParticleManager.ts)
• Audio (src/View/Audio/AudioManager.ts)
• User Interface & Debug – Any UI-specific elements like the debug UI (src/View/DebugUI.ts) to adjust settings and visualization tools.
• Public Assets Repository – The public directory holds 3D model files (.glb, .blend, etc.), audio assets, and other static resources like maps, which are loaded at runtime.
Relationships and Data Flow
• The central Game Engine (Game.ts) acts as the coordinator:
• It integrates the Input Manager, Controllers, and Core Game Objects.
• It manages the update cycle by periodically triggering updates (via the PeriodicUpdater in Core/PeriodicUpdater.ts) for both the physics engine and the rendering system.
• Input Management passes user actions to the Controllers (e.g., PlayerController for movement or CarController for vehicles).
• Controllers update the state of Game Objects (through the Core/Actor, Pawn, etc.), which in turn update their visual representations in the Rendering module.
• The Physics Engine receives updated state from game objects, calculates collisions and dynamics (with support from the Collider types), then passes physics updates back to the Core.
• The Rendering module:
• Uses Mesh loaders to interpret 3D assets.
• Integrates with the Camera Managers (switching between FPS/TPS views).
• Applies lighting, shadowing, and shader effects.
• The Audio system (AudioManager) and Particle system (ParticleManager) work in parallel to provide immersive effects triggered by in-game events.
• There’s a clear separation between visualization (src/View) and game logic (src/Core, src/Controller, src/Input), making it a modular design.
Important Architectural Patterns
• Modular Design: Each subsystem (Input, Physics, Rendering, etc.) is in its dedicated directory, facilitating loose coupling and easier maintenance.
• MVC-Like Separation: The game’s domain logic (Models and Controllers) is separated from the view/rendering components, similar to an MVC pattern.
• Abstraction and Extension: Interfaces in src/Interface, and the abstraction of colliders (Cube, Sphere, Trimesh) suggest extensibility for various game objects.
Technologies and Frameworks
• Three.js for rendering and 3D model handling.
• Ammo.js (with mention of a migration possibility to Rapier.js) for physics simulation.
• Relevant libraries like Tweakpane for UI debugging.
• Draco decoder (in src/View/Mesh/draco) for optimized 3D asset compression.
Final Touches
• Provide directional cues that clearly represent dataflows and dependencies among modules.