示例#1
0
        public NavGraph[] DeserializeGraphs()
        {
            this.graphs = new NavGraph[this.meta.graphs];
            int num = 0;

            for (int i = 0; i < this.meta.graphs; i++)
            {
                Type graphType = this.meta.GetGraphType(i);
                if (!object.Equals(graphType, null))
                {
                    num++;
                    ZipEntry zipEntry = this.zip["graph" + i + ".binary"];
                    if (zipEntry == null)
                    {
                        throw new FileNotFoundException(string.Concat(new object[]
                        {
                            "Could not find data for graph ",
                            i,
                            " in zip. Entry 'graph+",
                            i,
                            ".binary' does not exist"
                        }));
                    }
                    NavGraph     navGraph     = this.data.CreateGraph(graphType);
                    MemoryStream memoryStream = new MemoryStream();
                    zipEntry.Extract(memoryStream);
                    memoryStream.set_Position(0L);
                    BinaryReader reader           = new BinaryReader(memoryStream);
                    GraphSerializationContext ctx = new GraphSerializationContext(reader, null, i);
                    navGraph.DeserializeSettings(ctx);
                    this.graphs[i] = navGraph;
                    if (this.graphs[i].guid.ToString() != this.meta.guids[i])
                    {
                        throw new Exception("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" + this.graphs[i].guid.ToString() + " != " + this.meta.guids[i]);
                    }
                }
            }
            NavGraph[] array = new NavGraph[num];
            num = 0;
            for (int j = 0; j < this.graphs.Length; j++)
            {
                if (this.graphs[j] != null)
                {
                    array[num] = this.graphs[j];
                    num++;
                }
            }
            this.graphs = array;
            return(this.graphs);
        }
示例#2
0
        NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            // Get the graph type from the metadata we deserialized earlier
            var tp = meta.GetGraphType(zipIndex);

            // Graph was null when saving, ignore
            if (System.Type.Equals(tp, null))
            {
                return(null);
            }

            var entry = zip["graph" + zipIndex + jsonExt];

            if (entry == null)
            {
                throw new FileNotFoundException("Could not find data for graph " + zipIndex + " in zip. Entry 'graph" + zipIndex + jsonExt + "' does not exist");
            }

            // Create a new graph of the right type
            NavGraph graph = data.CreateGraph(tp);

            graph.graphIndex = (uint)(graphIndex);

#if !ASTAR_NO_JSON
            var entryText = GetString(entry);
            var reader    = new JsonReader(entryText, readerSettings);

            // Read the graph settings
            reader.PopulateObject(ref graph);
#else
            var reader = GetBinaryReader(entry);
            var ctx    = new GraphSerializationContext(reader, null, graph.graphIndex);
            graph.DeserializeSettings(ctx);
#endif

            if (graph.guid.ToString() != meta.guids[zipIndex])
            {
                throw new Exception("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" + graph.guid + " != " + meta.guids[zipIndex]);
            }

            return(graph);
        }
示例#3
0
        /** Deserializes graph settings.
         * \note Stored in files named "graph#.json" where # is the graph number.
         */
        public NavGraph[] DeserializeGraphs()
        {
            //for (int j=0;j<1;j++) {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();

            graphs = new NavGraph[meta.graphs];

            int nonNull = 0;

            for (int i = 0; i < meta.graphs; i++)
            {
                Type tp = meta.GetGraphType(i);

                //Graph was null when saving, ignore
                if (System.Type.Equals(tp, null))
                {
                    continue;
                }

                nonNull++;

                ZipEntry entry = zip["graph" + i + jsonExt];

                if (entry == null)
                {
                    throw new FileNotFoundException("Could not find data for graph " + i + " in zip. Entry 'graph+" + i + jsonExt + "' does not exist");
                }


                NavGraph tmp = data.CreateGraph(tp);                //(NavGraph)System.Activator.CreateInstance(tp);

#if !ASTAR_NO_JSON
                String entryText = GetString(entry);

                JsonReader reader = new JsonReader(entryText, readerSettings);

                //NavGraph graph = tmp.Deserialize(reader);//reader.Deserialize<NavGraph>();
                reader.PopulateObject(ref tmp);
#else
                var mem = new MemoryStream();
                entry.Extract(mem);
                mem.Position = 0;
                var reader = new BinaryReader(mem);
                var ctx    = new GraphSerializationContext(reader, null, i);
                tmp.DeserializeSettings(ctx);
#endif

                graphs[i] = tmp;
                if (graphs[i].guid.ToString() != meta.guids[i])
                {
                    throw new System.Exception("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" + graphs[i].guid.ToString() + " != " + meta.guids[i]);
                }

                //NavGraph graph = (NavGraph)JsonConvert.DeserializeObject (entryText,tp,settings);
            }

            NavGraph[] compressed = new NavGraph[nonNull];
            nonNull = 0;
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    compressed[nonNull] = graphs[i];
                    nonNull++;
                }
            }

            graphs = compressed;

            return(graphs);

            //watch.Stop();
            //Debug.Log ((watch.ElapsedTicks*0.0001).ToString ("0.00"));
            //}
        }
示例#4
0
        /** Deserializes graph settings.
         * \note Stored in files named "graph#.json" where # is the graph number.
         */
        public NavGraph[] DeserializeGraphs()
        {
            // Allocate a list of graphs to be deserialized
            graphs = new NavGraph[meta.graphs];

            int nonNull = 0;

            for (int i = 0; i < meta.graphs; i++)
            {
                // Get the graph type from the metadata we deserialized earlier
                var tp = meta.GetGraphType(i);

                // Graph was null when saving, ignore
                if (System.Type.Equals(tp, null))
                {
                    continue;
                }

                nonNull++;

                var entry = zip["graph" + i + jsonExt];

                if (entry == null)
                {
                    throw new FileNotFoundException("Could not find data for graph " + i + " in zip. Entry 'graph+" + i + jsonExt + "' does not exist");
                }

                // Create a new graph of the right type
                NavGraph graph = data.CreateGraph(tp);
                graph.graphIndex = (uint)(i + graphIndexOffset);

#if !ASTAR_NO_JSON
                var entryText = GetString(entry);

                var reader = new JsonReader(entryText, readerSettings);

                reader.PopulateObject(ref graph);
#else
                var mem = new MemoryStream();
                entry.Extract(mem);
                mem.Position = 0;
                var reader = new BinaryReader(mem);
                var ctx    = new GraphSerializationContext(reader, null, i + graphIndexOffset);
                graph.DeserializeSettings(ctx);
#endif

                graphs[i] = graph;
                if (graphs[i].guid.ToString() != meta.guids[i])
                {
                    throw new Exception("Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n" + graphs[i].guid + " != " + meta.guids[i]);
                }
            }

            // Remove any null entries from the list
            var compressed = new NavGraph[nonNull];
            nonNull = 0;
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    compressed[nonNull] = graphs[i];
                    nonNull++;
                }
            }

            graphs = compressed;

            return(graphs);
        }