private void ProcessTime(UnrealBinaryHeapEx <Invoker> invokers) { // Note: If the the delay is low enough this may loop forever (the timer would need a repeat // value lower than the time it takes to get from the end of Process() back to the EndValue check // - If this becomes a problem you could stop this from happening by holding onto the last invoker // processed and checking invoker!=lastInvoker // - Though if this is a problem it will make the game crawl anyway due to CallCount. A frame will // occasionally get through between the invoker spam if doing the lastInvoker check. //Invoker lastInvoker = null; while (invokers.Count > 0) { Invoker invoker = invokers.HeapTop(); ulong value = (ulong)WorldTimeHelper.GetTimeChecked(invoker.OwnerWorld).Ticks; if (invoker.EndValue <= value /*&& invoker != lastInvoker*/) { invokers.HeapPopDiscard(); invoker.Process(value); //lastInvoker = invoker; } else { break; } } }
internal void Process(ulong value) { cancelInvoke = false; int expectedAdditionalCallCount = 0; if (IsRepeated) { expectedAdditionalCallCount = (int)((value - EndValue) / RepeatedValue); } CallCount = expectedAdditionalCallCount + 1; // Clamp the call count to MaxCallCount int clampedAdditionalCallCount = expectedAdditionalCallCount; if (MaxCallCount > 0) { clampedAdditionalCallCount = Math.Min(MaxCallCount - 1, clampedAdditionalCallCount); } // target value may change if IsFirstRun is true ulong oldTargetValue = CurrentTargetValue; if (!InvokeInternal() || (HasStopAfterValue && HasStopAfterValueCompleted(oldTargetValue, 0))) { return; } uint additionalCalls = 0; for (; additionalCalls < clampedAdditionalCallCount && !cancelInvoke && Running; ++additionalCalls) { if (!InvokeInternal() || (HasStopAfterValue && HasStopAfterValueCompleted(oldTargetValue, additionalCalls + 1))) { return; } } if (IsRepeated) { if (RepeatConstantTime && Type == InvokerType.Delay) { ulong realTime = (ulong)WorldTimeHelper.GetTimeChecked(OwnerWorld).Ticks; BeginValue = value + (realTime - EndValue); } else { BeginValue += oldTargetValue + (additionalCalls * RepeatedValue); } collection.HeapPush(this); } else { collection = null; collectionGroup = null; Stop(); } }
private void UpdateValues(bool setStartValue) { if (!Running) { return; } if (setStartValue) { switch (Type) { case InvokerType.Delay: BeginValue = startingValue = (ulong)WorldTimeHelper.GetTimeChecked(OwnerWorld).Ticks; break; case InvokerType.Ticks: BeginValue = startingValue = EngineLoop.WorldTickCounter; break; case InvokerType.Frames: BeginValue = startingValue = EngineLoop.WorldFrameNumber; break; } } InvokerCollectionGroup newCollectionGroup = GetInvokerGroup(Group); UnrealBinaryHeapEx <Invoker> newCollection = newCollectionGroup == null ? null : newCollectionGroup.GetCollection(Type); if (collectionGroup != null && collection != null) { if (collectionGroup.Group != Group || newCollection != collection) { collection.HeapRemove(this); collection = null; collectionGroup = null; } } if (newCollection != null) { collectionGroup = newCollectionGroup; collection = newCollection; newCollection.HeapPush(this); } }