public virtual Page GetPage(PageID pageID) { Page page; this.mPages.TryGetValue(pageID, out page); return(page); }
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); } } }
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 } } }
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)); }
public virtual void HoldPage(PageID pageID) { Page page; if (this.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; }
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(); }
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(); } }
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); }
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); }
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); }
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); }
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(); } }
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); }
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); }
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(); } }
public void UnloadPage(PageID pageId) { UnloadPage(pageId, false); }
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(); } }
public virtual StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section) { return(null); }
/// <summary> /// Page class /// </summary> /// <param name="pageID"></param> public Page(PageID pageID) { mID = pageID; Touch(); }
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(); }
/// <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); }
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 ); } } }
/// <summary> /// /// </summary> /// <param name="pageId"></param> /// <param name="section"></param> /// <returns></returns> public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section) { return null; }
/// <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 ); }
/// <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(); }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
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; }
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; }
/// <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(); }
/// <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; }
/// <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); } }
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; }
/// <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; }
/// <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); }
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; }
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; }