protected void processLoading( ) { // Preload, load, unload and post unload as required /* We try to PreLoad * If no preload is required, then try to Load * If no load is required, then try to UnLoad * If no unload is required, then try to PostUnLoad. */ Page e; e = pagePreloadQueue.Pop(); if (e != null) { e.Preload(); } else { e = pageLoadQueue.Pop(); if (e != null) { e.Load(ref sceneRoot); if (e.IsLoaded == false) { if (e.IsPreLoaded == false) { // If we are not PreLoaded, then we must preload pagePreloadQueue.Push(e); } // If we are not loaded then queue again, since maybe we are not preloaded. pageLoadQueue.Push(e); } } else { e = pageUnloadQueue.Pop(); if (e != null) { e.Unload(); } else { e = pagePostunloadQueue.Pop(); if (e != null) { e.PostUnload(); if (e.IsPreLoaded) { // If we are not post unloaded the queue again pagePostunloadQueue.Push(e); } } } } } // load some renderables RenderableManager.Instance.ExecuteRenderableLoading(); }
public void Update(Camera cam) { // Here we have to look if we have to load, unload any of the LandScape Pages //Vector3 pos = cam.getPosition(); // Fix from Praetor, so the camera used gives you "world-relative" coordinates Vector3 pos = cam.DerivedPosition; //updateStats( pos ); // Update only if the camera was moved // make sure in the bounding box of landscape pos.y = 127.0f; if (Options.Instance.CameraThreshold <= (lastCameraPos - pos).LengthSquared) { // Check for the camera position in the LandScape Pages list, we check if we are in the inside the security zone // if not, launch the change routine and update the camera position currentCameraX, currentCameraY. if (pages[currentCameraPageX][currentCameraPageZ] != null && ( pages[currentCameraPageX][currentCameraPageZ].IsLoaded == false || pages[currentCameraPageX][currentCameraPageZ].IsCameraIn(pos) != CameraPageState.Inside ) ) { // JEFF // convert camera pos to page index long i, j; Data2DManager.Instance.GetPageIndices(pos, out i, out j); //if (((currentCameraPageX != i) || (currentCameraPageZ != j)) && Debug.Assert(i < width && j < heigth, "Page Indices out of bounds"); if ((pages[i] [j] == null) || (pages[i][j].IsCameraIn(pos) != CameraPageState.Outside) ) { long adjpages = Options.Instance.Max_Adjacent_Pages; long prepages = Options.Instance.Max_Preload_Pages; long w = width; long h = heigth; // We must load the next visible landscape pages, // and unload the last visibles // check the landscape boundaries long iniX = ((int)(i - adjpages) > 0)? i - adjpages: 0; long iniZ = ((int)(j - adjpages) > 0)? j - adjpages: 0; long finX = (i + adjpages >= w)? w - 1: i + adjpages; long finZ = (j + adjpages >= h)? h - 1: j + adjpages; long preIniX = ((int)(i - prepages) > 0)? i - prepages: 0; long preIniZ = ((int)(j - prepages) > 0)? j - prepages: 0; long preFinX = (i + prepages >= w)? w - 1: i + prepages; long preFinZ = (j + prepages >= h)? h - 1: j + prepages; // update the camera page position currentCameraPageX = i; currentCameraPageZ = j; // Have the current page be loaded now if (pages[currentCameraPageX][currentCameraPageZ].IsPreLoaded == false) { pages[currentCameraPageX][currentCameraPageZ].Preload(); } if (pages[currentCameraPageX][currentCameraPageZ].IsLoaded == false) { pages[currentCameraPageX][currentCameraPageZ].Load(ref sceneRoot); } // Queue the rest // Loading and unloading must be done one by one to avoid FPS drop, so they are queued. // No need to queue for preload since _ProcessLoading will do it in Load if required. // post unload as required for (j = 0; j < preIniZ; j++) { for (i = 0; i < preIniX; i++) { pageUnloadQueue.Push(pages[i][j]); } } for (j = preFinZ + 1; j < h; j++) { for (i = preFinX + 1; i < w; i++) { pageUnloadQueue.Push(pages[i][j]); } } // Preload as required for (j = preIniZ; j < iniZ; j++) { for (i = preIniX; i < iniX; i++) { pagePreloadQueue.Push(pages[i][j]); } } for (j = finZ; j <= preFinZ; j++) { for (i = finX; i <= preFinX; i++) { pagePreloadQueue.Push(pages[i][j]); } } // load as required for (j = iniZ; j <= finZ; j++) { for (i = iniX; i <= finX; i++) { if (!pages[i][j].IsLoaded) { pageLoadQueue.Push(pages[i][j]); } } } } } // Update the last camera position lastCameraPos = pos; Tile.Tile t = GetTile(pos, (long)currentCameraPageX, (long)currentCameraPageZ); if (t != null) { Tile.TileInfo CurrentTileInfo = t.Info; if (CurrentTileInfo != null) { currentCameraTileX = CurrentTileInfo.TileX; currentCameraTileZ = CurrentTileInfo.TileZ; } } } // Check for visibility Camera plsmCam = (cam); for (long j = 0; j < heigth; j++) { for (long i = 0; i < width; i++) { pages[i][j].Notify(pos, plsmCam); } } // Preload, load, unload and post unload as required this.processLoading(); }