mirror of
https://github.com/0TheSpy/Seaside.git
synced 2025-01-10 19:22:10 +08:00
50 lines
746 B
C++
50 lines
746 B
C++
#ifndef TIMEDEVENT_H
|
|
#define TIMEDEVENT_H
|
|
#ifdef _WIN32
|
|
#pragma once
|
|
#endif
|
|
|
|
class TimedEvent
|
|
{
|
|
public:
|
|
TimedEvent()
|
|
{
|
|
m_TimeBetweenEvents = -1;
|
|
m_fNextEvent = 0;
|
|
}
|
|
|
|
inline void Init(float rate)
|
|
{
|
|
m_TimeBetweenEvents = 1.0f / rate;
|
|
m_fNextEvent = 0;
|
|
}
|
|
|
|
inline void ResetRate(float rate)
|
|
{
|
|
m_TimeBetweenEvents = 1.0f / rate;
|
|
}
|
|
|
|
inline bool NextEvent(float& curDelta)
|
|
{
|
|
Assert(m_TimeBetweenEvents != -1);
|
|
|
|
if (curDelta >= m_fNextEvent)
|
|
{
|
|
curDelta -= m_fNextEvent;
|
|
|
|
m_fNextEvent = m_TimeBetweenEvents;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
m_fNextEvent -= curDelta;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private:
|
|
float m_TimeBetweenEvents;
|
|
float m_fNextEvent;
|
|
};
|
|
|
|
#endif |