Beispiel #1
0
    public void AddBehaviourToQueue(T beh, UpdateLoopSettings settings)
    {
        if (!settings.IsValid || !settings.ShouldBeRegistered)
        {
            return;
        }

        //Safety check for overflow
        CheckForOverflowAndExpand();

        //Just throw it somewhere in case if the entire queue is already marked for sorting
        if (NeedsSorting)
        {
            Queue[UpperBound] = beh;
            UpperBound++;
        }
        else if (settings.UpdateOrder >= UpperUpdateQueueBound)
        {
            Queue[UpperBound] = beh;
            UpperBound++;
            UpperUpdateQueueBound = settings.UpdateOrder;
        }
        else if (settings.UpdateOrder <= LowerUpdateQueueBound && LowerBound > -1)
        {
            Queue[LowerBound] = beh;
            LowerBound--;
            LowerUpdateQueueBound = settings.UpdateOrder;
        }
        //It's somewhere inbetween. Sigh, sorting...
        else
        {
            Queue[UpperBound] = beh;
            UpperBound++;
            NeedsSorting = true;
        }

        if (!HasEntries)
        {
            LowerUpdateQueueBound = UpperUpdateQueueBound;
            HasEntries            = true;
        }
    }
Beispiel #2
0
    public override void RemoveBehavioursMarkedForRemoval()
    {
        if (!NeedsRemovals || !HasEntries)
        {
            return;
        }

        int virtI             = 0;
        int initialUpperBound = UpperBound;

        for (int i = LowerBound + 1; i < initialUpperBound; i++)
        {
            UpdateLoopSettings settings = GetSettings(Queue[i]);
            Queue[i - virtI] = Queue[i];

            if (!settings.ShouldBeRegistered || !settings.IsValid)
            {
                virtI++;
                UpperBound--;
            }
        }

        for (int i = UpperBound; i < initialUpperBound; i++)
        {
            Queue[i] = null;
        }

        if (LowerBound + 1 >= UpperBound)
        {
            LowerBound = -1;
            UpperBound = 0;
            HasEntries = false;
        }
        else
        {
            UpperUpdateQueueBound = GetSettings(Queue[UpperBound - 1]).UpdateOrder;
        }

        NeedsRemovals = false;
    }
Beispiel #3
0
 public abstract void WriteSettings(UpdateLoopSettings config, T beh);
Beispiel #4
0
 public override void WriteSettings(UpdateLoopSettings config, ICoreUpdatable beh)
 {
     beh.UpdateLoopSettings_CoreUpdate = config;
 }