private void HandleResult(VMStackFrame frame, VMInstruction instruction, VMPrimitiveExitCode result) { switch (result) { /** Dont advance the instruction pointer, this primitive isnt finished yet **/ case VMPrimitiveExitCode.CONTINUE_NEXT_TICK: break; case VMPrimitiveExitCode.ERROR: Pop(result); break; case VMPrimitiveExitCode.RETURN_TRUE: case VMPrimitiveExitCode.RETURN_FALSE: /** pop stack and return false **/ Pop(result); break; case VMPrimitiveExitCode.GOTO_TRUE: MoveToInstruction(frame, instruction.TruePointer, true); break; case VMPrimitiveExitCode.GOTO_FALSE: MoveToInstruction(frame, instruction.FalsePointer, true); break; case VMPrimitiveExitCode.GOTO_TRUE_NEXT_TICK: MoveToInstruction(frame, instruction.TruePointer, false); break; case VMPrimitiveExitCode.GOTO_FALSE_NEXT_TICK: MoveToInstruction(frame, instruction.FalsePointer, false); break; } }
public void Pop(VMPrimitiveExitCode result) { Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (Stack.Count > 0) { if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else //interaction finished! { if (Queue[0].Callback != null) { Queue[0].Callback.Run(Entity); } if (Queue.Count > 0) { Queue.RemoveAt(0); } } }
public void Pop(VMPrimitiveExitCode result) { var discardResult = Stack[Stack.Count - 1].DiscardResult; var contextSwitch = (Stack.Count > 1) && Stack.LastOrDefault().ActionTree != Stack[Stack.Count - 2].ActionTree; if (contextSwitch && !Stack.LastOrDefault().ActionTree) { } Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (contextSwitch) //interaction switching back to main (it cannot be the other way...) { QueueDirty = true; var interaction = Queue[0]; //clear "interaction cancelled" since we are leaving the interaction if (interaction.Mode != VMQueueMode.ParentIdle) { Entity.SetFlag(VMEntityFlags.InteractionCanceled, false); } if (interaction.Callback != null) { interaction.Callback.Run(Entity); } if (Queue.Count > 0) { Queue.RemoveAt(0); } ContinueExecution = true; //continue where the Allow Push idle left off } if (Stack.Count > 0) { if (discardResult) { //TODO: merge this functionality with contextSwitch. Will have to change how Allow Push works. //only used by Run Immediately currently. QueueDirty = true; if (Queue.Count > 0) { Queue.RemoveAt(0); } ActiveQueueBlock--; result = VMPrimitiveExitCode.CONTINUE; } else if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } else if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else // :( { ContinueExecution = false; } }
public void Pop(VMPrimitiveExitCode result) { var discardResult = Stack[Stack.Count - 1].DiscardResult; var contextSwitch = (Stack.Count > 1) && Stack.LastOrDefault().ActionTree != Stack[Stack.Count - 2].ActionTree; Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (discardResult) //interaction switching back to main (it cannot be the other way...) { var interaction = Queue[ActiveQueueBlock]; EndCurrentInteraction(); result = (!interaction.Flags.HasFlag(TTABFlags.RunImmediately)) ? VMPrimitiveExitCode.CONTINUE_NEXT_TICK : VMPrimitiveExitCode.CONTINUE; } if (Stack.Count > 0) { if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } else if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else // :( { ContinueExecution = false; } }
public virtual void Load(VMThreadMarshal input, VMContext context) { Stack = new List <VMStackFrame>(); foreach (var item in input.Stack) { Stack.Add((item is VMRoutingFrameMarshal) ? new VMRoutingFrame(item, context, this) : new VMStackFrame(item, context, this)); } Queue = new List <VMQueuedAction>(); QueueDirty = true; foreach (var item in input.Queue) { Queue.Add(new VMQueuedAction(item, context)); } ActiveQueueBlock = input.ActiveQueueBlock; TempRegisters = input.TempRegisters; TempXL = input.TempXL; LastStackExitCode = input.LastStackExitCode; BlockingState = input.BlockingState; EODConnection = input.EODConnection; Interrupt = input.Interrupt; ActionUID = input.ActionUID; DialogCooldown = input.DialogCooldown; ScheduleIdleStart = input.ScheduleIdleStart; }
public void Deserialize(BinaryReader reader) { var stackN = reader.ReadInt32(); Stack = new VMStackFrameMarshal[stackN]; for (int i = 0; i < stackN; i++) { var type = reader.ReadByte(); Stack[i] = (type == 1) ? new VMRoutingFrameMarshal(Version) : new VMStackFrameMarshal(Version); Stack[i].Deserialize(reader); } var queueN = reader.ReadInt32(); Queue = new VMQueuedActionMarshal[queueN]; for (int i = 0; i < queueN; i++) { Queue[i] = new VMQueuedActionMarshal(Version); Queue[i].Deserialize(reader); } if (Version > 4) { ActiveQueueBlock = reader.ReadSByte(); } TempRegisters = new short[20]; for (int i = 0; i < 20; i++) { TempRegisters[i] = reader.ReadInt16(); } TempXL = new int[2]; for (int i = 0; i < 2; i++) { TempXL[i] = reader.ReadInt32(); } LastStackExitCode = (VMPrimitiveExitCode)reader.ReadByte(); if (reader.ReadBoolean()) { BlockingState = VMAsyncState.DeserializeGeneric(reader, Version); } if (Version > 2 && reader.ReadBoolean()) { EODConnection = new VMEODPluginThreadState(); EODConnection.Version = Version; EODConnection.Deserialize(reader); } else { BlockingState = null; } Interrupt = reader.ReadBoolean(); ActionUID = reader.ReadUInt16(); DialogCooldown = reader.ReadInt32(); if (Version > 15) { ScheduleIdleStart = reader.ReadUInt32(); } }
public void Deserialize(BinaryReader reader) { var stackN = reader.ReadInt32(); Stack = new VMStackFrameMarshal[stackN]; for (int i = 0; i < stackN; i++) { var type = reader.ReadByte(); Stack[i] = (type==1)?new VMRoutingFrameMarshal():new VMStackFrameMarshal(); Stack[i].Deserialize(reader); } var queueN = reader.ReadInt32(); Queue = new VMQueuedActionMarshal[queueN]; for (int i = 0; i < queueN; i++) { Queue[i] = new VMQueuedActionMarshal(); Queue[i].Deserialize(reader); } TempRegisters = new short[20]; for (int i = 0; i < 20; i++) TempRegisters[i] = reader.ReadInt16(); TempXL = new int[2]; for (int i = 0; i < 2; i++) TempXL[i] = reader.ReadInt32(); LastStackExitCode = (VMPrimitiveExitCode)reader.ReadByte(); if (reader.ReadBoolean()) { BlockingDialog = new VMDialogResult(); BlockingDialog.Deserialize(reader); } else BlockingDialog = null; Interrupt = reader.ReadBoolean(); ActionUID = reader.ReadUInt16(); DialogCooldown = reader.ReadInt32(); }
public void Pop(VMPrimitiveExitCode result) { var discardResult = Stack[Stack.Count - 1].DiscardResult; var contextSwitch = (Stack.Count > 1) && Stack.LastOrDefault().ActionTree != Stack[Stack.Count - 2].ActionTree; Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (discardResult) //interaction switching back to main (it cannot be the other way...) { QueueDirty = true; var interaction = Queue[ActiveQueueBlock]; //clear "interaction cancelled" since we are leaving the interaction if (interaction.Mode != VMQueueMode.ParentIdle) { Entity.SetFlag(VMEntityFlags.InteractionCanceled, false); } if (interaction.Callback != null) { interaction.Callback.Run(Entity); } if (Queue.Count > 0) { Queue.RemoveAt(ActiveQueueBlock); } if (Entity is VMAvatar && !IsCheck && ActiveQueueBlock == 0) { //some things are reset when an interaction ends //motive deltas reset between interactions ((VMAvatar)Entity).SetPersonData(VMPersonDataVariable.NonInterruptable, 0); //verified in ts1 ((VMAvatar)Entity).ClearMotiveChanges(); } ContinueExecution = true; //continue where the Allow Push idle left off ActiveQueueBlock--; if (ActiveQueueBlock > -1) { Queue[ActiveQueueBlock].Cancelled = interaction.Cancelled; } result = (!interaction.Flags.HasFlag(TTABFlags.RunImmediately)) ? VMPrimitiveExitCode.CONTINUE_NEXT_TICK : VMPrimitiveExitCode.CONTINUE; } if (Stack.Count > 0) { if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } else if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else // :( { ContinueExecution = false; } }
private void HandleResult(VMStackFrame frame, VMInstruction instruction, VMPrimitiveExitCode result) { switch (result) { // Don't advance the instruction pointer, this primitive isnt finished yet case VMPrimitiveExitCode.CONTINUE_NEXT_TICK: ContinueExecution = false; break; case VMPrimitiveExitCode.ERROR: Pop(result); break; case VMPrimitiveExitCode.RETURN_TRUE: case VMPrimitiveExitCode.RETURN_FALSE: /** pop stack and return false **/ Pop(result); break; case VMPrimitiveExitCode.GOTO_TRUE: MoveToInstruction(frame, instruction.TruePointer, true); break; case VMPrimitiveExitCode.GOTO_FALSE: MoveToInstruction(frame, instruction.FalsePointer, true); break; case VMPrimitiveExitCode.GOTO_TRUE_NEXT_TICK: MoveToInstruction(frame, instruction.TruePointer, false); break; case VMPrimitiveExitCode.GOTO_FALSE_NEXT_TICK: MoveToInstruction(frame, instruction.FalsePointer, false); break; case VMPrimitiveExitCode.CONTINUE: ContinueExecution = true; break; case VMPrimitiveExitCode.INTERRUPT: Stack.Clear(); QueueDirty = true; if (Queue.Count > 0) { Queue.RemoveAt(0); } LastStackExitCode = result; break; } }
public void Deserialize(BinaryReader reader) { var stackN = reader.ReadInt32(); Stack = new VMStackFrameMarshal[stackN]; for (int i = 0; i < stackN; i++) { var type = reader.ReadByte(); Stack[i] = (type == 1)?new VMRoutingFrameMarshal():new VMStackFrameMarshal(); Stack[i].Deserialize(reader); } var queueN = reader.ReadInt32(); Queue = new VMQueuedActionMarshal[queueN]; for (int i = 0; i < queueN; i++) { Queue[i] = new VMQueuedActionMarshal(); Queue[i].Deserialize(reader); } TempRegisters = new short[20]; for (int i = 0; i < 20; i++) { TempRegisters[i] = reader.ReadInt16(); } TempXL = new int[2]; for (int i = 0; i < 2; i++) { TempXL[i] = reader.ReadInt32(); } LastStackExitCode = (VMPrimitiveExitCode)reader.ReadByte(); if (reader.ReadBoolean()) { BlockingDialog = new VMDialogResult(); BlockingDialog.Deserialize(reader); } else { BlockingDialog = null; } Interrupt = reader.ReadBoolean(); ActionUID = reader.ReadUInt16(); DialogCooldown = reader.ReadInt32(); }
private void Pop(VMPrimitiveExitCode result) { Stack.RemoveAt(Stack.Count - 1); if (Stack.Count > 0) { if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } }
private void NextInstruction() { /** Next instruction **/ var currentFrame = Stack.LastOrDefault(); if (currentFrame == null) { return; } if (currentFrame is VMRoutingFrame) { HandleResult(currentFrame, null, ((VMRoutingFrame)currentFrame).Tick()); } else { VMInstruction instruction; VMPrimitiveExitCode result = currentFrame.Routine.Execute(currentFrame, out instruction); HandleResult(currentFrame, instruction, result); } }
public virtual void Load(VMThreadMarshal input, VMContext context) { Stack = new List <VMStackFrame>(); foreach (var item in input.Stack) { Stack.Add((item is VMRoutingFrameMarshal)? new VMRoutingFrame(item, context, this) : new VMStackFrame(item, context, this)); } Queue = new List <VMQueuedAction>(); foreach (var item in input.Queue) { Queue.Add(new VMQueuedAction(item, context)); } TempRegisters = input.TempRegisters; TempXL = input.TempXL; LastStackExitCode = input.LastStackExitCode; BlockingDialog = input.BlockingDialog; Interrupt = input.Interrupt; ActionUID = input.ActionUID; DialogCooldown = input.DialogCooldown; }
public void Deserialize(BinaryReader reader) { var stackN = reader.ReadInt32(); Stack = new VMStackFrameMarshal[stackN]; for (int i = 0; i < stackN; i++) { var type = reader.ReadByte(); Stack[i] = (type==1)?new VMRoutingFrameMarshal(Version):new VMStackFrameMarshal(Version); Stack[i].Deserialize(reader); } var queueN = reader.ReadInt32(); Queue = new VMQueuedActionMarshal[queueN]; for (int i = 0; i < queueN; i++) { Queue[i] = new VMQueuedActionMarshal(); Queue[i].Deserialize(reader); } if (Version > 4) ActiveQueueBlock = reader.ReadByte(); TempRegisters = new short[20]; for (int i = 0; i < 20; i++) TempRegisters[i] = reader.ReadInt16(); TempXL = new int[2]; for (int i = 0; i < 2; i++) TempXL[i] = reader.ReadInt32(); LastStackExitCode = (VMPrimitiveExitCode)reader.ReadByte(); if (reader.ReadBoolean()) BlockingState = VMAsyncState.DeserializeGeneric(reader, Version); if (Version > 2 && reader.ReadBoolean()) { EODConnection = new VMEODPluginThreadState(); EODConnection.Version = Version; EODConnection.Deserialize(reader); } else BlockingState = null; Interrupt = reader.ReadBoolean(); ActionUID = reader.ReadUInt16(); DialogCooldown = reader.ReadInt32(); }
void HandleResult(VMStackFrame frame, VMInstruction instruction, VMPrimitiveExitCode result) { switch (result) { // Don't advance the instruction pointer, this primitive isnt finished yet case VMPrimitiveExitCode.CONTINUE_NEXT_TICK: ScheduleIdleStart = Context.VM.Scheduler.CurrentTickID; Context.VM.Scheduler.ScheduleTickIn(Entity, 1); ContinueExecution = false; break; case VMPrimitiveExitCode.CONTINUE_FUTURE_TICK: ContinueExecution = false; break; case VMPrimitiveExitCode.ERROR: ContinueExecution = false; Pop(result); break; case VMPrimitiveExitCode.RETURN_TRUE: case VMPrimitiveExitCode.RETURN_FALSE: /** pop stack and return false **/ Pop(result); break; case VMPrimitiveExitCode.GOTO_TRUE: MoveToInstruction(frame, instruction.TruePointer, true); break; case VMPrimitiveExitCode.GOTO_FALSE: MoveToInstruction(frame, instruction.FalsePointer, true); break; case VMPrimitiveExitCode.GOTO_TRUE_NEXT_TICK: MoveToInstruction(frame, instruction.TruePointer, true); if (ContinueExecution) { ScheduleIdleStart = Context.VM.Scheduler.CurrentTickID; Context.VM.Scheduler.ScheduleTickIn(Entity, 1); ContinueExecution = false; } break; case VMPrimitiveExitCode.GOTO_FALSE_NEXT_TICK: MoveToInstruction(frame, instruction.FalsePointer, true); if (ContinueExecution) { ScheduleIdleStart = Context.VM.Scheduler.CurrentTickID; Context.VM.Scheduler.ScheduleTickIn(Entity, 1); ContinueExecution = false; } break; case VMPrimitiveExitCode.CONTINUE: ContinueExecution = true; break; case VMPrimitiveExitCode.INTERRUPT: Stack.Clear(); QueueDirty = true; if (Queue.Count > 0) { Queue.RemoveAt(0); } LastStackExitCode = result; break; } }
private void HandleResult(VMStackFrame frame, VMInstruction instruction, VMPrimitiveExitCode result) { switch (result) { // Don't advance the instruction pointer, this primitive isnt finished yet case VMPrimitiveExitCode.CONTINUE_NEXT_TICK: ContinueExecution = false; break; case VMPrimitiveExitCode.ERROR: Pop(result); break; case VMPrimitiveExitCode.RETURN_TRUE: case VMPrimitiveExitCode.RETURN_FALSE: /** pop stack and return false **/ Pop(result); break; case VMPrimitiveExitCode.GOTO_TRUE: MoveToInstruction(frame, instruction.TruePointer, true); break; case VMPrimitiveExitCode.GOTO_FALSE: MoveToInstruction(frame, instruction.FalsePointer, true); break; case VMPrimitiveExitCode.GOTO_TRUE_NEXT_TICK: MoveToInstruction(frame, instruction.TruePointer, false); break; case VMPrimitiveExitCode.GOTO_FALSE_NEXT_TICK: MoveToInstruction(frame, instruction.FalsePointer, false); break; case VMPrimitiveExitCode.CONTINUE: ContinueExecution = true; break; case VMPrimitiveExitCode.INTERRUPT: Stack.Clear(); if (Queue.Count > 0) Queue.RemoveAt(0); LastStackExitCode = result; break; } }
public void Pop(VMPrimitiveExitCode result) { Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (Stack.Count > 0) { if (result == VMPrimitiveExitCode.RETURN_TRUE) { result = VMPrimitiveExitCode.GOTO_TRUE; } if (result == VMPrimitiveExitCode.RETURN_FALSE) { result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else //interaction finished! { if (Queue[0].Callback != null) Queue[0].Callback.Run(Entity); if (Queue.Count > 0) Queue.RemoveAt(0); } }
public virtual void Load(VMThreadMarshal input, VMContext context) { Stack = new List<VMStackFrame>(); foreach (var item in input.Stack) { Stack.Add((item is VMRoutingFrameMarshal)? new VMRoutingFrame(item, context, this) : new VMStackFrame(item, context, this)); } Queue = new List<VMQueuedAction>(); foreach (var item in input.Queue) Queue.Add(new VMQueuedAction(item, context)); TempRegisters = input.TempRegisters; TempXL = input.TempXL; LastStackExitCode = input.LastStackExitCode; BlockingDialog = input.BlockingDialog; Interrupt = input.Interrupt; ActionUID = input.ActionUID; DialogCooldown = input.DialogCooldown; }
private void Pop(VMPrimitiveExitCode result) { StackPointer--; if (StackPointer >= 0){ if (result == VMPrimitiveExitCode.RETURN_TRUE){ result = VMPrimitiveExitCode.GOTO_TRUE; } if (result == VMPrimitiveExitCode.RETURN_FALSE){ result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack[StackPointer]; HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } }
private void Pop(VMPrimitiveExitCode result) { Stack.RemoveAt(Stack.Count - 1); if (Stack.Count > 0){ if (result == VMPrimitiveExitCode.RETURN_TRUE){ result = VMPrimitiveExitCode.GOTO_TRUE; } if (result == VMPrimitiveExitCode.RETURN_FALSE){ result = VMPrimitiveExitCode.GOTO_FALSE; } var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } }
public void Pop(VMPrimitiveExitCode result){ var discardResult = Stack[Stack.Count - 1].DiscardResult; var contextSwitch = (Stack.Count > 1) && Stack.LastOrDefault().ActionTree != Stack[Stack.Count - 2].ActionTree; if (contextSwitch && !Stack.LastOrDefault().ActionTree) { } Stack.RemoveAt(Stack.Count - 1); LastStackExitCode = result; if (contextSwitch) //interaction switching back to main (it cannot be the other way...) { QueueDirty = true; var interaction = Queue[0]; //clear "interaction cancelled" since we are leaving the interaction if (interaction.Mode != VMQueueMode.ParentIdle) Entity.SetFlag(VMEntityFlags.InteractionCanceled, false); if (interaction.Callback != null) interaction.Callback.Run(Entity); if (Queue.Count > 0) Queue.RemoveAt(0); ContinueExecution = true; //continue where the Allow Push idle left off } if (Stack.Count > 0) { if (discardResult) { //TODO: merge this functionality with contextSwitch. Will have to change how Allow Push works. //only used by Run Immediately currently. QueueDirty = true; if (Queue.Count > 0) Queue.RemoveAt(0); ActiveQueueBlock--; result = VMPrimitiveExitCode.CONTINUE; } else if (result == VMPrimitiveExitCode.RETURN_TRUE) result = VMPrimitiveExitCode.GOTO_TRUE; else if (result == VMPrimitiveExitCode.RETURN_FALSE) result = VMPrimitiveExitCode.GOTO_FALSE; var currentFrame = Stack.Last(); HandleResult(currentFrame, currentFrame.GetCurrentInstruction(), result); } else // :( { ContinueExecution = false; } }