Events and Lag

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
In the past I've created several maps which had a few dozen parallel process events running a lot of different functions, and it's created moderate amounts of lag.  No surprise there.

But yesterday I made a mostly empty map with about 200 Action Button/Event Touch events (6 pages each) grouped up in the same area (in order to create a randomized chessboard-style minigame), a couple of very light Parallel Processes, and nothing else... and it created significant amounts of lag (dropping the FPS on my middle-of-the-line desktop to about 20-40).  When I only had about 30 of these events insead of 200, it was running smoothly at 59 FPS.  I was really, really surprised at this, because (if I understand the processing correctly, at least) it doesn't need to actually process the event code for these events and yet the performance seems to be taking a hit.

So I'd like to ask if anyone who knows Ace really well can help me understand what about events requires a lot processing and what doesn't?

Do events themselves take up a lot of processing power?  Does it matter whether they have a graphic or not?  Does it matter whether they need to be animated?  Does the number of pages matter, assuming none of the pages are Parallel Processes?  Does any of the event code get evaluated (but not executed) if the event is never triggered?  Is there any reason why it might be better to have a Parallel Process event and 200 "dummy" Action Button events rather than 200 Event Touch events with the same code?  Is there anything else that might be helpful to know about economizing performance with Events?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
The number of events does matter, regardless of whether they are parallel process, player touch, or action button. I had a map with about 300 events (most of them doors to nowhere), and some people said they got 8 FPS. The reason is (at least as I understand it) RPGMaker checks all events to see if it needs to run them every frame, regardless of where they are on the map. A good anti-lag script can fix (some) of this by setting it up so that it only checks events distance x from the player.
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
Yeah, I had this problem with a map that had about 20 events, and a scrolling parralax. I reduced this to about 15, and it was back to proper FPS. I think there's a tip-off point somewhere that makes it hard for the engine to manage - and a scrolling parralax was probably the equivelant of about 100 more events.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
A good anti-lag script can fix (some) of this by setting it up so that it only checks events distance x from the player.
I guess this brings up one more question I should add on - do anti-lag scripts disable the events' natural movement as well if they're far from the player, or do they only disable the checks to see the Action Button/Player Touch/Event Touch events need to be processed?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
I guess this brings up one more question I should add on - do anti-lag scripts disable the events' natural movement as well if they're far from the player, or do they only disable the checks to see the Action Button/Player Touch/Event Touch events need to be processed?
RPG Maker doesn't move events that are not near the player, unless they have a forced move route. Anti lag scripts have the same behavior.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Whether there are commands or not, the engine still needs to check them on every frame to know whether there are commands or not. If a variable or a switch changes (or something else that affects the conditions on an event page), every one of them needs to be checked to see if a new page needs to be made active.


If you have events that move around (including the player), at every step, it looks at the map to see if there's an event it's going to collide with - this involves checking EVERY event on the map to see its location.


Faced with the same dilemma, I would consider writing a script that uses multiple sprites instead of events OR making better use of the events to minimize the number required. Can't really offer more suggestions without knowing more details about the mini game.


Also, even though you may not have many parallel process events, they could still be contributing to the lag - fixing them up might give you some improvement. First things first - do you have any Wait statements in there that will get run every iteration? If you don't, ask whether all that code NEEDS to run 60 times a second - if it doesn't, add a Wait at the very top of the event, prior to any conditional branches. See if you can reduce the number of parallel process events by combining them, or by modifying other events to run the code only when it's needed instead of continually.
 
Last edited by a moderator:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
Thanks to everyone who's given me some information - I really appreciate it! :)

If an event page has not been activated, then the number/complexity of event commands inside that event page should have no effect on performance, right?

Shaz, the event setup is extremely long, so I think it would be better to just show it to you in action and ask whether you think there might be a better approach besides using ~200 events.




Each crate has six event pages.  The first page processes the "event touch" when you move/jump onto that crate, dumping you into the water if you got there from a crate of the same color and otherwise transferring via self-switch to the second crate, which allows you to trigger the "action button" to jump in the direction that you're facing.  The third and fourth event pages do the exact same thing but for a different-colored crate; same with the fifth and sixth pages for the final color of crate.  These pages have a simple custom page condition using Hime's script (disabling his script reduced the lag a little, but not by a lot) and each crate's color is randomized at the start of the minigame before the crates appear.

I did a test and changed all Parallel Process events to Action Button events to ensure that this wasn't the cause of the lag; the average frame rate remained the same.

The idea to handle it with sprites instead of events is intriguing but I feel like it would take inoridinate amounts of time to set up and handle.  Maybe I'm wrong about that, though; I'm definitely less used to manipulating sprites than events.

Any other approaches you can think of for this type of thing?
 

felsenstern

Veteran
Veteran
Joined
Jan 23, 2015
Messages
709
Reaction score
262
First Language
German
Primarily Uses
RMVXA
If the map is always the same, then create the whole area in one sprite. You can handle this big sprite in a single event. To control the player action you just need another event. To make a crate disappear just put another event on top of it with the water graphics.

Events don't have to be fixed on a map, you can move them around and recycle them to lower the lag.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
I appreciate the suggestion, Felsenstern!  Unfortunately for me (though fortunately for my players, I suppose), I randomize every crate every time (though I do ensure there's always a winnable route).  The game is meant to be replayable.

I was considering generating ~200 sprites based on the random selections and then using a Parallel Process to check which tile the player has jumped to and doing the check there (instead of using Event Touch).  I guess your suggestion of using a few events that shift around based on the player's position instead of using a PP is quite clever.  But I feel like it would be a nightmare to control the crate sprites' "movement" (rocking), especially if the player completes the event and walks forward (the camera becomes unlocked at that point so the crate sprites would need to move down the screen at the same rate as the player is moving up, correct?).
 

felsenstern

Veteran
Veteran
Joined
Jan 23, 2015
Messages
709
Reaction score
262
First Language
German
Primarily Uses
RMVXA
Hmm... thinking this over, forget what I said. Why don't you take your crate animations to A1. Just design several rooms with different setups. You can use the region editor to mark the different crates... you would need someone to write a script for you to make the checks and then you would just need a very simple event to call the script and move your character... I think that would be the easiest and lag-friendliest version.

Why would you want to move the events/sprites on your own, whats wrong with leaving them and scrolling them out of the screen together with the background?

edit: not sure how this is solved but you also would have to change the animation cycle for the background from 1-2-3-r to 1-2-3-2-r

edit2: here is a thread about common events triggered by Region and Terrain Tag. I am still searching if it is possible to change the background animation cycle. http://forums.rpgmakerweb.com/index.php?/topic/11446-event-triggered-by-region/
 
Last edited by a moderator:

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,268
Reaction score
1,422
First Language
English
Primarily Uses
RMXP
Can you provide a demo for us to look into?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,574
Latest member
nikisknight
Top