Skip to content

Commit 64c4e4d

Browse files
committed
Use integer math instead of floats for timestamps
1 parent 76b9868 commit 64c4e4d

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

code/freespace2/freespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4871,7 +4871,7 @@ void game_set_frametime(int state)
48714871
Last_frame_timestamp = timestamp();
48724872

48734873
flFrametime = f2fl(Frametime);
4874-
timestamp_inc(flFrametime);
4874+
timestamp_inc(Frametime);
48754875

48764876
// wrap overall frametime if needed
48774877
if ( FrametimeOverall > (INT_MAX - F1_0) )

code/io/timer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ void timestamp_reset()
214214
// something like 1 minute (6000).
215215
#define MAX_TIME (INT_MAX/2)
216216

217-
void timestamp_inc(float frametime)
217+
void timestamp_inc(fix frametime)
218218
{
219-
timestamp_ticker += (int)(frametime*TIMESTAMP_FREQUENCY);
219+
auto frametime_ms = fixmul(frametime, F1_0 * TIMESTAMP_FREQUENCY);
220+
timestamp_ticker += f2i(frametime_ms);
220221

221222
if ( timestamp_ticker > MAX_TIME ) {
222223
timestamp_ticker = 2; // Roll!

code/io/timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extern int timestamp_ticker;
7373
extern void timestamp_reset();
7474

7575
// Call this once every frame with the frametime.
76-
extern void timestamp_inc(float frametime);
76+
extern void timestamp_inc(fix frametime);
7777

7878
// To do timing, call this with the interval you
7979
// want to check. Then, pass this to timestamp_elapsed

0 commit comments

Comments
 (0)