Log In  

it seems like all the drawing functions handle the floats fine by just truncating them anyway?

is there more memory overhead to store floats vs the int we get from flr?

what about the processor overhead from calling flr every time we want a random int?

P#35494 2017-01-11 21:59 ( Edited 2017-01-14 16:56)

Consider a situation where you want to choose a random element from a table. You can't index a sequential table with a non-integer, so:

element=table[flr(rnd(#table)+1)]

I don't think the overhead is significant.

EDIT: I did a quick test, comparing flr(a), band(a,0xffff), and (a-a%1), which are all equivalent, over 655,340 iterations. band(a,0xffff) is the fastest, but by a very small margin. In most situations, I'm not sure that you'd notice the difference.

P#35501 2017-01-11 22:46 ( Edited 2017-01-13 00:39)

I guess I should figure out how to test this stuff myself but I know almost nothing about optimization. So, the CPU overhead is small, what about for storing x,y position? I assume integers take less memory, so would it be preferable to convert float to int for objects rather than avoiding the flr() call ?

P#35546 2017-01-12 15:29 ( Edited 2017-01-12 20:29)

In Pico-8 there are no floating-point numbers, or integers for that matter. All numbers in Pico-8 are stored as 1:15:16 fixed-point—1 bit for the sign, 15 bits for the whole number, and 16 bits for the fractional component—which means that they all take up 32 bits of space in memory. The only difference between an integer and a number with a decimal is that the integer's bits after the decimal are set to zero.

Usually, the only reason you'd even care about memory footprint would be if you want to store something very large (e.g. an image, or a 3D model) in RAM and you need to compress it to save space. For example, if your data consists of numbers within a range of 0-255, you can represent them as 8-bit integers and then pack 4 of them into a single Pico-8 number.

P#35548 2017-01-12 15:44 ( Edited 2017-01-12 21:23)

Ah geez. Thanks for clearing that up for me. I have had some issues running out of memory when storing like more than a thousand tables in a list, but that was just me trying to see how many points I could connect with lines and not a real game situation

P#35670 2017-01-14 11:56 ( Edited 2017-01-14 16:56)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-15 23:38 | 0.013s | 4194k | Q:20