Entities spwan/w.e sure take a look and see if you can help

06/29/2011 16:53 { Angelius }#1
hello everyone .

what is the best way to do the clients/monsters/npc's spawns

like when a player jumps what is the best way to spawn the in range entities .

i have tried to store the entities in some kind of dictionary (Local entities) and spawn them on jumping/walking ...> slow

i have stored every single valid X/Y in the game maps as a key with a Dictionary associated to that key as a value and stored the entities in that dictionary depending on the X/Y and spawned them on jumping/walking ...> slow

you know we ............ Improvise but fail sometimes :P

i have tried a foreach in the client map entities and yet ....> slow

tried to stick to the way TQ does it but it spawns the entities only on jumping... i guess i did it wrong or maybe there is a different way to do the spawns and i cant figure it out .

however when i say slow it means that when 35/40 player goes online and walk/jump all together at the same time maybe a guild war or something the cpu usage goes a little bit higher which can kill the processor when it comes to 300 or maybe 400 player ,

and the spawn amount is around 700 to 800 entities in each map .

walking is worse than jumping though as a walk packet is being sent for each step a player takes .

thats all i got soooo anything Inspiring/creative/smart something i never thought about or maybe something to make it a little bit better :P .

i mean anything ?
06/29/2011 23:03 -impulse-#2
Use QuadTrees for best performance. (Prove me wrong and I'll agree with you:P)
06/30/2011 05:44 pro4never#3
I'm no expert on the matter by any means impulse but I seem to remember reading that Quad won't experience any noticeable performance gain until there were insane numbers of objects being processed (tens-hundreds of thousands+). A conquer map generally deals with the low thousands at the most (say... 100 players a map max and 1000 mobs, few hundred items seems fair for many maps)

Personally we've been using a spawn system reversed engineered from the leaked tq sources.

For our map system we just have something known as ILocatable object which contains Map, X, Y and UID for objects (anything needing to be located). Maps contain a collection of all locatable objects on the map. We can then Insert (adds to collection, spawns to local), Remove (removes from collection, despawns to local), Search based on uid and Query functions which allow us to just set up a viewing rectangle and pull objects which are contained by it.

Whenever a movable object is moved we run a Callupdate method which pulls all objects from the map inside the viewing rectangle and we then eliminate these results using a UID key system for currently spawned objects.

Anything in the spawned lists (by uid) that is NOT in the new pulled list needs to be DESPAWNED
Anything in the new list that is NOT in the spawned lists (by uid) needs to be SPAWNED
Anything contained in both needs to be IGNORED

Very simple system and has proven decently efficient and quite foolproof (just remember that on move you need to spawn Self to others and Others to self for players) and it will work out just fine.


Quad is a lovely idea for the map system but I just feel it's kind of overkill for conquer application. The improved query speed isn't much of a benefit when you have such delayed insertion/removal/movement speeds.
06/30/2011 11:34 Korvacs#4
QuadTree's were designed with 2d applications in mind (the 3d version is an OctTree), the speed gain you get from querying is based upon the fact that you only query what and where you need to query instead of running through an entire list looking for something that matches.

To be honest if you created a multi-threaded Quadtree system with dedicated threads for insertion/removal and moving the speed gains would definitely exceed querying a list, and if im honest i've never noticed slow insertion or removal speeds, moving is abit complex as you have to go up the tree untill you can go back down in, but thats only because i never bothered writing a horizontal move system whereby the area your in knows who and where its neighbours are so you can just jump next door so to speak.
06/30/2011 12:42 Korvacs#5
Quote:
Originally Posted by Y u k i View Post
You know, one thread can do multiple work. Why using 3 Threads if 1 for the Quadtree is enough?
Because your talking about inserting and removing and moving 50 - 100k objects, and thats only if you dont include items. One thread running, assuming your sleeping it would struggle to do the work, if your not sleeping it and are triggering it using an event for example would still struggle to be honest.
06/30/2011 22:46 Korvacs#6
Quote:
Originally Posted by Y u k i View Post
So how about an asynchronus threadpool (non blocking) with max. of lets say 3 Threads. Will only launch as much as needed. I do not try to be a pain in the ass, but i was recently invited to a microsoft .net teaching event, they explained on how to do it the real way.
That would indeed be a very nice and elegant solution, although since its always active i would question the need for a threadpool over 3 dedicated threads, simply because of the amount of work that the threads will be required to do when the server is under load.

I just wrote a synchronised non-blocking threadpool which can be used wherever i require a threadpool for task completion, its very nice :D
07/01/2011 09:29 Korvacs#7
Quote:
Originally Posted by Y u k i View Post
Since .net 3.5 the threadpool is empty when it gets initialized, or created however you wanna call it. After threads complete their work they will stay in the pool for 60 seconds on the 61st second beeing IDLE they get removed. so there is no acctual wasting.

Since a Thread uses more than 1MB of RAM id keep the count low.
I assumed we were talking about writing our own custom threadpools, mine doesnt use .Net's threadpool class.