Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
85ad17e7
Commit
85ad17e7
authored
Mar 25, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added high resolution timing API: SDL_GetPerformanceCounter(), SDL_GetPerformanceFrequency()
parent
98e5ddb3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
127 additions
and
1 deletion
+127
-1
SDL_timer.h
include/SDL_timer.h
+10
-0
SDL_systimer.c
src/timer/beos/SDL_systimer.c
+12
-0
SDL_systimer.c
src/timer/dummy/SDL_systimer.c
+12
-0
SDL_systimer.c
src/timer/nds/SDL_systimer.c
+12
-0
SDL_systimer.c
src/timer/unix/SDL_systimer.c
+36
-0
SDL_systimer.c
src/timer/wince/SDL_systimer.c
+12
-0
SDL_systimer.c
src/timer/windows/SDL_systimer.c
+22
-0
testtimer.c
test/testtimer.c
+11
-1
No files found.
include/SDL_timer.h
View file @
85ad17e7
...
@@ -47,6 +47,16 @@ extern "C" {
...
@@ -47,6 +47,16 @@ extern "C" {
*/
*/
extern
DECLSPEC
Uint32
SDLCALL
SDL_GetTicks
(
void
);
extern
DECLSPEC
Uint32
SDLCALL
SDL_GetTicks
(
void
);
/**
* \brief Get the current value of the high resolution counter
*/
extern
DECLSPEC
Uint64
SDLCALL
SDL_GetPerformanceCounter
(
void
);
/**
* \brief Get the count per second of the high resolution counter
*/
extern
DECLSPEC
Uint64
SDLCALL
SDL_GetPerformanceFrequency
(
void
);
/**
/**
* \brief Wait a specified number of milliseconds before returning.
* \brief Wait a specified number of milliseconds before returning.
*/
*/
...
...
src/timer/beos/SDL_systimer.c
View file @
85ad17e7
...
@@ -42,6 +42,18 @@ SDL_GetTicks(void)
...
@@ -42,6 +42,18 @@ SDL_GetTicks(void)
return
((
system_time
()
-
start
)
/
1000
);
return
((
system_time
()
-
start
)
/
1000
);
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
return
system_time
();
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
return
1000000
;
}
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
{
{
...
...
src/timer/dummy/SDL_systimer.c
View file @
85ad17e7
...
@@ -37,6 +37,18 @@ SDL_GetTicks(void)
...
@@ -37,6 +37,18 @@ SDL_GetTicks(void)
return
0
;
return
0
;
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
return
SDL_GetTicks
();
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
return
1000
;
}
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
{
{
...
...
src/timer/nds/SDL_systimer.c
View file @
85ad17e7
...
@@ -52,6 +52,18 @@ SDL_GetTicks(void)
...
@@ -52,6 +52,18 @@ SDL_GetTicks(void)
return
timer_ticks
;
return
timer_ticks
;
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
return
SDL_GetTicks
();
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
return
1000
;
}
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
{
{
...
...
src/timer/unix/SDL_systimer.c
View file @
85ad17e7
...
@@ -64,6 +64,7 @@ SDL_GetTicks(void)
...
@@ -64,6 +64,7 @@ SDL_GetTicks(void)
#if HAVE_CLOCK_GETTIME
#if HAVE_CLOCK_GETTIME
Uint32
ticks
;
Uint32
ticks
;
struct
timespec
now
;
struct
timespec
now
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
now
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
now
);
ticks
=
ticks
=
(
now
.
tv_sec
-
start
.
tv_sec
)
*
1000
+
(
now
.
tv_nsec
-
(
now
.
tv_sec
-
start
.
tv_sec
)
*
1000
+
(
now
.
tv_nsec
-
...
@@ -72,6 +73,7 @@ SDL_GetTicks(void)
...
@@ -72,6 +73,7 @@ SDL_GetTicks(void)
#else
#else
Uint32
ticks
;
Uint32
ticks
;
struct
timeval
now
;
struct
timeval
now
;
gettimeofday
(
&
now
,
NULL
);
gettimeofday
(
&
now
,
NULL
);
ticks
=
ticks
=
(
now
.
tv_sec
-
start
.
tv_sec
)
*
1000
+
(
now
.
tv_usec
-
(
now
.
tv_sec
-
start
.
tv_sec
)
*
1000
+
(
now
.
tv_usec
-
...
@@ -80,6 +82,40 @@ SDL_GetTicks(void)
...
@@ -80,6 +82,40 @@ SDL_GetTicks(void)
#endif
#endif
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
#if HAVE_CLOCK_GETTIME
Uint64
ticks
;
struct
timespec
now
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
now
);
ticks
=
now
.
tv_sec
;
ticks
*=
1000000000
;
ticks
+=
now
.
tv_nsec
;
return
(
ticks
);
#else
Uint64
ticks
;
struct
timeval
now
;
gettimeofday
(
&
now
,
NULL
);
ticks
=
now
.
tv_sec
;
ticks
*=
1000000
;
ticks
+=
now
.
tv_usec
;
return
(
ticks
);
#endif
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
#if HAVE_CLOCK_GETTIME
return
1000000000
;
#else
return
1000000
;
#endif
}
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
{
{
...
...
src/timer/wince/SDL_systimer.c
View file @
85ad17e7
...
@@ -87,6 +87,18 @@ SDL_GetTicks()
...
@@ -87,6 +87,18 @@ SDL_GetTicks()
return
((
Uint32
)
wce_rel_ticks
());
return
((
Uint32
)
wce_rel_ticks
());
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
return
SDL_GetTicks
();
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
return
1000
;
}
/* Give up approx. givem milliseconds to the OS. */
/* Give up approx. givem milliseconds to the OS. */
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
...
...
src/timer/windows/SDL_systimer.c
View file @
85ad17e7
...
@@ -99,6 +99,28 @@ SDL_GetTicks(void)
...
@@ -99,6 +99,28 @@ SDL_GetTicks(void)
return
(
ticks
);
return
(
ticks
);
}
}
Uint64
SDL_GetPerformanceCounter
(
void
)
{
LARGE_INTEGER
counter
;
if
(
!
QueryPerformanceCounter
(
&
counter
))
{
return
SDL_GetTicks
();
}
return
counter
.
QuadPart
;
}
Uint64
SDL_GetPerformanceFrequency
(
void
)
{
LARGE_INTEGER
frequency
;
if
(
!
QueryPerformanceFrequency
(
&
frequency
))
{
return
1000
;
}
return
frequency
.
QuadPart
;
}
void
void
SDL_Delay
(
Uint32
ms
)
SDL_Delay
(
Uint32
ms
)
{
{
...
...
test/testtimer.c
View file @
85ad17e7
...
@@ -29,8 +29,9 @@ callback(Uint32 interval, void *param)
...
@@ -29,8 +29,9 @@ callback(Uint32 interval, void *param)
int
int
main
(
int
argc
,
char
*
argv
[])
main
(
int
argc
,
char
*
argv
[])
{
{
int
desired
;
int
i
,
desired
;
SDL_TimerID
t1
,
t2
,
t3
;
SDL_TimerID
t1
,
t2
,
t3
;
Uint64
start
,
now
;
if
(
SDL_Init
(
SDL_INIT_TIMER
)
<
0
)
{
if
(
SDL_Init
(
SDL_INIT_TIMER
)
<
0
)
{
fprintf
(
stderr
,
"Couldn't initialize SDL: %s
\n
"
,
SDL_GetError
());
fprintf
(
stderr
,
"Couldn't initialize SDL: %s
\n
"
,
SDL_GetError
());
...
@@ -85,6 +86,15 @@ main(int argc, char *argv[])
...
@@ -85,6 +86,15 @@ main(int argc, char *argv[])
SDL_RemoveTimer
(
t2
);
SDL_RemoveTimer
(
t2
);
SDL_RemoveTimer
(
t3
);
SDL_RemoveTimer
(
t3
);
start
=
SDL_GetPerformanceCounter
();
for
(
i
=
0
;
i
<
1000000
;
++
i
)
{
ticktock
(
0
);
}
now
=
SDL_GetPerformanceCounter
();
printf
(
"1 million iterations of ticktock took %f ms
\n
"
,
(
double
)((
now
-
start
)
*
1000
)
/
SDL_GetPerformanceFrequency
());
SDL_Quit
();
SDL_Quit
();
return
(
0
);
return
(
0
);
}
}
/* vi: set ts=4 sw=4 expandtab: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment