/// <summary>
        /// start uniroutine interator
        /// </summary>
        /// <param name="enumerator">target enumerator</param>
        /// <param name="routineType">routine type</param>
        /// <param name="scope">routine execution scope</param>
        /// <param name="moveNextImmediately"></param>
        /// <returns>cancelation handle</returns>
        public static RoutineHandle RunUniRoutine(
            IEnumerator enumerator,
            RoutineType routineType,
            RoutineScope scope,
            bool moveNextImmediately = true)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(new RoutineHandle());
            }
#endif

            var routineObject = GetRoutineObject(scope);
            //get routine
            var routine = routineObject.GetRoutine(routineType);
            //add enumerator to routines
            var routineTask = routine.AddRoutine(enumerator, moveNextImmediately);
            if (routineTask == null)
            {
                return(new RoutineHandle(0, routineType, scope));
            }

            var routineValue = new RoutineHandle(routineTask.Id, routineType, scope);
            return(routineValue);
        }
        public Action <TimeSpan, IBasePlayer> GetTimedAction(BaseEnemy enemy, IBasePlayer player, BaseVerticalShooter.GameModel.IBaseMap gameMap)
        {
            var action = new Action <TimeSpan, IBasePlayer>((t, p) =>
            {
                if (enemy.State == CharacterState.Alive)
                {
                    if (accumulatedTime > Milestones.Last().End)
                    {
                        accumulatedTime = TimeSpan.FromSeconds(0);
                    }

                    var milestone    = GetCurrentMilestone();
                    this.RoutineType = milestone.RoutineType;

                    var milestoneExists = (milestone.Start != milestone.End);
                    if (milestoneExists && milestone.RoutineType == RoutineType.Walk)
                    {
                        Walk(enemy, gameMap, t);
                    }

                    accumulatedTime = accumulatedTime.Add(t);
                    enemy.CheckReload();
                }
            });

            return(action);
        }
Exemplo n.º 3
0
        public string GetSQLType()
        {
            var text = RoutineType.ToString();

            return(string.Join(string.Empty, text.AsEnumerable().Select(
                                   (c, i) => ((char.IsUpper(c) || i == 0) ? " " + char.ToUpper(c).ToString() : c.ToString())
                                   ).ToArray()).Trim());
        }
 public static IDisposableItem ExecuteRoutine(
     this IEnumerator enumerator,
     RoutineType routineType  = RoutineType.Update,
     bool moveNextImmediately = false,
     RoutineScope scope       = RoutineScope.Global)
 {
     return(Execute(enumerator, routineType, moveNextImmediately, scope).AsDisposable());
 }
Exemplo n.º 5
0
 protected RoutineSymbol(RoutineType type, TokenType opType)
 {
     RoutineType = type;
     OperatorType = opType;
     Block = new ProgramContext();
     AppendChild(Block);
     IsInitialize = true;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivationRecord"/> class.
 /// </summary>
 /// <param name="type">
 /// The routine type.
 /// </param>
 /// <param name="programCounter">
 /// The program counter.
 /// </param>
 /// <param name="argumentCount">
 /// The argument count.
 /// </param>
 /// <param name="localVariables">
 /// The local variables.
 /// </param>
 /// <param name="evaluationStack">
 /// The evaluation stack.
 /// </param>
 public ActivationRecord(RoutineType type, int programCounter, byte argumentCount, ImmutableArray<int> localVariables, ImmutableStack<int> evaluationStack)
 {
     this.argumentCount = argumentCount;
     this.type = type;
     this.localVariables = localVariables;
     this.programCounter = programCounter;
     this.evaluationStack = evaluationStack;
 }
 public static RoutineHandle Execute(
     this IEnumerator enumerator,
     RoutineType routineType  = RoutineType.Update,
     bool moveNextImmediately = false,
     RoutineScope scope       = RoutineScope.Global)
 {
     return(UniRoutineManager.RunUniRoutine(enumerator, routineType, scope, moveNextImmediately));
 }
        public static IDisposable ExecuteWithCondition(this object target,
                                                       Action action, Func <bool> condition,
                                                       RoutineType routineType = RoutineType.Update)
        {
            var enumerator = ExecuteWhile(target, action, condition);
            var disposable = enumerator.RunWithSubRoutines(routineType);

            return(disposable);
        }
Exemplo n.º 9
0
        private UniRoutine CreateRoutine(RoutineType routineType)
        {
            //create uni routine
            var routine = new UniRoutine();

            //run coroutine for target update type
            ExecuteRoutine(routine, routineType);

            return(routine);
        }
Exemplo n.º 10
0
 protected RoutineSymbol(TextPosition tp, string name, RoutineType type, TokenType opType, ProgramContext block)
     : base(tp)
 {
     Name = name;
     RoutineType = type;
     OperatorType = opType;
     Block = block;
     AppendChild(Block);
     IsInitialize = true;
 }
Exemplo n.º 11
0
 public void Stop()
 {
     if (_state != null)
     {
         _state.Exit();
     }
     _state = null;
     _disposables.Cancel();
     _disposables = null;
     _routineType = RoutineType.Update;
 }
Exemplo n.º 12
0
        public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
        {
            if (routineName == null)
                throw new ArgumentNullException("routineName");

            EventType = eventType;
            RoutineName = routineName;
            Arguments = arguments;
            RoutineType = routineType;
            Result = result;
        }
Exemplo n.º 13
0
        private IEnumerator ExecuteOnUpdate(IUniRoutine routine, RoutineType routineType)
        {
            var awaiter = GetRoutineAwaiter(routineType);

            while (true)
            {
                routine.Update();
                //wait time before next update
                yield return(awaiter);
            }
        }
Exemplo n.º 14
0
        private void ExecuteRoutine(
            IUniRoutine routine,
            RoutineType routineType)
        {
            if (routineType == RoutineType.LateUpdate)
            {
                AddLateRoutine(routine);
                return;
            }

            StartCoroutine(ExecuteOnUpdate(routine, routineType));
        }
Exemplo n.º 15
0
 public RoutineDeclaration(TextPosition tp, string name, RoutineType type, TokenType opType, TupleLiteral attr, TupleLiteral generic, TupleLiteral args, Element expli, ProgramContext block)
     : base(tp, name, type, opType, block)
 {
     AttributeAccess = attr;
     DecGenerics = generic;
     DecArguments = args;
     ExplicitType = expli;
     AppendChild(AttributeAccess);
     AppendChild(DecGenerics);
     AppendChild(DecArguments);
     AppendChild(ExplicitType);
 }
Exemplo n.º 16
0
        public static Routine GetRoutine(RoutineType routineTypeEnum)
        {
            IList<Type> routineTypes = _routinesTypes.Where<KeyValuePair<Type, RoutineTypeAttribute>>(t => t.Value.routineType == routineTypeEnum)
                                                           .Select(kvp => kvp.Key).ToList();
            if(routineTypes.Count() == 0) throw new Exception(string.Format("No routines of type {0} are defined!", routineTypeEnum.ToString()));

            if(routineTypes.Count() == 1) return CreateAndInitRoutine(routineTypes[0]);

            int index = new Random().Next(0, routineTypes.Count);
            Type routineType = routineTypes[index];
            return CreateAndInitRoutine(routineType);
        }
Exemplo n.º 17
0
        public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
        {
            if (routineName == null)
            {
                throw new ArgumentNullException("routineName");
            }

            EventType   = eventType;
            RoutineName = routineName;
            Arguments   = arguments;
            RoutineType = routineType;
            Result      = result;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Routine"/> class.
        /// </summary>
        /// <param name="catalog">The catalog.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="name">The name.</param>
        /// <param name="routineType">Type of the routine.</param>
        /// <param name="returnType">Type of the return.</param>
        /// <param name="definition">The definition.</param>
        /// <param name="created">The created.</param>
        /// <param name="lastAltered">The last altered.</param>
        public Routine(string catalog, string schema, string name, RoutineType routineType, SqlType returnType, string definition, DateTime created, DateTime lastAltered)
        {
            this.Catalog = catalog;
            this.Schema = schema;
            this.Name = name;
            this.RoutineType = routineType;
            this.ReturnType = returnType;
            this.Definition = definition;
            this.Created = created;
            this.LastAltered = lastAltered;

            this.parameters = new Collection<RoutineParameter>();
        }
Exemplo n.º 19
0
        public IUniRoutine GetRoutine(RoutineType routineType)
        {
            var index   = (int)routineType;
            var routine = _routines[index];

            if (routine != null)
            {
                return(routine);
            }
            routine          = CreateRoutine(routineType);
            _routines[index] = routine;
            return(routine);
        }
Exemplo n.º 20
0
        public static bool UserCanExecute(this IQuery query, RoutineType routineType, Invoke invoke)
        {
            if (routineType == RoutineType.Function &&
                query.IsSystemFunction(invoke))
            {
                return(true);
            }

            if (query.UserHasSecureAccess())
            {
                return(true);
            }

            return(query.UserHasPrivilege(DbObjectType.Routine, invoke.RoutineName, Privileges.Execute));
        }
Exemplo n.º 21
0
        private static YieldInstruction GetRoutineAwaiter(RoutineType routineType)
        {
            switch (routineType)
            {
            case RoutineType.Update:
                return(null);

            case RoutineType.EndOfFrame:
                return(new WaitForEndOfFrame());

            case RoutineType.FixedUpdate:
                return(new WaitForFixedUpdate());

            case RoutineType.LateUpdate:
                return(null);
            }

            return(null);
        }
Exemplo n.º 22
0
        protected override void GetEventData(Dictionary <string, object> data)
        {
            data["routine.eventType"] = EventType.ToString();
            data["routine.name"]      = RoutineName.FullName;

            if (Arguments != null)
            {
                data["routine.argc"] = Arguments.Length;
                for (int i = 0; i < Arguments.Length; i++)
                {
                    data[String.Format("routine.arg[{0}].name", i)]  = Arguments[i].Name;
                    data[String.Format("routine.arg[{0}].value", i)] = Arguments[i].Value.ToString();
                }
            }

            if (EventType != RoutineEventType.BeforeResolve)
            {
                data["routine.type"] = RoutineType.ToString();
            }

            base.GetEventData(data);
        }
Exemplo n.º 23
0
 public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(eventType, routineName, arguments, routineType, null)
 {
 }
Exemplo n.º 24
0
 public RoutineHandle(int id, RoutineType routineType, RoutineScope scope)
 {
     Id    = id;
     Type  = routineType;
     Scope = scope;
 }
Exemplo n.º 25
0
        public IUniRoutineTask AddRoutine(RoutineType type, IEnumerator enumerator, bool moveNextImmediately = true)
        {
            var routine = GetRoutine(type);

            return(routine.AddRoutine(enumerator, moveNextImmediately));
        }
Exemplo n.º 26
0
 /// <summary>
 /// Places a new routine on call stack.
 /// </summary>
 /// <param name="routineType">
 /// The type of the new routine.
 /// </param>
 /// <param name="programCounter">
 /// The program counter of the new routine.
 /// </param>
 /// <param name="argumentCount">
 /// The argument count of the new routine.
 /// </param>
 /// <param name="localVariableCount">
 /// The local variable count of the new routine.
 /// </param>
 public void BeginRoutine(RoutineType routineType, int programCounter, byte argumentCount, byte localVariableCount)
 {
     this.callingRoutines = this.callingRoutines.Add(new ActivationRecord(this.type, this.ProgramCounter, this.ArgumentCount, new ImmutableArray<int>(this.localVariables), this.evaluationStack));
     this.SetCurrentRoutine(routineType, programCounter, argumentCount, new int[localVariableCount], null);
 }
Exemplo n.º 27
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
     : this(RoutineEventType.AfterExecute, routineName, arguments, routineType, result)
 {
 }
Exemplo n.º 28
0
        /// <summary>
        /// Calls a routine.
        /// </summary>
        /// <param name="routineType">
        /// The routine type.
        /// </param>
        /// <param name="packedAddress">
        /// The packed address of the routine.
        /// </param>
        /// <param name="arguments">
        /// Routine arguments.
        /// </param>
        protected void CallRoutine(RoutineType routineType, ushort packedAddress, ImmutableStack<ushort> arguments)
        {
            if (packedAddress == 0)
            {
                this.Return(0, routineType);
                return;
            }

            var argumentCount = (byte)arguments.Count();
            var programCounter = this.UnpackRoutineAddress(packedAddress);
            var localVariableCount = this.Memory.ReadByte(programCounter);
            if (localVariableCount > MaximumLocalVariables)
            {
                this.FrontEnd.ErrorNotification(ErrorCondition.InvalidRoutine, "Called a routine at address " + programCounter + " with " + localVariableCount + " local variables.");
            }

            this.CallStack.BeginRoutine(routineType, programCounter + 1, argumentCount, localVariableCount);
            this.InitializeLocalVariables(localVariableCount);
            byte localVariableNumber = 0;
            foreach (var argument in arguments.Enumerable())
            {
                if (localVariableNumber >= localVariableCount)
                {
                    break;
                }

                this.CallStack.WriteLocalVariable(localVariableNumber++, argument);
            }
        }
Exemplo n.º 29
0
 public void SetRoutineType(RoutineType routineType)
 {
     _routineType = routineType;
 }
Exemplo n.º 30
0
 public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(eventType, routineName, arguments, routineType, null)
 {
 }
Exemplo n.º 31
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(RoutineEventType.BeforeExecute, routineName, arguments, routineType, null)
 {
 }
Exemplo n.º 32
0
        static public Routine CreateRoutine(MethodInfo finalNodeMethodInfo, string name, RoutineType type)
        {
            Routine routine = CreateInstance <Routine>();

            routine.m_type = type;
            routine.name   = name;
            routine.CreateFinalNode(finalNodeMethodInfo);

            return(routine);
        }
 public RoutineTypeAttribute(RoutineType pRoutineType, int routineOrder = 0)
 {
     routineType = pRoutineType;
     order = routineOrder;
 }
Exemplo n.º 34
0
        public static bool UserCanExecute(this IQueryContext context, RoutineType routineType, Invoke invoke)
        {
            if (routineType == RoutineType.Function &&
                context.IsSystemFunction(invoke)) {
                return true;
            }

            if (context.UserHasSecureAccess())
                return true;

            return context.UserHasPrivilege(DbObjectType.Routine, invoke.RoutineName, Privileges.Execute);
        }
Exemplo n.º 35
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(RoutineEventType.BeforeExecute, routineName, arguments, routineType, null)
 {
 }
Exemplo n.º 36
0
        /// <summary>
        /// Calls a routine with the address and arguments supplied by operands.
        /// </summary>
        /// <param name="type">
        /// The routine type to call.
        /// </param>
        protected void CallRoutineFromOperation(RoutineType type)
        {
            if (this.Operands.Count == 0)
            {
                this.FrontEnd.ErrorNotification(ErrorCondition.InvalidRoutine, "Tried to a call a routine but no address was given.");
            }

            ImmutableStack<ushort> arguments = null;
            var operandNumber = this.Operands.Count;
            while (operandNumber > 1)
            {
                arguments = arguments.Add(this.Operands[--operandNumber]);
            }

            this.CallRoutine(type, this.Operands.First, arguments);
        }
Exemplo n.º 37
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
     : this(RoutineEventType.AfterExecute, routineName, arguments, routineType, result)
 {
 }
Exemplo n.º 38
0
 /// <summary>
 /// Sets the current routine.
 /// </summary>
 /// <param name="routineType">
 /// The routine type.
 /// </param>
 /// <param name="programCounter">
 /// The program counter.
 /// </param>
 /// <param name="argumentCount">
 /// The argument count.
 /// </param>
 /// <param name="variables">
 /// The localVariables.
 /// </param>
 /// <param name="stack">
 /// The stack.
 /// </param>
 private void SetCurrentRoutine(RoutineType routineType, int programCounter, byte argumentCount, int[] variables, ImmutableStack<int> stack)
 {
     this.ArgumentCount = argumentCount;
     this.localVariables = variables;
     this.evaluationStack = stack;
     this.ProgramCounter = programCounter;
     this.type = routineType;
 }
Exemplo n.º 39
0
 private static void OperatorPrefix(SlimChainParser cp, out RoutineType type, out TokenType opType, out string name)
 {
     var ty = RoutineType.Routine;
     var oty = TokenType.Unknoun;
     var n = string.Empty;
     cp.Opt.Any(
             icp => icp.Text("rout", "routine").Self(() => ty = RoutineType.Routine),
             icp => icp.Text("func", "function").Self(() => ty = RoutineType.Function)
         ).Lt()
         .Text("operator")
         .Any(
             icp => icp.Type(t => n = t.Text, TokenType.LetterStartString),
             icp => icp.Take(t => { oty = t.TokenType; n = t.Text; })
         ).Lt();
     if(oty != TokenType.Unknoun)
     {
         switch(ty)
         {
             case RoutineType.Routine: ty = RoutineType.RoutineOperator; break;
             case RoutineType.Function: ty = RoutineType.FunctionOperator; break;
             default: throw new ArgumentException();
         }
     }
     else
     {
         switch (ty)
         {
             case RoutineType.Routine: ty = RoutineType.RoutineConverter; break;
             case RoutineType.Function: ty = RoutineType.FunctionConverter; break;
             default: throw new ArgumentException();
         }
     }
     type = ty;
     opType = oty;
     name = n;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Returns a value from a routine.
 /// </summary>
 /// <param name="returnValue">
 /// The return value.
 /// </param>
 /// <param name="type">
 /// The routine type.
 /// </param>
 protected override void Return(ushort returnValue, RoutineType type)
 {
     base.Return(returnValue, type);
     if (this.InputOperation != null && this.InputOperation.CatchValue == this.CallStack.CatchValue)
     {
         this.State = MachineState.ReadingInput;
         this.FlushBufferedOutput();
         if (this.InputOperation.TimedOut)
         {
             if (returnValue == 0)
             {
                 this.InputOperation.ResetTimeout();
                 if (!this.InputOperation.ReadCharacter && (this.ActiveDisplayWindow != this.InputOperation.Window || this.FrontEnd.CursorPosition != this.InputOperation.Cursor))
                 {
                     this.WriteToDisplay(this.InputOperation.InputText);
                 }
             }
             else
             {
                 if (this.InputOperation.ReadCharacter)
                 {
                     this.FinishInputCharacterOperation(new InputValue());
                 }
                 else
                 {
                     // todo: should we re-display input text when returning from an interrupt which terminates the input, before clearing it?
                     this.FinishInputLineOperation(string.Empty, new InputValue());
                 }
             }
         }
     }
 }
Exemplo n.º 41
0
 private static void RoutinePrefix(SlimChainParser cp, out RoutineType type, out string name)
 {
     var ty = RoutineType.Unknown;
     var n = string.Empty;
     cp.Any(
             icp => icp.Text("rout", "routine").Self(() => ty = RoutineType.Routine),
             icp => icp.Text("func", "function").Self(() => ty = RoutineType.Function)
         ).Lt()
         .Type(t => n = t.Text, TokenType.LetterStartString).Lt();
     type = ty;
     name = n;
 }
 public static IDisposableItem RunWithSubRoutines(
     this IEnumerator enumerator,
     RoutineType routineType = RoutineType.Update)
 {
     return(ExecuteRoutine(enumerator, routineType));
 }
Exemplo n.º 43
0
 public LambdaLiteral(TextPosition tp, string name, RoutineType type, TokenType op, TupleLiteral attr, TupleLiteral generic, TupleLiteral args, Element expli, ProgramContext block)
     : base(tp, name, type, op, attr, generic, args, expli, block)
 {
 }
Exemplo n.º 44
0
 /// <summary>
 /// Returns a value from a routine.
 /// </summary>
 /// <param name="returnValue">
 /// The return value.
 /// </param>
 /// <param name="type">
 /// The routine type.
 /// </param>
 protected virtual void Return(ushort returnValue, RoutineType type)
 {
     if (type == RoutineType.Function)
     {
         this.Store(returnValue);
     }
 }
Exemplo n.º 45
0
 public void Initialize(string name, RoutineType type, TokenType opType, IReadOnlyList<AttributeSymbol> attr, IReadOnlyList<GenericSymbol> gnr, IReadOnlyList<ArgumentSymbol> arg, TypeSymbol rt)
 {
     if (IsInitialize)
     {
         throw new InvalidOperationException();
     }
     IsInitialize = true;
     Name = name;
     RoutineType = type;
     OperatorType = opType;
     Block = new ProgramContext();
     _Attribute = attr;
     _Generics = gnr;
     _Arguments = arg;
     _CallReturnType = rt;
     AppendChild(Block);
 }