コード例 #1
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public void InsertRemovedBox(TREEBox box)
        {
            var oldIndex = box.InternalID;

            ApplyPointerDelta(1, oldIndex);
            Entries.Insert(oldIndex, box);
        }
コード例 #2
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
 public override void Read(IffFile iff, Stream stream)
 {
     using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
     {
         var zero    = io.ReadInt32();
         var version = io.ReadInt32();
         if (version > 1)
         {
             throw new Exception("Unexpected TREE version: " + version);
         }
         string magic = io.ReadCString(4); //HBGN
         if (magic != "EERT")
         {
             throw new Exception("Magic number should be 'EERT', got " + magic);
         }
         var entryCount = io.ReadInt32();
         Entries.Clear();
         for (int i = 0; i < entryCount; i++)
         {
             var box = new TREEBox(this);
             box.Read(io, version);
             box.InternalID = (short)i;
             Entries.Add(box);
         }
     }
 }
コード例 #3
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public void InsertPrimitiveBox(TREEBox box)
        {
            var primEnd = PrimitiveCount;

            ApplyPointerDelta(1, primEnd);

            box.InternalID = (short)primEnd;
            Entries.Insert(primEnd, box);
        }
コード例 #4
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public TREEBox MakeNewSpecialBox(TREEBoxType type)
        {
            //add box at end. no delta needs to be applied.
            var box = new TREEBox(this);

            box.InternalID      = (short)Entries.Count;
            box.PosisionInvalid = true;
            box.Type            = type;
            Entries.Add(box);
            return(box);
        }
コード例 #5
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public TREEBox MakeNewPrimitiveBox(TREEBoxType type)
        {
            var primEnd = PrimitiveCount;

            ApplyPointerDelta(1, primEnd);
            //find end of primitives and add box there. apply delta
            var box = new TREEBox(this);

            box.InternalID      = (short)primEnd;
            box.PosisionInvalid = true;
            box.Type            = type;
            Entries.Insert(primEnd, box);
            return(box);
        }
コード例 #6
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public void CorrectConnections(BHAV bhav)
        {
            //make sure there are enough primitives for the bhav
            var realPrimCount = bhav.Instructions.Length;
            var treePrimCount = Entries.FindLastIndex(x => x.Type == TREEBoxType.Primitive) + 1;

            ApplyPointerDelta(realPrimCount - treePrimCount, treePrimCount);
            if (realPrimCount > treePrimCount)
            {
                //add new treeboxes
                for (int i = treePrimCount; i < realPrimCount; i++)
                {
                    var box = new TREEBox(this);
                    box.InternalID      = (short)i;
                    box.PosisionInvalid = true;
                    box.Type            = TREEBoxType.Primitive;
                    Entries.Insert(i, box);
                }
            }
            else if (treePrimCount > realPrimCount)
            {
                //remove treeboxes
                for (int i = treePrimCount; i > realPrimCount; i--)
                {
                    Entries.RemoveAt(i - 1);
                }
            }

            //make sure connections for each of the primitives match the BHAV
            //if they don't, reconnect them or generate new boxes (true/false endpoints, maybe gotos in future)

            for (int i = 0; i < realPrimCount; i++)
            {
                var prim = bhav.Instructions[i];
                var box  = Entries[i];

                if (prim.TruePointer != GetTrueID(box.TruePointer))
                {
                    box.TruePointer = GetCorrectBox(prim.TruePointer);
                }
                if (prim.FalsePointer != GetTrueID((short)box.FalsePointer))
                {
                    box.FalsePointer = GetCorrectBox(prim.FalsePointer);
                }
            }
        }
コード例 #7
0
ファイル: TREE.cs プロジェクト: wishiwashi-hack/FreeSO
        public void DeleteBox(TREEBox box)
        {
            //remove box. apply delta
            var id = box.InternalID;

            foreach (var box2 in Entries)
            {
                if (box2.TruePointer == id)
                {
                    box2.TruePointer = -1;
                }
                if (box2.FalsePointer == id)
                {
                    box2.FalsePointer = -1;
                }
            }
            Entries.RemoveAt(id);
            ApplyPointerDelta(-1, id);
        }