public static ChunkManageResult CheckManageChunks() { if (result == null) { return(null); } else { ChunkManageResult res = result; result = null; return(res); } }
public void Update(Vector3 PlayerLocation) { if (PreparingChunksMode) { PrepareChunks(MaxNumToPrepare); return; } else if (CurrentlyManagingChunks) { ChunkManageResult ManageResult = ChunkManager.CheckManageChunks(); if (ManageResult != null) { CurrentlyManagingChunks = false; if (ManageResult.NewState == ChunkWorkState.DoNewJob) { this.ActiveJob = true; LastResult = ManageResult; UnloadedChunksCenter = ManageResult.NewCenter; MostRecentAllChunkJobList = ManageResult.AllChunkJobs; ChunkJobQueuer.QueueTasks(ManageResult.Jobs.ToArray()); } } } else if (UnityEngine.Time.time - LastUpdateTime > 3.0f) { LastUpdateTime = UnityEngine.Time.time; if (this.ActiveJob) { CheckForAndProcessLoadedChunks(); return; } UsedInput.LoadedChunks = LoadedChunks; UsedInput.PlayerLocation = PlayerLocation; UsedInput.CurrentChunksCenter = LoadedChunksCenter; Task.Run(() => ChunkManager.ManageChunks(UsedInput)); CurrentlyManagingChunks = true; return; } }
public static void ManageChunks(ChunkManageInput Input) { ChunkManageResult Result = new ChunkManageResult(); Result.NewState = ChunkWorkState.DoNothing; Vector3 PlayerGridLocationNormalized = GetNormalizedGridLocation(Input.PlayerLocation, Input); Vector3 PlayerGridLocationRounded = GetRoundedGridLocation(PlayerGridLocationNormalized); UnityEngine.Debug.Log("PlayerGridLocationRounded: " + PlayerGridLocationRounded); UnityEngine.Debug.Log("Input.CurrentChunksCenter: " + Input.CurrentChunksCenter); if (PlayerGridLocationRounded != Input.CurrentChunksCenter) { Result.NewState = ChunkWorkState.DoNewJob; List <ChunkJob> NeededChunks = new List <ChunkJob>(); Hashtable OldChunks = Input.LoadedChunks; List <ChunkJob> NewChunks = GetChunksAroundPoint(PlayerGridLocationRounded, Input); Result.AllChunkJobs = NewChunks; Result.NewCenter = PlayerGridLocationRounded; foreach (ChunkJob c in NewChunks) { if (!OldChunks.Contains(c.Key)) { NeededChunks.Add(c); } } Result.Jobs = NeededChunks; } result = Result; }