Represents a section of the PagedWorld which uses a given PageStrategy, and which is made up of a generally localised set of Page instances.
Exemple #1
0
        public PagedWorldSection CreateSection(PageStrategy strategy, SceneManager sceneMgr, string sectionName)
        {
            PagedWorldSection ret = CreateSection(sceneMgr, "General", sectionName);

            ret.Strategy = strategy;
            return(ret);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public PagedWorldSection GetSection(string name)
        {
            PagedWorldSection section = null;

            this.mSections.TryGetValue(name, out section);
            return(section);
        }
Exemple #4
0
        public override void NotifyCamera(Camera cam, PagedWorldSection section)
        {
            var stratData = (Grid2DPageStrategyData)section.StrategyData;

            Vector3 pos     = cam.DerivedPosition;
            Vector2 gridpos = Vector2.Zero;

            stratData.ConvertWorldToGridSpace(pos, ref gridpos);
            int x, y;

            stratData.DetermineGridLocation(gridpos, out x, out y);

            Real loadRadius = stratData.LoadRadiusInCells;
            Real holdRadius = stratData.HoldRadiusInCells;
            //scan the whole hold range
            Real fxmin = (Real)x - holdRadius;
            Real fxmax = (Real)x + holdRadius;
            Real fymin = (Real)y - holdRadius;
            Real fymax = (Real)y + holdRadius;

            int xmin = stratData.CellRangeMinX;
            int xmax = stratData.CellRangeMaxX;
            int ymin = stratData.CellRangeMinY;
            int ymax = stratData.CellRangeMaxY;

            // Round UP max, round DOWN min
            xmin = fxmin < xmin ? xmin : (int)System.Math.Floor(fxmin);
            xmax = fxmax > xmax ? xmax : (int)System.Math.Ceiling(fxmax);
            ymin = fymin < ymin ? ymin : (int)System.Math.Floor(fymin);
            ymax = fymax > ymax ? ymax : (int)System.Math.Ceiling(fymax);
            // the inner, active load range
            fxmin = (Real)x - loadRadius;
            fxmax = (Real)x + loadRadius;
            fymin = (Real)y - loadRadius;
            fymax = (Real)y + loadRadius;
            // Round UP max, round DOWN min
            int loadxmin = fxmin < xmin ? xmin : (int)System.Math.Floor(fxmin);
            int loadxmax = fxmax > xmax ? xmax : (int)System.Math.Ceiling(fxmax);
            int loadymin = fymin < ymin ? ymin : (int)System.Math.Floor(fymin);
            int loadymax = fymax > ymax ? ymax : (int)System.Math.Ceiling(fymax);

            for (int cy = ymin; cy <= ymax; ++cy)
            {
                for (int cx = xmin; cx <= xmax; ++cx)
                {
                    PageID pageID = stratData.CalculatePageID(cx, cy);
                    if (cx >= loadxmin && cx <= loadxmax && cy >= loadymin && cy <= loadymax)
                    {
                        // in the 'load' range, request it
                        section.LoadPage(pageID);
                    }
                    else
                    {
                        // in the outer 'hold' range, keep it but don't actively load
                        section.HoldPage(pageID);
                    }
                    // other pages will by inference be marked for unloading
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cam"></param>
        /// <param name="section"></param>
        public override void NotifyCamera(Camera cam, PagedWorldSection section)
        {
            Grid2DPageStrategyData stratData = (Grid2DPageStrategyData)section.StrategyData;

            Vector3 pos = cam.DerivedPosition;
            Vector2 gridpos = Vector2.Zero;
            stratData.ConvetWorldToGridSpace(pos, ref gridpos);
            int row = 0, col = 0;
            stratData.DetermineGridLocation(gridpos, ref row, ref col);

            float loadRadius = stratData.LoadRadiusInCells;
            float holdRadius = stratData.HoldRadiusInCells;
            //scan the whole hold range
            float frowmin = (float)row - holdRadius;
            float frowmax = (float)row + holdRadius;
            float fcolmin = (float)col - holdRadius;
            float fcolmax = (float)col + holdRadius;

            int clampRowAt = stratData.CellCountVert - 1;
            int clampColAt = stratData.CellCountHorz - 1;

            //round UP max, round DOWN min
            int rowmin = frowmin < 0 ? 0 : (int)System.Math.Floor(frowmin);
            int rowmax = frowmax > clampRowAt ? clampRowAt : (int)System.Math.Ceiling(frowmax);
            int colmin = fcolmin < 0 ? 0 : (int)System.Math.Floor(fcolmin);
            int colmax = fcolmax > clampColAt ? clampColAt : (int)System.Math.Ceiling(fcolmax);
            // the inner, active load range
            frowmin = (float)row - loadRadius;
            frowmax = (float)row + loadRadius;
            fcolmin = (float)col - loadRadius;
            fcolmax = (float)col + loadRadius;
            //round UP max, round DOWN min
            int loadrowmin = frowmin < 0 ? 0 : (int)System.Math.Floor(frowmin);
            int loadrowmax = frowmax > clampRowAt ? clampRowAt : (int)System.Math.Ceiling(frowmax);
            int loadcolmin = fcolmin < 0 ? 0 : (int)System.Math.Floor(fcolmin);
            int loadcolmax = fcolmax > clampColAt ? clampColAt : (int)System.Math.Ceiling(fcolmax);

            for (int r = rowmin; r <= rowmax; ++r)
            {
                for (int c = colmin; c <= colmax; ++c)
                {
                    PageID pageID = stratData.CalculatePageID(r, c);
                    if (r >= loadrowmin && r <= loadrowmax && c >= loadcolmin && c <= loadcolmax)
                    {
                        // int the 'load' range, request it
                        section.LoadPage(pageID);
                    }
                    else
                    {
                        // int the outer 'hold' range, keep it but don't actively load.
                        section.HoldPage(pageID);
                    }
                    // other paged will by inference be marked for unloading
                }
            }
        }
Exemple #6
0
        internal bool UnloadProcedualPage(Page page, PagedWorldSection section)
        {
            bool generated = false;

            if (this.mPageProvider != null)
            {
                generated = this.mPageProvider.UnloadProcedualPage(page, section);
            }

            return(generated);
        }
Exemple #7
0
        public override PageID GetPageID(Vector3 worldPos, PagedWorldSection section)
        {
            var stratData = (Grid2DPageStrategyData)section.StrategyData;

            Vector2 gridpos = Vector2.Zero;

            stratData.ConvertWorldToGridSpace(worldPos, ref gridpos);
            int x, y;

            stratData.DetermineGridLocation(gridpos, out x, out y);
            return(stratData.CalculatePageID(x, y));
        }
Exemple #8
0
        public Page(PageID pageID, PagedWorldSection parent)
            : base()
        {
            this.mID     = pageID;
            this.mParent = parent;

            WorkQueue wq = Root.Instance.WorkQueue;

            this.workQueueChannel = wq.GetChannel("Axiom/Page");
            wq.AddRequestHandler(this.workQueueChannel, this);
            wq.AddResponseHandler(this.workQueueChannel, this);
            Touch();
        }
Exemple #9
0
        public void DestroyWorldSection(ref PagedWorldSection coll)
        {
            PagedWorldSectionFactory fact = GetWorldSectionFactory(coll.Type);

            if (fact != null)
            {
                fact.DestroyInstance(ref coll);
            }
            else
            {
                coll.SafeDispose();                 // normally a safe fallback
            }
        }
Exemple #10
0
        internal StreamSerializer ReadPageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;

            if (this.mPageProvider != null)
            {
                ser = this.mPageProvider.ReadPageStream(pageId, section);
            }
            if (ser == null)
            {
                ser = this.mManager.ReadPageStream(pageId, section);
            }

            return(ser);
        }
Exemple #11
0
        public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;

            if (this.mPageProvider != null)
            {
                ser = this.mPageProvider.WritePageStream(pageId, section);
            }
            if (ser == null)
            {
                ser = this.mManager.WritePageStream(pageId, section);
            }

            return(ser);
        }
Exemple #12
0
        internal virtual bool UnPrepareProcedualPage(Page page, PagedWorldSection section)
        {
            bool generated = false;

            if (this.mPageProvider != null)
            {
                generated = this.mPageProvider.UnPrepareProcedualPage(page, section);
            }
            if (!generated)
            {
                generated = this.mManager.UnPrepareProcedualPage(page, section);
            }

            return(generated);
        }
Exemple #13
0
        internal StreamSerializer ReadPageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;

            if (this.mPageProvider != null)
            {
                ser = this.mPageProvider.ReadPageStream(pageId, section);
            }
            if (ser == null)
            {
                // use default implementation
                string nameStr = string.Format("{0}_{1}_{2}.page", section.World.Name, section.Name, pageId);
                var    stream  = ResourceGroupManager.Instance.OpenResource(nameStr);
                ser = new StreamSerializer(stream);
            }

            return(ser);
        }
Exemple #14
0
        internal StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;

            if (this.mPageProvider != null)
            {
                ser = this.mPageProvider.WritePageStream(pageId, section);
            }

            if (ser == null)
            {
                // use default implementation
                string nameStr = string.Format("{0}_{1}_{2}.page", section.World.Name, section.Name, pageId);
                // create file, overwrite if necessary
                var stream = ResourceGroupManager.Instance.CreateResource(nameStr, this.mPageResourceGroup, true);
                ser = new StreamSerializer(stream);
            }

            return(ser);
        }
Exemple #15
0
        public PagedWorldSection CreateSection(SceneManager sceneMgr, string typeName, string sectionName)
        {
            var theName = sectionName;

            if (theName == string.Empty)
            {
                do
                {
                    theName = this.mSectionNameGenerator.GetNextUniqueName();
                }while (this.mSections.ContainsKey(theName));
            }
            else if (this.mSections.ContainsKey(theName))
            {
                throw new AxiomException("World section named '{0}' already exists! PagedWorld.CreateSection", theName);
            }

            PagedWorldSection ret = null;

            if (typeName == "General")
            {
                ret = new PagedWorldSection(theName, this, sceneMgr);
            }
            else
            {
                PagedWorldSectionFactory fact = this.mManager.GetWorldSectionFactory(typeName);
                if (fact == null)
                {
                    throw new AxiomException("World section type '{0}' does not exist! PagedWorld::createSection", typeName);
                }

                ret = fact.CreateInstance(theName, this, sceneMgr);
            }
            this.mSections.Add(theName, ret);

            return(ret);
        }
Exemple #16
0
 public abstract void DestroyInstance(ref PagedWorldSection p);
Exemple #17
0
		public virtual void FrameEnd( Real timeElapsed, PagedWorldSection section )
		{
		}
Exemple #18
0
			public override bool UnPrepareProcedualPage( Page page, PagedWorldSection section ) { return true; }
Exemple #19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageId"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public StreamSerializer ReadPageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;
            if (mPageProvider != null)
                ser = mPageProvider.ReadPageStream(pageId, section);
            if (ser == null)
            {
                // use default implementation
                string nameStr = string.Empty;
                nameStr += section.World.Name + "_" + section.Name + "_" + pageId.Value + ".page";
                Stream stream = ResourceGroupManager.Instance.OpenResource(nameStr);

                ser = new StreamSerializer(stream);
            }

            return ser;
        }
Exemple #20
0
        /// <summary>
        /// Load a Page, for a given PagedWorldSection.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="section"></param>
        /// <param name="forceSync"></param>
        public void LoadPage(Page page, PagedWorldSection section, bool forceSync)
        {
            // Prepare in the background
            Request req = new Request(RequestType.PreparePage, page, section);
            AddBackgroundRequest(req, forceSync);

            // load will happen in the main thread once preparation is complete
        }
Exemple #21
0
 public Request(RequestType rt, Page p, PagedWorldSection s)
 {
     RequestType = rt;
     Page = p;
     Section = s;
 }
Exemple #22
0
 public virtual void FrameStart(Real timeSinceLastFrame, PagedWorldSection section)
 {
 }
Exemple #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
 {
     return null;
 }
Exemple #24
0
 public virtual void NotifyCamera(Camera cam, PagedWorldSection section)
 {
 }
Exemple #25
0
 public abstract PageID GetPageID(Vector3 worldPos, PagedWorldSection section);
Exemple #26
0
		internal StreamSerializer WritePageStream( PageID pageId, PagedWorldSection section )
		{
			StreamSerializer ser = null;

			if ( this.mPageProvider != null )
			{
				ser = this.mPageProvider.WritePageStream( pageId, section );
			}

			if ( ser == null )
			{
				// use default implementation
				string nameStr = string.Format( "{0}_{1}_{2}.page", section.World.Name, section.Name, pageId );
				// create file, overwrite if necessary
				var stream = ResourceGroupManager.Instance.CreateResource( nameStr, this.mPageResourceGroup, true );
				ser = new StreamSerializer( stream );
			}

			return ser;
		}
Exemple #27
0
		internal bool UnloadProcedualPage( Page page, PagedWorldSection section )
		{
			bool generated = false;
			if ( this.mPageProvider != null )
			{
				generated = this.mPageProvider.UnloadProcedualPage( page, section );
			}

			return generated;
		}
Exemple #28
0
		public virtual void NotifyCamera( Camera cam, PagedWorldSection section )
		{
		}
Exemple #29
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageId"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;

            if (mPageProvider != null)
                ser = mPageProvider.WritePageStream(pageId, section);
            if (ser == null)
            {
                // use default implementation
                string nameStr = string.Empty;
                nameStr += section.World.Name + "_" + section.Name + "_" + pageId.Value + ".page";

                // create file, overwrite if necessary
                
                
            }
            throw new NotImplementedException();
        }
Exemple #30
0
 public virtual void FrameEnd(Real timeElapsed, PagedWorldSection section)
 {
 }
Exemple #31
0
 /// <summary>
 /// Give a provider the opportunity to unprepare page content procedurally. 
 /// </summary>
 /// <param name="page"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public bool UnPrepareProcedualPage(Page page, PagedWorldSection section)
 {
     return false;
 }
Exemple #32
0
		public Page( PageID pageID, PagedWorldSection parent )
			: base()
		{
			this.mID = pageID;
			this.mParent = parent;

			WorkQueue wq = Root.Instance.WorkQueue;
			this.workQueueChannel = wq.GetChannel( "Axiom/Page" );
			wq.AddRequestHandler( this.workQueueChannel, this );
			wq.AddResponseHandler( this.workQueueChannel, this );
			Touch();
		}
Exemple #33
0
 /// <summary>
 /// Load a Page, for a given PagedWorldSection.
 /// </summary>
 /// <param name="page"></param>
 /// <param name="section"></param>
 public void LoadPage(Page page, PagedWorldSection section)
 {
     LoadPage(page, section, false);
 }
		public abstract void DestroyInstance( ref PagedWorldSection p );
Exemple #35
0
 /// <summary>
 /// Dispose of a page
 /// </summary>
 /// <param name="page"></param>
 /// <param name="section"></param>
 /// <param name="forceSync"></param>
 public void UnLoadPage(Page page, PagedWorldSection section, bool forceSync)
 {
     // unload in main thread, then unprepare in background
     Request req = new Request(RequestType.UnloadPage, page, section);
     AddRenderRequest(req, forceSync);
 }
Exemple #36
0
        /// <summary>
        /// Create a new section of the world.
        /// </summary>
        /// <param name="strategyName"></param>
        /// <param name="sceneMgr"></param>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        PagedWorldSection CreateSection(PageStrategy strategy, SceneManager sceneMgr,
            string sectionName)
        {
            string theName = sectionName;
            if (theName == string.Empty)
            {
                do
                {
                    theName = mSectionNameGenerator.GetNextUniqueName();
                }
                while (!mSections.ContainsKey(theName));
            }
            else if (mSections.ContainsKey(theName))
            {
                throw new Exception("World section named '" + theName + "' allready exists!" + 
                "[PageWorld.CreateSection]");
            }

            PagedWorldSection ret = new PagedWorldSection(theName, this, strategy, sceneMgr);
            mSections.Add(theName, ret);
            return ret;
        }
Exemple #37
0
		public void DestroyWorldSection( ref PagedWorldSection coll )
		{
			PagedWorldSectionFactory fact = GetWorldSectionFactory( coll.Type );
			if ( fact != null )
			{
				fact.DestroyInstance( ref coll );
			}
			else
			{
				coll.SafeDispose(); // normally a safe fallback
			}
		}
Exemple #38
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public virtual bool UnPrepareProcedualPage(Page page, PagedWorldSection section)
        {
            bool generated = false;
            if (mPageProvider != null)
                generated = mPageProvider.UnPrepareProcedualPage(page, section);
            if (!generated)
                generated = mManger.UnPrepareProcedualPage(page, section);

            return generated;
        }
Exemple #39
0
        /// <summary>
        /// Load world data from a serialiser (returns true if successful)
        /// </summary>
        /// <param name="stream"></param>
        public bool Load(StreamSerializer stream)
        {
            if (stream.ReadChunkBegin(CHUNK_ID, CHUNK_VERSION, "PageWorld") == null)
                return false;

            //name
            stream.Read(out mName);
            //sections
            while (stream.NextChunkId == PagedWorldSection.CHUNK_ID)
            {
                PagedWorldSection sec = new PagedWorldSection(this);
                bool sectionOk = sec.Load(stream);
                if (sectionOk)
                    mSections.Add(sec.Name, sec);
                else
                {
                    sec = null;
                    break;
                }
            }

            stream.ReadChunkEnd(CHUNK_ID);

            return true;
        }
Exemple #40
0
 public void DestroySection(PagedWorldSection section)
 {
     DestroySection(section.Name);
 }
Exemple #41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="section"></param>
 public void DestroySection(PagedWorldSection section)
 {
     DestroySection(section.Name);
 }
Exemple #42
0
		internal StreamSerializer ReadPageStream( PageID pageId, PagedWorldSection section )
		{
			StreamSerializer ser = null;
			if ( this.mPageProvider != null )
			{
				ser = this.mPageProvider.ReadPageStream( pageId, section );
			}
			if ( ser == null )
			{
				// use default implementation
				string nameStr = string.Format( "{0}_{1}_{2}.page", section.World.Name, section.Name, pageId );
				var stream = ResourceGroupManager.Instance.OpenResource( nameStr );
				ser = new StreamSerializer( stream );
			}

			return ser;
		}
Exemple #43
0
        /// <summary>
        /// Get a serialiser set up to write Page data for the given PageID.
        /// </summary>
        /// <param name="pageId"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
        {
            StreamSerializer ser = null;
            if (mPageProvider != null)
                ser = mPageProvider.WritePageStream(pageId, section);
            if (ser == null)
                ser = mManger.WritePageStream(pageId, section);

            return ser;
        }
Exemple #44
0
		public virtual void FrameStart( Real timeSinceLastFrame, PagedWorldSection section )
		{
		}
Exemple #45
0
        /// <summary>
        /// Internal method to notify a page that it is attached
        /// </summary>
        /// <param name="parent"></param>
        public void NotifyAttached(PagedWorldSection parent)
        {
            if (parent == null && mParent != null && mDebugNode != null)
            {
#warning unsure if movableobject is correct here
                // destroy while we have the chance
                List<MovableObject> nodes = (List<MovableObject>)mDebugNode.Objects;
                foreach (MovableObject m in nodes)
                    mParent.SceneManager.DestroyMovableObject(m);

                mDebugNode.RemoveAndDestroyAllChildren();
                mParent.SceneManager.DestroySceneNode(mDebugNode.Name);
                mDebugNode = null;
            }

            mParent = parent;

        }
Exemple #46
0
 /// <summary>
 /// Get a serialiser set up to read PagedWorld data for the given world filename. 
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public virtual StreamSerializer ReadPageStream(PageID pageId, PagedWorldSection section)
 {
     return null;
 }
Exemple #47
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public bool UnloadProcedualPage(Page page, PagedWorldSection section)
        {
            bool generated = false;
            if (mPageProvider != null)
                generated = mPageProvider.UnloadProcedualPage(page, section);

            return generated;
        }
Exemple #48
0
 /// <summary>
 /// Give a provider the opportunity to load page content procedurally. 
 /// </summary>
 /// <param name="page"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public virtual bool LoadProcedualPage(Page page, PagedWorldSection section)
 {
     return false;
 }
Exemple #49
0
 public virtual StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
 {
     return(null);
 }
Exemple #50
0
 public virtual bool UnloadProcedualPage(Page page, PagedWorldSection section)
 {
     return(false);
 }
Exemple #51
0
			public override void DestroyInstance( ref PagedWorldSection p )
			{
				if ( !p.IsDisposed )
				{
					p.Dispose();
				}
			}
Exemple #52
0
		public abstract PageID GetPageID( Vector3 worldPos, PagedWorldSection section );