protected override void Visit(ExpressionNode node) { Chunks.Add(new SendExpressionChunk { Code = node.Code, Position = Locate(node), SilentNulls = node.SilentNulls, AutomaticallyEncode = node.AutomaticEncoding }); }
private void VisitMarkdown(SpecialNode specialNode, SpecialNodeInspector inspector) { var markdownChunk = new MarkdownChunk(); Chunks.Add(markdownChunk); using (new Frame(this, markdownChunk.Body)) { Accept(inspector.Body); } }
protected override void Visit(ExtensionNode extensionNode) { var extensionChunk = new ExtensionChunk { Extension = extensionNode.Extension, Position = Locate(extensionNode) }; Chunks.Add(extensionChunk); using (new Frame(this, extensionChunk.Body)) extensionNode.Extension.VisitNode(this, extensionNode.Body, Chunks); }
/// <summary> /// Retrieves the requested chunk from the region, or /// generates it if a world generator is provided. /// </summary> /// <param name="position">The position of the requested local chunk coordinates.</param> public Chunk GetChunk(Vector3 position) { // TODO: This could use some refactoring lock (Chunks) { if (!Chunks.ContainsKey(position)) { if (regionFile != null) { // Search the stream for that region lock (regionFile) { var chunkData = GetChunkFromTable(position); if (chunkData == null) { if (WorldGenerator == null) { throw new ArgumentException("The requested chunk is not loaded.", "position"); } GenerateChunk(position); return(Chunks[position]); } regionFile.Seek(chunkData.Item1, SeekOrigin.Begin); int length = new MinecraftStream(regionFile).ReadInt32(); // TODO: Avoid making new objects here, and in the WriteInt32 int compressionMode = regionFile.ReadByte(); switch (compressionMode) { case 1: // gzip break; case 2: // zlib var nbt = new NbtFile(); nbt.LoadFromStream(regionFile, NbtCompression.ZLib, null); var chunk = Chunk.FromNbt(position, nbt); chunk.ParentRegion = this; Chunks.Add(position, chunk); break; default: throw new InvalidDataException("Invalid compression scheme provided by region file."); } } } else if (WorldGenerator == null) { throw new ArgumentException("The requested chunk is not loaded.", "position"); } else { Chunks.Add(position, WorldGenerator.GenerateChunk(position, this)); } } return(Chunks[position]); } }
bool WriteSections() { // SORT GameData[] schunks = Chunks.ToArray(); GameData[] skeys = Keys.ToArray(); SortData(schunks); SortData(skeys); // Last Chunk string json = JsonConvert.SerializeObject(LastChunkInfo); Writer.Write(StringToSection(json, SectionType.ChunkInfo), false); // Meta Data json = JsonConvert.SerializeObject(MetaData); Writer.Write(StringToSection(json, SectionType.MetaData), false); // End of Game Stats if (GameStats != null) { Writer.Write(RawToSection(GameStatsRaw, SectionType.EndOfGameStats), false); } // Informations byte[] sum = Encoding.UTF8.GetBytes(SummonerName); Writer.Write(RawToSection(BinaryUtil.Append(new byte[2] { PlayerInfos.Map, PlayerInfos.Queue }, sum, 2, sum.Length), SectionType.Informations), false); //// Chunks List <RawEntry24> ent = new List <RawEntry24>(); foreach (GameData c in schunks) { ent.Add(new RawEntry24(c)); } Writer.Write(new ReplaySection(ent, SectionType.Chunks), false); // Keys ent.Clear(); foreach (GameData k in skeys) { ent.Add(new RawEntry24(k)); } // FINAL SECTION FOR COMPUTE HASH Writer.Write(new ReplaySection(ent, SectionType.Keys), true); // Writer.WriteByte(65); return(true); }
/// <summary> /// Sets the chunk at the specified local position to the given value. /// </summary> public void SetChunk(Coordinates2D position, IChunk chunk) { if (!Chunks.ContainsKey(position)) { Chunks.Add(position, chunk); } chunk.IsModified = true; chunk.Coordinates = position; chunk.LastAccessed = DateTime.Now; Chunks[position] = chunk; }
/// <inheritdoc /> public void ClearChunks() { var chunks = Chunks.ToArray(); Chunks.Clear(); foreach (var chunk in chunks) { chunk.Value.Dispose(); } }
private static void CheckChunk(Vector3 chunkPosition) { if (!Chunks.ContainsKey(chunkPosition)) { PollAdd(chunkPosition); } else { CheckNeighbors(chunkPosition); } }
public bool IsChunkShaped(IndexPosition pos, out Chunk chunk) { if (Chunks.TryGetValue(pos, out chunk)) { return(chunk.State > ChunkState.Unshaped); } else { return(false); } }
/// <summary> /// Instantiates a chunk to the specified coordinate /// </summary> /// <param name="chunkCoordinate">The chunk's coordinate</param> /// <returns>The instantiated chunk</returns> private SimulationChunk CreateChunk(int3 chunkCoordinate) { SimulationChunk chunk = Instantiate(ChunkPrefab, (chunkCoordinate * ChunkSize).ToVectorInt(), Quaternion.identity).GetComponent <SimulationChunk>(); chunk.name = $"Chunk_{chunkCoordinate.x}_{chunkCoordinate.y}_{chunkCoordinate.z}"; chunk.World = this; chunk.Initialize(ChunkSize, Isolevel, chunkCoordinate, CubeSize); Chunks.Add(chunkCoordinate, chunk); return(chunk); }
/// <summary> /// Clones MIDI file by creating a copy of it. /// </summary> /// <returns>Copy of the MIDI file.</returns> public MidiFile Clone() { var result = new MidiFile(Chunks.Select(c => c.Clone())) { TimeDivision = TimeDivision.Clone() }; result._originalFormat = _originalFormat; return(result); }
public Option <T> Set <T>(Option <T> value) where T : IComponent { if (typeof(T) == typeof(Chunk)) { throw new InvalidOperationException( $"{ nameof(Chunk) } cannot be modified"); } return((value.HasValue) ? Entities[Chunks.GetOrCreateChunkEntity(Position)].Set <T>(value) : Entity.Map((chunk) => Entities[chunk].Set <T>(value))); }
public void Bind(Map m, TileSet ts, TileSetRenderer tsr, Palette p, Palette pp) { Map = m; TileSet = ts; TileSetRenderer = tsr; Palette = p; PlayerPalette = pp; playerPalettes = null; Chunks.Clear(); currentTool = null; }
private void EnsureCapacity(long value) { var nextIndex = GetChunkIndex(value); for (var i = this.Chunks.Count; i <= nextIndex; i++) { // allocate memory and initialize it to zero var chunk = SharedPools.ByteArray.Allocate(); Array.Clear(chunk, 0, chunk.Length); Chunks.Add(chunk); } }
public Block GetBlockInChunk(IndexPosition chunkIndex, int bx, int by, int bz, out Chunk chunk) { if (Chunks.TryGetValue(chunkIndex, out chunk) && chunk.State > ChunkState.Unshaped) { return(chunk.GetBlockSafe(bx, by, bz)); } else { return(Block.STONE); } }
private DateTimeOffset?GetTimestamp(bool earliest) { if (earliest) { var fc = Chunks.OrderBy(t => t.FirstEventRecordIdentifier).FirstOrDefault(); return(fc?.EarliestTimestamp); } var lc = Chunks.OrderBy(t => t.FirstEventRecordIdentifier).LastOrDefault(); return(lc?.LatestTimestamp); }
public static void AddChunk(float x, float y) { Chunk chunk; if (ContainsChunk(x, y)) { return; } chunk = new GameObject("chunk").AddComponent <Chunk>(); chunk.Init(x, y); Chunks.Add(chunk); }
private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector) { var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless"); var unlessChunk = new ConditionalChunk { Type = ConditionalType.Unless, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) }; Chunks.Add(unlessChunk); using (new Frame(this, unlessChunk.Body)) Accept(specialNode.Body); }
/// <summary> /// Loads the dat. /// </summary> /// <param name="datPath">The dat path.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool LoadDat(string datPath) { try { Chunks.Clear(); var data = File.ReadAllBytes(datPath).AsSpan(); var position = 0; while (position < data.Length) { var name = Encoding.UTF8.GetString(data.Slice(position, 4)).TrimEnd('\0'); position += 4; var value = MemoryMarshal.Read <uint>(data[position..]);
public void DestroyChunkModels() { foreach (Chunk data in Chunks.Values) { data.DestroyModel(); } Chunks.Clear(); _waypoints.Clear(); GC.Collect(); }
public virtual Chunk PutChunk(ChunkPos pos, short[,,] data) { Chunk chunk = data == null ? new ChunkClient(pos, this) : new ChunkClient(pos, this, data); if (!Chunks.TryAdd(chunk.Pos, chunk)) { Console.Error.WriteLine("Chunk already exists at " + chunk.Pos); return(null); } // throw new Exception("Chunk already exists at " + chunk.Pos); return(chunk); }
public EditorMap(bool interior, int width, int height, byte defaultSkin) : base(interior) { AlwaysPlaceEntities = true; Chunk = new Chunk(0, 0, width, height, this); Chunks.Add(Chunk); Chunk.PostWorldInitialize(true); Chunk.FillTiles(true, defaultSkin); }
private void CheckForValidity(bool force = false) { if (_isComplete && !force) { return; } IsValid = false; IsComplete = false; if (Chunks.Count <= 0) { return; } var tmp = Chunks.Aggregate <byte[], IEnumerable <byte> >(null, (current, b) => current == null ? b : current.Concat(b)).ToArray(); if (tmp.Length < 12) // Can't fit the header in here { return; } // Check the header if (_header.Where((t, i) => tmp[i] != t).Any()) { return; } // Another checking if (tmp[8] != 0x06) { return; } // Get the size and name var size = BitConverter.ToInt32(tmp.SubArray(4, 4).Reverse().ToArray(), 0); IsValid = true; // Get the name length const int nameOffset = 12; int nameLength = tmp[9]; if (tmp.Length > nameOffset + tmp[9]) { Name = Encoding.Unicode.GetString(tmp.SubArray(nameOffset, nameLength)); _isComplete = tmp.Length >= size + nameOffset + nameLength; Debug.WriteLine(tmp.Length); if (_isComplete) { Data = tmp.SubArray(nameOffset + nameLength, size - nameLength - 4).Concat(new byte[] { 0x00, 0x00 }).ToArray(); } } }
/// <summary> /// Find a chunk with bounds that match the specified coordinates, and the specified material. /// Returns null if none was found. /// </summary> public HexChunk FindChunkForCoordinatesAndMaterial(HexCoords coordinates, Material material) { // Try to find existing chunk. var matchingChunks = Chunks.Where(c => coordinates.IsWithinBounds(c.lowerBounds, c.upperBounds)) .Where(c => c.Material == material); if (matchingChunks.Count() > 1) { Debug.LogWarning("Overlapping chunks detected for coordinates " + coordinates + ". Taking first."); } return(matchingChunks.FirstOrDefault()); }
public bool TryGetChunk(Int2 chunkIndex, out Chunk chunk) { if (Chunks.TryGetValue(chunkIndex, out var currentChunk)) { chunk = currentChunk; return(true); } chunk = null; return(false); }
public bool IsChunkPopulated(IndexPosition pos) { Chunk chunk; if (Chunks.TryGetValue(pos, out chunk)) { return(chunk.State > ChunkState.Unpopulated); } else { return(false); } }
/// <summary> /// Appends a sequence of instructions to these selected flow instructions, /// producing a new flow instruction selection. /// </summary> /// <param name="extraInstructions">Additional instructions to append.</param> /// <returns>A flow instruction selection.</returns> public SelectedFlowInstructions <TInstruction> Append( IEnumerable <TInstruction> extraInstructions) { return(new SelectedFlowInstructions <TInstruction>( Chunks.Concat( new[] { new SelectedInstructions <TInstruction>( extraInstructions.ToArray(), EmptyArray <ValueTag> .Value) }) .ToArray())); }
public void UpdateWater() { if (Chunks.World.Paused || Debugger.Switches.DisableWaterUpdate) { return; } foreach (var chunk in Chunks.GetChunkEnumerator()) { DiscreteUpdate(Chunks, chunk); chunk.RebuildLiquids(); } }
public void UpdateWater() { if (Chunks.World.Paused) { return; } foreach (var chunk in Chunks.GetChunkEnumerator()) { DiscreteUpdate(Chunks, chunk); chunk.RebuildLiquids(); } }
private void AddUnordered(Chunk chunk) { var sendLiteral = Chunks.LastOrDefault() as SendLiteralChunk; if (sendLiteral == null) { Chunks.Add(chunk); } else { Chunks.Insert(Chunks.Count - 1, chunk); } }
private static void CompareConstantBuffer(SharpDX.D3DCompiler.ConstantBuffer expected, Chunks.Rdef.ConstantBuffer actual) { Assert.AreEqual((int) expected.Description.Flags, (int) actual.Flags); Assert.AreEqual(expected.Description.Name, actual.Name); Assert.AreEqual(expected.Description.Size, actual.Size); Assert.AreEqual((int) expected.Description.Type, (int) actual.BufferType); Assert.AreEqual(expected.Description.VariableCount, actual.Variables.Count); for (int i = 0; i < expected.Description.VariableCount; i++) CompareConstantBufferVariable(expected.GetVariable(i), actual.Variables[i]); }
/// <summary> /// Spawns a GameObject on many voxels in a chunk. /// </summary> /// <param name="chunk">Chunk.</param> /// <param name="chunkGridCoord">Chunk grid coordinate.</param> /// <param name="obj">Object.</param> void onManyVoxelPosition(Chunks chunk, Vec3Int chunkGridCoord, GameObject obj) { Vector3 chunkBCoords = new Vector3 (chunkGridCoord.x, chunkGridCoord.y, chunkGridCoord.z) * vxe.chunk_size; Random.seed = (int)Time.frameCount; for (int x=0; x<vxe.chunk_size; x++) for (int z=0; z<vxe.chunk_size; z++) { for (int y=vxe.chunk_size-1; y>=0; y--) { Voxel vx = chunk.getVoxel (new Vec3Int (x, y, z)); if (vx.isOccupied () && vxe.voxelHasSurface (vx, VF.VX_TOP_SHOWN)) { Vector3 voxelCoords = vxe.FromGridUnTrunc (chunkBCoords + new Vector3 (x, y, z)); if (Random.Range (0, 20) == 0) { GameObject newObj = Instantiate (obj, voxelCoords + Vector3.up * vxe.voxel_size * 1.0f, Quaternion.AngleAxis(Random.Range (0,360),Vector3.up)) as GameObject; newObj.transform.parent = obj.transform.parent; newObj.SetActive (true); spawns.push(newObj.GetComponent<SpawnObject>()); spawnCount++; break; } } } } }
/// <summary> /// Does a the whole pull spawn process in one place. /// </summary> /// <returns>The pull spawn.</returns> IEnumerator FullPullSpawn() { Vector3 chunkBaseCoords; List<GameObject> assetList; /*OPTIMIZE THIS LATER, make it nlog(n) at least !!!!!!!!!!!!!!! Mergesort quicksort COME ON MAN!!*/ /*While true or occupiedChunk Count != table count * Check if Vec3Int is in table and If the voxel Count meets the miniVoxel Count * Then spawn 3-5 objects in Chunk */ while (true) { for (int i =vxe.occupiedChunks.getCount() - 1; i>-1; i--) { //Chunk Voxel Coordinates from the Occupied Chunk Stack Vec3Int chunkVXCoords = vxe.occupiedChunks.peek (i); //Get the Correct Environment Assets based on Biome assetList = GetEnvironmentListBasedOnBiome (chunkVXCoords); //Chunks World Coords chunk = vxe.grid.voxelGrid [chunkVXCoords.x, chunkVXCoords.y, chunkVXCoords.z]; if (chunk == null || assetList.Count == 0) { continue; } if(spawnCount > max_spawns) yield break; //If the chunk is a surface and is not in the HashTable, do Spawning code if (!chunk.spawnPopulated && chunk.voxel_count > minVoxelCount) { if(Random.Range (0,3) == 0) { GameObject gbj = assetList [Random.Range (0,assetList.Count)]; onManyVoxelPosition (chunk, chunkVXCoords, gbj); } chunk.spawnPopulated = true; } yield return null; } yield return new WaitForSeconds(1.0f); } }