Hi guys,
So I'm developing my third game and actually reading the docs this time around and I'm now using the stat() function to see what's going on as I code.
I've got about 284 lines of code and a spritesheet of 785 bytes. No music or sound effects. Yet my mem usage is 43MB according to stat(0). Isn't...that a lot? Seems like a lot. What's going on here? Is it measuring the entire PICO-8 development environment usage or just my code?
Also, stat(1) for CPU usage from the docs states that a value of 1.0 is the program executing 100% of the time between frames, whereas anything over 1.0 is basically frame-skipping due to excessive load. I've of a value of 0.19. I'm guessing anything under 1.0 is "this is way easy, what else you got?" from the CPU, correct?
I've also been looking at the PICO-8 cheat-sheet and noticed the memory layout. And I know people use peek/poke/memcpy/memset to do....stuff. Why would I need to know the memory layout for PICO-8 and why is manually fiddling with the memory desirable? Procedurally generated graphics? Anything else?
Thanks!
The memory stat takes into account all the objects that get created at runtime, so any function that creates a new instance of an object will add towards this total.
Stat 1 is the % usage of the Cpu, 0.19 would mean the Cpu is at 19% capacity. In this case, you can throw 4 times the amount of stuff for the Cpu to manage for each frame.
Modifying the memory of pico 8 directly can be tricky but very useful when done well.
Here's one example of how manipulating the memory used to render the screen can be used to create a transition effect.
You could use the same principles to create a rippling water surface or a glitch effect when combined with sprite data.
The possibilities are endless! I'd recommend just booting a black cart and playing around with the memcpy function, see what happens :)
Stat(0) only takes into account lua memory, your spritesheet, music etc isn't included in that value. Also it's in kilobytes, not megabytes :) I'm not sure that's mentioned in the manual though.
The memory layout is designed to support functions like pget, pset, spr, map, music etc, which can only access their respective areas of ram.
It is only a suggestion though - if you're using peek/poke and so on, and want to do something more complicated you can ignore the layout as necessary. For example, you could treat cart rom as a contiguous block of 17,152 bytes containing.. well, whatever you can fit in there really...
edit: As Felice points out on the wiki, I should really be referring to kibibytes & mebibytes, but I'm using the old conventions (1024 bytes = 1 kilobyte). What can I say, I'm old and resistant to change.
@Catatafish - Ah - that makes more sense! In that case, the PICO-8 Wikia at http://pico-8.wikia.com is wrong: -
"Memory and CPU usage
stat(0) returns the amount of memory currently used by the Lua program. The value is a number of megabytes, between 0 and 2048."
@GibletsofJesus - thanks, I'll take a look at that effect and see what else I can do :) I'm going to need some fancy level start/transition effects anyway.
I fixed the wiki. Glad you noticed it.
Remember, anyone can edit a wiki. If you see a mistake, you should feel free to correct it. Just be sure you're correcting it correctly. :)
@Felice - That honestly had not occurred to me :D Thanks for fixing.
[Please log in to post a comment]