Sign in to follow this  

Tile Based Server App - Looping everytime you move

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Tile Based Server App - Looping everytime you move Lets 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
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.


That is perfect thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by luzarius
Quote:
Original post by hplus0603
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.


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?

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by hplus0603
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 :-)


Hmmm how about a binarytree? Am I on the right track?

Sorry for posting in the wrong forum! :)

Share this post


Link to post
Share on other sites

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this