PDA

View Full Version : Tracking Players & Objects in a map



Gadget
10-06-2003, 09:12 PM
OK, hopefully someone can point me in the right direction here...

I am trying desperately to keep track of lots of players, monsters, and items on a map. All players need to be able to see other players etc.

Initially I used SQL to select all players within visible tile range, and then add the coresponding TPlayer object into the other players 'ICanSee' list. This is way too slow (SQL hits with each player move), can anyone suggest a fast tidy way of being able to track objects on a 1000 x 1000 tile map? And... 1 tile can have more than one object!

One idea I had was to use some kind of Node setup? Nodes are fast and I could have multiple nodes on a tile? Maybe an array ot TNode (is there such a thing?) And if I used nodes, is there a quick way I could 'select' all nodes within a specific range? other than using loops and arrays?

There must be a 'standard' way to approach this?

Any help much appreciated!

Zanthos
11-06-2003, 06:53 PM
Instead of scanning your entire 1000x1000 map, a much quicker way is to split the map up into subdivisions of say 100x100, this can be changed to suit your needs, a logical value would be that which covers at least the screen area. Therefore, the worst case scenario can only be as much as 4 subdivisions visible at once(assuming you don't zoom in and out :) ). Thus now, instead of just keeping map coordinates of objects, you would also need to store the subdivision coordinates of the objects. Another approach would be for each subdivision to have a linked list, (TList or some other incarnation), of all the objects present in that area. The extra bit of work this also involves would be in ensuring that objects are registered to the correct subdivisions when they're moving around, which shouldn't be too difficult :)