Log In  


I've seen many approaches to combat the limited accuracy of the maths functions, time() due to the fixed point number size limit of 32,768

Given that all of this must have been solved during the 8-bit era are there any best practices or recommended solutions we should know about?



In the 8-bit area, we were happy if we only had to code 16 bit functionality into the 8-bit cores ;).


Well, I've implemented my own counter that I reset every so often. The code is as follows:

frames=0
sec=0
min=0
hr=0

function _update
frames+=1
if frames>30 then
frames=0
sec+=1
end

if sec>59 then
sec=0
min+=1
end

if min>59 then
min=0
hr+=1
end
end

This way you get nice "clock" that will easily tell you how much time game is running for, down to the frames. And it would only fail after 32678 hours, which frankly, no pico8 game will be really ran for. And if you expect to run it for that long or longer, you can implement days counter in similar way.

I believe this is similar to how it was done in 8-bit days (and since I've recently been fiddling with devving both for bbc micro and zx spectrum, I know thing or two) - if a byte is about to overflow, zero it and add whatever was the carried over to another byte. Repeat for how many bytes you need to represent whatever maximum value you want.


It might be safest to avoid "dropping" frames

if t>30 then 
 t-=31
 sec+=1
end

edited to reflect original amounts


True, but in this case dropping would never happen since we always increase by 1, each frame.



[Please log in to post a comment]