protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, BoxedValue iterator, BoxedValueList args)
        {
            var runtime = handler.PeekRuntime();

            if (runtime.TryBreakLoop())
            {
                return(false);
            }
            var localInfos = handler.LocalInfoStack.Peek();
            var localInfo  = localInfos.GetLocalInfo(m_LocalInfoIndex) as LocalInfo;

            if (null == localInfo)
            {
                localInfo = new LocalInfo {
                    Count = m_LoadedCount.Clone(), CurCount = 0
                };
                localInfos.SetLocalInfo(m_LocalInfoIndex, localInfo);
            }
            if (!handler.PeekRuntime().CompositeReentry)
            {
                Evaluate(instance, handler, iterator, args);
            }
            bool ret = true;

            while (ret)
            {
                if (localInfo.CurCount < localInfo.Count.Value)
                {
                    Prepare(handler);
                    runtime           = handler.PeekRuntime();
                    runtime.Iterator  = localInfo.CurCount;
                    runtime.Arguments = args;
                    ++localInfo.CurCount;
                    ret = true;
                    //没有wait之类命令直接执行
                    runtime.Tick(instance, handler, delta);
                    if (runtime.CommandQueue.Count == 0)
                    {
                        handler.PopRuntime(instance);
                        if (runtime.TryBreakLoop())
                        {
                            ret = false;
                            break;
                        }
                    }
                    else
                    {
                        //遇到wait命令,跳出执行,之后直接在StoryMessageHandler里执行栈顶的命令队列(降低开销)
                        break;
                    }
                }
                else
                {
                    ret = false;
                }
            }
            return(ret);
        }
Example #2
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, BoxedValue iterator, BoxedValueList args)
        {
            var runtime = handler.PeekRuntime();

            if (runtime.CompositeReentry)
            {
                return(false);
            }
            bool ret        = false;
            var  localInfos = handler.LocalInfoStack.Peek();
            var  conditions = localInfos.GetLocalInfo(m_LocalInfoIndex) as List <IStoryValue <int> >;

            if (null == conditions)
            {
                conditions = new List <IStoryValue <int> >();
                for (int i = 0; i < m_LoadedConditions.Count; ++i)
                {
                    conditions.Add(m_LoadedConditions[i].Clone());
                }
                localInfos.SetLocalInfo(m_LocalInfoIndex, conditions);
            }
            Evaluate(instance, handler, iterator, args);
            bool isElse = true;

            for (int i = 0; i < conditions.Count; ++i)
            {
                if (conditions[i].Value != 0)
                {
                    PrepareIf(i, handler);
                    runtime           = handler.PeekRuntime();
                    runtime.Iterator  = iterator;
                    runtime.Arguments = args;
                    isElse            = false;
                    break;
                }
            }
            if (isElse)
            {
                PrepareElse(handler);
                runtime           = handler.PeekRuntime();
                runtime.Iterator  = iterator;
                runtime.Arguments = args;
            }
            //没有wait之类命令直接执行
            runtime = handler.PeekRuntime();
            runtime.Tick(instance, handler, delta);
            if (runtime.CommandQueue.Count == 0)
            {
                handler.PopRuntime(instance);
                ret = false;
            }
            else
            {
                //遇到wait命令,跳出执行,之后直接在StoryMessageHandler里执行栈顶的命令队列(降低开销)
                ret = true;
            }
            return(ret);
        }
Example #3
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, object iterator, object[] args)
        {
            var runtime = handler.PeekRuntime();

            if (runtime.TryBreakLoop())
            {
                return(false);
            }
            bool ret        = true;
            var  localInfos = handler.LocalInfoStack.Peek();
            var  condition  = localInfos.GetLocalInfo(m_LocalInfoIndex) as IStoryValue <int>;

            if (null == condition)
            {
                condition = m_LoadedCondition.Clone();
                localInfos.SetLocalInfo(m_LocalInfoIndex, condition);
            }
            while (ret)
            {
                Evaluate(instance, handler, iterator, args);
                if (condition.Value != 0)
                {
                    Prepare(handler);
                    runtime           = handler.PeekRuntime();
                    runtime.Iterator  = iterator;
                    runtime.Arguments = args;
                    ret = true;
                    //没有wait之类命令直接执行
                    runtime.Tick(instance, handler, delta);
                    if (runtime.CommandQueue.Count == 0)
                    {
                        handler.PopRuntime();
                        if (runtime.TryBreakLoop())
                        {
                            ret = false;
                            break;
                        }
                    }
                    else
                    {
                        //遇到wait命令,跳出执行,之后直接在StoryMessageHandler里执行栈顶的命令队列(降低开销)
                        break;
                    }
                }
                else
                {
                    ret = false;
                }
            }
            return(ret);
        }
Example #4
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, object iterator, object[] args)
        {
            var localInfos = handler.LocalInfoStack.Peek();
            var localInfo  = localInfos.GetLocalInfo(m_LocalInfoIndex) as LocalInfo;

            if (null == localInfo)
            {
                localInfo = new LocalInfo {
                    List = new List <IStoryValue>()
                };
                for (int i = 0; i < m_LoadedIterators.Count; ++i)
                {
                    localInfo.List.Add(m_LoadedIterators[i].Clone());
                }
                localInfos.SetLocalInfo(m_LocalInfoIndex, localInfo);
            }
            if (!handler.PeekRuntime().CompositeReentry)
            {
                Evaluate(instance, handler, iterator, args);
            }
            bool ret = true;

            while (ret)
            {
                if (localInfo.Iterators.Count > 0)
                {
                    Prepare(handler);
                    var runtime = handler.PeekRuntime();
                    runtime.Iterator  = localInfo.Iterators.Dequeue();
                    runtime.Arguments = args;
                    ret = true;
                    //没有wait之类命令直接执行
                    runtime.Tick(instance, handler, delta);
                    if (runtime.CommandQueue.Count == 0)
                    {
                        handler.PopRuntime();
                    }
                    else
                    {
                        //遇到wait命令,跳出执行,之后直接在StoryMessageHandler里执行栈顶的命令队列(降低开销)
                        break;
                    }
                }
                else
                {
                    ret = false;
                }
            }
            return(ret);
        }
Example #5
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta, BoxedValue iterator, BoxedValueList args)
        {
            var runtime = handler.PeekRuntime();

            if (runtime.CompositeReentry)
            {
                return(false);
            }
            bool ret       = false;
            var  stackInfo = handler.PeekLocalInfo();

            for (int i = 0; i < m_ArgNames.Count; ++i)
            {
                if (i < stackInfo.Args.Count)
                {
                    instance.SetVariable(m_ArgNames[i], stackInfo.Args[i].Value);
                }
                else
                {
                    instance.SetVariable(m_ArgNames[i], BoxedValue.NullObject);
                }
            }
            foreach (var pair in stackInfo.OptArgs)
            {
                instance.SetVariable(pair.Key, pair.Value.Value);
            }
            Prepare(handler);
            runtime                    = handler.PeekRuntime();
            runtime.Arguments          = instance.NewBoxedValueList();
            runtime.Arguments.Capacity = stackInfo.Args.Count;
            for (int i = 0; i < stackInfo.Args.Count; i++)
            {
                runtime.Arguments.Add(stackInfo.Args[i].Value);
            }
            runtime.Iterator = stackInfo.Args.Count;
            //没有wait之类命令直接执行
            runtime.Tick(instance, handler, delta);
            instance.RecycleBoxedValueList(runtime.Arguments);
            if (runtime.CommandQueue.Count == 0)
            {
                handler.PopRuntime(instance);
            }
            else
            {
                //遇到wait命令,跳出执行,之后直接在StoryMessageHandler里执行栈顶的命令队列(降低开销)
                ret = true;
            }
            return(ret);
        }
Example #6
0
        private void PrepareElse(StoryMessageHandler handler)
        {
            var runtime = StoryRuntime.New();

            handler.PushRuntime(runtime);
            var queue = handler.PeekRuntime().CommandQueue;

            foreach (IStoryCommand cmd in queue)
            {
                cmd.Reset();
            }
            queue.Clear();
            for (int i = 0; i < m_LoadedElseCommands.Count; ++i)
            {
                IStoryCommand cmd = m_LoadedElseCommands[i];
                if (null != cmd.PrologueCommand)
                {
                    queue.Enqueue(cmd.PrologueCommand);
                }
                queue.Enqueue(cmd);
                if (null != cmd.EpilogueCommand)
                {
                    queue.Enqueue(cmd.EpilogueCommand);
                }
            }
        }
Example #7
0
 protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
 {
     handler.PeekRuntime().IsReturn = true;
     return(false);
 }