public ScBlock GetBlock(int x, int y, int z) { int blockX = x % 16; int blockZ = z % 16; int chunkX = (x - blockX) / 16; int chunkZ = (z - blockZ) / 16; ScChunk localChunk = ChunkDictionary .Where(localPair => localPair.Key.ChunkX == chunkX && localPair.Key.ChunkZ == chunkZ) .SingleOrDefault() .Value; if (localChunk == null) { throw new ArgumentException("Chunk not found."); } ////ScChunkPosition position = new ScChunkPosition(chunkX, chunkZ); ////if (!ChunkDictionary.ContainsKey(position)) //// throw new ArgumentException("Chunk not found."); ////ScChunk chunk = ChunkDictionary[position]; ////ScBlock block = chunk.GetBlockInChunk(blockX, y, blockZ); //return block; return(null); }
/// <summary> /// Replaces a chunk with another one /// </summary> /// <param name="id">Chunk id to replace</param> /// <param name="chunk">Replacement chunk</param> internal void ReplaceChunk(uint id, StorageChunk chunk) { Cache = null; var index = ChunkDictionary[id]; FailIndex(index); ChunkList[index] = chunk; ChunkDictionary.Remove(id); ChunkDictionary[chunk.Id] = index; }
void UpdateDirtyBlock(ChunkDictionary block) { if (block.LastSequenceNumber > MaxAppendedSequence) { if (MaxAppendedSequence >= block.FirstSequenceNumber && MaxAppendedSequence <= block.LastSequenceNumber) { Append(block, fromSequence: MaxAppendedSequence); // when storage data changed } } }
public void RemoveBlock(GameObject currentChunk, Block block) { ChunkDictionary.Remove(block.Position); //Ich entferne erst den Block auf dem Chunk IChunk chunk = currentChunk.GetComponent <IChunk>(); chunk.RemoveBlock(block); // Und erstelle anschließend mit den restlichen Blöcken den Chunk ModifyMesh.RemoveBlockFromMesh(currentChunk.transform, block); DeleteChunkIfNotNeeded(chunk); }
public void AddChunk(ScChunkPosition argChunkPosition, ScChunk chunk) { ChunkDictionary.Add(argChunkPosition, chunk); //if (_minX == 0) // _minX = chunk.ChunkX; //if (_minZ == 0) // _minZ = chunk.ChunkZ; //_minX = Math.Min(chunk.ChunkX, _minX); //_minZ = Math.Min(chunk.ChunkZ, _minZ); //_maxX = Math.Max(chunk.ChunkX, _maxX); //_maxZ = Math.Max(chunk.ChunkZ, _maxZ); }
public void AddBlock(Block block) { Vector3 centeredCubePosition = block.Position; ChunkDictionary.Add(block.Position, block.Position); (IChunk chunk, GameObject parent, bool hasCreatedNewChunk) = GenerateOrGetChunkGameObject(centeredCubePosition); chunk.AddBlock(block); if (!hasCreatedNewChunk) { ModifyMesh.Combine(block, parent); } else { ModifyMesh.CombineForAll(parent); } }
public void Append(ChunkDictionary block, long?fromSequence = null) { LastAppendedBlockIndex = block.BlockIndex; for (long seq = fromSequence ?? block.FirstSequenceNumber; seq <= block.LastSequenceNumber; seq++) { if (seq > MaxAppendedSequence) { MaxAppendedSequence = seq; } if (Chunks.ContainsKey(seq)) { continue; } var chunkView = CreateChunkView(block[seq]); chunkView.BlockIndex = block.BlockIndex; chunkView.Location = InsertionPoint; var firstFragmentIndex = TextLayer.Items.Count; // preserve old items count before appending some fragments chunkView.Build(); if (firstFragmentIndex == TextLayer.Items.Count) // no fragment was added { chunkView.FirstFragmentIndex = chunkView.LastFragmentIndex = -1; } else { chunkView.FirstFragmentIndex = firstFragmentIndex; chunkView.LastFragmentIndex = TextLayer.Items.Count - 1; TextLayer.Items.Last().IsTrailing = true; } Chunks.Add(seq, chunkView); } }