Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
dcbe0949
Commit
dcbe0949
authored
1 year ago
by
q3k
Browse files
Options
Downloads
Patches
Plain Diff
demo_worms: add primitive frame limiter
parent
5a4c0c3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/demo_worms.py
+25
-1
25 additions, 1 deletion
python_payload/demo_worms.py
with
25 additions
and
1 deletion
python_payload/demo_worms.py
+
25
−
1
View file @
dcbe0949
...
...
@@ -85,13 +85,37 @@ def init():
worms
.
append
(
Worm
())
ctx
=
hardware
.
get_ctx
()
# TODO(q3k): factor out frame limiter
last_render
=
None
target_fps
=
30
target_delta
=
1000
/
target_fps
frame_slack
=
None
last_report
=
None
def
run
():
global
last_render
global
last_report
global
frame_slack
now
=
time
.
ticks_ms
()
if
last_render
is
not
None
:
delta
=
now
-
last_render
if
frame_slack
is
None
:
frame_slack
=
target_delta
-
delta
if
delta
<
target_delta
:
return
if
last_report
is
None
or
(
now
-
last_report
)
>
1000
:
fps
=
1000
/
delta
print
(
f
'
fps:
{
fps
:
.
3
}
, frame budget slack:
{
frame_slack
:
.
3
}
ms
'
)
last_report
=
now
# Simulation is currently locked to FPS.
global
worms
for
w
in
worms
:
w
.
draw
()
w
.
move
()
hardware
.
display_update
()
time
.
sleep
(
0.001
)
last_render
=
now
def
foreground
():
...
...
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