Page MenuHomePhorge

FrameRateLimiter.h
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

FrameRateLimiter.h

#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

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)

Event Timeline