coastline 0.0.4
Loading...
Searching...
No Matches
racepacing.h
Go to the documentation of this file.
1#ifndef COASTLINE_PLATFORM_WIN_RACE_PACING_H
2#define COASTLINE_PLATFORM_WIN_RACE_PACING_H
3
4#include "common/frameclock.h"
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
17extern int g_dwRaceFrameCounter;
18
24extern unsigned g_dwLastFrameTimestamp;
30extern volatile unsigned g_dwRaceAccumulatedTime;
36extern int g_nRacePacingInterval;
42extern unsigned g_dwNextRaceFrameTime;
54extern unsigned g_dwLastRaceRenderTime;
60extern const unsigned g_adwRaceFrameIntervals[3];
61
63static inline void UpdateRaceFrameStatistics(void) {
64 unsigned now = GetHighResolutionTime();
65 unsigned elapsed = now - g_dwLastFrameTimestamp;
66 int sampleFrames = g_dwGameFpsSampleFrames;
67 int index = g_dwGameFpsFrameCountdown;
68 int i;
69
71 if (index < 0) {
72 for (i = 0; i < sampleFrames; i++) {
74 }
75 index = sampleFrames > 0 ? sampleFrames : 0;
76 }
77 g_dwRaceFrameCounter = (int)((unsigned)g_dwRaceFrameCounter + 1u);
78 if (g_dwRaceFrameCounter != 0) {
79 g_dwRaceAccumulatedTime += elapsed;
80 } else {
82 }
83 index = (int)((unsigned)index + 1u);
84 if (index >= sampleFrames) {
85 index = 0;
86 }
88 g_adwGameFpsFrameTimeSamples[index] = elapsed;
89}
90
92static inline void PaceRaceFrames(void) {
93 int rendered;
94 unsigned now;
95
101 return;
102 }
104 g_nRacePacingInterval = (int)((unsigned)g_nRacePacingInterval + 1u);
105 if (g_nRacePacingInterval > 2) {
107 }
113 }
114 return;
115 }
116 rendered = 1;
117 now = GetHighResolutionTime();
118 for (;;) {
119 unsigned lastRender = g_dwLastRaceRenderTime;
120 if ((now >= g_dwNextRaceFrameTime && now <= lastRender + 333u) || !rendered) {
121 break;
122 }
123 rendered = InterpolateFrameSnapshotsAndRender(lastRender + 333u < now);
124 now = GetHighResolutionTime();
125 if (rendered) {
128 }
129 }
130}
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif
The ticks of the frames of a race of the Boss Rally release, at 30 frames a second.
int g_dwGameFpsFrameCountdown
The game-loop sample written last, negative before the first loop.
int g_dwGameFpsSampleFrames
The number of game-loop durations averaged for the game frame rate.
u32 GetHighResolutionTime(void)
The time since the first call, from the performance counter in milliseconds rounded to the nearest,...
unsigned g_adwGameFpsFrameTimeSamples[GAME_FPS_FRAME_TIME_SAMPLE_COUNT]
Recent game-loop durations in milliseconds.
static void UpdateRaceFrameStatistics(void)
Record the duration of the preceding game loop.
Definition racepacing.h:63
unsigned g_dwLastRaceRenderTime
The time a snapshot was last drawn, in milliseconds.
unsigned g_dwLastFrameTimestamp
The time of the preceding game loop, in milliseconds.
volatile unsigned g_dwRaceAccumulatedTime
The milliseconds the race has run since its first frame.
unsigned g_dwNextRaceFrameTime
The time the next game frame is due, in milliseconds.
static void PaceRaceFrames(void)
Render interpolated snapshots until the next game frame is due.
Definition racepacing.h:92
const unsigned g_adwRaceFrameIntervals[3]
The milliseconds of three game frames in turn, a tenth of a second together.
int g_nRaceFramesWithoutRender
The game frames run since a snapshot was last drawn.
int g_nRacePacingInterval
The entry of g_adwRaceFrameIntervals that paces the next frame.
int g_dwRaceFrameCounter
The frame of the race, -1 before the first.
int InterpolateFrameSnapshotsAndRender(int forceRender)
Blend captured race frames and render the result, marking the referenced pool slots in use.
int g_bFrameTimerReset
Whether race timing must restart when simulation resumes after a pause or initialisation.