Changelog
- 2025-11-09: JobSystem Shutdown Pattern Documentation
- Documented proper shutdown sequence for applications using JobSystem
- Critical Pattern: Stop JobSystem BEFORE deleting objects that worker threads access
- Example: SimpleMiner's three-stage shutdown prevents crashes and memory leaks
g_jobSystem->Shutdown()- Stop all worker threads- Delete game objects (chunks, world, entities)
GEngine::Get().Shutdown()- Destroy engine systems
- Prevents race conditions where workers access deleted memory
- Allows proper DirectX resource cleanup before device destruction
- See SimpleMiner's App.cpp for reference implementation
- 2025-10-27: M4-T8 Async Architecture Refactoring
- Introduced Entity module with async entity management API (EntityAPI, EntityScriptInterface)
- Added generic StateBuffer template for lock-free double-buffering in Core module
- Refactored Camera system with CameraAPI and CameraStateBuffer for async updates
- Introduced IJSGameLogicContext interface for dependency inversion between Engine and Game
- Implemented thread-safe state synchronization between worker and main threads
- Applied SOLID principles: Single Responsibility, Dependency Inversion
- Extracted reusable components from DaemonAgent to Engine for multi-project usage
- 2025-09-15 10:46:17: Updated AI context initialization with current timestamp and module structure verification
- 2025-09-06 21:17:11: Comprehensive AI context documentation update with complete module coverage
- 2025-09-06 19:54:50: Initial AI context initialization and documentation
Daemon Engine is a modular, performance-oriented game engine built from the ground up with modern C++ practices. Designed for both educational purposes and production-ready game development, it provides a comprehensive suite of systems including advanced rendering, robust audio management, flexible input handling, cross-platform networking capabilities, and JavaScript scripting integration via V8.
The engine follows a modular, subsystem-based architecture where each major system operates independently but communicates through a global event system. The architecture emphasizes:
- Modular Design: Well-defined system boundaries for maintainability
- Performance-First: Optimized rendering pipeline with batch processing
- Data-Oriented Design: Cache-friendly data structures and processing patterns
- Event-Driven Communication: Loose coupling between systems
- Async JavaScript Integration: Lock-free worker thread architecture for dual-language game development
- Language: C++20 with modern practices
- Graphics API: DirectX 11
- Audio: FMOD integration with 3D spatial audio
- Scripting: V8 JavaScript engine integration with async worker architecture
- Platform: Windows (x64) with planned cross-platform support
- Build System: Visual Studio projects with MSBuild
The engine supports dual-threaded JavaScript game logic through lock-free double-buffering:
Main Thread (Rendering): Worker Thread (JavaScript):
+-- BeginFrame() +-- V8 Isolate Lock
+-- Process RenderCommands +-- JSEngine.update()
+-- SwapBuffers() | +-- entity.createMesh(...)
| +-- EntityStateBuffer | +-- camera.update(...)
| +-- CameraStateBuffer +-- Write to Back Buffers
+-- Render from Front Buffers +-- Submit RenderCommands
+-- EndFrame() +-- V8 Isolate Unlock
graph TD
A["Daemon Engine Root"] --> B["Code/Engine"];
B --> C["Core"];
B --> D["Renderer"];
B --> E["Audio"];
B --> F["Input"];
B --> G["Math"];
B --> H["Scripting"];
B --> I["Resource"];
B --> J["Network"];
B --> K["Platform"];
B --> L["Entity"];
A --> L["Code/ThirdParty"];
L --> M["FMOD"];
L --> N["V8"];
L --> O["TinyXML2"];
L --> P["STB"];
A --> Q["Docs"];
A --> R["Tools"];
click C "./Code/Engine/Core/CLAUDE.md" "View Core module documentation"
click D "./Code/Engine/Renderer/CLAUDE.md" "View Renderer module documentation"
click E "./Code/Engine/Audio/CLAUDE.md" "View Audio module documentation"
click F "./Code/Engine/Input/CLAUDE.md" "View Input module documentation"
click G "./Code/Engine/Math/CLAUDE.md" "View Math module documentation"
click H "./Code/Engine/Scripting/CLAUDE.md" "View Scripting module documentation"
click I "./Code/Engine/Resource/CLAUDE.md" "View Resource module documentation"
click J "./Code/Engine/Network/CLAUDE.md" "View Network module documentation"
click K "./Code/Engine/Platform/CLAUDE.md" "View Platform module documentation"
click L "./Code/Engine/Entity/CLAUDE.md" "View Entity module documentation"
| Module | Path | Responsibility | Entry Points | Status |
|---|---|---|---|---|
| Core | Code/Engine/Core/ |
Foundation systems, events, utilities, logging, StateBuffer | EngineCommon.hpp, EventSystem.hpp, StateBuffer.hpp |
Active |
| Entity | Code/Engine/Entity/ |
Async entity management, state synchronization | EntityAPI.hpp, EntityScriptInterface.hpp |
Active |
| Renderer | Code/Engine/Renderer/ |
DirectX 11 rendering pipeline, cameras, CameraAPI | Renderer.hpp, Camera.hpp, CameraAPI.hpp |
Active |
| Audio | Code/Engine/Audio/ |
FMOD-based 3D audio system | AudioSystem.hpp |
Active |
| Input | Code/Engine/Input/ |
Keyboard, mouse, controller input handling | InputSystem.hpp |
Active |
| Math | Code/Engine/Math/ |
Mathematical primitives and operations | MathUtils.hpp, Vec3.hpp, Mat44.hpp |
Active |
| Scripting | Code/Engine/Scripting/ |
V8 JavaScript integration, IJSGameLogicContext | V8Subsystem.hpp, IJSGameLogicContext.hpp |
Active |
| Resource | Code/Engine/Resource/ |
Asset loading, caching, resource management | ResourceSubsystem.hpp |
Active |
| Network | Code/Engine/Network/ |
TCP/UDP networking foundation | NetworkSubsystem.hpp |
Active |
| Platform | Code/Engine/Platform/ |
OS abstraction layer | Window.hpp |
Active |
- Visual Studio 2019 or later with C++20 support
- Windows 10 SDK (10.0.18362.0 or later)
- DirectX 11 compatible graphics hardware
- Git for version control
# Clone the repository
git clone https://github.com/dadavidtseng/DaemonEngine.git
cd DaemonEngine
# Open Visual Studio solution
start Engine.sln
# Build configuration
# - Set platform to x64
# - Choose Debug or Release configuration
# - Build solution (Ctrl+Shift+B)#include "Engine/Core/EngineCommon.hpp"
#include "Engine/Renderer/Renderer.hpp"
#include "Engine/Audio/AudioSystem.hpp"
// Initialize core systems
g_theRenderer = new Renderer();
g_theAudio = new AudioSystem();
g_eventSystem = new EventSystem();
// Game loop
while (isRunning) {
g_theRenderer->BeginFrame();
// Your game logic here
g_theRenderer->EndFrame();
}The project currently lacks a comprehensive testing framework but follows these practices:
- Manual testing through developer console
- Performance profiling via built-in debug systems
- Visual debugging through DebugRenderSystem
- Memory tracking and leak detection
- Thread Safety Analyzer (TSan) for async architecture validation
Recommended additions:
- Unit test framework integration (Google Test)
- Automated regression testing
- Performance benchmarking suite
- Async architecture stress tests
- Follow C++20 standards and modern practices
- Use PascalCase for classes and enums:
AudioSystem,eBlendMode - Use camelCase for functions and variables:
BeginFrame(),m_deviceContext - Use snake_case for file names:
audio_system.cpp(though project uses PascalCase currently) - Prefix member variables with
m_:m_config,m_isInitialized - Use explicit constructors where appropriate
- Prefer smart pointers over raw pointers for ownership
- Document all public APIs with comprehensive comments
- RAII: Resource management through constructors/destructors
- PIMPL: Used in V8Subsystem for implementation hiding
- Factory Pattern: Resource creation and management
- Observer Pattern: Event system for loose coupling
- Singleton Pattern: Global system access (used sparingly)
- Double-Buffering: Lock-free state synchronization for async architectures
- Dependency Inversion: Interface-based decoupling (IJSGameLogicContext)
- Memory pool allocators for frequent allocations
- Batch processing for rendering operations
- Cache-friendly data layout where possible
- Minimal dynamic allocations in performance-critical paths
- Lock-free double-buffering for async state synchronization
- Brief locked swap operations at frame boundaries
When working with this codebase using AI assistance:
- System Understanding: Always review module interfaces (
*.hppfiles) before making changes - Performance Impact: Consider rendering and audio performance implications
- Memory Management: Follow RAII patterns and avoid memory leaks
- Threading Safety: Be aware of multi-threaded contexts (ResourceSubsystem, AudioSystem, async JavaScript)
- Dependency Management: Understand third-party integration points (V8, FMOD, DirectX)
- Testing Approach: Use developer console and debug visualization for verification
- Documentation: Update module-level documentation for significant changes
- Async Architecture: Understand double-buffering pattern and thread boundaries
- Global system pointers in
EngineCommon.hpp - Event system for inter-module communication
- Resource system for asset management
- Scripting interface for gameplay programming
- StateBuffer for async state synchronization
- IJSGameLogicContext for game-specific JavaScript integration