Variable Animation Framerate

Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Variable Animation Framerate

Post by eradicator »

What?
For all types of animations and working_visualizations it would be nice if it was possible to specify the duration (in ticks?) that each frame is displayed. This would make it possible to have looped animations that have a pause/slowdown in the work cycle. For example a smeltery could have a long phase (4 seconds) where it slowly heats metal, which maybe only requires a new animation frame once per 60 ticks. But at the end of the operation the fluid metal is poured into casting basins which requires a faster animation of e.g 1 frame per tick for 60 ticks.

Currently this can only be achieved by having a total of 5*60=300 frames of animation where the first 240 frames are mostly exact copies of the previous one (60 copies of the first 4 frames each).

How?
With variable speed support it would be possible to only have 64 unique frames and define the time they are displayed like this:

Code: Select all

--start frame, end frame, ticks each frame is displayed.
frame_times = {
{1,4,60}, --first four frames are shown 60 ticks each
{5,64,1}, --last 60 frames are shown 1 tick each
}
Or more akin to video timestamps as a per-frame list:

Code: Select all

frame_times = {60, 60, 60, 60, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Why?
The point of doing this would be to allow animations with very long cycles without the increase in file size and memory usage(?) caused by large amounts of copied frames.


Edit:
I just noticed pyanodon has posted an example animation that demonstrates well the kind of "pulsed" animation that would benefit from this.
Image
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Variable Animation Framerate

Post by eradicator »

@FFF248:
Now that posilla is looking at optimizing texture handling i'd still like support for delayed animations without wasting tons of VRAM.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Variable Animation Framerate

Post by posila »

I just randomly saw this now.
Since 0.17 animation definition has frame_sequence. (not documented on wiki yet)
When used, frame_count is still expected to be number of frames in the source spritesheet, and frame_sequence is then list of 1-based frame indecies into the spritesheet. The actual lenght of the animation will then be lenght of the frame_sequence (times repeat_count, times two if run_mode is "forward-then-backward"). There is a limit for (actual) animation lenght of 255 frames, though.


Trivial example - frame_sequence defines same sequence in which the animation would load by default, so it is useless in this case:

Code: Select all

  frame_count = 4,
  frame_sequence = { 1, 2, 3, 4 }
The second example - first 5times repeat frame 2, then alternate between 4 and 3 two times. Frame 1 is not used.

Code: Select all

  frame_count = 4,
  frame_sequence = { 2, 2, 2, 2, 2, 4, 3, 4, 3 }
Indices can be used in any order, repeated or not used at all. Unused frames are not loaded into VRAM at all, frames referenced multiple times are loaded just once.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Variable Animation Framerate

Post by eradicator »

posila wrote:
Sat May 16, 2020 8:09 pm
Unused frames are not loaded into VRAM at all, frames referenced multiple times are loaded just once.
One of these rare occurances where i get exactly what i asked for :D. Thank you very much!
posila wrote:
Sat May 16, 2020 8:09 pm
There is a limit for (actual) animation lenght of 255 frames, though.
Hm...255/60 = 4.25 seconds? That is a bit on the short side, but i guess it'll have to do ;).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Variable Animation Framerate

Post by posila »

eradicator wrote:
Fri May 29, 2020 10:53 pm
Hm...255/60 = 4.25 seconds? That is a bit on the short side, but i guess it'll have to do ;).
animation speed < 1 is friend ;)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Variable Animation Framerate

Post by eradicator »

posila wrote:
Sat May 30, 2020 5:28 am
eradicator wrote:
Fri May 29, 2020 10:53 pm
Hm...255/60 = 4.25 seconds? That is a bit on the short side, but i guess it'll have to do ;).
animation speed < 1 is friends ;)
Having an animation that at least partially runs at full speed is kinda the point. Half speed (30fps) might still be feasible, but any lower than that won't look nice. That's why my original suggestion was based on "duration per frame". I.e. i was pondering concepts where the "machine" looks (almost) "paused" for longish intervals (say 30 seconds) and then runs a short full speed animation (say 3 seconds).

Sadly i don't currently have time to test any of this.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Implemented mod requests”