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?

P#21949 2016-05-31 17:08 ( Edited 2016-05-31 23:58)

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

P#21951 2016-05-31 17:19 ( Edited 2016-05-31 21:19)

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.

P#21967 2016-05-31 18:40 ( Edited 2016-05-31 23:57)

It might be safest to avoid "dropping" frames

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

edited to reflect original amounts

P#21980 2016-05-31 19:51 ( Edited 2016-05-31 23:54)

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

P#21981 2016-05-31 19:58 ( Edited 2016-05-31 23:58)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 23:41:07 | 0.006s | Q:16