public void LoadSubworldChunks(Subworld sub) { CurrentSubworld = sub; if (sub.ShouldUnloadWorldOnEnter()) { UnloadAllChunks(); } else { foreach (KeyValuePair <Vec2i, LoadedChunk2> kvp in LoadedChunks) { kvp.Value.gameObject.SetActive(false); } } SubworldChunks.Clear(); foreach (ChunkData cd in sub.SubworldChunks) { //Debug.Log("Object count:" + cd.WorldObjects.Count); SubworldChunks.Add(cd.Position, ChunkLoader.GetLoadedChunk(cd, 1)); //Debug.Log("sub chunk: " + cd.Position); //ChunkLoader.LoadChunk(cd); } CurrentSubworld = sub; //ChunkLoader.ForceLoadAll(); //TODO - fix this bad boy return; }
/// <summary> /// Checks if the specified chunk coordinate is currently loaded, /// checking both the world, and checking if a subworld is loaded /// </summary> /// <param name="chunkPos"></param> /// <returns></returns> public bool IsCurrentChunkPositionLoaded(Vec2i chunkPos) { if (InSubworld) { return(SubworldChunks.ContainsKey(chunkPos)); } return(LoadedChunks.ContainsKey(chunkPos)); }
/// <summary> /// Returns true if the ChunkRegionManager should unload the world when entering this subworld, /// returns false if the world should be kept loaded. /// ............ /// Designed sich that small subworlds do not require the world to be unloaded, resulting in quicker loading times /// </summary> /// <returns></returns> public virtual bool ShouldUnloadWorldOnEnter() { if (SubworldChunks.GetLength(0) * SubworldChunks.GetLength(1) <= 12) { return(false); } return(true); }
public void UnloadSubworldChunks() { //Iterate subworld chunks foreach (KeyValuePair <Vec2i, LoadedChunk2> kvp in SubworldChunks) { kvp.Value.gameObject.SetActive(false); ChunkLoader.AddToChunkBuffer(kvp.Value); } SubworldChunks.Clear(); }
public ChunkData GetChunkSafe(int x, int z) { if (SubworldChunks.GetLength(0) <= x || x < 0) { return(null); } if (SubworldChunks.GetLength(1) <= z || z < 0) { return(null); } return(SubworldChunks[x, z]); }
/// <summary> /// Checks the <see cref="LoadedChunks"/> dictionary for the relevent chunk position /// Returns null if not present /// </summary> /// <param name="chunk">The coordinate of the chunk we wish to find</param> /// <returns></returns> public LoadedChunk2 GetLoadedChunk(Vec2i chunk) { LoadedChunk2 lChunk; if (InSubworld) { if (SubworldChunks.TryGetValue(chunk, out lChunk)) { return(lChunk); } } if (LoadedChunks.TryGetValue(chunk, out lChunk)) { return(lChunk); } return(null); }