void FTimerManager::InternalUnPauseTimer(FTimerUnifiedDelegate const& InDelegate)
{
	// not currently threadsafe
	check(IsInGameThread());

	int32 PausedTimerIdx = FindTimerInList(PausedTimerList, InDelegate);
	if (PausedTimerIdx != INDEX_NONE)
	{
		FTimerData& TimerToUnPause = PausedTimerList[PausedTimerIdx];
		check(TimerToUnPause.Status == ETimerStatus::Paused);

		// Move it out of paused list and into proper TArray
		if( HasBeenTickedThisFrame() )
		{
			// Convert from time remaining back to a valid ExpireTime
			TimerToUnPause.ExpireTime += InternalTime;
			TimerToUnPause.Status = ETimerStatus::Active;
			ActiveTimerHeap.HeapPush(TimerToUnPause);
		}
		else
		{
			TimerToUnPause.Status = ETimerStatus::Pending;
			PendingTimerList.Add(TimerToUnPause);
		}

		// remove from paused list
		PausedTimerList.RemoveAtSwap(PausedTimerIdx);
	}
}
void FTimerManager::InternalSetTimer(FTimerUnifiedDelegate const& InDelegate, float InRate, bool InbLoop)
{
	// not currently threadsafe
	check(IsInGameThread());

	// if the timer is already set, just clear it and we'll re-add it, since 
	// there's no data to maintain.
	InternalClearTimer(InDelegate);

	if (InRate > 0.f)
	{
		// set up the new timer
		FTimerData NewTimerData;
		NewTimerData.Rate = InRate;
		NewTimerData.bLoop = InbLoop;
		NewTimerData.TimerDelegate = InDelegate;
		
		if( HasBeenTickedThisFrame() )
		{
			NewTimerData.ExpireTime = InternalTime + InRate;
			NewTimerData.Status = ETimerStatus::Active;
			ActiveTimerHeap.HeapPush(NewTimerData);
		}
		else
		{
			// Store time remaining in ExpireTime while pending
			NewTimerData.ExpireTime = InRate;
			NewTimerData.Status = ETimerStatus::Pending;
			PendingTimerList.Add(NewTimerData);
		}
	}
}
Example #3
0
void FTimerManager::InternalSetTimer(FTimerData& NewTimerData, float InRate, bool InbLoop, float InFirstDelay)
{
	check(NewTimerData.TimerDelegate.IsBound() || NewTimerData.TimerHandle.IsValid());

	NewTimerData.Rate = InRate;
	NewTimerData.bLoop = InbLoop;

	float FirstDelay = (InFirstDelay >= 0.f) ? InFirstDelay : InRate;

	if (HasBeenTickedThisFrame())
	{
		NewTimerData.ExpireTime = InternalTime + FirstDelay;
		NewTimerData.Status = ETimerStatus::Active;
		ActiveTimerHeap.HeapPush(NewTimerData);
	}
	else
	{
		// Store time remaining in ExpireTime while pending
		NewTimerData.ExpireTime = FirstDelay;
		NewTimerData.Status = ETimerStatus::Pending;
		PendingTimerList.Add(NewTimerData);
	}
}