Had a bit of time after work today.
Entity spawn packet functional. Not all values are logged but I got enough to do full char gears and such. I'll leave 'full' structure till I finish things like view gears at which point it will actually make a difference.
[Only registered and activated users can see links. Click Here To Register...]
Before I add in spawning other objects to players I'm debating how I want to handle it. After taking a peek at korv's UG project the idea of doing a PROPER system for it does sound infinitely superior.
What is the opinion of those in the know on spawning surroundings to clients? Looking for something efficient but preferably easy to implement.
For those who don't know what I mean...
many/most public sources use something along the lines of..
foreach(KeyValuePair<uint, Clients> Target in Game.OnlinePlayers)
{
if(Client.Map == Target.Value.Map)
{
if(Calcs.Distance(Client.X, Target.Value.X, Client.Y, Client.Value.Y) < 16)
{
Client.Send(SpawnClient(Target.Value));
}
}
}
Or something similar...
Now this is all well and good from the standpoint of 'it works'.... but think for a second... you are doing two or more calculations PER sever object... every time ANYTHING changes.
This gets processor intensive very quickly. Say you have something like 10,000 monsters loaded into the server, 500 npcs and 100 players... plus every single dropped item on the map... every single time any of those players jump you are going to run something like 20,000 calculations simply to spawn what's on their screen (because you are running through 2-3 calculations for every single object in the entire server). For a higher end server, this is simply not acceptable.
The alternative (as I understand it from korvs basic explanation) is to divide the maps into sections. Each section containing information about what it contains (mobs, npcs, players, items, etc). You then assign the character to the 'section' it belongs to and simplly spawn objects that server contains
pseudo example...
foreach(object A in Client.MapSection)
Spawn(A);
On movement you would then calculate which direction you are moving/how close to the border of your section you are and will then switch to the new section you are in.
Again, that's a very poor explanation of his system and I've had almost no chance to look into it.... but what is the best way to handle EFFICIENT spawning of server objects to a client? I am really hoping to be able to refine this server as I go so that I don't need to come back and re-code huge sections of it after the fact (most likely breaking other things that rely on the original code). It's far easier to just do it right the first time.
<edit>
So I just was thinking... I'm probably not thinking things through here and it would take up alot of ram but would doing a per cell system work well?
Eg: you have your map loaded into the source and for each cell you have values
Accessibility, height, MobObjects, itemObjects, ClientObjects, NpcObjects
These structures are stored in basically rows/columns associated with their X/Y values.
Any time a server object moves/is created their cell is changed to that location and you could do something to load into the character it's surrounding based on a 16x16 or w/e grid surrounding them and then spawn these items to it (so you only have to do a for loop through the nearby tiles to check the cell values for entities/items)
All I can think of for this though is heavy ram usage (storing that much data in memory for every cell/map....)
Alternatively a binary file could be used/read for the maps to reduce ram usage while maintaining speed and ease of access...
Guuhhh so many options and I can't think what would be a good one.
Advice appreciated as always.