Log In  

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!

P#48514 2018-01-24 14:40 ( Edited 2018-01-25 11:05)

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.

Cart #48518 | 2018-01-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
4

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 :)

P#48526 2018-01-24 19:34 ( Edited 2018-01-25 00:34)

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.

P#48528 2018-01-24 21:45 ( Edited 2018-01-26 03:48)

@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.

P#48534 2018-01-25 04:16 ( Edited 2018-01-25 09:16)

@arashi256

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. :)

P#48538 2018-01-25 05:56 ( Edited 2018-01-25 10:56)

@Felice - That honestly had not occurred to me :D Thanks for fixing.

P#48541 2018-01-25 06:05 ( Edited 2018-01-25 11:05)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 13:35:07 | 0.030s | Q:26