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
1
2
ID:160204
Oct 25 2008, 1:15 pm
|
|
In response to Jeff8500
|
|
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. |
In response to Kaioken
|
|
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 |
In response to Beatmewithastick
|
|
There is definitely room for optimization and fixes to make.
|
In response to Kaioken
|
|
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 |
In response to Beatmewithastick
|
|
I'm having similar problems.
|
In response to Beatmewithastick
|
|
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 |
In response to Beatmewithastick
|
|
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. |
In response to Beatmewithastick
|
|
I may have missed something, but why do you have for() twice?
for() I'm sure you don't need this. |
In response to Kaiochao
|
|
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. |
In response to Beatmewithastick
|
|
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. |
In response to CIB
|
|
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.
|
In response to Beatmewithastick
|
|
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).
|
In response to Kaioken
|
|
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. |
In response to Beatmewithastick
|
|
step_towards() probably use less CPU. It's quite stupid in comparison to step_to(), though.
|
In response to Jeff8500
|
|
Exactly, I need the monsters to find their way around obstacles.
|
In response to Beatmewithastick
|
|
A* For Beginners. A great article and uses tiles to explain it so the implementation is really straight-forward.
George Gough |
In response to KodeNerd
|
|
... That's quite out of place here, though.
|
In response to Beatmewithastick
|
|
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. |
1
2
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).