I think I've made an optimization of my own to pixelmovement. a big cause of the lag was can_bump() having to check 8 atoms (or more) at a time, 40 times per second.
Last time I checked, most of the CPU time was spent in set_flags(). can_bump gets called a lot, but the processing to compute a result is usually trivial. Here's the default can_bump proc:
if(isturf(a)) |
You'd have to call that thousands of times before the CPU time adds up to anything significant. Inlining this behavior in pixel_move would help, but because this isn't the bottleneck you're never going to see a huge performance gain from this.
As for can bump, you can exclude any atoms you're moving away from, so if you have a positive vel_y then you don't check the atoms to the south, southeast, or southwest. This cuts checking 9 turfs and their contents to checking 6 instead.
That's a reasonable change, but if the call to can_bump is very fast you might take more CPU time determining that you don't need to call can_bump. It's hard to beat "if(isturf(a)) return 1" :-)
Assuming it's still the case that most of the CPU time is spent in set_flags (for idle mobs at least, moving mobs may spend more time in pixel_move, but that's unavoidable), you'll see a bigger benefit by optimizing how/when it's called (which is one of the tips in How to Optimize a Pixel Movement Enabled Game). If you're not reading the mob's on_left, on_right, etc. vars anywhere, you might not need to call set_flags at all (for projectiles it's often not necessary).
I've added a line to check velocities, if a atom has zero velocity, don't bother checking if it moves.
This is already done in pixel_move(). The first line inside the loop is:
if(dpx == 0 && dpy == 0 && dpz == 0) break |
However, the call to pixel_move is only part of the movement loop. Things like gravity(), move(), action(), and set_flags() are still being called if the mob isn't moving (which is often necessary, because the environment can change in such a way that those calls are necessary).
I've added a line to check velocities, if a atom has zero velocity, don't bother checking if it moves. This cut the static CPU rate to 0. Before, the cpu would spike from 7-14 for each player on the server, now it only counts if they're moving. As for can bump, you can exclude any atoms you're moving away from, so if you have a positive vel_y then you don't check the atoms to the south, southeast, or southwest. This cuts checking 9 turfs and their contents to checking 6 instead. I don't have results for this yet but I thought I'd say something about t in the meantime.
As for any replies to things I've said in the last post: I'm not very good in explaining some ideas that I have but if I had the time to visually explain it you'd see what I mean. I'm terrible with the written word. (or typed in this case)
Edit: can_bump() calls 15-30 times per tick even though it's only checking 9 turfs, it seems to contribute to the issue.