Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F129942
FrameRateLimiter.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
FrameRateLimiter.h
View Options
#ifndef _ECHOFRAMERATELIMITER_H_
#define _ECHOFRAMERATELIMITER_H_
#include
<echo/Chrono/Chrono.h>
#include
<boost/timer/timer.hpp>
#include
<boost/thread.hpp>
namespace
Echo
{
class
FrameRateLimiter
{
public
:
FrameRateLimiter
(
Seconds
minFrameTime
,
Seconds
maxFrameTime
)
:
mMinFrameTime
(
minFrameTime
),
mMaxFrameTime
(
maxFrameTime
)
{
}
void
Start
()
{
mFrameTimer
.
start
();
}
inline
Seconds
GetLastFrameTime
()
{
mLastFrameTime
=
Nanoseconds
(
mFrameTimer
.
elapsed
().
wall
);
if
(
mLastFrameTime
>
mMaxFrameTime
)
{
mLastFrameTime
=
mMaxFrameTime
;
}
mFrameTimer
.
start
();
return
mLastFrameTime
;
}
inline
void
Limit
()
{
//The thread needs to stop processing for the minframetime-lastFrameTime.
Seconds
sleepTime
=
mMinFrameTime
-
mLastFrameTime
;
if
(
sleepTime
>
Seconds
(
0.
))
{
boost
::
this_thread
::
sleep_for
(
sleepTime
);
}
}
void
SetMMaxFrameTime
(
Seconds
maxFrameTime
)
{
mMaxFrameTime
=
maxFrameTime
;
}
const
Seconds
&
GetMaxFrameTime
()
const
{
return
mMaxFrameTime
;
}
void
SetMinFrameTime
(
const
Seconds
&
minFrameTime
)
{
mMinFrameTime
=
minFrameTime
;
}
const
Seconds
&
GetMinFrameTime
()
const
{
return
mMinFrameTime
;
}
private
:
Seconds
mMinFrameTime
;
Seconds
mMaxFrameTime
;
Seconds
mLastFrameTime
;
boost
::
timer
::
cpu_timer
mFrameTimer
;
};
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sun, May 18, 8:31 PM (1 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
76941
Default Alt Text
FrameRateLimiter.h (1 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment