how can i stop lag in my games?
There are lots of npcs so lag is killing
ID:259582
![]() Nov 11 2002, 5:47 pm
|
|
![]() Nov 11 2002, 5:48 pm
|
|
Get a faster modem, or get rid of some NPCs.
|
DBZ Kidd wrote:
Well then your out of luck. Nonsense. MC, is this MysticalCrystal we are talking about? |
Try not calling the NPC procs as often. Even better, only start the AI loop when someone enters the Z level. Each Z level should have a large area, and it's Entered() proc will trigger all NPCs to start their AI loops, and the Exited() turns them off.
|
Actually, you'd need to have a counter that was incremented every time somebody entered and decremented every time somebody exited, and only disable the AI if the counter reaches zero.
Also make sure you don't have all the AI procs executing all at once. For example: <code>mob/enemy New() ..() spawn() AI() proc/AI() //do AI stuff here spawn(30) .()</code> That's fine if there's just one or two of /mob/enemy in the game at a time. However, if you have 100 of them and they are all created at the same time, every 3 seconds 100 AI procs will be run! It's much better to spread them out a bit, like this: <code>mob/enemy New() ..() spawn(rand(0,30)) AI() proc/AI() //do AI stuff here spawn(30) .()</code> This way, 100 mobs will still slow the game down, but at least the calculations are spread out instead of occurring all at the same time. |
MC Staff wrote:
how can i stop lag in my games? It's probably not network lag. It's probably just your computer slowing down due to all the work. Does your AI code look something like this? <code> mob AI New(loc) spawn() AILoop() return ..(loc) proc AILoop() //AI stuff here spawn(10) AILoop() </code> This makes it so every AI mob will take up processor power even if players are miles away. Here's how I generally handle AI. mob Move(NewLoc,Dir) var/mob/M for(M as mob in view()) M.Disturb(src) return ..(NewLoc,Dir) proc Disturb(Who) AI Disturb(mob/Who) //Do your AI stuff here like //chasing player, talking, or whatever With this method you could have millions of mobs and they won't slow your game down. The AI that should take up CPU usage will instead of every single A mob. |