示例#1
0
        public void Tick()
        {
            if (DialogCooldown > 0) DialogCooldown--;
            #if !DEBUG
            try {
            #endif
            if (!Entity.Dead)
            {
                EvaluateQueuePriorities();
                if (Stack.Count == 0)
                {
                    if (Queue.Count == 0)
                    {
                        //todo: should restart main
                        return;
                    }
                    var item = Queue[0];
                    if (!IsCheck && item.Priority != VMQueuePriority.ParentIdle) Entity.SetFlag(VMEntityFlags.InteractionCanceled, false);
                    ExecuteAction(item);
                }
                if (!Queue[0].Callee.Dead)
                {
                    ContinueExecution = true;
                    while (ContinueExecution)
                    {
                        ContinueExecution = false;
                        NextInstruction();
                    }
                }
                else //interaction owner is dead, rip
                {
                    Stack.Clear();
                    if (Queue[0].Callback != null) Queue[0].Callback.Run(Entity);
                    if (Queue.Count > 0) Queue.RemoveAt(0);
                }
            }
            else
            {
                Queue.Clear();
            }

            #if !DEBUG
            } catch (Exception e) {
                var context = Stack[Stack.Count - 1];
                bool Delete = ((Entity is VMGameObject) && (DialogCooldown > 30 * 20 - 10));
                if (DialogCooldown == 0)
                {

                    var simExcept = new VMSimanticsException(e.Message, context);
                    string exceptionStr = "A SimAntics Exception has occurred, and has been suppressed: \r\n\r\n" + simExcept.ToString() + "\r\n\r\nThe object will be reset. Please report this!";
                    VMDialogInfo info = new VMDialogInfo
                    {
                        Caller = null,
                        Icon = context.Callee,
                        Operand = new VMDialogOperand { },
                        Message = exceptionStr,
                        Title = "SimAntics Exception!"
                    };
                    Context.VM.SignalDialog(info);
                    DialogCooldown = 30 * 20;
                }

                context.Callee.Reset(context.VM.Context);
                context.Caller.Reset(context.VM.Context);

                if (Delete) Entity.Delete(true, context.VM.Context);
            }
            #endif
            Interrupt = false;
        }
示例#2
0
        private void Client_OnDisconnect()
        {
            #if DEBUG
            //switch to server mode for debug purposes
            VMDialogInfo info = new VMDialogInfo
            {
                Caller = null,
                Icon = null,
                Operand = new VMDialogOperand { },
                Message = "You have disconnected from the server. Simulation is continuing locally for debug purposes.",
                Title = "Disconnected!"
            };
            VMHook.SignalDialog(info);

            VMHook.ReplaceNet(new VMServerDriver(37564, null));
            #else
            if (OnStateChange != null) OnStateChange(4, (float)CloseReason);
            #endif
        }
示例#3
0
        public void Tick(){
#if IDE_COMPAT
            if (ThreadBreak == VMThreadBreakMode.Pause) return;
            else if (ThreadBreak == VMThreadBreakMode.Immediate)
            {
                Breakpoint(Stack.LastOrDefault()); return;
            }
            if (RoutineDirty)
            {
                foreach (var frame in Stack)
                    if (frame.Routine.Chunk.RuntimeVer != frame.Routine.RuntimeVer) frame.Routine = Context.VM.Assemble(frame.Routine.Chunk); 
                RoutineDirty = false;
            }
#endif

            if (BlockingState != null) BlockingState.WaitTime++;
            if (DialogCooldown > 0) DialogCooldown--;
#if !THROW_SIMANTICS
            try {
#endif
                if (!Entity.Dead)
                {
                    if (QueueDirty)
                    {
                        EvaluateQueuePriorities();
                        TryRunImmediately();
                        QueueDirty = false;
                    }
                    if (Stack.Count == 0)
                    {
                        if (IsCheck) return; //running out of execution means check trees have ended.
                        Entity.ExecuteEntryPoint(1, Context, false);
                        if (Stack.Count == 0) return;
                    }
                    if ((!Stack.LastOrDefault().ActionTree) || (!Queue[0].Callee.Dead)) //main or our target is not dead
                    {
#if IDE_COMPAT
                        if (ThreadBreak == VMThreadBreakMode.ReturnTrue)
                        {
                            var bf = Stack[BreakFrame];
                            HandleResult(bf, bf.GetCurrentInstruction(), VMPrimitiveExitCode.RETURN_TRUE);
                            Breakpoint(Stack.LastOrDefault());
                            return;
                        }
                        if (ThreadBreak == VMThreadBreakMode.ReturnFalse)
                        {
                            var bf = Stack[BreakFrame];
                            HandleResult(bf, bf.GetCurrentInstruction(), VMPrimitiveExitCode.RETURN_TRUE);
                            Breakpoint(Stack.LastOrDefault());
                            return;
                        }
#endif
                        ContinueExecution = true;
                        while (ContinueExecution)
                        {
                            if (TicksThisFrame++ > MAX_LOOP_COUNT) throw new Exception("Thread entered infinite loop! ( >"+MAX_LOOP_COUNT+" primitives)");
                            ContinueExecution = false;
                            NextInstruction();
                        }
                    }
                    else //interaction owner is dead, rip
                    {
                        Entity.Reset(Context);
                    }
                }

#if !THROW_SIMANTICS
            } catch (Exception e) {
                if (Stack.Count == 0) return; //???
                var context = Stack[Stack.Count - 1];
                bool Delete = ((Entity is VMGameObject) && (DialogCooldown > 30 * 20 - 10));
                if (DialogCooldown == 0)
                {
                    
                    var simExcept = new VMSimanticsException(e.Message, context);
                    string exceptionStr = "A SimAntics Exception has occurred, and has been suppressed: \r\n\r\n" + simExcept.ToString() + "\r\n\r\nThe object will be reset. Please report this!";
                    VMDialogInfo info = new VMDialogInfo
                    {
                        Caller = null,
                        Icon = context.Callee,
                        Operand = new VMDialogOperand { },
                        Message = exceptionStr,
                        Title = "SimAntics Exception!"
                    };
                    Context.VM.SignalDialog(info);
                    DialogCooldown = 30 * 20;
                }

                context.Callee.Reset(context.VM.Context);
                context.Caller.Reset(context.VM.Context);

                if (Delete) Entity.Delete(true, context.VM.Context);
            }
#endif
        }
示例#4
0
文件: VM.cs 项目: RHY3756547/FreeSO
 /// <summary>
 /// Signals a Dialog to all listeners. (usually a UI)
 /// </summary>
 /// <param name="info">The dialog info to pass along.</param>
 public void SignalDialog(VMDialogInfo info)
 {
     if (OnDialog != null) OnDialog(info);
 }
示例#5
0
        public static void ShowDialog(VMStackFrame context, VMDialogOperand operand, STR source)
        {
            VMDialogInfo info = new VMDialogInfo
            {
                Block = (operand.Flags & VMDialogFlags.Continue) == 0,
                Caller = context.Caller,
                Icon = context.StackObject,
                Operand = operand,
                Message = ParseDialogString(context, source.GetString(operand.MessageStringID - 1), source),
                Title = (operand.TitleStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.TitleStringID - 1), source),
                IconName = (operand.IconNameStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.IconNameStringID - 1), source),

                Yes = (operand.YesStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.YesStringID - 1), source),
                No = (operand.NoStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.NoStringID - 1), source),
                Cancel = (operand.CancelStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.CancelStringID - 1), source),
            };
            context.VM.SignalDialog(info);
        }
示例#6
0
        public static void ShowDialog(VMStackFrame context, VMDialogOperand operand, STR source)
        {
            VMDialogInfo info = new VMDialogInfo
            {
                Block = (operand.Flags & VMDialogFlags.Continue) == 0,
                Caller = context.Caller,
                Icon = context.StackObject,
                Operand = operand,
                Message = ParseDialogString(context, source.GetString(Math.Max(0, operand.MessageStringID - 1)), source),
                Title = (operand.TitleStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.TitleStringID - 1), source),
                IconName = (operand.IconNameStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.IconNameStringID - 1), source),

                Yes = (operand.YesStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.YesStringID - 1), source),
                No = (operand.NoStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.NoStringID - 1), source),
                Cancel = (operand.CancelStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.CancelStringID - 1), source),
                DialogID = (context.CodeOwner.GUID << 32) | ((ulong)context.Routine.ID << 16) | context.InstructionPointer
            };
            context.VM.SignalDialog(info);
        }