public PagedWorldSection CreateSection(PageStrategy strategy, SceneManager sceneMgr, string sectionName) { PagedWorldSection ret = CreateSection(sceneMgr, "General", sectionName); ret.Strategy = strategy; return(ret); }
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); }
public PagedWorldSection GetSection(string name) { PagedWorldSection section = null; this.mSections.TryGetValue(name, out section); return(section); }
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 } } }
internal bool UnloadProcedualPage(Page page, PagedWorldSection section) { bool generated = false; if (this.mPageProvider != null) { generated = this.mPageProvider.UnloadProcedualPage(page, section); } return(generated); }
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)); }
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 void DestroyWorldSection(ref PagedWorldSection coll) { PagedWorldSectionFactory fact = GetWorldSectionFactory(coll.Type); if (fact != null) { fact.DestroyInstance(ref coll); } else { coll.SafeDispose(); // normally a safe fallback } }
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, 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 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); }
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 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); }
public abstract void DestroyInstance(ref PagedWorldSection p);
public virtual void FrameEnd( Real timeElapsed, PagedWorldSection section ) { }
public override bool UnPrepareProcedualPage( Page page, PagedWorldSection section ) { return true; }
/// <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> /// 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 }
public Request(RequestType rt, Page p, PagedWorldSection s) { RequestType = rt; Page = p; Section = s; }
public virtual void FrameStart(Real timeSinceLastFrame, PagedWorldSection section) { }
/// <summary> /// /// </summary> /// <param name="pageId"></param> /// <param name="section"></param> /// <returns></returns> public StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section) { return null; }
public virtual void NotifyCamera(Camera cam, PagedWorldSection section) { }
public abstract PageID GetPageID(Vector3 worldPos, PagedWorldSection section);
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; }
internal bool UnloadProcedualPage( Page page, PagedWorldSection section ) { bool generated = false; if ( this.mPageProvider != null ) { generated = this.mPageProvider.UnloadProcedualPage( page, section ); } return generated; }
public virtual void NotifyCamera( Camera cam, PagedWorldSection section ) { }
/// <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(); }
public virtual void FrameEnd(Real timeElapsed, PagedWorldSection section) { }
/// <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; }
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> /// 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 );
/// <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); }
/// <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; }
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 } }
/// <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; }
/// <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; }
public void DestroySection(PagedWorldSection section) { DestroySection(section.Name); }
/// <summary> /// /// </summary> /// <param name="section"></param> public void DestroySection(PagedWorldSection section) { DestroySection(section.Name); }
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; }
/// <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; }
public virtual void FrameStart( Real timeSinceLastFrame, PagedWorldSection section ) { }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
public virtual StreamSerializer WritePageStream(PageID pageId, PagedWorldSection section) { return(null); }
public virtual bool UnloadProcedualPage(Page page, PagedWorldSection section) { return(false); }
public override void DestroyInstance( ref PagedWorldSection p ) { if ( !p.IsDisposed ) { p.Dispose(); } }
public abstract PageID GetPageID( Vector3 worldPos, PagedWorldSection section );