Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glow-extras
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonathan Kunstwald
glow-extras
Commits
09f52dfd
Commit
09f52dfd
authored
7 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
Made update routine in mainLoop more robust
parent
edffb3ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
glfw/glow-extras/glfw/GlfwApp.cc
+50
-24
50 additions, 24 deletions
glfw/glow-extras/glfw/GlfwApp.cc
glfw/glow-extras/glfw/GlfwApp.hh
+1
-1
1 addition, 1 deletion
glfw/glow-extras/glfw/GlfwApp.hh
with
51 additions
and
25 deletions
glfw/glow-extras/glfw/GlfwApp.cc
+
50
−
24
View file @
09f52dfd
...
...
@@ -324,28 +324,31 @@ void GlfwApp::mainLoop()
double
lastTime
=
glfwGetTime
();
double
lastStatsTime
=
lastTime
;
double
timeAccum
=
0.000001
;
double
renderTimestep
=
1.0
/
mUpdateRate
;
mCurrentTime
=
0.0
;
size_t
primitives
=
0
;
size_t
fragments
=
0
;
double
gpuTime
=
0
;
double
cpuTime
=
0
;
int
updatesPerFrame
=
1
;
double
renderTimestep
=
1.0
/
mUpdateRate
;
// tracks time between renders, init is for first frame only
while
(
!
shouldClose
())
{
updateInput
();
// Update
auto
maxTicks
=
mMaxFrameSkip
;
while
(
timeAccum
>
0
)
{
if
(
maxTicks
--
<
0
)
{
glow
::
warning
()
<<
"Too many updates queued, frame skip of "
<<
timeAccum
<<
" secs"
;
timeAccum
=
0.0
;
break
;
}
double
dt
=
1.0
/
mUpdateRate
;
// # of updates
auto
updates
=
updatesPerFrame
;
if
(
timeAccum
>
updatesPerFrame
*
dt
)
// lags one behind: do one more
++
updates
;
if
(
timeAccum
<
-
dt
)
// is more than one ahead: skip one
--
updates
;
auto
dt
=
1.0
/
mUpdateRate
;
// do updates
for
(
auto
i
=
0
;
i
<
updates
;
++
i
)
{
auto
cpuStart
=
glfwGetTime
();
update
(
dt
);
cpuTime
+=
glfwGetTime
()
-
cpuStart
;
...
...
@@ -353,6 +356,29 @@ void GlfwApp::mainLoop()
mCurrentTime
+=
dt
;
}
// update adjustment (AFTER updates! timeAccum should be within -dt..dt now)
if
(
timeAccum
>
2.5
*
dt
)
{
++
updatesPerFrame
;
// glow::info() << "increasing frames per sec";
}
else
if
(
timeAccum
<
-
2.5
*
dt
)
{
if
(
updatesPerFrame
>
0
)
--
updatesPerFrame
;
// glow::info() << "decreasing frames per sec";
}
// frameskip
if
(
timeAccum
>
mMaxFrameSkip
*
dt
)
{
glow
::
warning
()
<<
"Too many updates queued, frame skip of "
<<
timeAccum
<<
" secs"
;
timeAccum
=
mMaxFrameSkip
*
dt
*
0.5
;
}
// glow::info() << updates << ", " << timeAccum / dt;
}
beginRender
();
// Render here
...
...
This diff is collapsed.
Click to expand it.
glfw/glow-extras/glfw/GlfwApp.hh
+
1
−
1
View file @
09f52dfd
...
...
@@ -79,7 +79,7 @@ class GlfwApp
private:
std
::
string
mTitle
=
"GLFW/GLOW Application"
;
///< window title
int
mUpdateRate
=
60
;
///< rate at which update(...) is called
double
mUpdateRate
=
60
;
///< rate at which update(...) is called
int
mMaxFrameSkip
=
4
;
///< maximum number of update(...) steps that are performed without rendering
GLFWwindow
*
mWindow
=
nullptr
;
///< current GLFW window
...
...
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