public WorldChunk(Coord _coord, GameObject _chunkObject, WorldChunkSettings setting, DisplayModes _displayMode, ChunkStates _requireState) { this.coord = _coord; this.state = ChunkStates.Created; this.displayMode = _displayMode; this.isVisible = false; this.isLoading = false; this.isComputing = false; this.isMeshing = false; this.requireState = _requireState; this.chunkObject = _chunkObject; this.chunkObject.transform.parent = setting.parent; this.chunkObject.transform.localScale = new Vector3(setting.size, .01f, setting.size); this.chunkObject.transform.localPosition = this.coord.ToWorldPosition(setting); MapDisplay.instance.UpdateChunkName(this, setting); // Request Data if (this.requireState >= ChunkStates.Loaded) { this.requestData(setting); } else { MapDisplay.instance.UpdateChunkDisplay(this); } }
public void OnWorldChunkComputedReceived(WorldChunkComputed _chunkComputed) { // Computed this.chunkComputed = _chunkComputed; this.state = ChunkStates.Computed; this.computingTime = Time.time - this.computingTime; this.isComputing = false; // Inform MapEndless MapEndless.instance.OnWorldChunkThreadReceived(this); // Rendering MapDisplay.instance.UpdateChunkDisplay(this); }
public void OnWorldChunkMeshReceived(MeshData meshData) { this.isMeshing = true; this.meshData = meshData; this.state = ChunkStates.Meshed; if (this.requireState < ChunkStates.Meshed) { this.requireState = ChunkStates.Meshed; } // Create Mesh a first time MapEndless.instance.OnWorldChunkThreadReceived(this); // Direct Update Mesh after creating (if some chunk as been updated during this thread) MeshGenerator.UpdateChunkMesh(this, MapEngine.instance.worldChunkSetting); }
public void OnChunkMerged() { WorldChunkSettings setting = MapEngine.instance.worldChunkSetting; this.state = ChunkStates.Merged; if (this.requireState < ChunkStates.Merged) // If all the chunk is merged but wasn't required for (ex: side chunk with not border) { this.requireState = ChunkStates.Merged; } MapDisplay.instance.UpdateChunkDisplay(this); this.isMeshing = true; // Create the first time the chunk borders values this.chunkBorders = new WorldChunkSideBorders(this, setting); // Request Mesh data MapThreading.instance.RequestWorldChunkMeshData(this, this.chunkBorders, setting, OnWorldChunkMeshReceived); }
public void CreateChunk(Coord coord, ChunkStates state) { if (devMaxChunkCoord > 0) { if (Math.Abs(coord.x) > devMaxChunkCoord || Math.Abs(coord.y) > devMaxChunkCoord) { Debug.Log("Avoid creation because " + coord + " is over DEV " + devMaxChunkCoord); return; } } GameObject chunkObject = Instantiate(chunkPrefab) as GameObject; WorldChunk newWorldChunk = new WorldChunk(coord, chunkObject, MapEngine.instance.worldChunkSetting, MapDisplay.instance.displayMode, state); this.worldChunks.Add(coord, newWorldChunk); }
public void UpdateState(WorldChunkSettings setting, ChunkStates requiredState) { if (this.requireState < requiredState) { this.requireState = requiredState; if (this.state == ChunkStates.Created && this.requireState > ChunkStates.Created) { if (this.isLoading) { return; } this.requestData(setting); } else if (this.state == ChunkStates.Loaded && this.requireState > ChunkStates.Loaded) { if (this.isComputing) { return; } this.requestComputed(setting); } else if (this.state == ChunkStates.Computed && this.requireState > ChunkStates.Computed) { // All zones are already computed by sideChunks but we didn't catch it, try now ? //this.TestMerged(setting); // Retest now is state still Computed if (this.state == ChunkStates.Computed) { for (int zone_idx = 0; zone_idx < this.worldZonesRefs.Count; zone_idx++) { this.worldZonesRefs [zone_idx].UpdateState(WorldZoneStates.Merged); } } this.MergeZones(setting); } } }
public void OnWorldChunkDataReceived(WorldChunkData _chunkData) { WorldChunkSettings setting = MapEngine.instance.worldChunkSetting; // Loaded this.chunkData = _chunkData; this.state = ChunkStates.Loaded; this.isLoading = false; // @TODO: if the chunk are loaded when it's no more displayed, will not be handled on `worldChunkInView` this.isVisible = true; // If it's not a border chunk (to compute the next chunk) request for computing if (this.requireState >= ChunkStates.Computed) { this.requestComputed(setting); } // Rendering MapDisplay.instance.UpdateChunkDisplay(this); // Inform MapEndless MapEndless.instance.OnWorldChunkThreadReceived(this); }