image cache log and prediction

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

image cache log and prediction

#1 Post by nananame » Sat Jun 27, 2020 4:31 am

I'm playing around with optimizing a game. Many images are loaded in through python ($renpy.show) instead of directly with show. Therefore I thought I'd do some simple image prediction.

I added $renpy.start_predict("images/*") - is this okay? will the wildcard predict all images in the folder? how about subfolders?

I cleared persistent data but I'm not sure if that will clear the images already in some cache for testing purposes. Will it? Is there another way?

Then I tried the game. There's no lag but I can't be sure whether that is from the aforementioned cache not being cleared. However, the image_cache file says "Total Miss" for files in the images folder which it should predict.

So my questions are:
- will clearing persistent data clear the image cache for testing purposes? if not, how? should I do renpy.free_memory() once then quit, remove that line and retry?
- and why are the images which should have been predicted "Total Miss"?
- a semi related question, can I predict multiple screens? for example: $renpy.start_predict_screen("screenname1) $renpy.start_predict_screen("screenname2) $renpy.start_predict_screen("screenname3) one after another or will they cancel each other out?


For clarification, the images aren't large and this is more me testing out prediction because images aren't loaded normally with "show" but through $renpy.show or are used in screens (which is another interesting question, if a screen uses an image - either as "add" or as a background for a button or anything - is it enough to predict the image itself?)

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#2 Post by nananame » Sun Jun 28, 2020 5:07 am

I figured out why the log was showing "Total Miss" - because I only used one *. The correct way to predict filenames is with a dot so "images/*.*" works.

I'm still wondering about some of the other stuff in the first post if anyone could enlighten me.

Also, encountered another conundrum. The log now quickly says "Overfull". I obviously need to increase cache size, right? This is a test game as I said. The images folder has about 40MB total. So I followed the instructions in the doc and set:
config.image_cache_size = None ---->so that this value isn't used
config.image_cache_size_mb = 200 ---->so that this value is used

If the total images are less than 40, shouldn't a cache of 200MB be large enough? Trying again the log again returns a lot of "Overfull". Can someone explain this please?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: image cache log and prediction

#3 Post by Remix » Sun Jun 28, 2020 2:43 pm

When Ren'Py predicts (loads an image into the memory cache) it does not hold the filesize that the original held.
It will take any image format it can read and convert it to a matrix of (rgba) tuples representing the colour of every pixel. This results in using roughly 8 bytes per pixel (if config.cache_surfaces is default True) which in turn means a 1280x720 image is always using 7.3 million bytes (around 7Mb) irrespective of how small the compressed png or jpg was. If you had 40 images at that size, you'd want around 300Mb, with some extra for gui stuff etc.

Untested: I think using multiple renpy.start_predict_screen() calls should be fine. Just be aware that if the cache got full, early predicted images might be cycled out of the cache. Note too that renpy.start_predict( filename pattern ) will keep running at every interaction (and try to reshuffle those images back into the cache if they dropped out) all the way until stop_predict is called.
Frameworks & Scriptlets:

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#4 Post by nananame » Mon Jun 29, 2020 5:37 am

When Ren'Py predicts (loads an image into the memory cache) it does not hold the filesize that the original held.
It will take any image format it can read and convert it to a matrix of (rgba) tuples representing the colour of every pixel. This results in using roughly 8 bytes per pixel (if config.cache_surfaces is default True) which in turn means a 1280x720 image is always using 7.3 million bytes (around 7Mb) irrespective of how small the compressed png or jpg was. If you had 40 images at that size, you'd want around 300Mb, with some extra for gui stuff etc.
Ah I see. So basically it's not the file size but image size that's taken into account no matter the way I determine the cache size? I understand now, thanks!
Note too that renpy.start_predict( filename pattern ) will keep running at every interaction (and try to reshuffle those images back into the cache if they dropped out) all the way until stop_predict is called.
How does this work exactly?
For example, I call start_predict(imagename). So this will be run at every interaction? Does it then make sense to do a stop_predict immediately after? (assuming stop_predict only stops running the prediction, but doesn't by itself remove the image from cahce)

So basically, in a situation where all images would fit in a cache, I do:
$renpy.start_predict("images/*.*") - this will now predict all images in the images folder
----->should something go between to give time to RenPy to do the prediction before running into the stop command?
$renpy.stop_predict("images/*.*) - this stops predicting, but keeps predicted images in the cache, right?

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#5 Post by nananame » Tue Jun 30, 2020 12:51 pm

I tried doing start predict, a pause and then stop predict. It obviously didn't predict every image in the folder as the log was full of "Total Miss"...

So should I even stop the prediction? I'm guessing that it's quite a bit resource heavy if it keeps predicting the same images at every interaction... Anyone? Looking for as much details on this as possible.

additionaly - if I predict images do I need to predict screens which use those images? Or is it an either/or situation?

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#6 Post by nananame » Sun Jul 05, 2020 3:30 am

-me being stupid in this post...ignore
Last edited by nananame on Wed Aug 12, 2020 5:23 am, edited 1 time in total.

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#7 Post by nananame » Tue Aug 11, 2020 12:24 pm

Still playing with image prediction and optimization :)

Does anyone know if there is a way I can know when the prediction is completed? For example, I use start prediction and give it a list of images to predict.

Then I pause the game, giving renpy time to predict, and then stop prediction.

Now, this pause is static. I have to code it in (e.g. pause 4.0).

Is there ANY WAY I can find out when all images are predicted? That would mean I can create a dynamic load screen.

I would love something like this (pseudo code):

Code: Select all

$renpy.start_predict("images/SomeFolder/*.*")###this would start predicting all images in this folder
label still_loading:
    if image.cache_prediction_still_going_on:
        pause 1.0
        jump still_loading
$renpy.stop_predict("images/SomeFolder/*.*")###this would stop predicting since now images are loaded
Anyone? There ought to be some way otherwise all loading is static, and we can't know how much time is needed to predict images on other machines...

nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

Re: image cache log and prediction

#8 Post by nananame » Thu Aug 13, 2020 4:47 am

I couldn't find a better way so I thought about checking the image load log generator.
It SEEMS to work but will require more testing. Would appreciate thoughts:

Code: Select all

$renpy.start_predict("images/SomeFolder/*.*")
label loadingstill:
    pause 1
    if next(renpy.get_image_load_log(age=1),False):####<----basically if the generator yields an image we jump to the label, give it another second of loading; if it returns false we move on
        jump loadingstill
$renpy.stop_predict("images/SomeFolder/*.*")

Post Reply

Who is online

Users browsing this forum: No registered users