   Trying to think of an efficient way for loading surrounding objects
  Hey all, just wanna say I love the site and have read through a bunch of posts and articles in the past. I should start by saying I'm not a super experienced programmer but I do know at least the basics of what I'm doing. Most of my programming experience has been related to coding private servers for Conquer online (using public C# sources). I've decided to start up my old server project again but am writing a server source from scratch (still in C#, it's the only language I'm very comfortable with) and am trying to think of efficiency before I start just plugging away at features (figure it's best to do things right the first time!) So, what I'm trying to think of is an efficient way to store and load objects in the server to players as they move around. Conquer uses a X/Y based 'tile' system and I have no problem reading the map files for accessibility/height information. For spawning surroundings though I need to think of a good way to pull server objects from within the nearby coords of my current position and then send spawn packets for each of them to the client.Players, Monsters, Npcs and items are what needs to be sent. Most public sources use the incredibly unefficient method of doing a foreach loop through the ENTIRE server dictionary of loaded monsters/players, checks if they are the same map and then runs a distance check vs current player location and if they are within range, sends the spawn packets.This is obviously a HUGE waste of processing power because you can easily run into tens of thousands of calculations PER movement.. this is obviously quite unacceptable for the server to be running every single time the player walks, jumps, changes map or a monster walks on screen. I have a few ideas of how it could be done but am sure there must be more efficient ways possible (I have never used or even dug at all into quadtree... it seems overkill from what little I've read though)What I was thinking of a possibility was to create a structure to hold 'tile data'. This would contain all objects on that current coordinates and could be held in some sort of data structure (not sure what would work best... a 2d array, dictionary? Regardless I was hoping if it's stored in a proper array I could then simply select the coords when moving and do a simple for loop to run through the objects on tiles +- 16 or so from the new location and if not visible to client already, spawn them. The thought I had though was memory usage if I'm doing this for every single coord for every single map in the server.. The option of using a binary file to store map data did occur. simply edit the .dat file as things are added/removed from locations... seems a rather complex way to do things though... was hoping for some better suggestions. My mind tends to go towards simple solutions that I'm used to already using (which is not a good thing as most of my experience has been with HORRIBLY written sources) Sorry for the long winded post, hopefully I covered what I'm trying to do properly though and you guys have some suggestions.Note: Trying to minimize ram and bandwidth use here mostly. As long as i'm not running into THOUSANDS of calculations per move I'm not picky.. I'd rather not be using tons of ram or something stupid on a server just to store map values when it could be better used for hosting more players in the long run. Bandwidth won't be much of an issue cause I can simply do a spawned bool to see if I've already sent the spawned packet already   
  Hi There,Organising your objects in a quad tree might be what you are after, it's hardly overkill, and covers exactly what you wanthttp://www.gamedev.net/reference/programming/features/quadtrees/The tree does not need to be dynamically sizing, but you're likely to get the best value out of it that way.[Edited by - chidj on September 6, 2010 1:48:58 AM]