I am trying to achieve a counter that will count how many seconds have passed in my game. It’s only seconds based and I need it for a game server project. All I want to do, literally all I want to do is 0 + 0.2
and then next tick 0.2+0.2
, 0.4+0.2
… This cannot be achieved with floats as eventually it will be 1.99999999998 instead of 2 and that would ruin the calculations. I’ve looked into Big Int, fixed precision libraries but I am not sure what should I use. I don’t want too much overhead as this is called 5-10 times a second. A simple 0 + 0.2
would work perfectly and that way I can get whether or not a second or half a second has passed and I can store the previous time in a simple number.
Idea is that player would have a timestamp of when the last action was performed, I’d check against the time if X time has passed ( time- lastTime > X
) and then if that’s true I’d perform something. I have access to the servers tick rate which I set to 0.2. I can always go with OS time if nothing else. Any recommendations on what to do?