50.000 NPC with 60FPS Raylib 3D C++ Flowfield Pathfinding
wishlist my two games: https://store.steampowered.com/app/4185770/cenkers_mod/ https://store.steampowered.com/app/4580790/Mine_Mage_Minion/ In this video, I’m pushing the limits of Raylib and C++ by simulating 50,000 active NPCs in a voxel-based world, maintaining a stable 60 FPS. This project showcases how efficient data structures and algorithms can handle massive entity counts even in a 3D environment. What makes this achievement even more significant is that this is running entirely on an integrated AMD APU (CPU with integrated graphics). No dedicated GPU was used for this benchmark, proving that high-performance code can deliver stunning results even on budget-friendly, integrated hardware. Technical Highlights: Architecture (ECS & SoA): The project utilizes a custom Entity Component System (ECS). Data is stored in a Structure of Arrays (SoA) format, which is highly cache-friendly, minimizing CPU cache misses during massive update loops. Flowfield Pathfinding: Instead of calculating individual A* paths for 50,000 agents (which would be impossible), I implemented a 32x32x32 local Flowfield Pathfinding system. The pathing cost is O(1) per agent, as they simply "read" the direction from a shared vector field updated around the player. Physics Tickrate (20 TPS): To ensure stability, the AI and Physics simulation run at a fixed 20 ticks per second (20Hz). This is decoupled from the rendering frame rate. Smooth State Interpolation: To maintain 60+ FPS visual smoothness despite the 20Hz physics, the engine uses linear interpolation (Lerp) for positions and spherical linear interpolation (Slerp) for rotations between physics frames. Swept AABB Collision: For accurate movement and to prevent clipping through voxel boundaries, a Swept AABB collision resolution is used, ensuring high precision even at high speeds. GPU Instancing: Rendering is handled via Hardware Instancing. Instead of 50,000 individual draw calls, the entire NPC army is sent to the GPU in a single batch, drastically reducing the overhead on the graphics pipeline. Object Pooling: All NPC entities are pre-allocated in a memory pool to avoid runtime allocations/deallocations (GC-like pauses), ensuring a stutter-free experience. Tools & Technologies: Language: C++ Graphics: Raylib Physics/Collision: Custom Swept AABB Optimization: Custom ECS & Flowfields Thanks for watching! If you're interested in game engine optimization and high-performance C++, don't forget to like and subscribe! #Raylib #Cpp #GameDev #Pathfinding #Flowfield #ECS #Simulation #Programming #Voxel #GameEngine
Download
0 formatsNo download links available.