void RenderNormalBatch(int batch) { for (int i = 0; i < chunks.Length; i++) { ChunkInfo info = chunks[i]; if (info.NormalParts == null || !info.Visible || info.Occluded) { continue; } ChunkPartInfo part = info.NormalParts[batch]; if (part.IndicesCount == 0) { continue; } usedNormal[batch] = true; if (part.IndicesCount > maxIndices) { DrawBigPart(info, ref part); } else { DrawPart(info, ref part); } if (part.spriteCount > 0) { api.DrawIndexedVb_TrisT2fC4b(part.spriteCount, 0); } game.Vertices += part.IndicesCount; } }
public void Setup() { var entriesInfo = new List <EntryInfo> { new EntryInfo(2, 22), new EntryInfo(3, 33) }; _chunkInfo = new ChunkInfo(entriesInfo, new EntryInfo(1, 11)); _chunkInfoBuilderMock = new Mock <IChunkInfoBuilder>(); _chunkInfoBuilderMock.Setup(x => x.Build(10)).Returns(_chunkInfo); _randomStringGeneratorMock = new Mock <IRandomStringGenerator>(); _randomStringGeneratorMock.Setup(x => x.Generate(11)).Returns("line1"); _randomStringGeneratorMock.Setup(x => x.Generate(22)).Returns("line2"); _randomStringGeneratorMock.Setup(x => x.Generate(33)).Returns("line3"); _randomNumberGeneratorMock = new Mock <IRandomNumberGenerator>(); _randomNumberGeneratorMock .SetupSequence(x => x.Generate(1, 10)) .Returns(1) .Returns(4); _randomNumberGeneratorMock.Setup(x => x.Generate(10, 100)).Returns(2); _randomNumberGeneratorMock.Setup(x => x.Generate(100, 1000)).Returns(3); }
private void DoRead(IDataQueue queue) { try { int page = 0; do { while (page < m_directory.Count) { lock (m_directory) { BinaryReader br = new BinaryReader(m_cache); m_cache.Seek(m_directory[page], SeekOrigin.Begin); ChunkInfo info = ChunkInfo.LoadInfo(br); for (int i = 0; i < info.Count; i++) { queue.PutRecord(BedTool.LoadRecord(br, m_table)); } } page++; } if (State == TabularDataViewState.Loading) { System.Threading.Thread.Sleep(100); } } while (State == TabularDataViewState.Loading); queue.PutEof(); } finally { queue.CloseWriting(); } }
public IEnumerable <IBedRecord> EnumRows(TableDataSetProperties props) { int page = 0; do { while (page < m_directory.Count) { lock (m_directory) { BinaryReader br = new BinaryReader(m_cache); m_cache.Seek(m_directory[page], SeekOrigin.Begin); ChunkInfo info = ChunkInfo.LoadInfo(br); for (int i = 0; i < info.Count; i++) { yield return(BedTool.LoadRecord(br, m_table)); } } page++; } if (State == TabularDataViewState.Loading) { System.Threading.Thread.Sleep(100); } } while (State == TabularDataViewState.Loading); }
public void BeginChunk(Hash chunk_id, int version_number = 0) { if (m_chunks.Count == m_max_chunks) { throw new Exception($"Too many chunks. MaxChunks={m_max_chunks}"); } if (m_current_chunk.IsValid()) { throw new Exception($"Need to call EndChunk on chunk {m_current_chunk} before calling BeginChunk again."); } if (m_chunks.ContainsKey(chunk_id)) { throw new Exception($"Chunk '{chunk_id}' already exists."); } m_chunks[chunk_id] = new ChunkInfo { m_position = m_position, m_version_number = version_number }; m_current_chunk = chunk_id; }
public void SaveWorldAndLoadedChunks() { int size = GManager.MAX_CHUNK_SIZE; foreach (KeyValuePair <Vector2Int, Chunk> ch in chunks) { int iX = ch.Key.x / size; int iZ = ch.Key.y / size; ChunkArea area = currAreas.Find(a => a.iX == iX && a.iZ == iZ); ChunkInfo chI = ch.Value.getChunkInfo(); if (area != null) { Vector3 pos = new Vector3(ch.Value.selfPosInt.x, 0, ch.Value.selfPosInt.y); area.chunks.TryGetValue(pos, out ChunkInfo inf); if (inf == null) { area.chunks.Add(pos, chI); } else { area.chunks[pos] = chI; } } } currAreas.ForEach(a => { using (FileStream fileStream = File.Open(chunksPath + "chA" + a.iX + "" + a.iZ + ".dat", FileMode.OpenOrCreate)) { binFormatter.Serialize(fileStream, a); } }); SaveWorld(); }
void DeleteChunk(ChunkInfo info) { info.Empty = false; info.OcclusionFlags = 0; info.OccludedFlags = 0; DeleteData(ref info.NormalParts); DeleteData(ref info.TranslucentParts); }
IEnumerator LoadAround(ChunkInfo info) { foreach (ChunkInfo chunk in ChunkInfo.ChunksInArea(info.gridX, info.gridZ, 1)) { CreateChunkAt(chunk.gridX, chunk.gridZ); yield return(null); } }
public static void ToBinary( ChunkCompressedInfo info, byte[] buffer, int offset) { Array.Copy(BitConverter.GetBytes(info.size), 0, buffer, offset, 4); ChunkInfo.ToBinary(info.target, buffer, offset + 4); }
public static ChunkCompressedInfo FromBinary( byte[] buffer, int offset) { return(new ChunkCompressedInfo( BitConverter.ToInt32(buffer, offset), ChunkInfo.FromBinary(buffer, offset + 4))); }
protected virtual void OnStreamDataAdded(StreamInfo stream, ChunkInfo dataChunk) { if (stream.AvailableTracks.Count() > 0) { var track = stream.AvailableTracks.First(); DownloadStreamData(track, dataChunk); } }
public static ChunkDecompressionInfo FromBinary( byte[] buffer, int offset) { return(new ChunkDecompressionInfo( ChunkInfo.FromBinary(buffer, offset), ChunkInfo.FromBinary(buffer, offset + ChunkInfo.SIZE))); }
public static void ToBinary( ChunkDecompressionInfo info, byte[] buffer, int offset) { ChunkInfo.ToBinary(info.source, buffer, offset); ChunkInfo.ToBinary(info.target, buffer, offset + ChunkInfo.SIZE); }
public L7cArchiveFileInfo(Stream fileData, string filePath, IList <L7cChunkEntry> chunks, L7cFileEntry entry) : base(fileData, filePath) { _chunkStream = new ChunkStream(fileData, entry.decompSize, ChunkInfo.ParseEntries(chunks)); Chunks = chunks; Entry = entry; }
/// <summary> /// Splits big file into some chunks by matching starting characters in each line /// </summary> /// <param name="inputFileName">Big file name</param> /// <param name="chars">Number of starting characters to split by</param> private void SplitFile(string inputFileName, int chars) { var files = new Dictionary <string, FileChunk>(StringComparer.CurrentCulture); using (var sr = new StreamReader(inputFileName, Encoding)) { while (sr.Peek() >= 0) { var line = sr.ReadLine(); DataItem entry = DataItem.FromString(line); //The length of the line is less than the current number of characters we split by //In this cases we add the line to the non-sorted file if (line.Length < chars) { ChunkInfo nameInfo; if (!chunks.TryGetValue(line, out nameInfo)) { chunks.Add(line, nameInfo = new ChunkInfo()); } nameInfo.AddSmallString(line, Encoding); } //Otherwise we add the line to the file corresponding to the first char characters of the line else { string start = entry.Text.Substring(0, chars); FileChunk sfi; if (!files.TryGetValue(start, out sfi)) { sfi = new FileChunk(Encoding); files.Add(start, sfi); } sfi.Append(line, Encoding); } } } //For each of the chunk we check if size of the chunk is still greater than the maxFileSize foreach (var file in files) { file.Value.Close(); //If it is - split to smaller chunks if (file.Value.Size > maxFileSize) { SplitFile(file.Value.FileName, chars + 1); File.Delete(file.Value.FileName); } //Otherwise save it to the dictionary else { SortFile(file.Value.FileName, file.Value.FileName); ChunkInfo nameInfo; if (!chunks.TryGetValue(file.Key, out nameInfo)) { chunks.Add(file.Key, nameInfo = new ChunkInfo()); } nameInfo.FileName = file.Value.FileName; } } }
void Print(string prefix, int cx, int cy, int cz) { ChunkInfo chunk = unsortedChunks[cx + chunksX * (cy + cz * chunksY)]; Console.WriteLine("{0} D {1}: V {2}, O {3}, {4}", prefix, chunk.DistanceFlags, chunk.OccludedFlags, chunk.OcclusionFlags, chunk.Occluded); // Console.WriteLine( chunk.DistanceFlags + " : " + chunk.OccludedFlags + " : " + chunk.OcclusionFlags + " , " + chunk.Occluded ); Vector3I p = chunkPos; int x1 = chunk.CentreX - 8, x2 = chunk.CentreX + 8; int y1 = chunk.CentreY - 8, y2 = chunk.CentreY + 8; int z1 = chunk.CentreZ - 8, z2 = chunk.CentreZ + 8; int dx = Math.Max(x1 - p.X, Math.Max(0, p.X - x2)); int dy = Math.Max(y1 - p.Y, Math.Max(0, p.Y - y2)); int dz = Math.Max(z1 - p.Z, Math.Max(0, p.Z - z2)); int distX, distY, distZ; // X axis collisions int dxLeft = Math.Abs(x1 - p.X), dxRight = Math.Abs(x2 - p.X); if (dxLeft < dxRight) { distX = dxLeft * dxLeft + dy * dy + dz * dz; } else { distX = dxRight * dxRight + dy * dy + dz * dz; } // Z axis collisions int dxFront = Math.Abs(z1 - p.Z), dxBack = Math.Abs(z2 - p.Z); if (dxFront < dxBack) { distZ = dx * dx + dy * dy + dxFront * dxFront; } else { distZ = dx * dx + dy * dy + dxBack * dxBack; } // Y axis collisions int dxBottom = Math.Abs(y1 - p.Y), dxTop = Math.Abs(y2 - p.Y); if (dxBottom < dxTop) { distY = dx * dx + dxBottom * dxBottom + dz * dz; } else { distY = dx * dx + dxTop * dxTop + dz * dz; } int distMin = Math.Min(distX, Math.Min(distY, distZ)); Console.WriteLine(" M {0} : X {1}, Y {2}, Z {3} ({4}, {5})", distMin, distX, distY, distZ, dxFront, dxBack); }
public L7cArchiveFileInfo(Stream fileData, string filePath, IList <L7cChunkEntry> chunks, L7cFileEntry entry) : base(new ChunkStream(fileData, entry.decompSize, ChunkInfo.ParseEntries(chunks)), filePath) { _origStream = fileData; _usesCompression = ((ChunkStream)FileData).UsesCompression; Chunks = chunks; Entry = entry; }
public void CloseChunk() { if (mOpenChunks.Count <= 0) throw new Exception("Attempt to close chunk with no chunks open"); ChunkInfo current = mOpenChunks.Peek(); if (current.Remaining > 0U) throw new Exception(string.Format("Attempt to close incomplete chunk ({0} of {1} bytes still needed)", current.Remaining, current.Length)); mOpenChunks.Pop(); }
public OptionalSubstitution(long recordPosition, BinaryReader dataStream, ChunkInfo chunk) { RecordPosition = recordPosition; Size = 4; SubstitutionId = dataStream.ReadInt16(); ValueType = (TagBuilder.ValueType)dataStream.ReadByte(); Log.Verbose("{This}", this); }
void DrawPart(ChunkInfo info, ref ChunkPartInfo part) { api.BindVb(part.VbId); bool drawLeft = info.DrawLeft && part.leftCount > 0; bool drawRight = info.DrawRight && part.rightCount > 0; bool drawBottom = info.DrawBottom && part.bottomCount > 0; bool drawTop = info.DrawTop && part.topCount > 0; bool drawFront = info.DrawFront && part.frontCount > 0; bool drawBack = info.DrawBack && part.backCount > 0; if (drawLeft && drawRight) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.leftCount + part.rightCount, part.leftIndex); api.FaceCulling = false; } else if (drawLeft) { api.DrawIndexedVb_TrisT2fC4b(part.leftCount, part.leftIndex); } else if (drawRight) { api.DrawIndexedVb_TrisT2fC4b(part.rightCount, part.rightIndex); } if (drawFront && drawBack) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.frontCount + part.backCount, part.frontIndex); api.FaceCulling = false; } else if (drawFront) { api.DrawIndexedVb_TrisT2fC4b(part.frontCount, part.frontIndex); } else if (drawBack) { api.DrawIndexedVb_TrisT2fC4b(part.backCount, part.backIndex); } if (drawBottom && drawTop) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b(part.bottomCount + part.topCount, part.bottomIndex); api.FaceCulling = false; } else if (drawBottom) { api.DrawIndexedVb_TrisT2fC4b(part.bottomCount, part.bottomIndex); } else if (drawTop) { api.DrawIndexedVb_TrisT2fC4b(part.topCount, part.topIndex); } }
public void Enqueue(ChunkInfo item) { if (Size == array.Length) { throw new InvalidOperationException("Queue limit reached"); } array[tail] = item; tail = (tail + 1) % array.Length; Size++; }
private static void ProcessRGBA(VoxFile File, BinaryReader Reader, ChunkInfo Info) { byte[] Pallete = File.Palette = new byte [256 * 4]; for (int i = 0; i < 256; i++) { for (int c = 0; c < 4; c++) { Pallete[i * 4 + c] = Reader.ReadByte(); } } }
public void ShouldSerializeDeserialize(long offset, int size) { var chunk = new ChunkInfo(offset, size); var buffer = new byte[ChunkInfo.SIZE]; ChunkInfo.ToBinary(chunk, buffer, 0); var result = ChunkInfo.FromBinary(buffer, 0); Assert.Equal(offset, result.offset); Assert.Equal(size, result.size); }
public bool HasCollision(ChunkInfo ci, int x, int y) { Vector2 worldPos = WorldMap.Chunk2World(ci, x, y); Box2D worldBox = new Box2D(worldPos, 0.5f, 0.5f); // Check against any player Box2D playerBox = GameManager.Instance.MainPlayer.Box; return(CollisionCode.TestBox2DBox2D(worldBox, playerBox)); }
void QueueChunk(int cx, int cy, int cz, ChunkQueue queue) { if (cx >= 0 && cy >= 0 && cz >= 0 && cx < chunksX && cy < chunksY && cz < chunksZ) { ChunkInfo info = unsortedChunks[cx + chunksX * (cy + cz * chunksY)]; if (!info.Visited) { queue.Enqueue(info); } info.Visited = true; } }
private ChunkInfo readChunk32(UInt64 position) { checkClosed(); br.BaseStream.Seek((Int64)position, SeekOrigin.Begin); ChunkInfo retVal = new ChunkInfo(); byte[] nameBytes = br.ReadBytes(4); retVal.name = Encoding.ASCII.GetString(nameBytes).ToUpper(); retVal.size = br.ReadUInt32(); return(retVal); }
protected override async Task <ChunkLayout> DeserializeBytesAsync(BinaryReader reader) { int chunks = reader.ReadInt32(); var chunkInfoArray = new ChunkInfo[chunks]; for (int i = 0; i < chunks; i++) { chunkInfoArray[i] = await _chunkInfoSerializer.DeserializeAsync(reader.BaseStream); } return(new ChunkLayout(chunkInfoArray)); }
public async Task <IChunk> DownloadChunk() { var chunkInfo = await ChunkSaver.GetNextEmptyChunk(Destination); var checkedChunkInfo = new ChunkInfo( chunkInfo.Start, Math.Min(ChunkLength, chunkInfo.Length) ); var chunk = await ChunkDownloader.DownloadChunk(checkedChunkInfo); return(chunk); }
internal Hashgraph.TopicMessage ToTopicMessage(Hashgraph.Address topic) { return(new Hashgraph.TopicMessage { Topic = topic, Concensus = ConsensusTimestamp.ToDateTime(), Messsage = Message.ToByteArray(), RunningHash = RunningHash.ToByteArray(), SequenceNumber = SequenceNumber, SegmentInfo = ChunkInfo?.ToMessageSegmentInfo() }); }
public void MergeFrom(RequestEnvelope other) { if (other == null) { return; } if (other.ApplicationMessageId.Length != 0) { ApplicationMessageId = other.ApplicationMessageId; } if (other.ApplicationMessageSeqNo != 0L) { ApplicationMessageSeqNo = other.ApplicationMessageSeqNo; } if (other.TechnicalMessageType.Length != 0) { TechnicalMessageType = other.TechnicalMessageType; } if (other.TeamSetContextId.Length != 0) { TeamSetContextId = other.TeamSetContextId; } if (other.Mode != global::Agrirouter.Request.RequestEnvelope.Types.Mode.Direct) { Mode = other.Mode; } recipients_.Add(other.recipients_); if (other.chunkInfo_ != null) { if (chunkInfo_ == null) { ChunkInfo = new global::Agrirouter.Commons.ChunkComponent(); } ChunkInfo.MergeFrom(other.ChunkInfo); } if (other.timestamp_ != null) { if (timestamp_ == null) { Timestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp(); } Timestamp.MergeFrom(other.Timestamp); } if (other.metadata_ != null) { if (metadata_ == null) { Metadata = new global::Agrirouter.Commons.Metadata(); } Metadata.MergeFrom(other.Metadata); } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
internal static ChunkInfo LoadInfo(BinaryReader br) { int size = br.ReadInt32(); var res = new ChunkInfo(); res.Lengths = new int[size]; for (int i = 0; i < size; i++) { int s = br.ReadInt32(); res.Lengths[i] = s; res.ChunkSize += s; } return res; }
void OccludeZ( int cx, int cy, int cz, int zOffset, ChunkInfo info ) { cz += zOffset; if( cz >= 0 && cz < chunksZ ) { ChunkInfo neighbour = unsortedChunks[cx + chunksX * (cy + cz * chunksY)]; if( (neighbour.OccludedFlags & neighbour.DistanceFlags) != neighbour.DistanceFlags ) info.Occluded = false; else info.OccludedFlags |= flagZ; } else { info.Occluded = false; } info.DistanceFlags |= flagZ; }
void OccludeY( int cx, int cy, int cz, int yOffset, ChunkInfo info ) { cy += yOffset; if( cy >= 0 && cy < chunksY ) { ChunkInfo neighbour = unsortedChunks[cx + chunksX * (cy + cz * chunksY)]; if( (neighbour.OccludedFlags & neighbour.DistanceFlags) != neighbour.DistanceFlags ) info.Occluded = false; else info.OccludedFlags |= flagY; } else { info.Occluded = false; } info.DistanceFlags |= flagY; }
void OccludeX( int cx, int cy, int cz, int xOffset, ChunkInfo info ) { cx += xOffset; if( cx >= 0 && cx < chunksX ) { ChunkInfo neighbour = unsortedChunks[cx + chunksX * (cy + cz * chunksY)]; if( (neighbour.OccludedFlags & neighbour.DistanceFlags) != neighbour.DistanceFlags ) info.Occluded = false; else info.OccludedFlags |= flagX; } else { info.Occluded = false; } info.DistanceFlags |= flagX; }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data //stream.SendNext(transform.position); //stream.SendNext(transform.rotation); stream.SendNext(info); } else { // Network player, receive data //this.correctPlayerPos = (Vector3)stream.ReceiveNext(); //this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); this.info = (ChunkInfo)stream.ReceiveNext(); } }
public void Enqueue( ChunkInfo item ) { if( Size == array.Length ) throw new InvalidOperationException( "Queue limit reached" ); array[tail] = item; tail = (tail + 1) % array.Length; Size++; }
void DrawBigPart( ChunkInfo info, ref ChunkPartInfo part ) { api.BindVb( part.VbId ); bool drawLeft = info.DrawLeft && part.leftCount > 0; bool drawRight = info.DrawRight && part.rightCount > 0; bool drawBottom = info.DrawBottom && part.bottomCount > 0; bool drawTop = info.DrawTop && part.topCount > 0; bool drawFront = info.DrawFront && part.frontCount > 0; bool drawBack = info.DrawBack && part.backCount > 0; if( drawLeft && drawRight ) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.leftCount + part.rightCount, part.leftIndex ); api.FaceCulling = false; } else if( drawLeft ) { api.DrawIndexedVb_TrisT2fC4b( part.leftCount, part.leftIndex ); } else if( drawRight ) { api.DrawIndexedVb_TrisT2fC4b( part.rightCount, part.rightIndex ); } if( drawFront && drawBack ) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.frontCount + part.backCount, part.frontIndex ); api.FaceCulling = false; } else if( drawFront ) { api.DrawIndexedVb_TrisT2fC4b( part.frontCount, part.frontIndex ); } else if( drawBack ) { api.DrawIndexedVb_TrisT2fC4b( part.backCount, part.backIndex ); } // Special handling for top and bottom as these can go over 65536 vertices and we need to adjust the indices in this case. if( drawBottom && drawTop ) { api.FaceCulling = true; if( part.IndicesCount > maxIndices ) { int part1Count = maxIndices - part.bottomIndex; api.DrawIndexedVb_TrisT2fC4b( part1Count, part.bottomIndex ); api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount - part1Count, maxVertex, 0 ); } else { api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount, part.bottomIndex ); } api.FaceCulling = false; } else if( drawBottom ) { int part1Count; if( part.IndicesCount > maxIndices && ( part1Count = maxIndices - part.bottomIndex ) < part.bottomCount ) { api.DrawIndexedVb_TrisT2fC4b( part1Count, part.bottomIndex ); api.DrawIndexedVb_TrisT2fC4b( part.bottomCount - part1Count, maxVertex, 0 ); } else { api.DrawIndexedVb_TrisT2fC4b( part.bottomCount, part.bottomIndex ); } } else if( drawTop ) { int part1Count; if( part.IndicesCount > maxIndices && ( part1Count = maxIndices - part.topIndex ) < part.topCount ) { api.DrawIndexedVb_TrisT2fC4b( part1Count, part.topIndex ); api.DrawIndexedVb_TrisT2fC4b( part.topCount - part1Count, maxVertex, 0 ); } else { api.DrawIndexedVb_TrisT2fC4b( part.topCount, part.topIndex ); } } }
void DeleteChunk( ChunkInfo info ) { info.Empty = false; info.OcclusionFlags = 0; info.OccludedFlags = 0; DeleteData( ref info.NormalParts ); DeleteData( ref info.TranslucentParts ); }
/// <summary> /// Splits big file into some chunks by matching starting characters in each line /// </summary> /// <param name="inputFileName">Big file name</param> /// <param name="chars">Number of starting characters to split by</param> private void SplitFile(string inputFileName, int chars) { var files = new Dictionary<string, FileChunk>(Comparer); using (var sr = new StreamReader(inputFileName, Encoding)) { while (sr.Peek() >= 0) { string entry = sr.ReadLine(); //The length of the line is less than the current number of characters we split by //In this cases we add the line to the non-sorted file if (entry.Length < chars) { ChunkInfo nameInfo; if (!chunks.TryGetValue(entry, out nameInfo)) chunks.Add(entry, nameInfo = new ChunkInfo()); nameInfo.AddSmallString(entry, Encoding); } //Otherwise we add the line to the file corresponding to the first char characters of the line else { string start = entry.Substring(0, chars); FileChunk sfi; if (!files.TryGetValue(start, out sfi)) { sfi = new FileChunk(Encoding); files.Add(start, sfi); } sfi.Append(entry, Encoding); } } } //For each of the chunk we check if size of the chunk is still greater than the maxFileSize foreach (var file in files) { file.Value.Close(); //If it is - split to smaller chunks if (file.Value.Size > maxFileSize) { SplitFile(file.Value.FileName, chars + 1); File.Delete(file.Value.FileName); } //Otherwise save it to the dictionary else { SortFile(file.Value.FileName, file.Value.FileName); ChunkInfo nameInfo; if (!chunks.TryGetValue(file.Key, out nameInfo)) chunks.Add(file.Key, nameInfo = new ChunkInfo()); nameInfo.FileName = file.Value.FileName; } } }
protected virtual void OnDownloadStreamDataCompleted(TrackInfo track, ChunkInfo dataChunk, Stream streamData, StreamInfo stream) { if (DataReceived != null) { streamData.Seek(0, SeekOrigin.Begin); int length = (int)streamData.Length; var data = new byte[length]; int count; int sum = 0; do { count = streamData.Read(data, sum, length - sum); sum += count; } while (count > 0 && sum < length); DataReceived(this, new DataReceivedInfo(data, dataChunk, track, stream)); } }
// Use this for initialization void Start () { info = GetComponent<Chunk>().getInfo(); }
void ProcessQueue( ChunkInfo src, ChunkQueue queue ) { Vector3I p = new Vector3I( src.CentreX, src.CentreY, src.CentreZ ); while( queue.Size > 0 ) { ChunkInfo chunk = queue.Dequeue(); chunk.VisibilityFlags = chunk.OcclusionFlags; int x1 = chunk.CentreX - 8, x2 = chunk.CentreX + 8; int y1 = chunk.CentreY - 8, y2 = chunk.CentreY + 8; int z1 = chunk.CentreZ - 8, z2 = chunk.CentreZ + 8; int cx = chunk.CentreX >> 4; int cy = chunk.CentreY >> 4; int cz = chunk.CentreZ >> 4; int xOffset, yOffset, zOffset; int dx = Math.Max( x1 - p.X, Math.Max( 0, p.X - x2 ) ); int dy = Math.Max( y1 - p.Y, Math.Max( 0, p.Y - y2 ) ); int dz = Math.Max( z1 - p.Z, Math.Max( 0, p.Z - z2 ) ); int distX, distY, distZ; // X axis collisions int dxLeft = Math.Abs( x1 - p.X ), dxRight = Math.Abs( x2 - p.X ); if( dxLeft < dxRight ) { distX = dxLeft * dxLeft + dy * dy + dz * dz; xOffset = -1; } else { distX = dxRight * dxRight + dy * dy + dz * dz; xOffset = 1; } // Z axis collisions int dxFront = Math.Abs( z1 - p.Z ), dxBack = Math.Abs( z2 - p.Z ); if( dxFront < dxBack ) { distZ = dx * dx + dy * dy + dxFront * dxFront; zOffset = -1; } else { distZ = dx * dx + dy * dy + dxBack * dxBack; zOffset = 1; } // Y axis collisions int dxBottom = Math.Abs( y1 - p.Y ), dxTop = Math.Abs( y2 - p.Y ); if( dxBottom < dxTop ) { distY = dx * dx + dxBottom * dxBottom + dz * dz; yOffset = -1; } else { distY = dx * dx + dxTop * dxTop + dz * dz; yOffset = 1; } int distMin = Math.Min( distX, Math.Min( distY, distZ ) ); bool occlude = true; byte flags = 0; if( distMin == distX ) OccludeX( cx, cy, cz, xOffset, ref occlude, ref flags ); if( distMin == distZ ) OccludeZ( cx, cy, cz, zOffset, ref occlude, ref flags ); if( distMin == distY ) OccludeY( cx, cy, cz, yOffset, ref occlude, ref flags ); if( occlude ) chunk.Occluded = true; chunk.VisibilityFlags = (byte)( flags | chunk.OcclusionFlags ); QueueChunk( cx - 1, cy, cz, queue ); QueueChunk( cx + 1, cy, cz, queue ); QueueChunk( cx, cy, cz - 1, queue ); QueueChunk( cx, cy, cz + 1, queue ); QueueChunk( cx, cy - 1, cz, queue ); QueueChunk( cx, cy + 1, cz, queue ); } Console.WriteLine( "======================" ); }
void CreateChunkCache() { int index = 0; for( int z = 0; z < length; z += 16 ) { for( int y = 0; y < height; y += 16 ) { for( int x = 0; x < width; x += 16 ) { chunks[index] = new ChunkInfo( x, y, z ); unsortedChunks[index] = chunks[index]; index++; } } } }
private void InitBuffers() { _freeCount = _maxChunkCount; _freeHead = 0; _head = -1; _tail = -1; var lastIndex = _maxChunkCount - 1; for(var i = 0; i < lastIndex; ++i) { // The free list does not maintain prev links _chunks[i] = new ChunkInfo(this, i, i + 1); } _chunks[lastIndex] = new ChunkInfo(this, lastIndex, -1); }
public DataChunk(ChunkInfo chunkInfo) { ChunkInfo = chunkInfo; }
void OnNewMapLoaded( object sender, EventArgs e ) { width = NextMultipleOf16( game.Map.Width ); height = NextMultipleOf16( game.Map.Height ); length = NextMultipleOf16( game.Map.Length ); chunksX = width >> 4; chunksY = height >> 4; chunksZ = length >> 4; chunks = new ChunkInfo[chunksX * chunksY * chunksZ]; unsortedChunks = new ChunkInfo[chunksX * chunksY * chunksZ]; distances = new int[chunks.Length]; CreateChunkCache(); builder.OnNewMapLoaded(); }
private void UploadChunk(string filePath, string s3objectName, ref ChunkInfo chunk) { // structuredLog("I", "uploading chunk with index: " + chunk.chunkIndex); // if (logger != null) logger.Log("Thread: " + System.Threading.Thread.CurrentThread.ManagedThreadId); if (logger != null) logger.Log("Start Synchronizer Read Chunk From File"); byte[] chunkBuffer = new byte[chunk.rsize]; using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { fs.Seek(chunk.roffset, SeekOrigin.Begin); BinaryReader br = new BinaryReader(fs); br.Read(chunkBuffer, 0, chunkBuffer.Length);//read chunk into buffer fs.Close(); } if (logger != null) logger.Log("End Synchronizer Read Chunk From File"); // Here is the compression and encryption for the chunk if (logger != null) logger.Log("Start Synchronizer Compress Chunk"); byte[] compressedChunkBuffer = Compress(chunkBuffer);// for now if (logger != null) logger.Log("End Synchronizer Compress Chunk"); if (logger != null) logger.Log("Start Synchronizer Encrypt Chunk"); byte[] encryptedCompressedChunkBuffer = Encrypt(compressedChunkBuffer); if (logger != null) logger.Log("End Synchronizer Encrypt Chunk"); if (logger != null) logger.Log("Start Synchronizer Upload Chunk"); string chunkObjectName = ChunkObjectNamePrefix + s3objectName + "-" + chunk.chunkIndex; if (UploadByteArrayToS3Object(chunkObjectName, encryptedCompressedChunkBuffer)) { chunk.SetBlobName(chunkObjectName); chunk.SetCSize(encryptedCompressedChunkBuffer.Length); } else throw new Exception("Chunk upload for given chunk has failed. FileName: " + s3objectName + " . Chunk:" + chunk.ToString()); if (logger != null) logger.Log("End Synchronizer Upload Chunk"); }
/// <summary> /// Downloads the chunk of data that is part of the specified track and has the specified timestamp id. /// </summary> /// <param name="track">the track that contains the data to be downloaded.</param> /// <param name="chunk">the chunk to be downloaded.</param> public void DownloadStreamData(TrackInfo track, ChunkInfo chunk) { if (track != null) { _chunkDownloadManager.AddRequest(track, chunk.TimeStamp); } }
void DrawTranslucentPart( ChunkInfo info, ref ChunkPartInfo part ) { api.BindVb( part.VbId ); bool drawLeft = (drawAllFaces || info.DrawLeft) && part.leftCount > 0; bool drawRight = (drawAllFaces || info.DrawRight) && part.rightCount > 0; bool drawBottom = (drawAllFaces || info.DrawBottom) && part.bottomCount > 0; bool drawTop = (drawAllFaces || info.DrawTop) && part.topCount > 0; bool drawFront = (drawAllFaces || info.DrawFront) && part.frontCount > 0; bool drawBack = (drawAllFaces || info.DrawBack) && part.backCount > 0; if( drawLeft && drawRight ) { api.DrawIndexedVb_TrisT2fC4b( part.leftCount + part.rightCount, part.leftIndex ); } else if( drawLeft ) { api.DrawIndexedVb_TrisT2fC4b( part.leftCount, part.leftIndex ); } else if( drawRight ) { api.DrawIndexedVb_TrisT2fC4b( part.rightCount, part.rightIndex ); } if( drawFront && drawBack ) { api.DrawIndexedVb_TrisT2fC4b( part.frontCount + part.backCount, part.frontIndex ); } else if( drawFront ) { api.DrawIndexedVb_TrisT2fC4b( part.frontCount, part.frontIndex ); } else if( drawBack ) { api.DrawIndexedVb_TrisT2fC4b( part.backCount, part.backIndex ); } if( drawBottom && drawTop ) { api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount, part.bottomIndex ); } else if( drawBottom ) { api.DrawIndexedVb_TrisT2fC4b( part.bottomCount, part.bottomIndex ); } else if( drawTop ) { api.DrawIndexedVb_TrisT2fC4b( part.topCount, part.topIndex ); } }
void DrawPart( ChunkInfo info, ref ChunkPartInfo part ) { api.BindVb( part.VbId ); bool drawLeft = info.DrawLeft && part.leftCount > 0; bool drawRight = info.DrawRight && part.rightCount > 0; bool drawBottom = info.DrawBottom && part.bottomCount > 0; bool drawTop = info.DrawTop && part.topCount > 0; bool drawFront = info.DrawFront && part.frontCount > 0; bool drawBack = info.DrawBack && part.backCount > 0; if( drawLeft && drawRight ) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.leftCount + part.rightCount, part.leftIndex ); api.FaceCulling = false; } else if( drawLeft ) { api.DrawIndexedVb_TrisT2fC4b( part.leftCount, part.leftIndex ); } else if( drawRight ) { api.DrawIndexedVb_TrisT2fC4b( part.rightCount, part.rightIndex ); } if( drawFront && drawBack ) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.frontCount + part.backCount, part.frontIndex ); api.FaceCulling = false; } else if( drawFront ) { api.DrawIndexedVb_TrisT2fC4b( part.frontCount, part.frontIndex ); } else if( drawBack ) { api.DrawIndexedVb_TrisT2fC4b( part.backCount, part.backIndex ); } if( drawBottom && drawTop ) { api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.bottomCount + part.topCount, part.bottomIndex ); api.FaceCulling = false; } else if( drawBottom ) { api.DrawIndexedVb_TrisT2fC4b( part.bottomCount, part.bottomIndex ); } else if( drawTop ) { api.DrawIndexedVb_TrisT2fC4b( part.topCount, part.topIndex ); } }
void DeleteChunk( ChunkInfo info ) { info.Empty = false; DeleteData( ref info.NormalParts ); DeleteData( ref info.TranslucentParts ); }