Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_123 - Travail Pratique 001 - Simulation Système Planétaire
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_123 - Travail Pratique 001 - Simulation Système Planétaire
Commits
cf42040f
Commit
cf42040f
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Update drawing timing
parent
dc0f2b69
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+16
-26
16 additions, 26 deletions
main.c
with
16 additions
and
26 deletions
main.c
+
16
−
26
View file @
cf42040f
...
...
@@ -21,41 +21,31 @@ int main() {
return
EXIT_FAILURE
;
}
int32_t
time_elapsing_per_second
=
3600
*
24
*
365
;
int32_t
update_per_second
=
1000
;
printf
(
"%d
\n
"
,
time_elapsing_per_second
/
update_per_second
);
SolarSystem
*
solar_system
=
solar_system_create
(
time_elapsing_per_second
/
update_per_second
);
int32_t
hz
=
240
;
int32_t
a
=
0
;
int32_t
b
=
0
;
int32_t
elapsed_seconds
=
0
;
int32_t
time_elapsing_per_second
=
3600
*
24
*
100
;
int32_t
refresh_rate
=
240
;
int32_t
elapsed_time
=
0
;
double
sleep_duration
=
1
.
0
/
refresh_rate
*
1E9
;
SolarSystem
*
solar_system
=
solar_system_create
(
time_elapsing_per_second
/
refresh_rate
);
int64_t
tmp
=
time
(
NULL
)
%
1000
;
while
(
true
)
{
solar_system_update
(
solar_system
);
b
+=
1
;
if
((
double
)
b
>=
(
double
)
update_per_second
/
hz
*
(
a
+
1
))
{
a
+=
1
;
gfx_present
(
context
);
solar_system_draw
(
solar_system
,
context
);
if
(
b
>=
update_per_second
)
{
b
=
0
;
elapsed_seconds
+=
1
;
if
(
elapsed_time
%
refresh_rate
==
0
)
{
char
title
[
100
];
sprintf
(
title
,
"Solar System (%d)"
,
elapsed_
seconds
);
sprintf
(
title
,
"Solar System (%d
: %ld
)"
,
elapsed_
time
/
refresh_rate
,
(
time
(
NULL
)
-
tmp
)
%
1000
);
SDL_SetWindowTitle
(
context
->
window
,
title
);
}
if
(
a
%
hz
==
0
)
a
=
0
;
}
if
(
gfx_keypressed
()
==
SDLK_ESCAPE
)
break
;
struct
timespec
t
=
{.
tv_sec
=
0
,
.
tv_nsec
=
1
.
0
/
update_per_second
*
1E9
};
struct
timespec
t
=
{.
tv_sec
=
0
,
.
tv_nsec
=
sleep_duration
};
nanosleep
(
&
t
,
NULL
);
elapsed_time
+=
1
;
}
gfx_destroy
(
context
);
...
...
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