コード例 #1
0
ファイル: PagedWorld.cs プロジェクト: bostich83/axiom
        public bool Load(StreamSerializer stream)
        {
            if (stream.ReadChunkBegin(CHUNK_ID, CHUNK_VERSION, "PageWorld") == null)
            {
                return(false);
            }

            //name
            stream.Read(out this.mName);
            //sections
            while (stream.NextChunkId == PagedWorld.CHUNK_SECTIONDECLARATION_ID)
            {
                stream.ReadChunkBegin();
                string sectionType, sectionName;
                stream.Read(out sectionType);
                stream.Read(out sectionName);
                stream.ReadChunkEnd(CHUNK_SECTIONDECLARATION_ID);
                // Scene manager will be loaded
                PagedWorldSection sec = CreateSection(null, sectionType, sectionName);
                bool sectionOk        = sec.Load(stream);
                if (!sectionOk)
                {
                    DestroySection(sec);
                }
            }

            stream.ReadChunkEnd(CHUNK_ID);

            return(true);
        }
コード例 #2
0
ファイル: Page.cs プロジェクト: suntabu/axiom
        protected virtual bool PrepareImpl(StreamSerializer stream, ref PageData dataToPopulate)
        {
            //now do the real loading
            if (stream.ReadChunkBegin(CHUNK_ID, CHUNK_VERSION, "Page") == null)
            {
                return(false);
            }

            // pageID check (we should know the ID we're expecting)
            int storedID = -1;

            stream.Read(out storedID);
            if (this.mID.Value != storedID)
            {
                LogManager.Instance.Write("Error: Tried to populate Page ID {0} with data corresponding to page ID {1}",
                                          this.mID.Value,
                                          storedID);
                stream.UndoReadChunk(CHUNK_ID);
                return(false);
            }

            PageManager mgr = Manager;

            while (stream.NextChunkId == Page.CHUNK_CONTENTCOLLECTION_DECLARATION_ID)
            {
                Chunk  collChunk = stream.ReadChunkBegin();
                string factoryName;
                stream.Read(out factoryName);
                stream.ReadChunkEnd(CHUNK_CONTENTCOLLECTION_DECLARATION_ID);
                //Supported type?
                IPageContentCollectionFactory collFact = mgr.GetContentCollectionFactory(factoryName);
                if (collFact != null)
                {
                    PageContentCollection collInst = collFact.CreateInstance();
                    if (collInst.Prepare(stream))
                    {
                        dataToPopulate.collectionsToAdd.Add(collInst);
                    }
                    else
                    {
                        LogManager.Instance.Write("Error preparing PageContentCollection type: {0} in {1}", factoryName, ToString());
                        collFact.DestroyInstance(ref collInst);
                    }
                }
                else
                {
                    LogManager.Instance.Write("Unsupported PageContentCollection type: {0} in {1}", factoryName, ToString());
                    //skip
                    stream.ReadChunkEnd(collChunk.id);
                }
            }

            this.mModified = false;
            return(true);
        }
コード例 #3
0
        public void BasicReadWriteTest()
        {
            String  fileName    = "testSerialiser.dat";
            Vector3 aTestVector = new Vector3(0.3f, 15.2f, -12.0f);
            String  aTestString = "Some text here";
            int     aTestValue  = 99;

            int[] aTestArray = new int[5]
            {
                5, 4, 3, 2, 1
            };

            uint chunkID = StreamSerializer.MakeIdentifier("TEST");

            byte[] buffer = new byte[1024];

            // write the data
            {
                Stream stream = new MemoryStream(buffer); // arch.Create(fileName, true));

                using (StreamSerializer serializer = new StreamSerializer(stream))
                {
                    serializer.WriteChunkBegin(chunkID);

                    serializer.Write(aTestVector);
                    serializer.Write(aTestString);
                    serializer.Write(aTestValue);
                    serializer.Write(aTestArray);
                    serializer.WriteChunkEnd(chunkID);
                }
            }

            // read it back
            {
                Stream stream = new MemoryStream(buffer); //arch.Open(fileName);

                using (StreamSerializer serializer = new StreamSerializer(stream))
                {
                    Chunk c = serializer.ReadChunkBegin();
                    Assert.AreEqual(chunkID, c.id);
                    Assert.AreEqual(sizeof(float) * 3 + sizeof(int) + aTestString.Length + 4 + sizeof(int) * aTestArray.Length + sizeof(int), (int)c.length);

                    Vector3 inVector;
                    String  inString;
                    int     inValue;
                    int[]   inArray;

                    serializer.Read(out inVector);
                    serializer.Read(out inString);
                    serializer.Read(out inValue);
                    serializer.Read(out inArray);
                    serializer.ReadChunkEnd(chunkID);

                    Assert.AreEqual(aTestVector, inVector);
                    Assert.AreEqual(aTestString, inString);
                    Assert.AreEqual(aTestValue, inValue);
                    Assert.AreEqual(aTestArray, inArray);
                }
            }
        }
コード例 #4
0
        public bool Load(StreamSerializer stream)
        {
            if (stream.ReadChunkBegin(CHUNK_ID, CHUNK_VERSION, "Grid2DPageStrategyData") == null)
            {
                return(false);
            }

            byte readMode = 0;

            stream.Read(out readMode);
            this.mMode = (Grid2Mode)readMode;

            Vector3 orgin;

            stream.Read(out orgin);
            Origin = orgin;

            stream.Read(out this.mCellSize);
            stream.Read(out this.mLoadRadius);
            stream.Read(out this.mHoldRadius);
            stream.Read(out this.mMinCellX);
            stream.Read(out this.mMaxCellX);
            stream.Read(out this.mMinCellY);
            stream.Read(out this.mMaxCellY);

            stream.ReadChunkEnd(CHUNK_ID);

            return(true);
        }
コード例 #5
0
        public virtual bool Load(StreamSerializer stream)
        {
            if (stream.ReadChunkBegin(CHUNK_ID, CHUNK_VERSION, "PagedWorldSection") == null)
            {
                return(false);
            }

            //name
            stream.Read(out this.mName);
            // AABB
            stream.Read(out this.mAABB);
            // SceneManager type
            string       smType, smInstanceName;
            SceneManager sm = null;

            stream.Read(out smType);
            stream.Read(out smInstanceName);
            if (Root.Instance.HasSceneManager(smInstanceName))
            {
                sm = Root.Instance.GetSceneManager(smInstanceName);
            }
            else
            {
                sm = Root.Instance.CreateSceneManager(smType, smInstanceName);
            }
            SceneManager = sm;
            //page strategy name
            string stratName = string.Empty;

            stream.Read(out stratName);
            SetStrategy(stratName);
            //page strategy data
            bool strategyDataOk = this.mStrategyData.Load(stream);

            if (!strategyDataOk)
            {
                LogManager.Instance.Write(
                    "Error: PageStrategyData for section '{0}' was not loaded correctly, check file contens", this.mName);
            }

            // Load any data specific to a subtype of this class
            LoadSubtypeData(stream);

            stream.ReadChunkEnd(CHUNK_ID);

            return(true);
        }
コード例 #6
0
        public override bool Prepare(StreamSerializer stream)
        {
            if (stream.ReadChunkBegin(SUBCLASS_CHUNK_ID, SUBCLASS_CHUNK_VERSION, "SimplePageContentCollection") == null)
            {
                return(false);
            }

            bool ret = true;

            foreach (var i in this.mContentList)
            {
                ret &= i.Prepare(stream);
            }

            stream.ReadChunkEnd(SUBCLASS_CHUNK_ID);
            return(ret);
        }