05-27-2023, 08:59 AM
One of the most expensive functions in RPG Maker is the Window#draw_text function. Even if a window is not visible, calling these draw commands would still consume resources.
One way to diagnose the problem is figure out which scene (or scenes) have the worse lag. Are you experiencing a slowdown on the map, in battle, or in a specific menu screen? Does this scene have a large window with a lot of things that get redrawn?
Other things to look for...
If you want to profile a specific block of code you can do...
...which should tell you how long it takes for a function to complete. Most functions should take fractions of a second. If it takes a half second or longer, you've probably found the culprit (or one of many culprits.)
A HUD is an easy example of a script which can lag if not done correctly. For instance, if the HUD constantly redraws HP and SP (even when those values haven't changed), it will lag. If Hero 1's HP changes, but the entire HUD gets redrawn from that single change, that can cause lag too. Clearing the rect of only the item that needs to be redrawn, and redrawing only that item, is more economical than redrawing everybody's everything because of 1 person's change.
Hope this helps. Best of luck to you.
One way to diagnose the problem is figure out which scene (or scenes) have the worse lag. Are you experiencing a slowdown on the map, in battle, or in a specific menu screen? Does this scene have a large window with a lot of things that get redrawn?
Other things to look for...
- Scripts with a bunch of complex math calculations.
- Scripts with a bunch of draw / draw_text functions.
- Scripts that redraw gradient bars constantly.
- Scripts which may be constantly re-sorting an array.
- Two or more scripts which may be contradicting each other's functions.
- Scripts which have recursion issues; do you randomly get Stack Level Too Deep?
If you want to profile a specific block of code you can do...
Code:
time = Time.now
# ...The function...
puts("Execution Time: #{Time.now - time}")
...which should tell you how long it takes for a function to complete. Most functions should take fractions of a second. If it takes a half second or longer, you've probably found the culprit (or one of many culprits.)
A HUD is an easy example of a script which can lag if not done correctly. For instance, if the HUD constantly redraws HP and SP (even when those values haven't changed), it will lag. If Hero 1's HP changes, but the entire HUD gets redrawn from that single change, that can cause lag too. Clearing the rect of only the item that needs to be redrawn, and redrawing only that item, is more economical than redrawing everybody's everything because of 1 person's change.
Hope this helps. Best of luck to you.