Hey, currently my game is going great, but I have tons and tons of monsters that spawn and begin walking towards the user, using many checks for each movement. When I have these 100+ enemies spawning, is there any way to reduce the lag?
None of the monsters ever go out of site, it's just a small map and you have all these hundreds of monsters attacking you.
Thanks!
--Beatmewithastick
ID:160204
![]() Oct 25 2008, 1:15 pm
|
|
Reusing vars excessively on purpose is rather pointless.
The effect is very very minimal - if not actually counterproductive. And local vars are also highly temporary. Rather, yes, you should cut down on the actual resources instead of number of vars. |
I'll try and let you know what happens.
EDIT: I tried to fix it, but my AI system bases a lot on movement checks too. I'm still getting a lot of lag. Here's my previous AI code: mob Here's my updated AI code: mob not much to be changed, it my opinion. Here's my base movement code: mob So is there anything there that really significantly causes lag when you have hundreds of them rushing at you at once? :S Thanks. --Beatmewithastick |
Do you think it would significantly reduce the lag with hundreds of monsters?
I want to make sure it's easily possible. --Beatmewithastick EDIT: I'm working on a system where all ai run off a single infinite loop, instead of each monster having their own infinite loop. EDIT: Well, I did it, but it still lags like hell. :s var/mob/ai_handle/ai_handler |
Okay, I just reduced the code to basically nothing, just as a test and it still lags (CPU lag) like hell. :S
var/mob/ai_handle/ai_handler |
I just did a little test, I'm beginning to think it has something to do with step_to.
mob mob EDIT: okay, so I just confirmed it. Is there anything as simplistic as step_to that functions the same way that I can use in place of step_to? I still need the monsters to create paths. Without the lag. |
I may have missed something, but why do you have for() twice?
for() I'm sure you don't need this. |
Erm.. It's an infinite loop.
EDIT: Oh, well I could have done it with a single for(), but I just copied/paste my original code to demonstrate with had two for's because the second one was checking for(mob/m in world).Just ignore that. |
Beatmewithastick wrote:
EDIT: okay, so I just confirmed it. Is there anything as simplistic as step_to that functions the same way that I can use in place of step_to? This so called "AI" is nothing but a costly implementation of the already existing walk_to proc. Instead of calling step_to(src,m) every tick, simply call walk_to(src,m,1,1) once and your problem will be solved. |
There's a lot of problems with this though: It needs to keep checking to make sure the target exists, and if the target get's too close it needs to started step_towards in order to Bump() the target.
|
If you use 0 for the distance argument in a proc like walk_to(), it WILL try to get on the same tile as the destination mob and will bump into it (multiple times at that, unless you stop the walk() after the first one, etc).
|
What happens though if the target is lost?
I wish there was just a non-laggy step_to available. :s It gives a lot more freedom. |
A* For Beginners. A great article and uses tiles to explain it so the implementation is really straight-forward.
George Gough |
Beatmewithastick wrote:
What happens though if the target is lost? ... mob All do-able with walk-to. There indeed are more complicated situations where you will require more control, in this case I would recommend Deadron's pathlib, but you should first learn how to use the simple things. |
It should, in theory, use less RAM. Well, my example probably doesn't because I made that extra var, but you get the point. Also delete useless resources that aren't being used (empty lists).