Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
4ccba2a9
Commit
4ccba2a9
authored
1 year ago
by
Sal
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-inaccurate-fps-counter' into 'next'
Fix inaccuracies in FPS counter Closes
#1047
See merge request
!2047
parents
08c6e76d
e3824b9f
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/screen.c
+8
-30
8 additions, 30 deletions
src/screen.c
with
8 additions
and
30 deletions
src/screen.c
+
8
−
30
View file @
4ccba2a9
...
@@ -478,11 +478,11 @@ double averageFPS = 0.0f;
...
@@ -478,11 +478,11 @@ double averageFPS = 0.0f;
#define USE_FPS_SAMPLES
#define USE_FPS_SAMPLES
#ifdef USE_FPS_SAMPLES
#ifdef USE_FPS_SAMPLES
#define
FPS_SAMPLE_RAT
E
(
0.05
) // How often to update FPS samples, in seconds
#define
MAX_FRAME_TIM
E 0.05
#define NUM_FPS_SAMPLES (16) // Number of samples to store
#define NUM_FPS_SAMPLES (16) // Number of samples to store
static
double
fps_samples
[
NUM_FPS_SAMPLES
]
;
static
double
total_frame_time
=
0
.
0
;
static
double
updateElapsed
=
0
.
0
;
static
int
frame_index
;
#endif
#endif
static
boolean
fps_init
=
false
;
static
boolean
fps_init
=
false
;
...
@@ -505,34 +505,12 @@ void SCR_CalculateFPS(void)
...
@@ -505,34 +505,12 @@ void SCR_CalculateFPS(void)
fps_enter
=
fps_finish
;
fps_enter
=
fps_finish
;
#ifdef USE_FPS_SAMPLES
#ifdef USE_FPS_SAMPLES
updateElapsed
+=
frameElapsed
;
total_frame_time
+=
frameElapsed
;
if
(
frame_index
++
>=
NUM_FPS_SAMPLES
||
total_frame_time
>=
MAX_FRAME_TIME
)
if
(
updateElapsed
>=
FPS_SAMPLE_RATE
)
{
static
int
sampleIndex
=
0
;
int
i
;
fps_samples
[
sampleIndex
]
=
frameElapsed
;
sampleIndex
++
;
if
(
sampleIndex
>=
NUM_FPS_SAMPLES
)
sampleIndex
=
0
;
averageFPS
=
0
.
0
;
for
(
i
=
0
;
i
<
NUM_FPS_SAMPLES
;
i
++
)
{
averageFPS
+=
fps_samples
[
i
];
}
if
(
averageFPS
>
0
.
0
)
{
averageFPS
=
1
.
0
/
(
averageFPS
/
NUM_FPS_SAMPLES
);
}
}
while
(
updateElapsed
>=
FPS_SAMPLE_RATE
)
{
{
updateElapsed
-=
FPS_SAMPLE_RATE
;
averageFPS
=
1
.
0
/
(
total_frame_time
/
frame_index
);
total_frame_time
=
0
.
0
;
frame_index
=
0
;
}
}
#else
#else
// Direct, unsampled counter.
// Direct, unsampled counter.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment