   Tile Based Server App - Looping everytime you move
Tile Based Server App - Looping everytime you moveLets say I'm moving from tile 14,13 to 14,14.I loop 200 times to check for players around my area.  Each loop represents checking one tile for another player. So looping 200 times means checking 200 tiles around my position.Is it a bad idea to loop everytime I move just so I can detect other players?I tried to search for other topics about this but I could not find any so please forgive me if this has been asked to death.I just did the math... It seems like a really bad idea to loop. What if I want to see 200 tiles all around me. That is like 200x200 .. Each move would result in 40,000 checks.Good lord I guess this means zoning or something right?Luzarius   
  You wouldn't need to resend/redo all the info. You would only need to do a dirty rectangle like update of what has changed.   ;  This sounds like game design rather than network design.Anyway, you will typically put all entities in some kind of hierarchical data structure, where you can ask it "what entities intersect a circle with radius R centered at X,Y" and get back a list in quick order.For your case, I'd suggest a quadtree (you can google for that).Note that objects typically will be linked into more than one list; there'll be a list for "objects within this tile", "objects within this quadtree node", etc. Keeping all the links up to date is an important function of a game framework, platform or library.;Quote:Original post by hplus0603This sounds like game design rather than network design.Anyway, you will typically put all entities in some kind of hierarchical data structure, where you can ask it "what entities intersect a circle with radius R centered at X,Y" and get back a list in quick order.For your case, I'd suggest a quadtree (you can google for that).Note that objects typically will be linked into more than one list; there'll be a list for "objects within this tile", "objects within this quadtree node", etc. Keeping all the links up to date is an important function of a game framework, platform or library.That is perfect thanks.   ;Quote:Original post by luzariusQuote:Original post by hplus0603This sounds like game design rather than network design.Anyway, you will typically put all entities in some kind of hierarchical data structure, where you can ask it "what entities intersect a circle with radius R centered at X,Y" and get back a list in quick order.For your case, I'd suggest a quadtree (you can google for that).Note that objects typically will be linked into more than one list; there'll be a list for "objects within this tile", "objects within this quadtree node", etc. Keeping all the links up to date is an important function of a game framework, platform or library.That is perfect thanks.The list you refer to. Is it ok to create an array of hashtables? One hashtable representing each zone of a game world?;  The problem with vector is that it re-allocates its members when re-sizing.Thus, if you know the number of elements up front, you can first create the array using std::vector::resize(), and then add items to them, and it will be efficient. If you call resize() or push_back() on the vector after you've started adding items to the hash tables in the vector, then that'll be inefficient (but still "legal").And I'm moving this thread into Game Programming now, as it still doesn't actually have any networking content :-)   ;Quote:Original post by hplus0603The problem with vector is that it re-allocates its members when re-sizing.Thus, if you know the number of elements up front, you can first create the array using std::vector::resize(), and then add items to them, and it will be efficient. If you call resize() or push_back() on the vector after you've started adding items to the hash tables in the vector, then that'll be inefficient (but still "legal").And I'm moving this thread into Game Programming now, as it still doesn't actually have any networking content :-)Hmmm how about a binarytree?  Am I on the right track?Sorry for posting in the wrong forum! :)   ;  If you want a container that doesn't re-allocate its items, and you need to dynamically resize it, typically std::list<> and std::map<> are good choices.   