Theo - Insane Anti Lag (Version 1.1 added page check enhancer!)

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by TheoAllen, Dec 5, 2014.

  1. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Theo - Insane Anti Lag
    For those who insane enough to put a lot of events on map
    Version : 1.1​
     ​
    Introduction :
    As most of you already know, lag is common problem in RPG Maker games. You may think it was because you have many events on map. And so, to avoid lag, you split your map into part and limiting the event as well. 
     
    It's not entirely wrong because when you have a lot of events, program need to checks all events. However, it wasn't done efficienly. This script increase the efficiency on how default script works and prevent unecessary update when it's not needed to gain speed.

    However, I can not guarantee that it will have high compatibility since I overwrite most of stuff. I will likely to make compatibility with my own scripts. But I'm not sure about someone's script.
     
    Screenshot :
     
    [​IMG] 

    Features :

    • Optimize Event XY. Registered all events into table for faster collision detection using default 32 x 32 grid movement
    • Optimize Event Start. Registered any event that started to prevent check all event and see which is starting
    • Optimize Sprite. Prevent update character sprites located on far away
    • Insane - Table search. When you have insane number of events. It checked map table instead of iterating through all event. So, if you have 10.000 events you will have no worry about performance.
    • Insane - Sprite dispose. When the sprite is off screen, it disposed immediately to prevent performance loss.
    • Insane - Enhance page checking to prevent mini freeze when checking all event pages (*NEW)
    Testing :
    Tested using Core i3 @ 2.40 GHZ, 4GB of RAM, Windows 7 64-bit with no additional scripts, I got following results :

    • 150 x 150 map with 250 events. I got 60 FPS while no antilag I got 49 FPS at the minimum
    • 17 x 13 Full load of events. All events are on high frequency. I got 30 FPS while no antlag I got 10 FPS
    • 150 x 150 map with 10.000 events, all events are off screen. I got perfect 60 FPS while no antilag I got 1 FPS
    • 150 x 150 map with 10.000 events, and have around 190 events on screen, I got 55 FPS at the minimum. While no antilag, I got 0 FPS.
    Limitation :

    • So far this will only works with default grid based movement, not intended to be used together with any pixel movement.
    • Using insane mode antilag will only works if events on screen is around 250 despite of the total events on map.
    • Using larger screen resolution may affect the performance as well
    Download :
    Click here
     
    Final Note :
    After all, these are just my attempt to speed up the game. Performance are still under influence by many factors. These include but may not limited to

    • Your CPU speed
    • Your laptop / PC temperature
    • How much power do you give for your CPU
    • Multi tasking
    • Someone's scripts
    I once used RM in old computer. When I switched to more advanced laptop, I saw that 60 FPS is really smooth.

    If your CPU seems overheat, turn off your laptop / PC for a while for cooling. My laptop was once overheat due to broken fan. When I played my own game I got 10 FPS. I made my own antilag and no one of them worked until I realized my laptop was overheat.

    Power saver mode in laptop may affect performance. Try to go high performance instead and let see if the lag gone. Once my friend played my game using power saver mode, and he got 15 FPS.

    If you have many programs running at same time, it may cause a little lag in RPG Maker games. Something like the screen won't be updated for a while.

    Some scripts can affect performance if it's not done right. This antilag script is tested using default script without additional scripts which directly affect something on map.
     
    For scripter, feel free to modify my script to be better and better. You can edit and repost in your own version as long as you credit me, as TheoAllen or Theolized RGSS3.
     
    Special Thanks :

    • Tsukihime for performance analisyst
    • KilloZapit who helped me to brainstorm this concept
    • Galv
     
    Last edited by a moderator: Feb 20, 2015
    #1
    Guiguimu, Helladen, Quxios and 4 others like this.
  2. KeyToTruth12

    KeyToTruth12 Grammar Nazi Veteran

    Messages:
    124
    Likes Received:
    7
    Location:
    http://forums.pcsx2.net/User-KeyToTruth12
    First Language:
    English
    Let's try it~

    Edit: it works!
     
    Last edited by a moderator: Dec 5, 2014
    #2
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    #3
  4. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,312
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    I just tested this with a 800x470 res on a 25x15 map with 1 event and it was putting out 35 fps (just the same as before I put the script in) so unfortunately, this doesn't help with the inadequacies that the new dll (that steam FORCES us to now use) brings. :/

    Not that I really expected it to, just kinda hoped ^_^
     
    #4
  5. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    800 x 470 is not standar RM resolution. I already stated in the limitation
     
    #5
  6. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,312
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    lol yea I know, was worth trying though ^_^

    I really dont fancy having to rewrite tilemap into a more efficient dll, but atm, that seems like the thing that would improve performance the most imo. :)

    Anyway, cool script dude. I never thought of disposing events when outwith the screen, always just left them there not updating. :p
     
    #6
    TheoAllen likes this.
  7. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I also tried your antilag script, at the first glance it seems work with many events, but when the character sprites become too much, your script wont work. Hence the idea came up. I guessed that the total of the sprite itself affect the performance even they're not being updated   :)
     
    #7
  8. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,312
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    No doubt.

    There are also many other random things that can be done for extra performance. Like using a region based movement restriction script, cache-ing various bits of data to avoid the heavy calcs that get done for them (such as finding out if an event can walk on tile [x,y])

    Also, when you dont use Tilemap/tiles at all, it lifts the performance dramatically, so yea, tilemap certainly needs redone (well). Thats where the biggest performance boost would come from, for the larger resolutions :D
     
    #8
  9. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I also tried to caching the calculation of round_x_with_direction in Game_Map but it doesn't seems affect the performance so much. So I scrapped the idea. And the way I use @character.screen_x in Sprite_Character is one of the pre-caching trick

    Well, I don't have the knowledge over the tilemap so I dunno. I don't even know the structure of map data and the tilemap lol

    If anyone want to rewrite my script can add tilemap optimization, that would be great.
     
    #9
  10. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,312
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    Heres a base structure :)

    https://raw.githubusercontent.com/CaptainJet/RM-StarRuby/master/ruby/class/Tilemap.rb

    FYI - that base is just as efficient as the default setup - so it could very well be an exact replica for all we know ^_^

    Edit:

    Just had a good look thought that code and again - it seems to come back to the plane class.. I wonder if RM will ever be fully 'issue free' :p

    Obviously those extensive Tilemap calc during each update wont be helping things either :D
     
    Last edited by a moderator: Dec 6, 2014
    #10
    TheoAllen likes this.
  11. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I guess that's why they limit the resuliton to 640 x 480 at maximum since it's seems the maximum efficiency of the engine can handle. When the resolution is absurbly large, it would be problematic.
     
    #11
  12. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,061
    Location:
    Toronto
    First Language:
    English
    The plane is not necessary. It's only used to support looping.

    Code:
    The Plane class. Planes are special sprites that tile bitmap patterns across the entire screen and are used to display parallax backgrounds and so on.
    If you don't need looping, don't use a Plane.
     
    Last edited by a moderator: Dec 7, 2014
    #12
    ?????? likes this.
  13. ??????

    ?????? Diabolical Codemaster Veteran

    Messages:
    6,264
    Likes Received:
    2,312
    Location:
    Your OS
    First Language:
    Binary
    Primarily Uses:
    RMMV
    Yea, I personally have no need for the loop, but some folks would.  Suppose it would be easy enough to add some sorta check for that and then create a sprite/plane based on requirements :p
     
    #13
  14. MisterTorgue

    MisterTorgue Explosioooooooons! Veteran

    Messages:
    326
    Likes Received:
    54
    Location:
    Badass Crater of Badassitude
    First Language:
    Explosions!
    The anti lag seems to work pretty darn well with the KHAS lighting system!

    I had to try to minimize lighting events without making the maps dark at night time, however now it seems like there is no lag in the big cities when I have a lot of events running.

    thank you Theo :)
     
    #14
    TheoAllen likes this.
  15. SerpentRose

    SerpentRose Veteran Veteran

    Messages:
    46
    Likes Received:
    12
    Location:
    Texas
    First Language:
    English
    Very nice! I was having lag in a small city sector with just lighting events and this cleared that up. Compatible with my long, ever-growing list of scripts, too.
     
    #15
    TheoAllen likes this.
  16. MisterTorgue

    MisterTorgue Explosioooooooons! Veteran

    Messages:
    326
    Likes Received:
    54
    Location:
    Badass Crater of Badassitude
    First Language:
    Explosions!
    I can second that, I have a lot of scripts currently (trying to remove ones that I dont need) but all lag issues I was having have cleared up due to this it seems!
     
    #16
    TheoAllen likes this.
  17. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,082
    Likes Received:
    12,256
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    So far so good! My biggest map (150 x 150, about 400 events, no lighting scripts yet) ran 59 - 60 FPS (the oddball 59 FPS occurs on my laptop from time to time on empty maps even though).
     
    #17
    TheoAllen likes this.
  18. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Thank you guys for trying and reporting that this has good compatibility among various scripts.

    However, it's known that it has incompatibility with Falcao ABS as some people reported to me.

    Just let you to know.
     
    Last edited by a moderator: Dec 12, 2014
    #18
    MisterTorgue likes this.
  19. MisterTorgue

    MisterTorgue Explosioooooooons! Veteran

    Messages:
    326
    Likes Received:
    54
    Location:
    Badass Crater of Badassitude
    First Language:
    Explosions!
    Hi Theo,

    Just found an issue with this script.

    When its on it seems to let me actually walk through moving events (still ones it doesn't)

    Not sure why?
     
    #19
  20. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,376
    Likes Received:
    4,947
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    It's actually how default script works. I'm sure this is what you mean

    [​IMG]

    For example, when event move from (3,3) to (3,4), now (3,3) will be passable and (3,4) will not
    Actual event position is (3,4), but the graphics may late.
     
    #20

Share This Page