World grid and ES - How to handle?

I am migrating the code of a game to an entity system and have a general question. How would the ES and a world grid based movement stick together?

In my legacy code, I used an Object[][] array in a LevelMap class. Every character used to know its position/index on the level map. If I hit the RIGHT key, my movement code checked if there were any blockers on the map at index x+1,y and moved to that. This array turned out as very unflexible due to the limited capacity. An other problem where the position during movement from x to x+1. I had to lock both fields while the movement was not complete.

Now I reimplemented this using an ES. In the new code, there are no character classes, there is no map, there are just entities and components. This is hard for the movement code. When I hit the RIGHT key, the system has to check all entities with a CollisionGroupComponent if their position is right to the position of the moving character. This is a potential bottleneck because there may be hundreds or thousands of entities with a collision group.

How would you handle that? Should I still use a system that holds a map and how often should it be synchronized with real locations? Is there another approach that I miss?

It’s about organising your data. You need some sort of index onto the objects from the co-ordinates so that you can quickly check them.

In Mythruna, my Position component also contains a sort of “zone ID” that is calculated from the coordinates. That way I can filter on zone ID.

@pspeed said: In Mythruna, my Position component also contains a sort of "zone ID" that is calculated from the coordinates. That way I can filter on zone ID.

Zones are fine, but will run into the same issue. (At the borders, objects of zone A and B may collide or need to interact some way)

Nethertheless I think I have to implement such filter queries, for now I am using the base version ( Map<Entity,Map> ).

@3H said: Zones are fine, but will run into the same issue. (At the borders, objects of zone A and B may collide or need to interact some way)

Nethertheless I think I have to implement such filter queries, for now I am using the base version ( Map<Entity,Map> ).

Yes, when doing collisions you have to look at the current zone and the 8 neighboring zones. This is still less than comparing everything to the whole universe.

…many times these zones are cached anyway.