Hosted Projects - FS2 Required > Just Another Day

All about APNGs

(1/3) > >>

Nightmare:

--- Quote from: Axem on July 12, 2018, 01:48:14 am ---The first time an animation plays, there will always be a little big of lag, but after it loops through it tends to get better.

--- End quote ---

Does the game not pre-load files referenced by scripting files? While experimenting with some custom death flash I've noticed that there's some lag too. Or does that effect only APNG/PNG files, and is there a way to prevent that?

Axem:
Welllll...

It's complicated. I'll try and run down the basics of how this all works.

When a VN Scene is loaded, the script does go through the whole file and looks for any actor animations that could be called. It will load them, then unload them right after so we're sort of caching the file. Sort of. A cold file load on an APNG for JAD is pretty noticable, it would cause a very noticeable spike of lag. Maybe 0.25 - 0.5 s? I never timed it, but its pretty lame. But by having the files loaded and unloaded, enough stuff is cached that the file can load again almost right away. So this is always done at VN start so you think its just part of the script loading.

Now, we've got the file loaded, but that doesn't necessarily mean you're out of the woods. All the APNGs are streamed in. This is so I don't have to load... well there's like 2GB of just APNGs in JAD. Obviously not everything would be used in one scene, but I think to draw it on the screen it needs to be decompressed to essentially a raw bitmap (think .bmp plus alpha!) and all of this needs to get thrown from your hard disk and into RAM. So it's going to steal all that RAM and take forever. This is all on top of already loaded assets inside FreeSpace as well!

Anyway, back to streaming. The APNGs are streamed in (eternal thanks to niffiwan for that), and how that works is each frame gets loaded as needed, then thrown away once I need another animation. So the first run through takes a little bit of time to actually get loaded up. So if an APNG has 90 frames, we're basically dividing up the load into 90 smaller bits in semi-real time, which is more seamless than loading all 90 together while waiting for a full second or something. And then the next time it loops, the animation is already in memory and is painlessly simple to play over again. I did my best to try and stagger animations so that initial load would just be done on one animation at a time. But sometimes I can't because the scene needs 4 people to be there at the start...

Things could be improved if the dark art of multi-threading was attainable, or perhaps some sort of movie codec with a reliable transparency feature. But I think for a silly mod like JAD, the system is as good as it needs to be. Maybe I can revisit when I go commercial. ;)

Oh and by the way, if you are wondering "gee, if it was like that before, how did you improve performance?" Wings of Dawn is using the VN script too, and Spoon wanted a way to have characters have a frame around them, so I added that feature to the VN script. Problem is, if there is no base, the script still tries to load one. And if it doesn't see one, it will keep trying to find and load it every. single. frame. That's a bit of a slowdown. So added some instructions to tell the script "don't bother looking if there is no base".

So I made things worse by accident, and I'm hoping they are better now.

Volta:
The VN scenes do work much smoother as long i don't rush trough the dialog and the interrogation works now again too, thanks!

But the interrogation scene doesn't cache anything for some reason  :nono:
Do the APNG script cache stuff into the OpenGL Nvidia/Amd GPU cache folder? i wonder if my GPU cache is corrupt but i did delete the folder so there souldn't be a problem (it regenerates on it's own if you play a OpenGL based game)

Is it possible to just use a Normal PNG file without the animations? Or is it also possible do use a lower resolution APNG version of the mod?  ;)

m!m:

--- Quote from: Axem on July 12, 2018, 03:11:54 am ---When a VN Scene is loaded, the script does go through the whole file and looks for any actor animations that could be called. It will load them, then unload them right after so we're sort of caching the file. Sort of. A cold file load on an APNG for JAD is pretty noticable, it would cause a very noticeable spike of lag. Maybe 0.25 - 0.5 s? I never timed it, but its pretty lame. But by having the files loaded and unloaded, enough stuff is cached that the file can load again almost right away. So this is always done at VN start so you think its just part of the script loading.

--- End quote ---
As far as I can tell from looking at the source, unloading a texture will remove all related data from the bmpman system of FSO so the next time it still needs to load the complete file. However, your operating system caches data which was loaded from your disk in RAM so the next time the file is opened it doesn't need to be read from the disk which is the probably cause for the improved performance you are seeing.
I would like to add support for movie files with an alpha channel but so far I could not find a way to support that with FFmpeg :(

Axem:
Yeah, it's not a real cache. That's why I said it sort of caches it, its probably the OS that still has the file in recent memory. Or something. I'm not sure how it works, but it do.

The interrogation scene is probably slowest because there's always 4 characters active, even if 2 are visible. Maybe its too much for your amount of memory or something? The best I can suggest right now is to grin and bear it. That sequence is probably the worst out of the campaign.


--- Quote from: m!m on July 12, 2018, 10:29:43 am ---I would like to add support for movie files with an alpha channel but so far I could not find a way to support that with FFmpeg :(

--- End quote ---

Yeah... :( In my research about that, I saw claims that VP8 could do that, but I could never get it to work. There was even a proof of concept file they had and it worked, but I could never make my own working files.

Navigation

[0] Message Index

[#] Next page

Go to full version