Rendering to renpy window

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
Noisyedge
Newbie
Posts: 5
Joined: Mon Sep 03, 2018 1:54 pm
Github: Noisyedge
Contact:

Rendering to renpy window

#1 Post by Noisyedge » Mon Sep 03, 2018 2:05 pm

For a university course I currently have to write a simple ant simulator game. While not required, I would get bonus points for a gui/visual representation.
Since the project itself is rather boring, I'm trying to make it a little more interestibg by adding a story mode of some sorts, which I wanted to do in renpy. most of the "required" ui (the visual representation of the simulator) is already written in pygame, but since I need to render 100x100 hexagons with ants on them, the performance is quite poor (probably due to a lot of scaling and rotation transformations)
since ideally I want to show the ui in the same window as the VN part of the game, I need to render the ui into the renpy window.

Since neither google nor a quick search throug the documentation gave me any results, what are my options for that?
I know renpy has a 2d game engine "build in", but I haven't been able to find much information about it.
Ideally I want to use hardware accelerated rendering (like pyglet), but just getting an opengl-context to pass onto some c ffi code would be fine as well.

I'd appreciaty any kind of direction what I can and can't do to the renpy window.

User avatar
PyTom
Ren'Py Creator
Posts: 15476
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: Rendering to renpy window

#2 Post by PyTom » Mon Sep 03, 2018 3:04 pm

Ren'Py doesn't support being integrated with for that. I'd suggest looking at creator-defined displayables, and see if you can make it work with one of those. Other than that, it's not going to work.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Noisyedge
Newbie
Posts: 5
Joined: Mon Sep 03, 2018 1:54 pm
Github: Noisyedge
Contact:

Re: Rendering to renpy window

#3 Post by Noisyedge » Mon Sep 03, 2018 5:14 pm

What would be a rough guess for the performance of renpys custom displayables compared to pygame when I only need to display PNGs with alpha channel and a lot of scaling, and no real animations except scolling and zooming over the map?
(Just asking so I don‘t end up rewriting it just to end up with the same Problem again)

User avatar
Remix
Eileen-Class Veteran
Posts: 1458
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: Rendering to renpy window

#4 Post by Remix » Mon Sep 03, 2018 6:26 pm

Ren'Py would handle caching of images better and does use a bespoke SDL2 pipeline rather than pygame's SDL one, you'd just have to become aware of the ways in Ren'Py to handle the pieces you want...

If you had to, how many fully different images are you looking at and what size are they? (even fully dynamic scaling can be reduced to a range... If an ant ranges from 1px to 20px long and can point in 16 directions you could just cache 320 images rather than effectively creating each from scratch)

Ren'Py's viewport (scrollable area) does iirc cleverly handle visible/non-visible areas so that parts outside the seen area are not drawn, cutting down on that overhead.

I would likely advise checking out viewport and spritemanager in the docs as areas to start playing, likely moving onto a creator-defined-container once you are happy with process speed for multiple blits.
Frameworks & Scriptlets:

User avatar
PyTom
Ren'Py Creator
Posts: 15476
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: Rendering to renpy window

#5 Post by PyTom » Mon Sep 03, 2018 8:28 pm

In general, Ren'Py's displayables should be significantly more performant than the equivalent code in Pygame, since Ren'Py does all of its drawing on the GPU, ideally in massive parallel. That's different than Pygame, which does its drawing in a single core on the CPU. You do have to be careful to use renpy.render on displayables so that Ren'Py's cache can get the right images, but it should be pretty easy to get superior performance.

The main issue is the difference between pygame's event handling. While pygame has a main loop, Ren'Py has the .event method which takes a Pygame event object, and then x and y coordinates for it. The x and y coordinates may be different than those in the object, since Ren'Py takes care of scaling things when the user changes the window size.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Noisyedge
Newbie
Posts: 5
Joined: Mon Sep 03, 2018 1:54 pm
Github: Noisyedge
Contact:

Re: Rendering to renpy window

#6 Post by Noisyedge » Mon Sep 03, 2018 10:28 pm

Thank you for pointing me in the right direction.
The Problem with scaling is that I need to support field sizes ranging from 2x2 hexagons to 128x128 hexagons, with any number of them taken by ants (and since everything would be much to small on a 128x128 I need zooming and scrolling) to caching all the possible sizes is not an option.
Actually, I increased Performance quite a lot by using the resizing and rotation transformations from PIL (or rather Pillow) instead of the ones from pygame.
Just out of curiosity, assuming I loaded/calculated an Image using PIL/Pillow, would I be somehow able to turn that into a displayable for renpy (without saving it to disk first)?

User avatar
PyTom
Ren'Py Creator
Posts: 15476
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: Rendering to renpy window

#7 Post by PyTom » Tue Sep 04, 2018 12:08 am

There isn't really a good wat to integrate PIL with Ren'Py. Also, you wouldn't want to. Ren'Py's Transform occurs on the GPU, so it's basically free in most cases.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Noisyedge
Newbie
Posts: 5
Joined: Mon Sep 03, 2018 1:54 pm
Github: Noisyedge
Contact:

Re: Rendering to renpy window

#8 Post by Noisyedge » Tue Sep 04, 2018 3:20 am

ok, then I'll try my best at porting things over to renpy natively. I actually didn't expect it to support HW acceleration this well. last time I looked at it (which was many years back) it didn't seem to really have any of that. :shock:
thank you for the helpfull input.

Post Reply

Who is online

Users browsing this forum: Google [Bot]