/// <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); }
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()); }
protected RoutineSymbol(RoutineType type, TokenType opType) { RoutineType = type; OperatorType = opType; Block = new ProgramContext(); AppendChild(Block); IsInitialize = true; }
/// <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); }
private UniRoutine CreateRoutine(RoutineType routineType) { //create uni routine var routine = new UniRoutine(); //run coroutine for target update type ExecuteRoutine(routine, routineType); return(routine); }
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; }
public void Stop() { if (_state != null) { _state.Exit(); } _state = null; _disposables.Cancel(); _disposables = null; _routineType = RoutineType.Update; }
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; }
private IEnumerator ExecuteOnUpdate(IUniRoutine routine, RoutineType routineType) { var awaiter = GetRoutineAwaiter(routineType); while (true) { routine.Update(); //wait time before next update yield return(awaiter); } }
private void ExecuteRoutine( IUniRoutine routine, RoutineType routineType) { if (routineType == RoutineType.LateUpdate) { AddLateRoutine(routine); return; } StartCoroutine(ExecuteOnUpdate(routine, routineType)); }
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); }
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); }
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; }
/// <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>(); }
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); }
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)); }
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); }
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); }
public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType) : this(eventType, routineName, arguments, routineType, null) { }
public RoutineHandle(int id, RoutineType routineType, RoutineScope scope) { Id = id; Type = routineType; Scope = scope; }
public IUniRoutineTask AddRoutine(RoutineType type, IEnumerator enumerator, bool moveNextImmediately = true) { var routine = GetRoutine(type); return(routine.AddRoutine(enumerator, moveNextImmediately)); }
/// <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); }
public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result) : this(RoutineEventType.AfterExecute, routineName, arguments, routineType, result) { }
/// <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); } }
public void SetRoutineType(RoutineType routineType) { _routineType = routineType; }
public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType) : this(RoutineEventType.BeforeExecute, routineName, arguments, routineType, null) { }
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; }
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); }
/// <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); }
/// <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; }
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; }
/// <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()); } } } } }
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)); }
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) { }
/// <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); } }
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); }