Beispiel #1
0
 public void Execute(IRoutine routine)
 {
     for (int i = 0; i < this.count; i++)
     {
         routine.Execute();
     }
 }
 public void Execute(IRoutine routine)
 {
     for (int i = 0; i < this.count; i++)
     {
         routine.Execute();
     }
 }
        public static InvokeResult Execute(this IRoutine routine, InvokeArgument[] args, IRequest request, IVariableResolver resolver, IGroupResolver group)
        {
            var invoke = new Invoke(routine.ObjectInfo.FullName, args);

            var executeContext = new InvokeContext(invoke, routine, resolver, group, request);

            return(routine.Execute(executeContext));
        }
Beispiel #4
0
        public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group)
        {
            var request = new Invoke(routine.FullName, args);

            if (query != null &&
                !query.UserCanExecuteFunction(request))
            {
                throw new InvalidOperationException();
            }

            var executeContext = new InvokeContext(request, routine, resolver, group, query);

            return(routine.Execute(executeContext));
        }
Beispiel #5
0
        public static InvokeResult Execute(this IRoutine routine, DataObject[] args)
        {
            var exps = new SqlExpression[0];

            if (args != null && args.Length > 0)
            {
                exps = new SqlExpression[args.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    exps[i] = SqlExpression.Constant(args[i]);
                }
            }

            return(routine.Execute(exps));
        }
        public static InvokeResult Execute(this IRoutine routine, Field[] args)
        {
            var invokeArgs = new InvokeArgument[0];

            if (args != null && args.Length > 0)
            {
                invokeArgs = new InvokeArgument[args.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    invokeArgs[i] = new InvokeArgument(SqlExpression.Constant(args[i]));
                }
            }

            return(routine.Execute(invokeArgs));
        }
Beispiel #7
0
        /// <summary>
        /// Executes one tick of the AI.
        /// </summary>
        private void Tick(TimeSpan elapsed)
        {
            // Get a thread to run the states on if we don't have one.
            // If there aren't any on the stack, create one.
            if (NL == IntPtr.Zero)
            {
                if (lua_gettop(GL) == 0)
                {
                    NL = lua_newthread(GL);
                }
                else
                {
                    NL = lua_tothread(GL, -1);
                }
            }

            // If no routine is active, start the current state function,
            // which should create routines.
            if (_currentRoutine == null)
            {
                lua_getglobal(NL, this.CurrentStateName);
                if (!lua_isfunction(NL, -1))
                {
                    Log.Warning("EntityAi: Function '{0}' not defined.", this.CurrentStateName);
                    lua_settop(NL, 0);
                    return;
                }

                var stateResult = lua_resume(NL, 0);
                if (stateResult != 0 && stateResult != LUA_YIELD)
                {
                    Log.Error("EntityAi: Error while executing '{0}': {1}", this.CurrentStateName, lua_tostring(NL, -1));

                    // Don't continue if an error occurred.
                    GL = IntPtr.Zero;
                    return;
                }
            }

            // If we don't have a routine even after calling the state
            // function, don't do anything.
            if (_currentRoutine == null)
            {
                return;
            }

            // Execute the current routine
            var routineResult = _currentRoutine.Execute(elapsed);

            switch (routineResult)
            {
            // Keep going while the routine is still running
            case RoutineResult.Running:
                return;

            // Clear routine and continue, to resume the script
            case RoutineResult.Success:
            {
                this.ResetRoutine();
                break;
            }

            // Clear routine and return, to restart the state
            case RoutineResult.Fail:
            {
                this.ResetRoutine();
                return;
            }
            }

            // If the current routine was completed, resume the script,
            // so we can get the next routine. We might not have a new
            // routine after this call if the state function ended,
            // but the next tick will take care of that and restart
            // the state.
            var result = lua_resume(NL, 0);

            if (result != 0 && result != LUA_YIELD)
            {
                Log.Error("EntityAi: Error while advancing state: {0}", lua_tostring(NL, -1));

                GL = IntPtr.Zero;
                return;
            }

            // If the state reached its end and there's more than one thread
            // on the stack, pop one, so we get back to the previous state.
            if (result == 0 && lua_gettop(GL) > 1)
            {
                lua_pop(GL, 1);
            }
        }