Example #1
0
        public void Read(BinaryBuffer buf, PrefabFooter footer)
        {
            var typeLocalID = buf.ReadInt();
            var typeGUID    = footer.LocalToGuid(typeLocalID);
            var type        = DeltaCore.Get <Type>(typeGUID);

            bindings = NodeBindings.GetBindings(type);

            var numFields = footer.collectionCounts.Pop();

            if (numFields > 0)
            {
                fields = new FieldOverride[bindings.fields.Length];
            }

            for (var iField = 0; iField < numFields; iField++)
            {
                var overrideIndex = buf.ReadInt();
                var fieldSize     = footer.fieldSizes.Dequeue();

                //Index if the type matches
                if (footer.DoesFieldTypeMatch(typeLocalID, iField))
                {
                    fields[overrideIndex] = new FieldOverride {
                        buf      = buf,
                        position = buf.position,
                        length   = fieldSize
                    };
                }

                buf.position += fieldSize;
            }

            var numChildren = footer.collectionCounts.Pop();

            if (numChildren > 0)
            {
                children = new PrefabNode[numChildren];
            }

            for (var iChild = 0; iChild < numChildren; iChild++)
            {
                var child = new PrefabNode();
                children[iChild] = child;
                child.Read(buf, footer);
            }
        }
Example #2
0
        //Parse type metadata in the footer so we can avoid indexing fields that no longer exist
        public void Read(BinaryBuffer buf)
        {
            collectionCounts.Clear();
            var collectionCountCount = buf.ReadInt();

            for (int i = 0; i < collectionCountCount; i++)
            {
                collectionCounts.Push(buf.ReadInt());
            }

            fieldSizes.Clear();
            var fieldSizesCount = buf.ReadInt();

            for (int i = 0; i < fieldSizesCount; i++)
            {
                fieldSizes.Enqueue(buf.ReadInt());
            }

            //Guids
            var typeTablePosition = buf.position + 5;

            buf.position = buf.ReadInt();             //Jump to guid table

            localIDToGuid.Clear();
            var numGuids = buf.ReadInt();

            for (int iGuid = 0; iGuid < numGuids; iGuid++)
            {
                localIDToGuid.Add(buf.ReadGuid());
            }

            var currentPosition = buf.position;

            //Jump back to type table
            buf.position = typeTablePosition;
            fieldTypeMatchTable.Clear();
            var numNodeTypes = buf.ReadInt();

            for (int localID = 0; localID < numNodeTypes; localID++)
            {
                var type     = DeltaCore.Get <Type>(localIDToGuid[localID]);
                var metaNode = NodeBindings.GetBindings(type);

                var oldFieldCount     = buf.ReadInt();
                var currentFieldCount = metaNode.fields.Length;
                var fieldTypeMatches  = new bool[Math.Max(oldFieldCount, currentFieldCount)];
                fieldTypeMatchTable.Add(fieldTypeMatches);

                for (int iField = 0; iField < fieldTypeMatches.Length; iField++)
                {
                    if (iField >= oldFieldCount)
                    {
                        continue;
                    }

                    var oldSubTypeLength = buf.ReadInt();
                    var currentTypeUnits = TypeUnitUtility.GetTypeUnits(metaNode.fields[iField].type);

                    var matches = true;
                    if (oldSubTypeLength != currentTypeUnits.Length)
                    {
                        matches = false;
                    }

                    for (int iTypeUnit = 0; iTypeUnit < oldSubTypeLength; iTypeUnit++)
                    {
                        var currentGUID  = DeltaCore.GetGUID(currentTypeUnits[iTypeUnit]);
                        var previousGUID = localIDToGuid[buf.ReadInt()];
                        if (currentGUID != previousGUID)
                        {
                            matches = false;
                        }
                    }

                    fieldTypeMatches[iField] = matches;
                }
            }

            buf.position = currentPosition;
        }
Example #3
0
        public static T Create <T>(string name) where T : Node
        {
            var guid = DeltaCore.ResolveString(name);

            return(Create(DeltaCore.Get <Prefab>(guid)) as T);
        }