-
Notifications
You must be signed in to change notification settings - Fork 8
Spatial Grid
The spatial grid is a performance optimization tool used by the physics engine (defined in engine/physics.py).
It divides the 3D game world into a series of uniform mathematical buckets or "cells."
Instead of performing a "narrow-phase" collision check between every single object in the scene—which would be computationally expensive (O(N^2))—the engine uses the grid for a "broad-phase" check. It only calculates collisions for objects that occupy the same or adjacent grid cells.
-
Grid Size: The dimensions of each cell are generally defined in
engine/constants.py -
Dynamic Updates: As entities move, they are removed from their old cell and registered into a new one. Toggling sg allows you to verify that these updates are happening correctly and that objects aren't "leaking" out of the partitioning system.
-
Command Registration: In editor/console_commands.py, the command is mapped to the toggle_spatial_grid method, which interacts directly with the Physics class.