caching render objects safely

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
User avatar
Vaendryl
Regular
Posts: 39
Joined: Thu Dec 26, 2013 10:10 pm
Projects: Sunrider
Organization: Love in Space
IRC Nick: vaendryl
Contact:

caching render objects safely

#1 Post by Vaendryl »

I was thinking that maybe showing a lot of displaybles on screen could be sped up by storing a render object inside the displayable instance and have the render method return that if nothing's changed, or maybe store a couple of different renders and just return the one that's needed rather than rerender one each frame.

example:

Code: Select all

    class CachingDisplayable(renpy.Displayable):
        def __init__(self, child, **kwargs):
            super(CachingDisplayable, self).__init__(**kwargs)
            self.child = child
            self.render_cache = None
        
        def render(self, width, height, st, at):
            if self.render_cache is not None:
                self.render_cache = renpy.render(self.child, width, height, st, at)            
            return self.render_cache
obviously, the main issue that comes to mind right away is that render objects can't be pickled. any save routine would have to be updated to purge the cache of all displayables, but that should be possible in theory.

anyone know if going to these lengths has any value? I'm not even sure if ren'py already does this internally making it unlikely there'd be any gains.

there also seems to be an issue where cached renders turn completely black when the game window changes size or switches to full screen mode. anyone know anything about this? are there triggers I can use to purge the caches when the user changes the window size?

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:

Re: caching render objects safely

#2 Post by PyTom »

Ren'Py does cache it internally, and clears the cache appropriately. So there's not much benefit from doing it yourself, and you've hit the problems.
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

User avatar
Vaendryl
Regular
Posts: 39
Joined: Thu Dec 26, 2013 10:10 pm
Projects: Sunrider
Organization: Love in Space
IRC Nick: vaendryl
Contact:

Re: caching render objects safely

#3 Post by Vaendryl »

thanks for the answer, man.

main advantage I'd hope to get was to not just cache a single render but multiple, basically caching a simple animation. I don't suppose you've got any ideas about that?

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:

Re: caching render objects safely

#4 Post by PyTom »

That should work provided you set st and at correctly.
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

Post Reply

Who is online

Users browsing this forum: Google [Bot]