//Event Handler //--------------------------------------------------------------------------- public void Handle_PlayerLeaveChunk(IEvent _event) { GSW.RestartTimer(); //Interpret Event E_Player_LeaveChunk LeaveChunk = (_event as E_Player_LeaveChunk); AreaRect TempArea = m_CoverArea; TempArea.Move(LeaveChunk.Offset); int i, j = 0; ChunkInWorld SpawnLoc; for (i = TempArea.left; i <= TempArea.right; ++i) { for (j = TempArea.bottom; j <= TempArea.top; ++j) { SpawnLoc = new ChunkInWorld(new Vector2Int(i, j), m_World); m_WorldEntity.Spawn(SpawnLoc); m_CoveredLoc.Remove(SpawnLoc.Value); } } //remove not covered chunk foreach (var uncoverd in m_CoveredLoc) { m_WorldEntity.Remove(new ChunkInWorld(uncoverd, m_World)); } //update cover area SetCoverArea(TempArea); }
public void ApplyModification(ChunkInWorld chunkInWorld, Chunk chunk, IWorld world) { if (m_Helpers.TryGetValue(chunkInWorld.Value, out var helper)) { helper.ApplyModification(chunk, world); } }
public void Handle_PlayerSpawn(IEvent _event) { E_Player_Spawned Player_Spawned = _event.Cast <E_Player_Spawned>(); ChunkInWorld SpawnCenter = new ChunkInWorld(Player_Spawned.SpawnPos, m_World); //figure out visiable area m_CoverArea = new AreaRect(SpawnCenter.Value, (int)m_PlayerMng.PlayerView); }
public Chunk GetChunk(ChunkInWorld _chunkinworld) { if (m_Chunks.TryGetValue(_chunkinworld.Value, out Chunk TempChunk)) { return(TempChunk); } else { return(null); } }
//Event Handler //--------------------------------------------------------------------------- public bool SpawnAtArea(Vector3 center, int extend, IWorld world) { ChunkInWorld SpawnCenter = new ChunkInWorld(center, world); //figure out visiable area AreaRect ViewArea = new AreaRect(SpawnCenter.Value, extend); for (int i = ViewArea.left; i <= ViewArea.right; ++i) { for (int j = ViewArea.bottom; j <= ViewArea.top; ++j) { m_CoveredLoc.Add(new Vector2Int(i, j)); m_WorldEntity.Spawn(new ChunkInWorld(new Vector2Int(i, j), world)); } } SetCoverArea(ViewArea); return(true); }
//public Function //--------------------------------------------------------------------------- public void Spawn(ChunkInWorld _chunkinworld) { Chunk TempChunk; //Case: The Chunk has already spawned if (m_Chunks.ContainsKey(_chunkinworld.Value)) { //Debug.Log("already spawned"); return; } //Case: The Chunk is in GarbageCache else if (m_Garbages.TryRemove(_chunkinworld.Value, out TempChunk)) { TempChunk.gameObject.SetActive(true); m_Chunks.Add(_chunkinworld.Value, TempChunk); //Debug.Log("From garbage"); } //instantiate new else { //make a chunk instance TempChunk = Instantiate(Prefab_Chunk, transform).GetComponent <Chunk>(); //Init Chunk TempChunk.SetLocation(_chunkinworld); TempChunk.GenerateBlocks(); //Load data From save file m_SaveMng.LoadBlock(_chunkinworld, TempChunk); //Build Mesh //TempChunk.BuildMesh(); m_ChunkMeshBuilder.AddRequest(TempChunk); //Add Chunk m_Chunks.Add(_chunkinworld.Value, TempChunk); //Debug.Log("Make New"); } }
public void Remove(ChunkInWorld _chunkinworld) { //Case: The Chunk has spawned if (m_Chunks.TryGetValue(_chunkinworld.Value, out var removedChunk)) { //remove from chunk dictionary m_Chunks.Remove(_chunkinworld.Value); //disactive chunk removedChunk.gameObject.SetActive(false); //add to garbage Cache Chunk removedLRU = m_Garbages.Put(_chunkinworld.Value, removedChunk); //destroy lru garbage if (removedLRU != null) { //Debug.Log("remove"+removedLRU.Loc); Destroy(removedLRU.gameObject); } } }
public void SetLocation(ChunkInWorld chunkInWorld) { GSW.RestartTimer(); //Set Location m_ChunkinWorld = chunkInWorld; transform.localPosition = m_ChunkinWorld.ToCoord3D(m_World); //Set Name transform.name = "Chunk" + "[" + m_ChunkinWorld.Value.x + "]" + "[" + m_ChunkinWorld.Value.y + "]"; //Compute Unity Position m_Coord = chunkInWorld.ToCoord2DInt(m_World); //create Height map m_HeightMap = MonoSingleton <GameSystem> .Instance.WorldMngIns.GetComponent <MapMaker>().GetBlendedHeightMap(m_ChunkinWorld.Value); // = MonoSingleton<GameSystem>.Instance.WorldMngIns.GetComponent<BiomeMng>().MakeHeightMap(m_ChunkinWorld.Value); //Create Sections InitAllSections(); //StartCoroutine("CreCreateAllSections_Corou"); }
static public Chunk GetChunk(ChunkInWorld chunkinworld, IWorld _World) { return(_World.Entity.GetChunk(chunkinworld)); }
public void LoadBlock(ChunkInWorld chunkInWorld, Chunk chunk) { m_SaveHelper.ApplyModification(chunkInWorld, chunk, m_WorldMng.WorldServ); }