Pyramid is a modern, multi-platform game engine designed with flexibility and performance in mind. The engine supports multiple graphics APIs and provides a clean abstraction layer for rendering. Built with C++17 best practices, the engine features a multi-layered architecture that separates concerns while maintaining high performance through SIMD optimizations and efficient memory management.
The Pyramid Engine is organized into five distinct layers, each with specific responsibilities:
- Game Loop: Main game loop with update and render cycles
- Event System: Platform-independent event handling
- Memory Management: Custom allocators and memory pools
- Configuration: Engine settings and runtime configuration
- Platform Abstraction: Unified interface for platform-specific operations
- Window Management: Platform-specific window creation and management
- Input Handling: Keyboard, mouse, and controller input
- System Integration: File I/O, timing, and system services
- Graphics Context: Platform-specific graphics context management
- Graphics Device Abstraction: Multi-API support (OpenGL, DirectX planned)
- Rendering Pipeline: Organized rendering stages with command buffers
- Resource Management: Textures, buffers, and shader management
- Camera System: Advanced camera with projections and frustum culling
- Scene Rendering: Efficient scene rendering with visibility culling
- SIMD-Optimized Operations: Runtime CPU feature detection
- Vector and Matrix Classes: Vec2, Vec3, Vec4, Mat3, Mat4
- Quaternion Support: Rotations and orientation
- Geometric Utilities: Intersection testing and spatial operations
- Performance Optimizations: Fast approximations and batch processing
- Logging System: Thread-safe logging with file rotation
- Asset Management: Resource loading and management
- Serialization: Scene and object serialization
- Debug Tools: Performance monitoring and visualization
- Math Utilities: Additional mathematical functions and utilities
The Pyramid Engine features a production-ready logging system located in the Utils module:
- Thread Safety: Full mutex protection with deadlock prevention
- Multiple Log Levels: Trace, Debug, Info, Warn, Error, Critical with runtime filtering
- File Output: Automatic rotation with configurable size limits (default 10MB, 5 files)
- Source Location: Automatic tracking of file, function, and line numbers
- Structured Logging: Key-value pair support for analytics and debugging
- Multiple Interfaces: C-style, stream-style, and structured logging APIs
- Performance Optimized: Early exit filtering and local buffer management
- Logger Class: Singleton pattern with thread-safe operations
- LoggerConfig: Runtime configuration for all logging aspects
- LogEntry: Structured representation of log messages with metadata
- SourceLocation: Automatic capture of source code location information
- File Rotation: Automatic log file management with size-based rotation
// Basic logging
PYRAMID_LOG_INFO("Game started with version: ", 1.0f);
// Stream-style logging
PYRAMID_ERROR_STREAM() << "Failed to load: " << filename;
// Structured logging for analytics
std::unordered_map<std::string, std::string> fields;
fields["level"] = "forest_1";
fields["score"] = "1500";
PYRAMID_LOG_STRUCTURED(LogLevel::Info, "Level completed", fields);The Pyramid Engine features a production-ready scene management system with advanced spatial partitioning capabilities, located in the Pyramid::SceneManagement namespace:
- SceneManager: Central scene lifecycle management and organization
- Octree: Spatial partitioning system for efficient object queries
- AABB: Axis-aligned bounding box implementation with intersection testing
- Query System: Multiple spatial query types with performance optimization
- Performance Monitoring: Real-time statistics and profiling capabilities
namespace Pyramid::SceneManagement {
class SceneManager {
// Scene lifecycle management
std::shared_ptr<Scene> CreateScene(const std::string& name);
void SetActiveScene(std::shared_ptr<Scene> scene);
// Spatial partitioning
void EnableSpatialPartitioning(bool enable);
void SetOctreeDepth(u32 depth);
void RebuildSpatialPartition();
// Spatial queries
QueryResult QueryScene(const QueryParams& params);
std::vector<std::shared_ptr<RenderObject>> GetVisibleObjects(const Camera& camera);
std::vector<std::shared_ptr<RenderObject>> GetObjectsInRadius(const Vec3& center, f32 radius);
std::shared_ptr<RenderObject> GetNearestObject(const Vec3& position);
// Performance monitoring
const SceneStats& GetStats() const;
};
class Octree {
// Spatial partitioning with configurable depth and object limits
void Insert(std::shared_ptr<RenderObject> object);
std::vector<std::shared_ptr<RenderObject>> QueryPoint(const Vec3& point);
std::vector<std::shared_ptr<RenderObject>> QuerySphere(const Vec3& center, f32 radius);
std::vector<std::shared_ptr<RenderObject>> QueryBox(const AABB& bounds);
std::shared_ptr<RenderObject> FindNearest(const Vec3& position);
};
}- Octree Implementation: Hierarchical spatial subdivision with configurable depth (default 8 levels)
- Query Types: Point, sphere, box, ray, and frustum-based spatial queries
- Performance: O(log n) object lookup complexity vs O(n) brute force
- Memory Efficient: Smart pointer-based resource management with RAII principles
- Configurable: Adjustable octree depth and objects per node for different use cases
The scene management system supports multiple query types optimized for different game scenarios:
- Point Queries: Find objects at specific locations
- Sphere Queries: Radius-based object discovery (explosions, AI awareness)
- Box Queries: Rectangular region object detection (triggers, areas)
- Ray Queries: Line-based intersection testing (line of sight, projectiles)
- Frustum Queries: Camera-based visibility culling for rendering
Real-time statistics tracking for optimization and debugging:
struct SceneStats {
u32 totalNodes; // Total scene nodes
u32 totalObjects; // Total render objects
u32 visibleObjects; // Currently visible objects
u32 octreeNodes; // Octree node count
u32 octreeDepth; // Current octree depth
f32 lastQueryTime; // Last query execution time (ms)
f32 lastUpdateTime; // Last update execution time (ms)
};The graphics system is built around a flexible abstraction layer that supports multiple graphics APIs with a focus on performance and modern rendering techniques:
- IGraphicsDevice: Core interface for all graphics implementations
- OpenGL (3.3 - 4.6) - Currently implemented
- DirectX 9/10/11/12 (planned)
- Vulkan (planned)
- Metal (planned for Apple platforms)
- Command Buffer System: Efficient GPU command batching and submission
- Render Pass Framework: Organized rendering stages with clear separation
- Resource Management: Unified handling of textures, buffers, and shaders
- State Management: Optimized graphics state changes with minimal overhead
- Camera System: Advanced camera with projections and frustum culling
- Scene Management: Spatial partitioning and visibility culling
- Multi-API Support: Unified interface across different graphics APIs
- Version Detection: Automatic feature detection and fallback
- Modern OpenGL: UBOs, advanced shaders, instanced rendering
- Buffer Management: Vertex, index, uniform, and shader storage buffers
- Shader System: Flexible shader creation and management
- Texture Management: 2D texture creation and loading from files
- State Optimization: Minimal state changes and efficient batching
-
Geometry Stage
- Vertex buffer binding and attribute setup
- Index buffer management for indexed rendering
- Instance data for instanced rendering
-
Shader Stage
- Vertex and fragment shader compilation and linking
- Uniform buffer object management
- Shader storage buffer for compute operations
-
Rasterization Stage
- Viewport and scissor setup
- Depth testing and stencil operations
- Blending and color operations
-
Output Stage
- Framebuffer management
- Multiple render targets support
- Present with optional vsync
The window management system provides a platform-independent interface for window creation and management:
-
Window: Abstract window interface
- Window creation and destruction
- Event processing
- Context management
- Window state handling
-
Win32OpenGLWindow: Windows implementation
- Native Win32 API integration
- OpenGL context management
- Window procedure handling
- Message processing
- Platform-specific window implementations
- Event handling system
- Input management
- Resolution and display mode handling
- Window state management (minimize, maximize, close)
- Message processing and event dispatch
- Graphics context integration
The main game loop is managed by the Game class, which provides:
- Game state management
- Update and render cycle
- Event processing
- Graphics device management
Pyramid-Engine/
├── Engine/ # Core engine library
│ ├── Core/ # Core engine functionality
│ │ ├── include/Pyramid/Core/ # Public headers
│ │ │ ├── Game.hpp # Main game class
│ │ │ └── Prerequisites.hpp # Common definitions
│ │ └── source/ # Implementation files
│ │ └── Game.cpp # Game loop implementation
│ ├── Graphics/ # Graphics abstraction layer
│ │ ├── include/Pyramid/Graphics/ # Public headers
│ │ │ ├── GraphicsDevice.hpp # Graphics device interface
│ │ │ ├── Camera.hpp # Camera system
│ │ │ ├── Texture.hpp # Texture management
│ │ │ ├── Buffer/ # Buffer management
│ │ │ ├── Shader/ # Shader system
│ │ │ ├── Renderer/ # Rendering system
│ │ │ ├── Scene/ # Scene Management
│ │ │ │ ├── SceneManager.hpp # Scene lifecycle management
│ │ │ │ └── Octree.hpp # Spatial partitioning system
│ │ │ └── OpenGL/ # OpenGL implementation
│ │ └── source/ # Implementation files
│ │ ├── GraphicsDevice.cpp # Device factory
│ │ ├── Camera.cpp # Camera implementation
│ │ ├── Texture.cpp # Texture loading
│ │ ├── Scene/ # Scene management
│ │ ├── Renderer/ # Rendering pipeline
│ │ └── OpenGL/ # OpenGL backend
│ ├── Platform/ # Platform-specific code
│ │ ├── include/Pyramid/Platform/ # Public headers
│ │ │ ├── Window.hpp # Window interface
│ │ │ └── Windows/ # Windows-specific
│ │ └── source/ # Implementation files
│ │ └── Windows/ # Win32 implementation
│ ├── Math/ # SIMD-optimized math library
│ │ ├── include/Pyramid/Math/ # Public headers
│ │ │ ├── Math.hpp # Unified math header
│ │ │ ├── Vec2.hpp, Vec3.hpp, Vec4.hpp # Vector classes
│ │ │ ├── Mat3.hpp, Mat4.hpp # Matrix classes
│ │ │ ├── Quat.hpp # Quaternion class
│ │ │ ├── MathSIMD.hpp # SIMD operations
│ │ │ └── MathCommon.hpp # Common definitions
│ │ └── source/ # Implementation files
│ ├── Utils/ # Utilities and services
│ │ ├── include/Pyramid/Util/ # Public headers
│ │ │ ├── Log.hpp # Logging system
│ │ │ ├── Image.hpp # Image loading
│ │ │ ├── PNGLoader.hpp # PNG format support
│ │ │ ├── JPEGLoader.hpp # JPEG format support
│ │ │ └── ... # Other utilities
│ │ └── source/ # Implementation files
│ ├── Audio/ # Audio system (planned)
│ ├── Physics/ # Physics system (planned)
│ ├── Input/ # Input handling (planned)
│ ├── Renderer/ # Renderer module (legacy)
│ └── Scene/ # Scene module (legacy)
│ ├── Audio/ # Audio system
│ └── Physics/ # Physics system
├── Examples/ # Example projects
│ └── BasicGame/ # Basic game example
├── Tools/ # Development tools
│ └── AssetProcessor/ # Asset processing tools
├── Tests/ # Test projects
│ ├── Unit/ # Unit tests
│ └── Integration/ # Integration tests
├── vendor/ # Third-party dependencies
│ └── glad/ # OpenGL loader
└── docs/ # Documentation
- GLAD: OpenGL loader
- Windows API: Window management (Windows platform)
- CMake: Build system
- Visual Studio 2022: Development environment
The project uses CMake for build configuration:
- Minimum CMake version: 3.16.0
- Multi-configuration support
- Proper dependency management
- Installation rules
Currently supported platforms:
- Windows 10/11 (primary)
Planned platform support:
- Linux
- macOS
The graphics pipeline is designed to be API-agnostic:
-
Graphics Device Layer
- IGraphicsDevice interface
- API-specific implementations (OpenGL, DirectX)
- Resource management
- State management
-
Shader System
- Abstract shader interface
- GLSL support (OpenGL)
- HLSL support (planned for DirectX)
- Shader compilation and linking
- Uniform/constant buffer management
-
Buffer Management
- Vertex buffer abstraction
- Index buffer support (planned)
- Constant/uniform buffer support (planned)
- Dynamic buffer updates
-
Rendering
- Geometry management
- Material system (planned)
- Texture management (planned)
- Render state management (planned)
The Pyramid Engine features a comprehensive, SIMD-optimized math library that forms the foundation for all 3D operations:
- Vector Classes: Vec2, Vec3, Vec4 with full operator support
- Matrix Classes: Mat3, Mat4 for transformations and projections
- Quaternion: Quat for rotations and orientation
- Math Utilities: Constants, functions, and geometric operations
- SIMD Optimizations: Runtime CPU feature detection and optimization
- Runtime Detection: Automatic detection of CPU capabilities (SSE, SSE2, SSE3, SSE4.1, AVX, FMA)
- Fallback Paths: Scalar implementations for systems without SIMD support
- Batch Operations: SIMD-optimized processing of arrays of mathematical objects
- Memory Alignment: 16-byte aligned structures for optimal SIMD performance
- Comprehensive Operations: All standard 3D math operations with operator overloading
- Performance Optimizations: Fast inverse square root, trigonometric approximations
- Geometric Utilities: Ray-sphere intersection, frustum culling, spatial operations
- Transformation Utilities: TRS (Translate, Rotate, Scale) matrix creation
- Camera Utilities: Perspective and orthographic projection matrices
using namespace Pyramid::Math;
// Vector operations
Vec3 position(1.0f, 2.0f, 3.0f);
Vec3 direction = Vec3::Forward;
Vec3 newPosition = position + direction * 5.0f;
// Matrix transformations
Mat4 translation = Mat4::CreateTranslation(position);
Mat4 rotation = Mat4::CreateRotationY(Radians(45.0f));
Mat4 scale = Mat4::CreateScale(2.0f);
Mat4 transform = translation * rotation * scale;
// Camera matrices
Mat4 view = Mat4::CreateLookAt(Vec3(0, 0, 5), Vec3::Zero, Vec3::Up);
Mat4 projection = Mat4::CreatePerspective(Radians(60.0f), 16.0f/9.0f, 0.1f, 1000.0f);
Mat4 mvp = projection * view * transform;The enhanced logging system is designed for multi-threaded game engines:
- Mutex Protection: All logging operations are protected by a single mutex
- Deadlock Prevention: Local buffer usage prevents recursive locking
- Race Condition Elimination: Configuration access is properly synchronized
- Performance Optimization: Early exit checks minimize lock contention
- SIMD Acceleration: Automatic utilization of available CPU features
- Memory Layout: Structure of Arrays (SoA) for batch operations
- Cache Optimization: Cache-friendly data access patterns
- Branch Reduction: Minimized branching in critical paths
- Command Buffer Batching: Reduced API call overhead through batching
- State Management: Minimal state changes and efficient tracking
- Resource Management: Efficient buffer and texture management
- Visibility Culling: Frustum and occlusion culling for performance
- RAII Principles: Automatic resource management through smart pointers
- Memory Pools: Custom allocators for frequently allocated objects
- Alignment: Proper memory alignment for SIMD operations
- Leak Detection: Comprehensive memory leak detection and reporting
- Early Exit: Log level filtering occurs before expensive operations
- Local Buffers: Message formatting uses stack-allocated buffers
- Minimal Overhead: Release builds can disable debug/trace logging entirely
- File I/O Optimization: Buffered file writing with configurable flush intervals
- SIMD Utilization: Automatic detection and use of available CPU features
- Cache-Friendly Design: Data structures optimized for cache performance
Planned features and improvements:
- Complete math library
- Physics system
- Audio system
- Scene graph
- Asset management
- Input system
- Networking
- Scripting support
- Remote logging capabilities
- Log analysis and visualization tools