Hello,
For fun, I'm building a Vampire Survivors style game. There will be a lot of mobs on screen, so I've built a grid partitioning system and each weapon only checks for collisions with mobs nearby.
The grid size is 30, so that's a 16 x 9 grid.
My question is this, currently, I'm initialising the grid on every frame and re-populating all the mob positions into their grids.
Should I move to initialising just once and updating mob positions in the grid on every frame? I'm not sure whether that will actually be quicker because I will have to delete the mob from one grid position and add it to another.
Also, that seems hard to implement :-)
Thanks in advance
Russ
use lua sparse tables for that:
- each cell has a table of entities, keyed by enemy
- each entity has a table of cell
something like:
function update_entity(e) local x,y=e.x//32,e.y//32 local cell = _grid[x+y*32] — the ‘1’ value is useless (except maybe for counting) cell.entities[e]=1 e.cells[cell]=1 end |
and don’t scratch the grid each frame, if an entity has moved grid, unregister it from current cell using the ‘cells’ table
[Please log in to post a comment]