on_updated: on_tick that works when paused

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
L0laapk3
Inserter
Inserter
Posts: 47
Joined: Sun Mar 18, 2018 10:01 pm
Contact:

on_updated: on_tick that works when paused

Post by L0laapk3 »

When using game.tick_paused, I don't understand how to unpause the game after that.

The only delayed entry points that might work that I can find are GUI or key events. Is this true, or am I missing something important?
If not, I propose to add some kind of on_updated event, which works similar to on_tick, except it would only trigger on every 'draw' of the game instead of every update. This would serve 2 purposes:
1. It will keep functioning when the game is game.tick_paused. This way you can run code even when the game is paused withouth any user interaction.
2. Since it would only run every update instead of every tick, it could also help with the problem I was having here: viewtopic.php?f=65&t=65045

Maybe it should be split up into 2 events: on_updated which would work like on_tick but also when paused and on_redrawn which would only trigger when the screen is redrawn similar to described as above.

For the rest of this post, I'll explain my use case:

In factoriomaps, my goal is to generate day and night images that are exactly alike. It's important that these images are taken of the same tick, otherwise this would result in tears between the day and night version all over the map. In 0.16, I had to choose between restarting the game to do day and night separately, which can take a painful amount of time when dealing with a lot of mods, or taking the screenshots 1 tick apart.
In 0.16, my workflow was as follows:
tick 0: set daytime to day.
tick 1: hope the game has rendered, capture all day screenshots, set daytime to night.
tick 2: hope the game has rendered again and capture all night screenshots.
This left me with a day and night version of the capture that were 1 tick apart and thus had tears everywhere.

My hope is that I can use an event like on_updated to follow a similar workflow but while the game is paused.

Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

Re: on_updated: on_tick that works when paused

Post by Boodals »

Having two on_tick events is probably never going to happen because it would double the performance cost of on_tick, which is probably already significant.
A much better solution is to add an on_paused_tick which just fires every tick when the game is paused, instead of the regular on_tick. Then, if you want to register an event that happens every tick whether or not the game is paused, you can use script.on_event({defines.events.on_tick, defines.events.on_paused_tick}, ... )

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: on_updated: on_tick that works when paused

Post by orzelek »

I'm pretty sure that game doesn't tick when paused.
What you are looking for is instant screenshot method that doesn't defer to after tick. Depending on how rendering is done it might be tad problematic.

Alternatively new parameter to screenshot method that passes time of day for screenshoot could help you with getting proper same tick screenshots.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_updated: on_tick that works when paused

Post by Rseding91 »

Such an event still wouldn't work for what you want. The game has no direct connection between asking for a screenshot to be taken and when it happens. It can be in the same tick or it can be several later or never.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2124
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: on_updated: on_tick that works when paused

Post by Ranakastrasz »

What happens if you set the gamespeed to zero?
Or something really low anyway.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: on_updated: on_tick that works when paused

Post by DaveMcW »

You can simply run a loop that counts to a billion to distract the CPU until the screenshot finishes. What OP wants, and the devs won't give, is a way to wait for exactly the right amount of time.

L0laapk3
Inserter
Inserter
Posts: 47
Joined: Sun Mar 18, 2018 10:01 pm
Contact:

Re: on_updated: on_tick that works when paused

Post by L0laapk3 »

DaveMcW wrote:
Wed Mar 27, 2019 6:08 pm
You can simply run a loop that counts to a billion to distract the CPU until the screenshot finishes. What OP wants, and the devs won't give, is a way to wait for exactly the right amount of time.
No, that wouldnt do anything for me I think, since all the lua stuff is ran synchronously.
Rseding91 wrote:
Wed Mar 27, 2019 4:24 pm
Such an event still wouldn't work for what you want. The game has no direct connection between asking for a screenshot to be taken and when it happens. It can be in the same tick or it can be several later or never.
How about some delayed event/hook while the game is paused? This doesn't really address my main point in the OP, sorry for starting about multiple things at once.

Post Reply

Return to “Modding interface requests”