示例#1
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            GraphicChunk = (SPR2)chunk;
            ActiveIff = res;

            FrameList.Items.Clear();
            for (int i=0; i< GraphicChunk.Frames.Length / 3; i++)
            {
                FrameList.Items.Add("Rotation " + i);
            }

            bool hasFrames = (FrameList.Items.Count > 0);
            Graphics = null;
            if (hasFrames) FrameList.SelectedIndex = 0;
            else
            {
                SPRBox1.Image = null;
                SPRBox2.Image = null;
                SPRBox3.Image = null;
            }
            DeleteButton.Enabled = hasFrames;
            ImportButton.Enabled = hasFrames;
            ExportButton.Enabled = hasFrames;
            ImportAll.Enabled = hasFrames;
            ExportAll.Enabled = hasFrames;
        }
示例#2
0
        public IffResWindow OpenResourceWindow(GameIffResource res, GameObject target)
        {
            if (ResourceWindow.ContainsKey(res.MainIff))
            {
                var resWindow = ResourceWindow[res.MainIff];
                var form      = (Form)resWindow;
                if (form.WindowState == FormWindowState.Minimized)
                {
                    form.WindowState = FormWindowState.Normal;
                }
                resWindow.Activate();
                resWindow.SetTargetObject(target);
                return(resWindow);
            }
            //detect if object, spawn iff res if not.
            //WARNING: if OBJD missing or present in files it should not be, bad things will happen!

            IffResWindow window;
            var          objs = res.List <OBJD>();

            if (objs != null && objs.Count > 0 && res is GameObjectResource)
            {
                window = new ObjectWindow(res, (target == null) ? GameContent.Get.WorldObjects.Get(objs[0].GUID) : target);
            }
            else
            {
                window = new IffResourceViewer(res.MainIff.Filename, res, target);
            }

            ResourceWindow.Add(res.MainIff, window);
            window.Show();
            window.Activate();
            return(window);
        }
示例#3
0
        public SPR2SelectorDialog(GameIffResource iff, GameObject srcObj)
            : this()
        {
            iffRes.Init(
                new Type[] { typeof(SPR2) },
                new string[] { "Sprites" },
                new OBJDSelector[][]
                {
                    new OBJDSelector[]
                    {
                        new OBJDSelector("Chosen Sprite", null, new OBJDSelector.OBJDSelectorCallback((IffChunk chunk) => {
                            var spr = (SPR2)chunk;
                            if (spr != null) {
                                ChosenID = spr.ChunkID;
                                DialogResult = DialogResult.OK;
                            }
                            Close();
                        }))
                    }
                }
                );
            iffRes.ChangeIffSource(iff);
            iffRes.ChangeActiveObject(srcObj);

            iffRes.SetAlphaOrder(false);
        }
示例#4
0
        public virtual VMRoutine Assemble(BHAV bhav, GameIffResource res)
        {
            var routine = new VMRoutine();

            PopulateRoutineFields(bhav, routine);
            return(routine);
        }
示例#5
0
        public SPR2SelectorDialog(GameIffResource iff, GameObject srcObj) : this()
        {
            iffRes.Init(
                new Type[] { typeof(SPR2) },
                new string[] { "Sprites" },
                new OBJDSelector[][]
            {
                new OBJDSelector[]
                {
                    new OBJDSelector("Chosen Sprite", null, new OBJDSelector.OBJDSelectorCallback((IffChunk chunk) => {
                        var spr = (SPR2)chunk;
                        if (spr != null)
                        {
                            ChosenID     = spr.ChunkID;
                            DialogResult = DialogResult.OK;
                        }
                        Close();
                    }))
                }
            }
                );
            iffRes.ChangeIffSource(iff);
            iffRes.ChangeActiveObject(srcObj);

            iffRes.SetAlphaOrder(false);
        }
示例#6
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            OTFFile tuning = null;

            if (res is GameObjectResource)
            {
                tuning = ((GameObjectResource)res).Tuning;
            }
            else if (res is GameGlobalResource)
            {
                tuning = ((GameGlobalResource)res).Tuning;
            }
            if (tuning == null)
            {
                XMLDisplay.Text = "No OTF is present for this iff.";
            }
            else
            {
                using (var stream = new StringWriter())
                {
                    var writer = new XmlTextWriter(stream);
                    writer.Formatting  = Formatting.Indented;
                    writer.Indentation = 2;

                    tuning.Document.Save(writer);

                    XMLDisplay.Text = stream.ToString();
                }
            }
        }
示例#7
0
        public IffResWindow OpenResourceWindow(GameIffResource res, GameObject target)
        {
            if (ResourceWindow.ContainsKey(res.MainIff))
            {
                var resWindow = ResourceWindow[res.MainIff];
                var form = (Form)resWindow;
                if (form.WindowState == FormWindowState.Minimized) form.WindowState = FormWindowState.Normal;
                resWindow.Activate();
                resWindow.SetTargetObject(target);
                return resWindow;
            }
            //detect if object, spawn iff res if not.
            //WARNING: if OBJD missing or present in files it should not be, bad things will happen!

            IffResWindow window;
            var objs = res.List<OBJD>();
            if (objs != null && objs.Count > 0)
            {
                window = new ObjectWindow(res, (target == null) ? Content.Content.Get().WorldObjects.Get(objs[0].GUID) : target);
            }
            else
            {
                window = new IffResourceViewer(res.MainIff.Filename, res, target);
            }

            ResourceWindow.Add(res.MainIff, window);
            window.Show();
            window.Activate();
            return window;
        }
示例#8
0
        private void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null)
            {
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }
            System.Diagnostics.Debug.WriteLine("Invoke: " + bhav.ChunkLabel);
            System.Diagnostics.Debug.WriteLine("");

            var routine    = frame.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine     = routine,
                Caller      = frame.Caller,
                Callee      = frame.Callee,
                CodeOwner   = codeOwner,
                StackObject = frame.StackObject
            };

            childFrame.Args = new short[routine.Arguments];
            for (var i = 0; i < childFrame.Args.Length; i++)
            {
                var argValue = args.Arguments[i];
                if (argValue == -1)
                {
                    /** TODO: Is this the right rule? Maybe a flag decides when to copy from temp? **/
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
示例#9
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            GraphicChunk = (SPR2)chunk;
            ActiveIff    = res;

            FrameList.Items.Clear();
            for (int i = 0; i < GraphicChunk.Frames.Length / 3; i++)
            {
                FrameList.Items.Add("Rotation " + i);
            }

            bool hasFrames = (FrameList.Items.Count > 0);

            Graphics = null;
            if (hasFrames)
            {
                FrameList.SelectedIndex = 0;
            }
            else
            {
                SPRBox1.Image = null;
                SPRBox2.Image = null;
                SPRBox3.Image = null;
            }
            DeleteButton.Enabled = hasFrames;
            ImportButton.Enabled = hasFrames;
            ExportButton.Enabled = hasFrames;
            ImportAll.Enabled    = hasFrames;
            ExportAll.Enabled    = hasFrames;
        }
示例#10
0
        public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null)
            {
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }

            var routine    = frame.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine     = routine,
                Caller      = frame.Caller,
                Callee      = frame.Callee,
                CodeOwner   = codeOwner,
                StackObject = frame.StackObject
            };

            childFrame.Args = new short[4];
            for (var i = 0; i < childFrame.Args.Length; i++)
            {
                var argValue = args.Arguments[i];
                if (argValue == -1)
                {
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
示例#11
0
        private async Task <RoslynSimanticsModule> LoadModule(GameIffResource res)
        {
            var module = Parent.GetModuleFor(res);
            await module.GetModuleAsync();

            return(module);
        }
示例#12
0
        public IffResourceViewer(string name, GameIffResource iff, GameObject srcObj) : this()
        {
            iffRes.Init();
            iffRes.ChangeIffSource(iff);
            iffRes.ChangeActiveObject(srcObj);

            Text = "Iff Editor - " + name;
        }
示例#13
0
 public ObjectWindow(GameIffResource iff, GameObject obj) : this()
 {
     DefinitionEditor.Init(null, this);
     IffResView.Init();
     IffResView.ChangeIffSource(iff);
     ActiveObj = obj;
     ActiveIff = iff;
     RegenObjMeta(iff);
 }
示例#14
0
 public ObjectWindow(GameIffResource iff, GameObject obj)
     : this()
 {
     DefinitionEditor.Init(null, this);
     IffResView.Init();
     IffResView.ChangeIffSource(iff);
     ActiveObj = obj;
     ActiveIff = iff;
     RegenObjMeta(iff);
 }
示例#15
0
        public SelectTreeDialog(GameIffResource res)
        {
            InitializeComponent();
            Resource = res;

            CurrentFullList = new List <InstructionIDNamePair>();
            CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.Private));
            CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.SemiGlobal));
            CurrentFullList.AddRange(GetAllSubroutines(ScopeSource.Global));

            RenderList();
        }
示例#16
0
        public void SetActiveObject(GameObject active)
        {
            ActiveObject = active;
            ActiveIff    = active.Resource;
            ActiveDGRP   = null;

            SelectSpriteBox.Enabled = false;
            groupBox3.Enabled       = false;

            int sprID = active.OBJ.DynamicSpriteBaseId;
            var spr2  = ActiveIff.Get <SPR2>((ushort)sprID);

            if (spr2 != null)
            {
                FirstDynLabel.Text = spr2.ChunkLabel;
            }
            else if (sprID == 0)
            {
                FirstDynLabel.Text = "None Selected";
            }
            else
            {
                FirstDynLabel.Text = "Unknown SPR2#" + sprID;
            }

            sprID = active.OBJ.DynamicSpriteBaseId + active.OBJ.NumDynamicSprites - 1;
            if (active.OBJ.NumDynamicSprites == 0)
            {
                sprID = 0;
            }
            spr2 = ActiveIff.Get <SPR2>((ushort)sprID);

            if (spr2 != null)
            {
                LastDynLabel.Text = spr2.ChunkLabel;
            }
            else if (sprID < 1)
            {
                LastDynLabel.Text = "None Selected";
            }
            else
            {
                LastDynLabel.Text = "Unknown SPR2#" + sprID;
            }

            DGRPEdit.ShowObject(active.OBJ.GUID);

            UpdateDGRPList(true);
            var allowEdit = (ActiveObject.OBJ.ObjectType != OBJDType.Person);

            groupBox1.Enabled = allowEdit;
            DGRPBox.Enabled   = allowEdit;
        }
示例#17
0
        public bool RegenObjMeta(GameIffResource res)
        {
            var objd    = res.List <OBJD>();
            var entries = new List <ObjectRegistryEntry>();

            foreach (var obj in objd)
            {
                var entry = new ObjectRegistryEntry
                {
                    GUID     = obj.GUID,
                    Filename = res.MainIff.Filename,
                    Name     = obj.ChunkLabel,
                    Group    = (short)obj.MasterID,
                    SubIndex = obj.SubIndex
                };
                entries.Add(entry);
            }

            if (entries.Count == 0)
            {
                return(false);
            }

            entries = entries.OrderBy(x => x.SubIndex).OrderBy(x => x.Group).ToList();

            var GUID = (ActiveObj == null) ? 0 : ActiveObj.OBJ.GUID;

            //populate object selected box with options
            ObjCombo.Items.Clear();
            int i = 0;

            foreach (var item in entries)
            {
                ObjCombo.Items.Add(item);
                if (item.GUID == GUID)
                {
                    ObjCombo.SelectedIndex = i;
                }
                i++;
            }
            if (ObjCombo.SelectedIndex == -1)
            {
                ObjCombo.SelectedIndex = 0;
            }

            Text = "Edit Object - " + ActiveObjTable.Filename;
            return(true);
        }
示例#18
0
        //type 2 will be function callback.

        public void Run(VMEntity cbOwner)
        {
            if (type == 1)
            {
                BHAV            bhav;
                GameIffResource CodeOwner = null;
                var             Action    = Target.TreeTable.InteractionByIndex[Interaction];
                ushort          ActionID  = Action.ActionFunction;

                if (ActionID < 4096)
                { //global
                    bhav = null;
                    //unimp as it has to access the context to get this.
                }
                else if (ActionID < 8192)
                { //local
                    bhav      = Target.Object.Resource.Get <BHAV>(ActionID);
                    CodeOwner = Target.Object.Resource;
                }
                else
                { //semi-global
                    bhav      = Target.SemiGlobal.Resource.Get <BHAV>(ActionID);
                    CodeOwner = Target.SemiGlobal.Resource;
                }

                var routine = vm.Assemble(bhav);
                var args    = new short[4];
                if (SetParam)
                {
                    args[0] = cbOwner.ObjectID;
                }

                Caller.Thread.EnqueueAction(
                    new TSO.Simantics.engine.VMQueuedAction
                {
                    Callee            = Target,
                    CodeOwner         = CodeOwner,
                    Routine           = routine,
                    Name              = Target.TreeTableStrings.GetString((int)Action.TTAIndex),
                    StackObject       = this.StackObject,
                    Args              = args,
                    InteractionNumber = Interaction,
                    Priority          = VMQueuePriority.Maximum //not sure if this is meant to be the case!
                }
                    );
            }
        }
示例#19
0
        public void SetActiveIff(GameIffResource iff)
        {
            ActiveObj = iff;
            ActiveIff = iff.MainIff;
            var piffs = ActiveIff.RuntimeInfo.Patches;

            ActivePIFF     = piffs.FirstOrDefault();
            ActivePIFFs[0] = ActiveIff.RuntimeInfo.Patches.FirstOrDefault(x => x.Filename?.EndsWith(".str.piff") != true);
            ActivePIFFs[1] = null;
            ActivePIFFs[2] = ActiveIff.RuntimeInfo.Patches.FirstOrDefault(x => x.Filename?.EndsWith(".str.piff") == true);

            PIFFButton.Enabled = ActivePIFFs[0] != null;
            SPFButton.Enabled  = ActivePIFFs[1] != null;
            STRButton.Enabled  = ActivePIFFs[2] != null;

            SelectPIFF(Array.FindIndex(ActivePIFFs, x => x != null));
        }
示例#20
0
        public void SetActiveObject(GameObject obj)
        {
            ActiveObj = obj.Resource;
            ActiveIff = obj.Resource.MainIff;
            var piffs = ActiveIff.RuntimeInfo.Patches;

            ActivePIFF     = piffs.FirstOrDefault();
            ActivePIFFs[0] = obj.Resource.Iff.RuntimeInfo.Patches.FirstOrDefault(x => x.Filename?.EndsWith(".str.piff") != true);
            ActivePIFFs[1] = (obj.Resource.Sprites == null) ? null : obj.Resource.Sprites.RuntimeInfo.Patches.FirstOrDefault();
            ActivePIFFs[2] = obj.Resource.Iff.RuntimeInfo.Patches.FirstOrDefault(x => x.Filename?.EndsWith(".str.piff") == true);

            PIFFButton.Enabled = ActivePIFFs[0] != null;
            SPFButton.Enabled  = ActivePIFFs[1] != null;
            STRButton.Enabled  = ActivePIFFs[2] != null;

            SelectPIFF(Array.FindIndex(ActivePIFFs, x => x != null));
        }
示例#21
0
        public void SetActiveObject(GameObject active)
        {
            ActiveObject = active;
            ActiveIff    = active.Resource;
            ActiveDGRP   = null;

            Debug3D.ShowObject(active.OBJ.GUID);

            UpdateDGRPList(true);
            var allowEdit = (ActiveObject.OBJ.ObjectType != OBJDType.Person);

            DGRPBox.Enabled = allowEdit;

            var lower = active.OBJ.ChunkParent.Filename.ToLowerInvariant();

            if (!DGRP3DMesh.ParamsByIff.TryGetValue(lower, out ActiveParams))
            {
                ActiveParams = new DGRPRCParams();
            }

            ActiveFSOR     = ActiveIff.List <FSOR>()?.FirstOrDefault();
            InternalChange = true;
            if (ActiveFSOR == null)
            {
                IffMode = false;
            }
            else
            {
                IffMode      = true;
                ActiveParams = ActiveFSOR.Params;
            }

            SimpleCheck.Checked  = ActiveParams.Simplify;
            DoorCheck.Checked    = ActiveParams.DoorFix;
            CounterCheck.Checked = ActiveParams.CounterFix;
            BlenderCheck.Checked = ActiveParams.BlenderTweak;
            Rot1.Checked         = ActiveParams.Rotations[0];
            Rot2.Checked         = ActiveParams.Rotations[1];
            Rot3.Checked         = ActiveParams.Rotations[2];
            Rot4.Checked         = ActiveParams.Rotations[3];

            IffCheck.Checked = IffMode;

            InternalChange = false;
        }
 public RoslynSimanticsModule(RoslynSimanticsContext context, GameIffResource file)
 {
     Context = context;
     File    = file;
     if (file is GameGlobalResource)
     {
         if (file.MainIff.Filename == "global.iff")
         {
             IsGlobal = true;
         }
         else
         {
             IsSemiGlobal = true;
         }
     }
     Name     = CSTranslationContext.FormatName(File.MainIff.Filename.Replace(".iff", ""));
     FilePath = Path.Combine(Context.CacheDirectory, Name);
 }
示例#23
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            Resource   = res;
            Strings    = res.Get <TTAs>(chunk.ChunkID);
            ActiveTTAB = (TTAB)chunk;

            if (Strings == null)
            {
                //we have a problem... make us some strings!
                Strings                = new TTAs();
                Strings.ChunkLabel     = chunk.ChunkLabel;
                Strings.ChunkID        = chunk.ChunkID;
                Strings.ChunkProcessed = true;
                res.MainIff.AddChunk(Strings);
            }

            UpdateListing();
            UpdateSelection(-1);
        }
示例#24
0
        public RoslynSimanticsModule GetModuleFor(GameIffResource res)
        {
            var source = res.MainIff;
            var name   = CSTranslationContext.FormatName(source.Filename.Substring(0, source.Filename.Length - 4));
            RoslynSimanticsModule result;

            lock (FormattedNameToRoslynModule) {
                if (FormattedNameToRoslynModule.TryGetValue(name, out result))
                {
                    return(result);
                }
                else
                {
                    //try to create one!
                    result = new RoslynSimanticsModule(Context, res);
                    FormattedNameToRoslynModule[name] = result;
                    return(result);
                }
            }
        }
示例#25
0
        public bool RunInMyStack(BHAV bhav, GameIffResource CodeOwner)
        {
            var prevFrame = Stack[Stack.Count - 1];
            var OldStack  = Stack;
            var OldQueue  = Queue;

            Stack = new List <VMStackFrame>()
            {
                prevFrame
            };
            Queue = new List <VMQueuedAction>()
            {
                Queue[0]
            };
            ExecuteSubRoutine(prevFrame, bhav, CodeOwner, new VMSubRoutineOperand(new short[] { -1, -1, -1, -1 }));
            Stack.RemoveAt(0);
            if (Stack.Count == 0)
            {
                Stack = OldStack;
                Queue = OldQueue;
                return(false);
                //bhav was invalid/empty
            }
            var frame = Stack[Stack.Count - 1];

            while (Stack.Count > 0)
            {
                NextInstruction();
            }

            //copy child stack things to parent stack

            prevFrame.Args        = frame.Args;
            prevFrame.StackObject = frame.StackObject;
            Stack = OldStack;
            Queue = OldQueue;

            return((LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) ? true : false);
        }
示例#26
0
        public string GetTuningVariableLabel(GameIffResource res, uint tableID, uint keyID)
        {
            var bcon = res.Get <BCON>((ushort)(tableID));

            if (bcon != null)
            {
                var trcn = res.Get <TRCN>((ushort)(tableID));
                if (trcn != null && keyID < trcn.Entries.Length)
                {
                    return(trcn.Entries[keyID].Label);
                }
                return(bcon.ChunkLabel + " #" + keyID);
            }

            var tuning = res.Get <OTFTable>((ushort)(tableID));

            if (tuning != null)
            {
                return(tuning.GetKey((int)keyID)?.Label ?? "");
            }
            return(tableID + ":" + keyID);
        }
示例#27
0
        public bool RegenObjMeta(GameIffResource res)
        {
            var objd = res.List<OBJD>();
            var entries = new List<ObjectRegistryEntry>();

            foreach (var obj in objd)
            {
                ObjectRegistryEntry entry = new ObjectRegistryEntry
                {
                    GUID = obj.GUID,
                    Filename = res.MainIff.Filename,
                    Name = obj.ChunkLabel,
                    Group = (short)obj.MasterID,
                    SubIndex = obj.SubIndex
                };
                entries.Add(entry);
            }

            if (entries.Count == 0) return false;

            entries = entries.OrderBy(x => x.SubIndex).OrderBy(x => x.Group).ToList();

            var GUID = (ActiveObj == null) ? 0 : ActiveObj.OBJ.GUID;
            //populate object selected box with options
            ObjCombo.Items.Clear();
            int i = 0;
            foreach (var item in entries)
            {
                ObjCombo.Items.Add(item);
                if (item.GUID == GUID) ObjCombo.SelectedIndex = i;
                i++;
            }
            if (ObjCombo.SelectedIndex == -1) ObjCombo.SelectedIndex = 0;

            Text = "Edit Object - " + ActiveObjTable.Filename;
            return true;
        }
示例#28
0
        public override VMRoutine Assemble(BHAV bhav, GameIffResource res)
        {
            VMRoutine routine;
            var       assembly = Assemblies.GetModuleFor(bhav.ChunkParent);
            object    func     = assembly?.GetFunction(bhav.ChunkID);

            if (func != null)
            {
                if (func is IBHAV)
                {
                    routine = new VMAOTRoutine((IBHAV)func);
                }
                else
                {
                    routine = new VMAOTInlineRoutine((IInlineBHAV)func);
                }
            }
            else
            {
                routine = new VMRoutine();
            }
            PopulateRoutineFields(bhav, routine);
            return(routine);
        }
示例#29
0
        public void SetActiveResource(IffChunk chunk, GameIffResource res)
        {
            Resource = res;
            Strings = res.Get<TTAs>(chunk.ChunkID);
            ActiveTTAB = (TTAB)chunk;

            if (Strings == null)
            {
                //we have a problem... make us some strings!
                Strings = new TTAs();
                Strings.ChunkLabel = chunk.ChunkLabel;
                Strings.ChunkID = chunk.ChunkID;
                Strings.ChunkProcessed = true;
                res.MainIff.AddChunk(Strings);
            }

            UpdateListing();
            UpdateSelection(-1);
        }
示例#30
0
 public void CloseResourceWindow(GameIffResource res)
 {
     ResourceWindow.Remove(res.MainIff);
 }
示例#31
0
        public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null){
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }

            var routine = Context.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine = routine,
                Caller = frame.Caller,
                Callee = frame.Callee,
                CodeOwner = codeOwner,
                StackObject = frame.StackObject
            };
            childFrame.Args = new short[(routine.Arguments>4)?routine.Arguments:4];
            for (var i = 0; i < childFrame.Args.Length; i++){
                short argValue = (i>3)?(short)-1:args.Arguments[i];
                if (argValue == -1)
                {
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
示例#32
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
 }
示例#33
0
        private void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args)
        {
            if (bhav == null){
                Pop(VMPrimitiveExitCode.ERROR);
                return;
            }
            System.Diagnostics.Debug.WriteLine("Invoke: " + bhav.ChunkLabel);
            System.Diagnostics.Debug.WriteLine("");

            var routine = frame.VM.Assemble(bhav);
            var childFrame = new VMStackFrame
            {
                Routine = routine,
                Caller = frame.Caller,
                Callee = frame.Callee,
                CodeOwner = codeOwner,
                StackObject = frame.StackObject
            };
            childFrame.Args = new short[routine.Arguments];
            for (var i = 0; i < childFrame.Args.Length; i++){
                var argValue = args.Arguments[i];
                if (argValue == -1)
                {
                    /** TODO: Is this the right rule? Maybe a flag decides when to copy from temp? **/
                    argValue = TempRegisters[i];
                }
                childFrame.Args[i] = argValue;
            }
            Push(childFrame);
        }
示例#34
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveChunk = (BHAV)chunk;
     ActiveMeta = res.Get<TPRP>(chunk.ChunkID);
     RefreshDisplay();
 }
示例#35
0
        public bool RunInMyStack(BHAV bhav, GameIffResource CodeOwner, short[] passVars, VMEntity stackObj)
        {
            var OldStack = Stack;
            var OldQueue = Queue;
            VMStackFrame prevFrame = new VMStackFrame() { Caller = Entity, Callee = Entity };
            if (Stack.Count > 0)
            {
                prevFrame = Stack[Stack.Count - 1];
                Stack = new List<VMStackFrame>() { prevFrame };
            } else
            {
                Stack = new List<VMStackFrame>();
            }

            if (Queue.Count > 0)
            {
                Queue = new List<VMQueuedAction>() { Queue[0] };
            } else
            {
                Queue = new List<VMQueuedAction>();
            }

            ExecuteSubRoutine(prevFrame, bhav, CodeOwner, new VMSubRoutineOperand(passVars));
            Stack.RemoveAt(0);
            if (Stack.Count == 0)
            {
                Stack = OldStack;
                Queue = OldQueue;
                return false;
                //bhav was invalid/empty
            }
            var frame = Stack[Stack.Count - 1];
            frame.StackObject = stackObj;

            while (Stack.Count > 0)
            {
                NextInstruction();
            }

            //copy child stack things to parent stack

            //prevFrame.Args = frame.Args;
            //prevFrame.StackObject = frame.StackObject;
            Stack = OldStack;
            Queue = OldQueue;

            return (LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) ? true : false;
        }
示例#36
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveRes = chunk;
 }
示例#37
0
 public VMBHAVOwnerPair(BHAV bhav, GameIffResource owner)
 {
     this.bhav = bhav;
     this.owner = owner;
 }
示例#38
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveChunk = (BHAV)chunk;
     ActiveMeta  = res.Get <TPRP>(chunk.ChunkID);
     RefreshDisplay();
 }
        public override VMPrimitiveExitCode Execute(VMStackFrame context)
        {
            var      operand = context.GetCurrentOperand <VMPushInteractionOperand>();
            VMEntity interactionSource;

            if ((operand.Flags & (1 << 1)) > 0)
            {
                interactionSource = context.VM.GetObjectById((short)context.Locals[operand.ObjectLocation]);
            }
            else
            {
                interactionSource = context.VM.GetObjectById((short)context.Args[operand.ObjectLocation]);
            }

            VMQueuePriority priority;

            if (operand.Priority == 0)
            {
                priority = context.Thread.Queue[0].Priority;
            }
            else
            {
                priority = (VMQueuePriority)(operand.Priority - 1);
            }

            BHAV            bhav;
            GameIffResource CodeOwner = null;
            var             Action    = interactionSource.TreeTable.InteractionByIndex[operand.Interaction];
            ushort          ActionID  = Action.ActionFunction;

            if (ActionID < 4096)
            { //global
                bhav = null;
                //unimp as it has to access the context to get this.
            }
            else if (ActionID < 8192)
            { //local
                bhav      = interactionSource.Object.Resource.Get <BHAV>(ActionID);
                CodeOwner = interactionSource.Object.Resource;
            }
            else
            { //semi-global
                bhav      = interactionSource.SemiGlobal.Resource.Get <BHAV>(ActionID);
                CodeOwner = interactionSource.SemiGlobal.Resource;
            }

            var routine = context.VM.Assemble(bhav);

            context.StackObject.Thread.EnqueueAction(
                new TSO.Simantics.engine.VMQueuedAction
            {
                Callee            = interactionSource,
                CodeOwner         = CodeOwner,
                Routine           = routine,
                Name              = interactionSource.TreeTableStrings.GetString((int)Action.TTAIndex),
                StackObject       = interactionSource,
                InteractionNumber = operand.Interaction,
                Priority          = priority
            }
                );

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
示例#40
0
 public VMTreeByNameTableEntry(BHAV bhav, GameIffResource owner)
 {
     this.bhav = bhav;
     this.Owner = owner;
 }
示例#41
0
        public bool RunInMyStack(BHAV bhav, GameIffResource CodeOwner)
        {
            var prevFrame = Stack[Stack.Count - 1];
            var OldStack = Stack;
            var OldQueue = Queue;

            Stack = new List<VMStackFrame>() { prevFrame };
            Queue = new List<VMQueuedAction>() { Queue[0] };
            ExecuteSubRoutine(prevFrame, bhav, CodeOwner, new VMSubRoutineOperand(new short[] {-1, -1, -1, -1}));
            Stack.RemoveAt(0);
            if (Stack.Count == 0)
            {
                Stack = OldStack;
                Queue = OldQueue;
                return false;
                //bhav was invalid/empty
            }
            var frame = Stack[Stack.Count - 1];

            while (Stack.Count > 0)
            {
                NextInstruction();
            }

            //copy child stack things to parent stack

            prevFrame.Args = frame.Args;
            prevFrame.StackObject = frame.StackObject;
            Stack = OldStack;
            Queue = OldQueue;

            return (LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) ? true : false;
        }
示例#42
0
 public void ChangeIffSource(GameIffResource iff)
 {
     ActiveIff = iff;
     RefreshResList();
 }
示例#43
0
 public void ChangeIffSource(GameIffResource iff)
 {
     ActiveIff = iff;
     RefreshResList();
 }
示例#44
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveString = (STR)chunk;
     UpdateStrings();
 }
示例#45
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveConst      = (BCON)chunk;
     ActiveConstLabel = res.Get <TRCN>(chunk.ChunkID);
     UpdateStrings();
 }
示例#46
0
 public void CloseResourceWindow(GameIffResource res)
 {
     ResourceWindow.Remove(res.MainIff);
 }
示例#47
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveString = (STR)chunk;
     UpdateStrings();
 }