Kon Engine 🦀
A modular 2D game engine in Rust with a custom SparseSet-based ECS. Built from scratch to learn how game engines actually work.
⚠️ Heads up: This is an experimental/educational project. I'm building this to understand engine internals, not to compete with existing engines.
What's Inside
The project is split into workspace crates:
Currently Working:
kon_core- App lifecycle, plugins, eventskon_ecs- Custom ECSkon_macros- Proc macros for#[system]and#[component]
Still Cooking 🚧:
kon_math- Math stuff with Glam integration (WIP)kon_window- Winit-based window management (WIP)kon_input- Input handling (WIP)kon_renderer- WGPU renderer (WIP)kon_physics- 2D physics (Planned)kon_editor- Editor tools (Planned)
Features
- Plugin-based architecture
- Custom SparseSet ECS with O(1) component access
- Write systems as regular Rust functions
- Type-safe queries like
Query<(Pos, Vel)> - Event system for decoupled communication
- Window context management
- Keyboard/mouse input
- Hardware-accelerated 2D rendering
- Collision detection and physics
- Integrated editor
Performance Analysis
Below are flamegraphs from stress tests showing where the engine spends its time under heavy load.
ECS Stress Test (100k Entities)
This test runs 100,000 entities through multiple systems each frame. Most CPU time is spent in actual component logic rather than query overhead, which shows the zero-allocation iteration is working as intended.
Heavy Component Bottleneck Test
This test uses 10,000 entities with large components (100 floats each). The results are memory-bound rather than logic-bound, which means SparseSet is doing its job keeping data contiguous.
Quick Example
Here's how you write a simple simulation:
use *;
// Define your data
// Setup runs once
// Movement runs every frame
// Update runs every frame
// Wire everything together
How to Use
As a dependency:
Or in your Cargo.toml:
[]
= "0.1.4"
From source:
# Run examples
License
Dual-licensed under MIT or Apache 2.0, pick whichever works for you.
- MIT: LICENSE-MIT or http://opensource.org/licenses/MIT
- Apache 2.0: LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0