Thread: [Level Pack] SRB2-The Emerald Isles v. 3.0.7
View Single Post
Old 06-11-2015   #17
Kuja
 
Kuja's Avatar
Default

Quote:
Originally Posted by MascaraSnake View Post
So I figured out what's causing the debilitating lag, at least for me. It's not the maps per se - it's the Lua scripts. Without any Lua scripts, both acts of FGZ run at full speed for me, whereas with them, they drop down to 7 FPS for minutes at a time. SRB2's Lua interface is quite inefficient in some respects, especially when it comes to the MobjThinker hook: What the MobjThinker hook does is replace the thinker for a specific object type. So every time an object runs its thinker, it has to check if there's any Lua script loaded that changes the thinker. Doing that is pretty time-consuming for boring technical reasons I don't want to go over (and don't understand 100% anyway). FGZ2 has over 7000 objects, so that's a LOT of checks that run every single tic.

On top of that, your "super for all characters" script is very inefficient itself: You use a MobjThinker hook with MT_PLAYER, so that hook already runs once for each player. But inside the hook, you iterate over all players again. So if there are 5 players in the map, for example, your script applies the same code 5 times to each player. The hook already iterates over all players for you, so inside the hook you only need to apply the effect to the player that the hook gives you. Even better, use a ThinkFrame hook instead and then iterate over all players inside of that, to avoid the performance issues with the MobjThinker hook.

Strangely, even when I optimized your script (which means there were no longer any MobjThinker hooks in use), there was still considerable lag. It only dropped as low as 20 FPS in situations where it would previously be 7 FPS, but that's still pretty annoying. You should consider removing those two Lua scripts. The features they add aren't particularly relevant, and I don't think they're worth making FGZ unplayable for.
Lua is such a mysterious animal. This is probably why I shouldn't try things. Thank you for taking the time to diagnose that for me.

I'll update it and take out the scripts. I'm still testing the acts and updating it with the other suggestions in this thread, so it'll probably be another day or two before I'm ready to release the next iteration.
Kuja is offline   Reply With Quote