示例#1
0
        private Activity DequeueActivity(bool firstRun)
        {
            // Load the available activities into the queue if the queue is empty
            // or on first run (repeat session situation)
            if (!ExecutionQueue.Any() || firstRun)
            {
                // Add activities based on the execution count which describes
                // the overall distribution or weight of different activities
                // being executed.
                List <Activity> activities = new List <Activity>();
                foreach (var item in MasterList.OrderBy(n => n.ExecutionOrder))
                {
                    activities.Add(item);
                }

                if (Randomize)
                {
                    // If randomize was set for this collection of activities, then shuffle them
                    activities.Shuffle();
                    TraceFactory.Logger.Debug("Activities were shuffled");
                }

                foreach (Activity activity in activities)
                {
                    // Then enqueue each activity onto the execution queue.
                    ExecutionQueue.Enqueue(activity);
                }
            }

            _currentActivityExecutionCount = 1;

            return(ExecutionQueue.Dequeue());
        }
示例#2
0
            public static void Spawn(MulticastDelegate f)
            {
                var sw = Stopwatch.StartNew();

                var e = new WaitExecution(CurrentScript, (LuaThread)LuaThread.running().Values[0], 0,
                                          () => f.FastDynamicInvoke(sw.Elapsed.TotalSeconds, Game.Workspace.DistributedGameTime));

                ExecutionQueue.Enqueue(e);
            }
示例#3
0
            public static double Wait(double seconds)
            {
                seconds = Math.Max(seconds, LuaSettings.DefaultWaitTime);

                var sw = Stopwatch.StartNew();

                var e = new WaitExecution(CurrentScript, (LuaThread)LuaThread.running().Values[0], seconds);

                ExecutionQueue.Enqueue(e);

                YieldThread();

                return(sw.Elapsed.TotalSeconds);
            }
        private Activity DequeueActivity(bool firstRun)
        {
            //during a repeat session the previous session would have queued the execution queue, which makes it run out of order by 1 activity
            //by clearning the queue for the repeat session, we maintain the same order.
            if (firstRun)
            {
                ExecutionQueue.Clear();
            }

            //if there is any queued item return the topmost
            if (ExecutionQueue.Any())
            {
                return(ExecutionQueue.Dequeue());
            }

            // Load the available activities into the queue if the queue is empty
            // or on first run (repeat session situation)
            // Add activities based on the execution count which describes
            // the overall distribution or weight of different activities
            // being executed.
            List <Activity> activities = new List <Activity>();

            foreach (var activity in MasterList.OrderBy(n => n.ExecutionOrder))
            {
                for (int i = 0; i < activity.ExecutionValue; i++)
                {
                    activities.Add(activity);
                }
            }

            if (Randomize)
            {
                activities.Shuffle();
                TraceFactory.Logger.Debug("Activities were shuffled");
            }

            foreach (Activity activity in activities)
            {
                ExecutionQueue.Enqueue(activity);
            }

            return(ExecutionQueue.Dequeue());
        }
示例#5
0
        internal static void Init()
        {
            LoggerInternal = LogManager.GetLogger(nameof(ScriptService));
            EnumTypes      = typeof(Engine).Assembly.GetTypes().Where(x => x.IsEnum);
            CacheTypes();
            Lua = new Lua(LuaIntegerType.Int32, LuaFloatType.Double);

            GlobalEnvironment = new ScriptGlobal(Lua);

            ExecutionQueue = new ConcurrentWorkQueue <Execution>(execution =>
            {
                if (!execution.TryFulfill())
                {
                    ExecutionQueue.Enqueue(execution); // send to back of queue
                }
                else
                {
                    execution.Set();
                }
            });
        }
示例#6
0
 public void addToExecutionQueue(string cmdToExecute)            // for use by the SonOfStrikeApi callback and implements the multithread queue
 {
     "Queueing command:{0}".format(cmdToExecute).debug();
     ExecutionQueue.Enqueue(cmdToExecute);
     processExecutionQueue();
 }
示例#7
0
 private async Task <T> Run <T>(Task <T> task)
 {
     ExecutionQueue.Enqueue(task);
     Process();
     return(await task);
 }
示例#8
0
 private async Task Run(Task task)
 {
     ExecutionQueue.Enqueue(task);
     Process();
     await task;
 }
示例#9
0
 public void EnqueueExecutable(IExecutable executable)
 {
     ExecutionQueue.Enqueue(executable);
 }