Beispiel #1
0
        /// <summary>
        /// Adds a function(returing bool) to the gamestate's queue list and will be executed on the next tick sorted by its priority(default:Priorities.PRIORITY_DEFAULT=512)
        /// as long as the function returns true the function stays in the execution-queue until it returns false
        /// </summary>
        /// <param name="func"></param>
        /// <param name="priority"></param>
        public void AddTick(Func <bool> func, int priority = Priorities.PRIORITY_DEFAULT, ExecutionDomain exeType = ExecutionDomain.unknown)
        {
            var envelope = new TickEnvelope()
            {
                func            = func,
                priority        = priority,
                executionDomain = exeType
            };

            OnTick.Add(envelope);
            isTickListDirty = true;
        }
Beispiel #2
0
        /// <summary>
        /// Adds an action to the gamestate's queue list and will be executed on the next tick sorted by its priority(default:Priorities.PRIORITY_DEFAULT=512)
        /// and will be removed from the executionlist afterwards
        /// </summary>
        /// <param name="act"></param>
        /// <param name="priority"></param>
        /// <param name="exeType"></param>
        public void AddTick(Action act, int priority = Priorities.PRIORITY_DEFAULT, ExecutionDomain exeType = ExecutionDomain.unknown)
        {
            TickEnvelope envelope = new TickEnvelope()
            {
                action          = act,
                priority        = priority,
                executionDomain = exeType
            };

            OnTick.Add(envelope);
            isTickListDirty = true;
        }
Beispiel #3
0
        /// <summary>
        /// Do the actual execution of all tick-actions sorted by their priority
        /// </summary>
        private void ExecuteTickList()
        {
            // CAUTION: this method is called every tick. so keep it as fast as possible


            if (isTickListDirty)
            {
                OnTick          = OnTick.OrderBy(env => env.priority).ToList();
                isTickListDirty = false;
            }

            // using this kind of execution cause I think this is the fastest way
            for (int i = OnTick.Count - 1; i >= 0; i--)
            {
                TickEnvelope currentEnvelope = OnTick[i];
                if (currentEnvelope.action != null)
                {
                    // execute the action
                    currentEnvelope.action();
                    removeList.Add(currentEnvelope);
                }
                else if (currentEnvelope.func != null)
                {
                    bool keepOnExecuting = currentEnvelope.func();
                    if (!keepOnExecuting)
                    {
                        removeList.Add(currentEnvelope);
                    }
                    else
                    {
                        currentEnvelope.calls++; // sensless stat!?!
                    }
                }
                else
                {
                    Debug.LogError("Tick-Envelope without logic... removing");
                    removeList.Add(currentEnvelope);
                }
            }

            for (int i = removeList.Count - 1; i >= 0; i = 0)
            {
                OnTick.Remove(removeList[i]);
            }
        }