Example #1
0
        public virtual Page GetPage(PageID pageID)
        {
            Page page;

            this.mPages.TryGetValue(pageID, out page);
            return(page);
        }
Example #2
0
        public virtual void FrameEnd(Real timeElapsed)
        {
            this.mStrategy.FrameEnd(timeElapsed, this);
            var ids = new PageID[this.mPages.Count];

            this.mPages.Keys.CopyTo(ids, 0);

            for (int i = 0; i < this.mPages.Count; ++i)
            {
                // if this page wasn't used, unload
                Page p = this.mPages[ids[i]];

                if (!p.IsHeld)
                {
                    UnloadPage(p);

                    // update indices since unloading will invalidate it
                    ids = new PageID[this.mPages.Count];
                    this.mPages.Keys.CopyTo(ids, 0);

                    // pre-decrement since unloading will remove it
                    --i;
                }
                else
                {
                    p.FrameEnd(timeElapsed);
                }
            }
        }
Example #3
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
                }
            }
        }
Example #4
0
        public virtual Page LoadOrCreatePage(Vector3 worldPos)
        {
            PageID id = GetPageID(worldPos);

            // this will create a Page instance no matter what, even if load fails
            // we force the load attempt to happen immediately (forceSynchronous)
            LoadPage(id, true);
            return(GetPage(id));
        }
Example #5
0
        public virtual void HoldPage(PageID pageID)
        {
            Page page;

            if (this.mPages.TryGetValue(pageID, out page))
            {
                page.Touch();
            }
        }
Example #6
0
        public void CalculateCell(PageID inPageID, out int x, out int y)
        {
            // inverse of calculatePageID
            // unsigned versions
            var y16 = (UInt16)(inPageID.Value & 0xFFFF);
            var x16 = (UInt16)((inPageID.Value >> 16) & 0xFFFF);

            x = (Int16)x16;
            y = (Int16)y16;
        }
Example #7
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();
        }
Example #8
0
        public virtual void UnloadPage(PageID pageID, bool forceSynchonous)
        {
            if (!this.mParent.Manager.ArePagingOperationsEnabled)
            {
                return;
            }

            if (this.mPages.ContainsKey(pageID))
            {
                Page page = this.mPages[pageID];
                this.mPages.Remove(pageID);
                page.UnLoad();
                page.SafeDispose();
            }
        }
Example #9
0
        public virtual StreamSerializer ReadPageStream(PageID pageID)
        {
            StreamSerializer stream = null;

            if (this.mPageProvider != null)
            {
                stream = this.mPageProvider.ReadPageStream(pageID, this);
            }
            if (stream == null)
            {
                stream = this.mParent.ReadPageStream(pageID, this);
            }

            return(stream);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        public StreamSerializer WritePageStream(PageID pageID)
        {
            StreamSerializer stream = null;

            if (this.mPageProvider != null)
            {
                stream = this.mPageProvider.WritePageStream(pageID, this);
            }
            if (stream == null)
            {
                stream = this.mParent.WritePageStream(pageID, this);
            }

            return(stream);
        }
Example #13
0
        public virtual void LoadPage(PageID pageID, bool forceSynchronous)
        {
            if (!this.mParent.Manager.ArePagingOperationsEnabled)
            {
                return;
            }

            if (!this.mPages.ContainsKey(pageID))
            {
                var page = new Page(pageID, this);
                page.Load(forceSynchronous);
                this.mPages.Add(pageID, page);
            }
            else
            {
                this.mPages[pageID].Touch();
            }
        }
Example #14
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);
        }
Example #15
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);
        }
Example #16
0
		public virtual void LoadPage( PageID pageID, bool forceSynchronous )
		{
			if ( !this.mParent.Manager.ArePagingOperationsEnabled )
			{
				return;
			}

			if ( !this.mPages.ContainsKey( pageID ) )
			{
				var page = new Page( pageID, this );
				page.Load( forceSynchronous );
				this.mPages.Add( pageID, page );
			}
			else
			{
				this.mPages[ pageID ].Touch();
			}
		}
Example #17
0
 public void UnloadPage(PageID pageId)
 {
     UnloadPage(pageId, false);
 }
Example #18
0
		public virtual void UnloadPage( PageID pageID, bool forceSynchonous )
		{
			if ( !this.mParent.Manager.ArePagingOperationsEnabled )
			{
				return;
			}

			if ( this.mPages.ContainsKey( pageID ) )
			{
				Page page = this.mPages[ pageID ];
				this.mPages.Remove( pageID );
				page.UnLoad();
				page.SafeDispose();
			}
		}
Example #19
0
 public virtual StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
 {
     return(null);
 }
Example #20
0
 /// <summary>
 /// Page class
 /// </summary>
 /// <param name="pageID"></param>
 public Page(PageID pageID)
 {
     mID = pageID;
     Touch();
 }
Example #21
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();
		}
Example #22
0
 /// <summary>
 /// Ask for a page to be loaded with the given (section-relative) PageID
 /// </summary>
 /// <param name="pageID">The page ID to load</param>
 public void LoadPage(PageID pageID)
 {
     LoadPage(pageID, false);
 }
Example #23
0
		public virtual void FrameEnd( Real timeElapsed )
		{
			this.mStrategy.FrameEnd( timeElapsed, this );
			var ids = new PageID[this.mPages.Count];
			this.mPages.Keys.CopyTo( ids, 0 );

			for ( int i = 0; i < this.mPages.Count; ++i )
			{
				// if this page wasn't used, unload
				Page p = this.mPages[ ids[ i ] ];

				if ( !p.IsHeld )
				{
					UnloadPage( p );

					// update indices since unloading will invalidate it
					ids = new PageID[this.mPages.Count];
					this.mPages.Keys.CopyTo( ids, 0 );

					// pre-decrement since unloading will remove it
					--i;
				}
				else
				{
					p.FrameEnd( timeElapsed );
				}
			}
		}
Example #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pageId"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section)
 {
     return null;
 }
Example #25
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;
 }
		public override void UnloadPage( PageID pageID, bool forceSynchonous )
		{
			if ( !mParent.Manager.ArePagingOperationsEnabled )
			{
				return;
			}

			base.UnloadPage( pageID, forceSynchonous );

			// trigger terrain unload
			long x, y;
			// pageID is the same as a packed index
			this.terrainGroup.UnpackIndex( pageID.Value, out x, out y );
			this.terrainGroup.UnloadTerrain( x, y );
		}
		public override void LoadPage( PageID pageID, bool forceSynchronous )
		{
			if ( !mParent.Manager.ArePagingOperationsEnabled )
			{
				return;
			}

			if ( mPages.ContainsKey( pageID ) )
			{
				// trigger terrain load
				long x, y;
				// pageID is the same as a packed index
				this.terrainGroup.UnpackIndex( pageID.Value, out x, out y );
				this.terrainGroup.DefineTerrain( x, y );
				this.terrainGroup.LoadTerrain( x, y, forceSynchronous );
			}

			base.LoadPage( pageID, forceSynchronous );
		}
Example #28
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();
        }
Example #29
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;
        }
Example #30
0
 /// <summary>
 /// Ask for a page to be unloaded with the given (section-relative) PageID
 /// </summary>
 /// <param name="pageId">The page ID to unload</param>
 public void UnloadPage(PageID pageId)
 {
     UnloadPage(pageId, false);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="inPageID"></param>
 /// <param name="row"></param>
 /// <param name="col"></param>
 public void CalculateRowCol(PageID inPageID, ref int row, ref int col)
 {
     // inverse of calculatePageID
     row = inPageID.Value / mGridExtentsHorz;
     col = inPageID.Value % mGridExtentsHorz;
 }
Example #32
0
 /// <summary>
 /// Ask for a page to be kept in memory if it's loaded.
 /// </summary>
 /// <param name="pageID"></param>
 public virtual void HoldPage(PageID pageID)
 {
     Page page;
     if (mPages.TryGetValue(pageID, out page))
         page.Touch();
 }
		public void CalculateCell( PageID inPageID, out int x, out int y )
		{
			// inverse of calculatePageID
			// unsigned versions
			var y16 = (UInt16)( inPageID.Value & 0xFFFF );
			var x16 = (UInt16)( ( inPageID.Value >> 16 ) & 0xFFFF );

			x = (Int16)x16;
			y = (Int16)y16;
		}
Example #34
0
        /// <summary>
        /// Get a serialiser set up to write Page data for the given PageID. 
        /// </summary>
        /// <param name="pageID"></param>
        public StreamSerializer WritePageStream(PageID pageID)
        {
            StreamSerializer stream = null;
            if (mPageProvider != null)
                stream = mPageProvider.WritePageStream(pageID, this);
            if (stream == null)
                stream = mParent.WritePageStream(pageID, this);

            return stream;
        }
Example #35
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;
		}
Example #36
0
		public virtual StreamSerializer ReadPageStream( PageID pageID )
		{
			StreamSerializer stream = null;
			if ( this.mPageProvider != null )
			{
				stream = this.mPageProvider.ReadPageStream( pageID, this );
			}
			if ( stream == null )
			{
				stream = this.mParent.ReadPageStream( pageID, this );
			}

			return stream;
		}
Example #37
0
 /// <summary>
 /// Ask for a page to be loaded with the given (section-relative) PageID
 /// </summary>
 /// <param name="pageID">The page ID to load</param>
 /// <param name="forceSynchronous">If true, the page will always be loaded synchronously</param>
 public virtual void LoadPage(PageID pageID, bool forceSynchronous)
 {
     Page page;
     if (!mPages.TryGetValue(pageID, out page))
     {
         page = new Page(pageID);
         // attach page immediately, but notice that it's not loaded yet
         AttachPage(page);
         Manager.Queue.LoadPage(page, this, forceSynchronous);
     }
     else
         page.Touch();
 }
Example #38
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;
        }
Example #39
0
 /// <summary>
 /// Ask for a page to be unloaded with the given (section-relative) PageID
 /// </summary>
 /// <param name="pageID">The page ID to unload</param>
 /// <param name="forceSynchonous">If true, the page will always be unloaded synchronously</param>
 public virtual void UnloadPage(PageID pageID, bool forceSynchonous)
 {
     Page page;
     if (mPages.TryGetValue(pageID, out page))
     {
         mPages.Remove(pageID);
         page.NotifyAttached(null);
         Manager.Queue.UnLoadPage(page, this, forceSynchonous);
     }
 }
Example #40
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;
		}
Example #41
0
 /// <summary>
 /// Retrieves a Page.
 /// </summary>
 /// <param name="pageID"></param>
 /// <returns></returns>
 public virtual Page GetPage(PageID pageID)
 {
     Page page;
     mPages.TryGetValue(pageID, out page);
     return page;
 }
Example #42
0
 /// <summary>
 /// Ask for a page to be loaded with the given (section-relative) PageID
 /// </summary>
 /// <remarks>
 /// You would not normally call this manually, the PageStrategy is in
 /// charge of it usually.
 /// If this page is already loaded, this request will not load it again.
 /// If the page needs loading, then it may be an asynchronous process depending
 /// on whether threading is enabled.
 /// </remarks>
 /// <param name="pageID">The page ID to load</param>
 public void LoadPage(PageID pageID)
 {
     LoadPage(pageID, false);
 }
Example #43
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;
		}
Example #44
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;
		}