Page 1 of 2

How Ren'Py handles the memory?

Posted: Sun Apr 19, 2009 8:17 pm
by killdream
Actually it's a lousy title, sorry i.i

Well, I was playing with the particles factory to create a falling snow effect. Particles should fade over the course of time, and since I couldn't do that with At functions I decided to put a im.alpha to change the alpha in every frame (yes, a lousy workaround as well). It works just perfecly, but it's not much memory effective.

Does Ren'Py caches every result of a im function? (That would explain why memory keeps increasing as long as the particles are on screen) And if it does, is there some way of actually turning this cache function off?

Re: How Ren'Py handles the memory?

Posted: Tue Apr 21, 2009 7:37 am
by Cynebeald
From the documentation:
Caching. By default, image manipulators are cached in memory before they are loaded. Supplying the cache=False argument to an image manipulator will prevent this caching. This should only be used when an image manipulator is never used directly (such as by an image statement).

Re: How Ren'Py handles the memory?

Posted: Tue Apr 21, 2009 7:52 am
by Cynebeald
On second thought, maybe should NOT disable caching, because renpy would have to apply alpha to each particle every time it is drawn, and that could cause performance problems. How about pre-computing the different faded versions of the particles? This is going to use more memory than not caching at all, but on the other hand it could be smoother than blending particles every time.

Re: How Ren'Py handles the memory?

Posted: Tue Apr 21, 2009 9:46 am
by Jake
Cynebeald wrote:On second thought, maybe should NOT disable caching, because renpy would have to apply alpha to each particle every time it is drawn, and that could cause performance problems.
But then, if you're - say - doing a rotation based on how long the displayable has been displayed, you rapidly run out of memory as Ren'Py caches millions of ever-so-slightly-different result images just on the very unlikely off-chance that it's going to be able to re-use one of them again later.

Serously, the naïve approach to this ran my 2GB Windows machine out of memory in about 2.5 seconds, when I was working with zooming an 800x600 graphic.



(And speaking of gaps in the documentation, since each of the im.* manipulators has its own page, it would be a good idea to mention the cache and rle parameters on those pages - or at least mention that there are other params common to all manipulators which aren't described on that page. I'd just gone straight to the im.FactorZoom page and missed that there was a cache parameter at all, originally.)

Re: How Ren'Py handles the memory?

Posted: Tue Apr 21, 2009 10:01 am
by killdream
Hm, yep, I changed it to precompute all possible images in an array in the particles factory, it works very nice since the particles are really small, thanks for the advice ^^

And yeah, I always go to the function index reference too, so I didn't found out about the caching/rle stuff. But well, Ren'Py documentation is a wiki after all, so I think anyone can workaround this in their free-time (guess I'll write some doc examples later)

Hm, and actually SDL can manage some effects in real-time without caching stuff - I used some in my tetris game, they'd work just fine besides the fact of pygame being really high-level (maybe it'll be better when they change to pygame 2.0, implementing SDL gfx would help, but I think using OpenGL would make Ren'Py _really_ better * support to 3d transforms in a 2d enviroment would be nice for lots of effects *)

Re: How Ren'Py handles the memory?

Posted: Tue Apr 21, 2009 3:28 pm
by Watercolorheart
I wish I could find a tutorial for particles in Ren'Py.... I keep on trying to learn how to use them in Ren'Py, failing miserably, and then use another program to make them and export an image series or some such .... like 10 frames for water, 5 frames for rain behind a window, 8 frames for fire flickering...

The documentation on the factories and what each tuple is leaves me more confused than it did before I even tried to make, say, bubbles or rain.

Re: How Ren'Py handles the memory?

Posted: Wed Apr 22, 2009 9:18 am
by EvilDragon
BCS wrote:The documentation on the factories and what each tuple is leaves me more confused than it did before I even tried to make, say, bubbles or rain.
This.

Until then, SnowBlossom is good enough for snow, rain, leaves, mists, etc. Coupled with randomness and different spline movement per particle (is this even possible?), you can have some really cool effects. For example, snowflakes don't drop horizontally on the ground, they wiggle in all directions before they drop to the floor. I sense that a combination of low-frequency sine and cosine curves (one used for horizontal, one for vertical direction), would give enough wiggleness for that. A random wiggle curve would probably be even better.

Re: How Ren'Py handles the memory?

Posted: Wed Apr 22, 2009 11:51 am
by PyTom
It's possible with Particles but not SnowBlossom.

Re: How Ren'Py handles the memory?

Posted: Wed Apr 22, 2009 2:58 pm
by killdream
Well, actually the only thing you really need is to apply wind's force in the particles (you apply random window force so it looks more real, without sine/cosine based curves that are really not efficient and not needed too), so they seem more real. In my case I needed particles of different sizes (that looks like it have some depth, as particles falling far from the screen will appear smaller than those falling near the screen) and that faded as they felt (I don't remember why I wanted it, though, I already changed the main menu alot .-.).

If someone wants it, I can comment better the code and share it.

This is more or less how the effects look, actually (aside that it falls faster in mine, but the logic is pretty much the same)
http://www.kirupa.com/developer/flash8/snow.htm

Re: How Ren'Py handles the memory?

Posted: Wed Apr 22, 2009 5:52 pm
by EvilDragon
killdream wrote:If someone wants it, I can comment better the code and share it.

This is more or less how the effects look, actually (aside that it falls faster in mine, but the logic is pretty much the same)
http://www.kirupa.com/developer/flash8/snow.htm
Cookbook it?

Re: How Ren'Py handles the memory?

Posted: Thu Apr 23, 2009 4:51 am
by jack_norton
Nice effect, yes I think could be a valuable addition to the cookbook.

Re: How Ren'Py handles the memory?

Posted: Thu Apr 23, 2009 12:43 pm
by killdream
Cookbook'd =D

I took a while to comment/rewrite the code in a more generic way. Things are pretty much chaotic here, since the dead line for the demo of my first commercial project is comming closer and... there's loooot of work to do i.i (though, I'm not the most doomed one, since I'm doing just programming)

Re: How Ren'Py handles the memory?

Posted: Thu Apr 23, 2009 1:46 pm
by jack_norton
What game are you making? a normal one or a hentai game? :mrgreen:

Re: How Ren'Py handles the memory?

Posted: Thu Apr 23, 2009 2:11 pm
by killdream
jack_norton wrote:What game are you making? a normal one or a hentai game? :mrgreen:
I can't do this kind of games, I'm a christian protestant guy after all. And although I don't mind reading/playing games that can have sexual content if the story is great, I'm not a fan of it myself and wouldn't put it just for fanservice.

The commercial project is an hybrid VN/RPG game. Can't say much about the story and such for now otherwise Ryuno will kill me for sure xD but when we finish the demo I should make a WIP thread here, though.

And, no, the game doesn't have christian/whatever messages in it =D

Re: How Ren'Py handles the memory?

Posted: Thu Apr 30, 2009 1:21 am
by zanaikin
Cynebeald wrote:From the documentation:
Caching. By default, image manipulators are cached in memory before they are loaded. Supplying the cache=False argument to an image manipulator will prevent this caching. This should only be used when an image manipulator is never used directly (such as by an image statement).
=O

Can you select to prevent caching for entire UI widgets / layers ? I couldn't find anything about it in the UI functions docs.

Also, is there a way to lower the graphics cache limit ?