Ejemplo n.º 1
0
void GameTimerManager::Tick(float deltaTime)
{
	mAreTimersTicking = true;
	
	// Tick the active timers
	for (auto& t : mActiveTimers)
	{
		TimerInfo& timer = t.second;
		if (timer.mStatus == Active)
		{
			timer.mRemainingTime -= deltaTime;
			if (timer.mRemainingTime <= 0.0f)
			{
				// Trigger the timer
				timer.mDelegate->Execute();
				// Is this looping?
				if (timer.mIsLooping)
				{
					timer.mRemainingTime += timer.mDuration;
				}
				else
				{
					timer.mStatus = Cleared;
					mClearedTimers.push_back(timer.mHandle);
				}
			}
		}
	}

	// Remove any ended timers
	for (auto& h : mClearedTimers)
	{
		auto iter = mActiveTimers.find(h);
		if (iter != mActiveTimers.end())
		{
			RemoveFromObjMap(iter->second.mObj, h);
			mActiveTimers.erase(h);
		}
	}
	mClearedTimers.clear();

	// Add any pending timers
	for (auto& t : mPendingTimers)
	{
		TimerInfo& timer = t.second;
		if (timer.mStatus == Pending)
		{
			timer.mStatus = Active;
		}
		mActiveTimers.emplace(timer.mHandle, timer);
	}
	mPendingTimers.clear();

	mAreTimersTicking = false;
}
Ejemplo n.º 2
0
void GameTimerManager::ClearTimer(const TimerHandle& handle)
{
	// Is this pending?
	auto iter = mPendingTimers.find(handle);
	if (iter != mPendingTimers.end())
	{
		// We can just remove this from pending timers
		RemoveFromObjMap(iter->second.mObj, handle);
		mPendingTimers.erase(iter);
	}
	else
	{
		iter = mActiveTimers.find(handle);
		if (iter != mActiveTimers.end())
		{
			iter->second.mStatus = Cleared;
			mClearedTimers.push_back(handle);
		}
	}
}
Ejemplo n.º 3
0
void GameTimerManager::Tick(float deltaTime)
{
    mAreTimersTicking = true;
    for( auto& t : mActiveTimers)
    {
        t.second.mRemainingTime -= deltaTime;
        if(t.second.mRemainingTime <= 0.0f)
        {
            t.second.mDelegate->Execute();
            if(t.second.mIsLooping)
            {
                t.second.mRemainingTime = t.second.mDuration;
            }
            else
            {
                t.second.mStatus = Cleared;
                mClearedTimers.push_back(t.first);
            }
        }
    }
    for( auto& t : mClearedTimers)
    {
        auto iter = mActiveTimers.find(t);
        if( iter != mActiveTimers.end() )
        {
            RemoveFromObjMap(iter->second.mObj, t);
            mActiveTimers.erase(iter);
        }
    }
    mClearedTimers.clear();
    for( auto& t : mPendingTimers)
    {
        t.second.mStatus = Active;
        mActiveTimers.emplace(t.first, t.second);
    }
    mPendingTimers.clear();
    mAreTimersTicking = false;
}