Increasing processing speed

Im working on a strategy game in a similar style to crusader kings.

Yes it works thanks to common events.

But now whenever the day is updated or a battle takes place there is a minor drop in fps.

I've made sure to avoid parallel processes. In fact out of all my common events only the battle system has a parallel process that is turned on at the start of a battle and turns off once the calulations are complete.

The other events are run only when needed and handle things like income, how the ai spends its money and the ai strategic planning.

would having all these things done inside a plugin rather than common events improve performance?

Edit: I've also staggered the updates so that they don't happen all at once.
I haven't played Crusader Kings so I'm not exactly sure what your system is doing or exactly how it is implemented, but I'll take a shot at some possible assumptions:

The day being updated, as in if you use tints to adjust between day and night, will lower fps on systems with terrible CPU and GPU. I am sure a few other commands, especially graphical ones, can do the same on low end systems. There really isn't much you can do there besides either 1) don't use those commands, 2) make your minimum specs higher than low end systems, or 3) get your hands dirty with the PIXI engine and try to implement a solution that is more streamlined for older systems. The last one is usually not an option for most people nor usually worth it for most people who even have that option.

Battles can also drop to lower fps at the start on some low end systems to. I'm not too sure why, I never really looked into it, but it is something I noticed. I don't know off my head, but could you use autorun for an event in battle that happens at the start and then shuts off afterward? That should give you a slight boost over parallel process.

Generally doing things by plugin won't make much a difference, but again that also depends on how things were done via the editor vs done via a plugin and without knowing the system itself exactly nor how you went about making it doesn't really tell us anything. Things done by a plugin can also make things a lot better but also a lot worse.

You should also look into your system specs. That could be a huge factor right there. Test this out on different machines from high end to middle to low end if possible and see how the results vary. What size are the graphics you are using? A lot of big custom graphics could cause some performance issues. What about plugins you are using? Some could be horribly written, though if you disable plugins and test you can generally test this out. You also should mention how huge the fps drop is. If you went from 60 to 50 fps and it is a low end system, you are probably better off not worrying about it than if it dropped to 10 fps where then yes, tweaks should certainly be made.

People can only give generic answers unless they understand exactly what you have.

I've moved this thread to MV Support. Thank you.

Not sure why this was moved to support as I'm not having any issue with RPGMV but rather am looking for tips on how to better optimize my game in order to increase the processing speed of events.

@ChampX
I appreciate your reply but perhaps you should have looked up what crusader kings is or asked me to clarify first as that would have saved both of us time.

Crusader Kings is a strategy game played on the map of Europe where the player will control a single nation. Battles are fought by moving your armies to other provinces and the game will crunch numbers behind the scenes based on the composition of the armies before finding the winner.

Through the use of common events I've managed to create this system successfully in MV. Whenever my time system updates to a new day several common events will run setting goals for the ai, updating income and expenses and Ect.

When these updates occur there is a noticeable slowdown for about 5-10 seconds.

When two armies meet on the map a parallel common event is run that calculates the winner based on the values of the armies and any applicable modifiers before announcing the winner and turning itself off. Because I don't want the battle to start and end almost instantly I've had to set it as a looping parallel process that will run these calculations until one army reaches 0 troops.

I'd say FPS drops to somewhere between 10-30 during battles

Hope that clarifies things.

The graphics are very minimal. No tile sets are used and Any events use 48x48 sprites.

@ChampX
So you say having this stuff done in a plugin rather than common events won't help?

Ideally I'd like to be able to play my game on my phone and hate dealing with low fps.

Perhaps I'll have to save this question for after I've released a demo
Not sure if you'll be able to find a "solution" to the lag problem, BUT, you can do things so that the player doesn't notice them as much. For example, at the beginning of all those events popping up, you can add a fake "Now Loading" picture that covers up the whole screen, and then have it erased at the end of it. If done right, the player won't know the wiser. Probably not the solution you were looking for, but in the meantime, it could at least help make it less noticeable to the player.
Not sure if you'll be able to find a "solution" to the lag problem, BUT, you can do things so that the player doesn't notice them as much. For example, at the beginning of all those events popping up, you can add a fake "Now Loading" picture that covers up the whole screen.

While that doesn't solve the problem during battles, that is actually a good idea for how to update the data for the next in-game day. Thanks!
Not sure why this was moved to support as I'm not having any issue with RPGMV but rather am looking for tips on how to better optimize my game in order to increase the processing speed of events

"how to" was why it was moved to support. Game Mechanics Design is for discussion of the design of in-game mechanics (systems that the player puts to use), which processing speed is not. If Support is not the correct area, then it would be JS/Plugin support or requests.

Also, the issue happens at certain points in your game, when certain common events are run. This also points to MV Support as being the correct area. It would be good for you to post some of these events so we can take a look at exactly what's running at those times.
I'm not sure how to post code into the forums so I'll just write it out here. It will be easier for me to explain as the way I name my variables can seem like nonsense.

Note: I have two different types of units, lets call one "troops" and the other "cavalry".

Before this common event is called:
Using a seperate common event, information such as who is fighting, where the battle is happening and the technology level of the combatants is dropped into variables that will hold this information for the duration of the battle. Once that information has been collected a switch is turned on that will activate this parallel battle system.

Parallel Battle System:
If Battle = ON:
Label: start
Wait: 120 frames. "So that battle will not be instant"
RanVar = Random 1..2
If RanVar = 1
Choice = Random 1..5 "Used to determine whether to hurt cavalry or troops"
Cavalry = DefCav
DefDmg = Random 2..10
Cavalry *= DefDmg
DefDmg *= FortLvl
DefDmg *= DefTechLvl
DefDmg += Cavalry

If(Choice < 5)
EnemyTroop -= DefDmg
Else
"Check if theres any cavalry and subtract from them"

"An if command is now made to check if the enemy troops are under or = 0 and if so jump to the label at the end to turn off the switch and activate the common event that cleans up after battles"

If RanVar = 2
"Same calculations done as before only this time for the attacker"

Jump to Label: start
Label: end
Common Event: Victory
Control Switch: Battle = OFF

Looking at it, it doesn't seem like much but when a battle is activated there is some minor chugging done as it loops over.
If you mean event commands, a screenshot, or a group of screenshots, is really the very best way. Don't crop it to just the commands - make sure the entire event window is in there, as the stuff outside the command list is just as important, and is often where the error is.

There's a lot of stuff that your list of commands doesn't show, and I'm really interested in something elsewhere in the window. Could you please post up a screenshot, or as many as are needed to show the entire event?

If that's a common event, I'd like to know what the trigger is, and if there's no trigger, I'd like to see a screenshot of the event that calls it.
It's a parallel common event that is triggered when a switch is flipped on.

Not sure how screenshots will help as my naming system wont make much sense

Spoiler: Common event that turns on the battle switch


Spoiler: Battle




All other common events you see there are only activated when required. Often they will be activated in order. For example Purchase Prep will be activated first which once finished will activate Purchase and once that events finished it will activate Purchase Unprep.
There certainly doesn't seem to be anything very processor-intensive in all of that.

Do you have any other events - on map, or common events, that might be getting triggered by that switch or by the variables? Does it happen on ALL maps? If you create a new map and only add the bare minimum events to trigger the battle does it happen there?

You mentioned the day being updated has a similar effect but you haven't gone into a lot of detail. Is it EXACTLY the same effect, or not quite?

What's in those events where you're turning on the self switches?
The lag doesnt break the game, its just slightly noticeable at all times regardless of which map I'm on.

*I'm very sure nothing else uses that switch. At least nothing complex.

*The self switches simply change to event pages that shows a different sprite so the player knows where the battle is happening.

*Every 24 hours there is a similar effect but much less noticeable.

Could it be that too many common events are being run one after the other?

Right now, every 14 in-game hours, a common event chain will be run. Recommendation Prep > >Recommendation>>Recommendation Unprep>>Battle Prep 1>>Battle Prep 2>>Battle>>Victory>>Loss>>Counter>>Counter Unprep.

Looking at my game I now realize I have 2 other, smaller, common event chains being activated at the same time.

None of these common events are anymore complex than what you've seen here but 3 chains all at once may be stretching the system.
its just slightly noticeable at all times regardless of which map I'm on
Does that mean there's always a bit of lag and not just when these events are starting? That could point to something completely different.

At least nothing complex
doesn't need to be complex. An event to change the bgm or screen tint can cause lag if it's not done properly (yes, there really is a "wrong" way to make an event that runs a single command).

If you want to zip up your project and load it up somewhere (that doesn't require registration to download), I might be able to take a look at it for you. However, I'd ask that you make it incredibly easy for me to reproduce the issue - put the starting point on a map where it's more obvious (if there is such a thing), if I need to interact with an event to trigger it, put the event right there for me. I don't want to have to follow a series of 20 steps to make it happen - the less time between hitting the map and having the issue, the better.
No, no its during these events.

Sure I'll make a basic demo that will feature these events. Will take some time.
Well the problem was mainly due to the lighting and time system plugins. Not a big deal. I've sent you a PM about a different issue if you could take a look at it please.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/increasing-processing-speed.93974/