Page 1 of 1

Rendering to renpy window

Posted: Mon Sep 03, 2018 2:05 pm
by Noisyedge
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.

Re: Rendering to renpy window

Posted: Mon Sep 03, 2018 3:04 pm
by PyTom
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.

Re: Rendering to renpy window

Posted: Mon Sep 03, 2018 5:14 pm
by Noisyedge
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)

Re: Rendering to renpy window

Posted: Mon Sep 03, 2018 6:26 pm
by Remix
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.

Re: Rendering to renpy window

Posted: Mon Sep 03, 2018 8:28 pm
by PyTom
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.

Re: Rendering to renpy window

Posted: Mon Sep 03, 2018 10:28 pm
by Noisyedge
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)?

Re: Rendering to renpy window

Posted: Tue Sep 04, 2018 12:08 am
by PyTom
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.

Re: Rendering to renpy window

Posted: Tue Sep 04, 2018 3:20 am
by Noisyedge
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.