Many scaled images, best implementation of

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
jenny
Newbie
Posts: 2
Joined: Wed Jan 17, 2007 3:31 am
Contact:

Many scaled images, best implementation of

#1 Post by jenny »

I am writing a VN. I have 5 characters, with an average of about 3 different images each, and each image shows up on average at about 3 different scales. That's 45 images.

What is the relative cost in CPU cycles and memory consumption for these two implementations? Does Ren'Py instantiate images during the init: block, only on the fly, or is there some caching strategy?

Thank you in advance,

Yours truly,
Jenny


----------------
Choice A: Define an image at the top of the .py source, and use it later, like this:

init:
# compute tina_wpx and tina_hpx
image tina sitting = im.Scale("tinasitting.png", tina_wpx*1.0, tina_hpx*1.0, bilinear=True)
image tina sitting50 = im.Scale("tinasitting.png", tina_wpx*.50, tina_hpx*.50, bilinear=True)
image tina sitting33 = im.Scale("tinasitting.png", tina_wpx*.33, tina_hpx*.33, bilinear=True)

image tina kissing50 = im.Scale("tinakissing.png", tina_wpx*.50, tina_hpx*.50, bilinear=True)

# compute jenny_wpx and jenny_hpx
image jenny standing = im.Scale("jennystanding.png", jenny_wpx*1.0, jenny_hpx*1.0, bilinear=True)
image jenny standing50 = im.Scale("jennystanding.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)
image jenny standing33 = im.Scale("jennystanding.png", jenny_wpx*.33, jenny_hpx*.33, bilinear=True)

image jenny kissed50 = im.Scale("jennykissed.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)

image jenny surprised50 = im.Scale("jennysurprised.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)

# [... later in the source ...]

label first_kiss:
scene bg our_place
show jenny standing50
show tina sitting50

t "\"I really like you.\""

scene bg our_place_hearts_n_flowers
show jenny kissed50
show tina kissing50

j "She kissed me ... What do I do now?"

scene bg our_place
show jenny surprised50
show tina sitting50

t "\"Really.\""

----------------
Choice B: Scale and show the image in one place:

init:
# compute tina_wpx and tina_hpx
# compute jenny_wpx and jenny_hpx

# [... later in the source ...]

label first_kiss:
scene bg our_place
show image im.Scale("jennystanding.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)
show image im.Scale("tinasitting.png", tina_wpx*.50, tina_hpx*.50, bilinear=True)

t "\"I really like you.\""

scene bg our_place_hearts_n_flowers
show image im.Scale("jennykissed.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)
show image im.Scale("tinakissing.png", tina_wpx*.50, tina_hpx*.50, bilinear=True)

j "She kissed me ... What do I do now?"

scene bg our_place
show image im.Scale("jennysurprised.png", jenny_wpx*.50, jenny_hpx*.50, bilinear=True)
show image im.Scale("tinasitting.png", tina_wpx*.50, tina_hpx*.50, bilinear=True)

t "\"Really.\""

----------------
The Sight status:
Plot, dialog 100%, Script 50%, Python 40%
Art: Ha ha ha! 20% placeholders, Music: Sigh, 0%

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#2 Post by PyTom »

They will both be treated identically when it comes from program performance. Ren'Py loads images a few screens before they are used, by reading forward in the program and predicting what is likely to run, and determining what images that code uses.

I would suggest that the first example is better, because the indirection used means that you don't have to repeat the complex use of im.Scale every time an image is used.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

jenny
Newbie
Posts: 2
Joined: Wed Jan 17, 2007 3:31 am
Contact:

#3 Post by jenny »

Thank you, that is the kind of answer I wanted to hear.
The Sight status:
Plot, dialog 100%, Script 50%, Python 40%
Art: Ha ha ha! 20% placeholders, Music: Sigh, 0%

Post Reply

Who is online

Users browsing this forum: Google [Bot], snotwurm