TimerInfo重命名为TimerEntity,并加入e2d namespace
This commit is contained in:
parent
f91973255d
commit
384f332b6d
|
|
@ -1,73 +1,76 @@
|
||||||
#include "..\e2dtool.h"
|
#include "..\e2dtool.h"
|
||||||
#include "..\e2dnode.h"
|
#include "..\e2dnode.h"
|
||||||
|
|
||||||
class TimerInfo
|
namespace e2d
|
||||||
{
|
{
|
||||||
public:
|
class TimerEntity
|
||||||
TimerInfo(
|
|
||||||
const e2d::Function& func,
|
|
||||||
const e2d::String& name,
|
|
||||||
double delay,
|
|
||||||
int updateTimes,
|
|
||||||
bool paused
|
|
||||||
)
|
|
||||||
: running(!paused)
|
|
||||||
, stopped(false)
|
|
||||||
, runTimes(0)
|
|
||||||
, totalTimes(updateTimes)
|
|
||||||
, delay(max(delay, 0))
|
|
||||||
, lastTime(e2d::Time::getTotalTime())
|
|
||||||
, callback(func)
|
|
||||||
, name(name)
|
|
||||||
{
|
{
|
||||||
}
|
public:
|
||||||
|
TimerEntity(
|
||||||
void update()
|
const e2d::Function& func,
|
||||||
{
|
const e2d::String& name,
|
||||||
if (callback)
|
double delay,
|
||||||
|
int updateTimes,
|
||||||
|
bool paused
|
||||||
|
)
|
||||||
|
: running(!paused)
|
||||||
|
, stopped(false)
|
||||||
|
, runTimes(0)
|
||||||
|
, totalTimes(updateTimes)
|
||||||
|
, delay(max(delay, 0))
|
||||||
|
, lastTime(e2d::Time::getTotalTime())
|
||||||
|
, callback(func)
|
||||||
|
, name(name)
|
||||||
{
|
{
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++runTimes;
|
void update()
|
||||||
lastTime += delay;
|
|
||||||
|
|
||||||
if (runTimes == totalTimes)
|
|
||||||
{
|
{
|
||||||
stopped = true;
|
if (callback)
|
||||||
}
|
{
|
||||||
}
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
bool ready()
|
++runTimes;
|
||||||
{
|
lastTime += delay;
|
||||||
if (this->running)
|
|
||||||
|
if (runTimes == totalTimes)
|
||||||
|
{
|
||||||
|
stopped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ready()
|
||||||
{
|
{
|
||||||
if (this->delay == 0)
|
if (this->running)
|
||||||
return true;
|
{
|
||||||
|
if (this->delay == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
if ((e2d::Time::getTotalTime() - this->lastTime) >= this->delay)
|
if ((e2d::Time::getTotalTime() - this->lastTime) >= this->delay)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool running;
|
bool running;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
int runTimes;
|
int runTimes;
|
||||||
int totalTimes;
|
int totalTimes;
|
||||||
double delay;
|
double delay;
|
||||||
double lastTime;
|
double lastTime;
|
||||||
e2d::String name;
|
e2d::String name;
|
||||||
e2d::Function callback;
|
e2d::Function callback;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static std::vector<TimerInfo*> s_vTimers;
|
static std::vector<e2d::TimerEntity*> s_vTimers;
|
||||||
|
|
||||||
|
|
||||||
void e2d::Timer::start(const Function& func, double delay, int updateTimes, bool paused, const String& name)
|
void e2d::Timer::start(const Function& func, double delay, int updateTimes, bool paused, const String& name)
|
||||||
{
|
{
|
||||||
auto timer = new (std::nothrow) TimerInfo(func, name, delay, updateTimes, paused);
|
auto timer = new (std::nothrow) TimerEntity(func, name, delay, updateTimes, paused);
|
||||||
s_vTimers.push_back(timer);
|
s_vTimers.push_back(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +81,7 @@ void e2d::Timer::start(const Function& func, const String& name)
|
||||||
|
|
||||||
void e2d::Timer::startOnce(const Function& func, double timeOut)
|
void e2d::Timer::startOnce(const Function& func, double timeOut)
|
||||||
{
|
{
|
||||||
auto timer = new (std::nothrow) TimerInfo(func, L"", timeOut, 1, false);
|
auto timer = new (std::nothrow) TimerEntity(func, L"", timeOut, 1, false);
|
||||||
s_vTimers.push_back(timer);
|
s_vTimers.push_back(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue