public override void QueryForChunks(ref RenderPassDesc desc) { // Restore the vertex buffer contents if the graphics device was lost. if (this.vertexBuffer.IsContentLost) { this.vertexBuffer.SetData(this.particles); } // If there are any particles waiting in the newly added queue, we'd better upload them to the GPU ready for drawing. if (this.firstNewParticle != this.firstFreeParticle) { AddNewParticlesToVertexBuffer(); } // If there are any active particles, draw them now! if (this.firstActiveParticle != this.firstFreeParticle) { ParticleChunk chunk = this.parentEntity.Game.Graphics.AllocateParticleChunk(); chunk.vertices = this.vertexBuffer; chunk.indices = this.indexBuffer; chunk.Material = this.material; chunk.Type = PrimitiveType.TriangleList; chunk.ParticleSettings = this.settings; chunk.CurrentTime = this.currentTime; chunk.StartVertexIndex = this.firstActiveParticle * 4; chunk.StartIndex = this.firstActiveParticle * 6; if (this.firstActiveParticle < this.firstFreeParticle) { // If the active particles are all in one consecutive range, we can draw them all in a single call. chunk.NumVerts = (this.firstFreeParticle - this.firstActiveParticle) * 4; chunk.PrimitiveCount = (this.firstFreeParticle - this.firstActiveParticle) * 2; } else { // If the active particle range wraps past the end of the queue // back to the start, we must split them over two draw calls. chunk.NumVerts = (this.settings.MaxParticles - this.firstActiveParticle) * 4; chunk.PrimitiveCount = (this.settings.MaxParticles - this.firstActiveParticle) * 2; if (this.firstFreeParticle > 0) { ParticleChunk chunkTwo = this.parentEntity.Game.Graphics.AllocateParticleChunk(); chunkTwo.vertices = this.vertexBuffer; chunkTwo.indices = this.indexBuffer; chunkTwo.StartVertexIndex = 0; chunkTwo.NumVerts = this.firstFreeParticle * 4; chunkTwo.StartIndex = 0; chunkTwo.PrimitiveCount = this.firstFreeParticle * 2; chunkTwo.Material = this.material; chunkTwo.Type = PrimitiveType.TriangleList; chunkTwo.ParticleSettings = this.settings; chunkTwo.CurrentTime = this.currentTime; } } } ++drawCounter; }
public void ExtractBinary(string inputPath, string outputPath, ProgressWrapper progress) { byte[] fileBuffer = File.ReadAllBytes(inputPath); Directory.CreateDirectory(Path.Combine(outputPath, AssetType.Particle.GetFolderName())); int i = HeaderSize; while (i < fileBuffer.Length) { ParticleChunk chunk = ReadParticleChunk(fileBuffer, i); i += chunk.Buffer.Length; progress.Report($"Creating Particle file for chunk \"{chunk.Name}\".", i / (float)fileBuffer.Length); File.WriteAllBytes(Path.Combine(outputPath, AssetType.Particle.GetFolderName(), chunk.Name + AssetType.Particle.GetFileExtension()), chunk.Buffer[chunk.Name.Length..]);
private static AnalyzerFileResult?TryReadParticleFile(string sourceFileName, byte[] sourceFileBytes) { try { ParticleFileHandler fileHandler = new ParticleFileHandler(); fileHandler.ValidateFile(sourceFileBytes); int i = ParticleFileHandler.HeaderSize; List <IChunk> chunks = new List <IChunk>(); while (i < sourceFileBytes.Length) { ParticleChunk chunk = ParticleFileHandler.ReadParticleChunk(sourceFileBytes, i); i += chunk.Buffer.Length; chunks.Add(chunk); } return(new AnalyzerFileResult(sourceFileName, (uint)sourceFileBytes.Length, ParticleFileHandler.HeaderSize, chunks)); } catch { return(null); } }
public void ReleaseParticleChunk(ParticleChunk chunk) { ReleaseChunk(chunk, deadParticleChunkList); }