Ejemplo n.º 1
0
 public static VMPrimitiveExitCode EvaluateCheck(VMContext context, VMEntity entity, VMQueuedAction action)
 {
     var temp = new VMThread(context, entity, 5);
     temp.EnqueueAction(action);
     while (temp.Queue.Count > 0) //keep going till we're done! idling is for losers!
     {
         temp.Tick();
     }
     context.ThreadRemove(temp); //hopefully this thread should be completely dereferenced...
     return temp.LastStackExitCode;
 }
Ejemplo n.º 2
0
        private void ExecuteAction(VMQueuedAction action)
        {
            var frame = new VMStackFrame {
                Caller      = Entity,
                Callee      = action.Callee,
                CodeOwner   = action.CodeOwner,
                Routine     = action.Routine,
                StackObject = action.StackObject
            };

            if (action.Args == null)
            {
                frame.Args = new short[4];                      //always 4? i got crashes when i used the value provided by the routine, when for that same routine edith displayed 4 in the properties...
            }
            else
            {
                frame.Args = action.Args;  //WARNING - if you use this, the args array MUST have the same number of elements the routine is expecting!
            }
            Push(frame);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Add an item to the action queue
 /// </summary>
 /// <param name="invocation"></param>
 public void EnqueueAction(VMQueuedAction invocation)
 {
     if (Queue.Count == 0) //if empty, just queue right at the front (or end, if you're like that!)
     {
         this.Queue.Add(invocation);
         Context.ThreadActive(this);
     }
     else //we've got an even harder job! find a place for this interaction based on its priority
     {
         for (int i = Queue.Count - 1; i > 0; i--)
         {
             if (invocation.Priority >= Queue[i].Priority) //if the next queue element we need to skip over is of the same or a higher priority we'll stay right here, otherwise skip over it!
             {
                 this.Queue.Insert(i + 1, invocation);
                 return;
             }
         }
         this.Queue.Insert(1, invocation); //this is more important than all other queued items that are not running, so stick this to run next.
     }
     EvaluateQueuePriorities();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Add an item to the action queue
 /// </summary>
 /// <param name="invocation"></param>
 public void EnqueueAction(VMQueuedAction invocation)
 {
     if (Queue.Count == 0) //if empty, just queue right at the front (or end, if you're like that!)
     {
         this.Queue.Add(invocation);
         Context.ThreadActive(this);
     }
     else //we've got an even harder job! find a place for this interaction based on its priority
     {
         for (int i = Queue.Count - 1; i > 0; i--)
         {
             if (invocation.Priority >= Queue[i].Priority) //if the next queue element we need to skip over is of the same or a higher priority we'll stay right here, otherwise skip over it!
             {
                 this.Queue.Insert(i+1, invocation);
                 return;
             }
         }
         this.Queue.Insert(1, invocation); //this is more important than all other queued items that are not running, so stick this to run next.
     }
     EvaluateQueuePriorities();
 }
Ejemplo n.º 5
0
        public static VMPrimitiveExitCode EvaluateCheck(VMContext context, VMEntity entity, VMQueuedAction action)
        {
            var temp = new VMThread(context, entity, 5);

            temp.EnqueueAction(action);
            while (temp.Queue.Count > 0) //keep going till we're done! idling is for losers!
            {
                temp.Tick();
            }
            context.ThreadRemove(temp); //hopefully this thread should be completely dereferenced...
            return(temp.LastStackExitCode);
        }
Ejemplo n.º 6
0
        public void ExecuteEntryPoint(int entry, VMContext context, bool runImmediately)
        {
            if (entry == 11)
            {
                //user placement, hack to do auto floor removal/placement for stairs
                if (Object.OBJ.LevelOffset > 0 && Position != LotTilePos.OUT_OF_WORLD)
                {
                    var floor = context.Architecture.GetFloor(Position.TileX, Position.TileY, Position.Level);
                    var placeFlags = (VMPlacementFlags)ObjectData[(int)VMStackObjectVariable.PlacementFlags];
                    if ((placeFlags & VMPlacementFlags.InAir) > 0)
                        context.Architecture.SetFloor(Position.TileX, Position.TileY, Position.Level, new FloorTile(), true);
                    if ((placeFlags & VMPlacementFlags.OnFloor) > 0 && (floor.Pattern == 0))
                        context.Architecture.SetFloor(Position.TileX, Position.TileY, Position.Level, new FloorTile { Pattern = 1 } , true);
                }
            }
            if (EntryPoints[entry].ActionFunction > 255)
            {
                BHAV bhav;
                GameIffResource CodeOwner;
                ushort ActionID = EntryPoints[entry].ActionFunction;
                if (ActionID < 4096)
                { //global

                    bhav = context.Globals.Resource.Get<BHAV>(ActionID);
                }
                else if (ActionID < 8192)
                { //local
                    bhav = Object.Resource.Get<BHAV>(ActionID);
                }
                else
                { //semi-global
                    bhav = SemiGlobal.Resource.Get<BHAV>(ActionID);
                }

                CodeOwner = Object.Resource;

                var routine = context.VM.Assemble(bhav);
                if (bhav == null) return; //throw new Exception("Invalid BHAV call!");

                short[] Args = null;
                VMEntity StackOBJ = null;
                if (entry == 1)
                {
                    if (MainParam != 0)
                    {
                        Args = new short[4];
                        Args[0] = MainParam;
                        MainParam = 0;
                    }
                    if (MainStackOBJ != 0)
                    {
                        StackOBJ = context.VM.GetObjectById(MainStackOBJ);
                        MainStackOBJ = 0;
                    }
                }

                var action = new TSO.Simantics.engine.VMQueuedAction
                {
                    Callee = this,
                    CodeOwner = CodeOwner,
                    /** Main function **/
                    StackObject = StackOBJ,
                    Routine = routine,
                    Args = Args
                };

                if (runImmediately)
                    VMThread.EvaluateCheck(context, this, action);
                else
                    this.Thread.EnqueueAction(action);
            }
        }
Ejemplo n.º 7
0
        private void ExecuteAction(VMQueuedAction action)
        {
            var frame = new VMStackFrame {
                Caller = Entity,
                Callee = action.Callee,
                CodeOwner = action.CodeOwner,
                Routine = action.Routine,
                StackObject = action.StackObject
            };
            if (action.Args == null) frame.Args = new short[4]; //always 4? i got crashes when i used the value provided by the routine, when for that same routine edith displayed 4 in the properties...
            else frame.Args = action.Args; //WARNING - if you use this, the args array MUST have the same number of elements the routine is expecting!

            Push(frame);
        }
Ejemplo n.º 8
0
        public void ExecuteEntryPoint(int entry,VMContext context,bool runImmediately)
        {
            if (EntryPoints[entry].ActionFunction > 255)
            {
                BHAV            bhav;
                GameIffResource CodeOwner;
                ushort          ActionID = EntryPoints[entry].ActionFunction;
                if (ActionID < 4096)
                { //global
                    bhav      = context.Globals.Resource.Get <BHAV>(ActionID);
                    CodeOwner = context.Globals.Resource;
                }
                else if (ActionID < 8192)
                { //local
                    bhav      = Object.Resource.Get <BHAV>(ActionID);
                    CodeOwner = Object.Resource;
                }
                else
                { //semi-global
                    bhav      = SemiGlobal.Resource.Get <BHAV>(ActionID);
                    CodeOwner = SemiGlobal.Resource;
                }

                var routine = context.VM.Assemble(bhav);
                if (bhav == null)
                {
                    return;               //throw new Exception("Invalid BHAV call!");
                }
                short[]  Args     = null;
                VMEntity StackOBJ = null;
                if (entry == 1)
                {
                    if (MainParam != 0)
                    {
                        Args      = new short[4];
                        Args[0]   = MainParam;
                        MainParam = 0;
                    }
                    if (MainStackOBJ != 0)
                    {
                        StackOBJ     = context.VM.GetObjectById(MainStackOBJ);
                        MainStackOBJ = 0;
                    }
                }

                var action = new TSO.Simantics.engine.VMQueuedAction
                {
                    Callee    = this,
                    CodeOwner = CodeOwner,
                    /** Main function **/
                    StackObject = StackOBJ,
                    Routine     = routine,
                    Args        = Args
                };

                if (runImmediately)
                {
                    VMThread.EvaluateCheck(context,this,action);
                }
                else
                {
                    this.Thread.EnqueueAction(action);
                }
            }
        }
Ejemplo n.º 9
0
        public void ExecuteEntryPoint(int entry, VMContext context, bool runImmediately)
        {
            if (EntryPoints[entry].ActionFunction > 255)
            {
                BHAV bhav;
                GameIffResource CodeOwner;
                ushort ActionID = EntryPoints[entry].ActionFunction;
                if (ActionID < 4096)
                { //global

                    bhav = context.Globals.Resource.Get<BHAV>(ActionID);
                    CodeOwner = context.Globals.Resource;
                }
                else if (ActionID < 8192)
                { //local
                    bhav = Object.Resource.Get<BHAV>(ActionID);
                    CodeOwner = Object.Resource;
                }
                else
                { //semi-global
                    bhav = SemiGlobal.Resource.Get<BHAV>(ActionID);
                    CodeOwner = SemiGlobal.Resource;
                }

                var routine = context.VM.Assemble(bhav);
                if (bhav == null) return; //throw new Exception("Invalid BHAV call!");

                short[] Args = null;
                VMEntity StackOBJ = null;
                if (entry == 1)
                {
                    if (MainParam != 0)
                    {
                        Args = new short[4];
                        Args[0] = MainParam;
                        MainParam = 0;
                    }
                    if (MainStackOBJ != 0)
                    {
                        StackOBJ = context.VM.GetObjectById(MainStackOBJ);
                        MainStackOBJ = 0;
                    }
                }

                var action = new TSO.Simantics.engine.VMQueuedAction
                {
                    Callee = this,
                    CodeOwner = CodeOwner,
                    /** Main function **/
                    StackObject = StackOBJ,
                    Routine = routine,
                    Args = Args
                };

                if (runImmediately)
                    VMThread.EvaluateCheck(context, this, action);
                else
                    this.Thread.EnqueueAction(action);
            }
        }