I've got a 2D map, on which entities interact.
Should an entity's position be kept on the map object, or on the entity object itself, or both? Why? What does decide where a property is kept? What questions am I supposed to ask myself when deciding that?
Some use cases are:
- checking what entities are on a given tile (performant if the entities are kept inside, say, an array on the map object, unperformant if the position is kept on the entity)
- checking where a given entity is (easy if the position is on the entity instead - the above reversed)
My current thoughts are:
- the position 'logically' should be kept on the map, because a position is something that just exists within an entity. An entity needs to live in some kind of a spatial space to have a position, and map is such a space.
- there should be multiple data structures to ease various operations. For example, if entities are kept inside a 2D array, finding where a given entity is would be a linear operation (all cells must be iterated), and, say, a hashmap would bring it down to const time.