fixed bugs
This commit is contained in:
parent
05450175a3
commit
9537a5b50d
|
|
@ -59,7 +59,7 @@ void e2d::Time::__updateLast()
|
|||
|
||||
s_tNow = steady_clock::now();
|
||||
s_nInterval = static_cast<int>(duration_cast<milliseconds>(s_tNow - s_tLastUpdate).count());
|
||||
s_fTotalTime = static_cast<double>(duration_cast<milliseconds>(s_tNow - s_tStart).count()) / 1000.0f;
|
||||
s_fTotalTime = static_cast<double>(duration_cast<milliseconds>(s_tNow - s_tStart).count()) / 1000.0;
|
||||
}
|
||||
|
||||
void e2d::Time::__sleep()
|
||||
|
|
|
|||
|
|
@ -16,15 +16,43 @@ e2d::Timer::Timer()
|
|||
TimerManager::add(this);
|
||||
}
|
||||
|
||||
e2d::Timer::Timer(const String & name, const TimerCallback & callback, double interval /* = 0 */, int repeatTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */)
|
||||
: Timer()
|
||||
e2d::Timer::Timer(const TimerCallback & callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */)
|
||||
: m_bRunning(false)
|
||||
, m_nRunTimes(0)
|
||||
, m_Callback(nullptr)
|
||||
, m_fInterval(0)
|
||||
, m_fLast(0)
|
||||
, m_nUpdateTimes(-1)
|
||||
, m_bAtOnce(false)
|
||||
, m_bAutoRelease(false)
|
||||
, m_bClear(false)
|
||||
{
|
||||
this->setName(name);
|
||||
this->setCallback(callback);
|
||||
this->setUpdateTimes(repeatTimes);
|
||||
this->setUpdateTimes(updateTimes);
|
||||
this->setInterval(interval);
|
||||
m_bAutoRelease = autoRelease;
|
||||
m_bAtOnce = atOnce;
|
||||
TimerManager::add(this);
|
||||
}
|
||||
|
||||
e2d::Timer::Timer(const String & name, const TimerCallback & callback, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */)
|
||||
: m_bRunning(false)
|
||||
, m_nRunTimes(0)
|
||||
, m_Callback(nullptr)
|
||||
, m_fInterval(0)
|
||||
, m_fLast(0)
|
||||
, m_nUpdateTimes(-1)
|
||||
, m_bAtOnce(false)
|
||||
, m_bAutoRelease(false)
|
||||
, m_bClear(false)
|
||||
{
|
||||
this->setName(name);
|
||||
this->setCallback(callback);
|
||||
this->setUpdateTimes(updateTimes);
|
||||
this->setInterval(interval);
|
||||
m_bAutoRelease = autoRelease;
|
||||
m_bAtOnce = atOnce;
|
||||
TimerManager::add(this);
|
||||
}
|
||||
|
||||
bool e2d::Timer::isRunning() const
|
||||
|
|
@ -69,9 +97,10 @@ void e2d::Timer::setCallback(const TimerCallback & callback)
|
|||
m_Callback = callback;
|
||||
}
|
||||
|
||||
void e2d::Timer::setUpdateTimes(int repeatTimes)
|
||||
void e2d::Timer::setUpdateTimes(int updateTimes)
|
||||
{
|
||||
m_nUpdateTimes = repeatTimes;
|
||||
m_nUpdateTimes = updateTimes;
|
||||
m_bClear = (m_nUpdateTimes == 0);
|
||||
}
|
||||
|
||||
void e2d::Timer::setRunAtOnce(bool bAtOnce)
|
||||
|
|
@ -81,7 +110,7 @@ void e2d::Timer::setRunAtOnce(bool bAtOnce)
|
|||
|
||||
void e2d::Timer::update()
|
||||
{
|
||||
if (m_Callback && m_nRunTimes < m_nUpdateTimes)
|
||||
if (m_Callback)
|
||||
{
|
||||
m_Callback();
|
||||
}
|
||||
|
|
@ -89,7 +118,7 @@ void e2d::Timer::update()
|
|||
m_nRunTimes++;
|
||||
m_fLast += m_fInterval;
|
||||
|
||||
if (m_nRunTimes >= m_nUpdateTimes)
|
||||
if (m_nRunTimes == m_nUpdateTimes)
|
||||
{
|
||||
if (m_bAutoRelease)
|
||||
{
|
||||
|
|
@ -104,7 +133,7 @@ void e2d::Timer::update()
|
|||
|
||||
bool e2d::Timer::isReady() const
|
||||
{
|
||||
if (m_bRunning)
|
||||
if (m_bRunning && !m_bClear)
|
||||
{
|
||||
if (m_bAtOnce && m_nRunTimes == 0)
|
||||
return true;
|
||||
|
|
@ -113,9 +142,7 @@ bool e2d::Timer::isReady() const
|
|||
return true;
|
||||
|
||||
if ((Time::getTotalTime() - m_fLast) >= m_fInterval)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ class Timer :
|
|||
public:
|
||||
Timer();
|
||||
|
||||
Timer(
|
||||
const TimerCallback &callback, /* 定时器回调函数 */
|
||||
double interval = 0, /* 时间间隔(秒) */
|
||||
int times = -1, /* 执行次数(设 -1 为永久执行) */
|
||||
bool atOnce = false, /* 是否立即执行 */
|
||||
bool autoRelease = false /* 自动清除 */
|
||||
);
|
||||
|
||||
Timer(
|
||||
const String &name, /* 定时器名称 */
|
||||
const TimerCallback &callback, /* 定时器回调函数 */
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@
|
|||
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Scene.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Size.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\String.cpp" />
|
||||
<ClCompile Include="..\..\core\Manager\ActionManager.cpp" />
|
||||
<ClCompile Include="..\..\core\Manager\MusicManager.cpp" />
|
||||
|
|
|
|||
|
|
@ -191,5 +191,11 @@
|
|||
<ClCompile Include="..\..\core\Shape\Rect.cpp">
|
||||
<Filter>Shape</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Common\Point.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Common\Size.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -193,7 +193,9 @@
|
|||
<ClCompile Include="..\..\core\Common\Font.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Image.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Scene.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\Size.cpp" />
|
||||
<ClCompile Include="..\..\core\Common\String.cpp" />
|
||||
<ClCompile Include="..\..\core\Manager\ActionManager.cpp" />
|
||||
<ClCompile Include="..\..\core\Manager\MusicManager.cpp" />
|
||||
|
|
|
|||
|
|
@ -192,5 +192,11 @@
|
|||
<ClCompile Include="..\..\core\Shape\Rect.cpp">
|
||||
<Filter>Shape</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Common\Point.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Common\Size.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue