private static bool LoadSoundInfo(ChunkReader chunkIO, Wad2 wad, Dictionary <long, WadSample> samples, out WadSoundInfo soundInfo, out long index) { var tempSoundInfo = new WadSoundInfo(0); long tempIndex = 0; float volume = 0; float chance = 0; float pitch = 0; float range = 0; chunkIO.ReadChunks((id2, chunkSize2) => { // XML_SOUND_SYSTEM if (id2 == Wad2Chunks.SoundInfoIndex) { tempIndex = chunkIO.ReadChunkLong(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoVolume) { volume = chunkIO.ReadChunkFloat(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoRange) { range = chunkIO.ReadChunkFloat(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoPitch) { pitch = chunkIO.ReadChunkFloat(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoChance) { chance = chunkIO.ReadChunkFloat(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoDisablePanning) { tempSoundInfo.DisablePanning = chunkIO.ReadChunkBool(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoRandomizePitch) { tempSoundInfo.RandomizePitch = chunkIO.ReadChunkBool(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoRandomizeVolume) { tempSoundInfo.RandomizeVolume = chunkIO.ReadChunkBool(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoLoopBehaviour) { tempSoundInfo.LoopBehaviour = (WadSoundLoopBehaviour)(3 & chunkIO.ReadChunkByte(chunkSize2)); } else if (id2 == Wad2Chunks.SoundInfoName || id2 == Wad2Chunks.SoundInfoNameObsolete) { tempSoundInfo.Name = chunkIO.ReadChunkString(chunkSize2); } else if (id2 == Wad2Chunks.SoundInfoSampleIndex) { tempSoundInfo.Samples.Add(samples[chunkIO.ReadChunkInt(chunkSize2)]); // Legacy } else { return(false); } return(true); }); // Convert from floats to ints tempSoundInfo.Volume = (int)Math.Round(volume * 100.0f); tempSoundInfo.RangeInSectors = (int)range; tempSoundInfo.Chance = (int)Math.Round(chance * 100.0f); tempSoundInfo.PitchFactor = (int)Math.Round((pitch - 1.0f) * 100.0f); // Try to get the old ID tempSoundInfo.Id = TrCatalog.TryGetSoundInfoIdByDescription(wad.GameVersion, tempSoundInfo.Name); if (string.IsNullOrWhiteSpace(tempSoundInfo.Name)) { tempSoundInfo.Name = TrCatalog.GetOriginalSoundName(wad.GameVersion, unchecked ((uint)tempIndex)); } index = tempIndex; soundInfo = tempSoundInfo; return(true); }
private static WadMesh LoadMesh(ChunkReader chunkIO, long chunkSize, Dictionary <long, WadTexture> textures) { var mesh = new WadMesh(); long obsoleteIndex = 0; chunkIO.ReadChunks((id2, chunkSize2) => { if (id2 == Wad2Chunks.MeshIndex) { obsoleteIndex = chunkIO.ReadChunkLong(chunkSize2); } else if (id2 == Wad2Chunks.MeshName) { mesh.Name = chunkIO.ReadChunkString(chunkSize2); } else if (id2 == Wad2Chunks.MeshSphere) { // Read bounding sphere float radius = 0; Vector3 center = Vector3.Zero; chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshSphereCenter) { center = chunkIO.ReadChunkVector3(chunkSize3); } else if (id3 == Wad2Chunks.MeshSphereRadius) { radius = chunkIO.ReadChunkFloat(chunkSize3); } else { return(false); } return(true); }); mesh.BoundingSphere = new BoundingSphere(center, radius); } else if (id2 == Wad2Chunks.MeshBoundingBox) { // Read bounding box Vector3 min = Vector3.Zero; Vector3 max = Vector3.Zero; chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshBoundingBoxMin) { min = chunkIO.ReadChunkVector3(chunkSize3); } else if (id3 == Wad2Chunks.MeshBoundingBoxMax) { max = chunkIO.ReadChunkVector3(chunkSize3); } else { return(false); } return(true); }); mesh.BoundingBox = new BoundingBox(min, max); } else if (id2 == Wad2Chunks.MeshVertexPositions) { chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshVertexPosition) { mesh.VerticesPositions.Add(chunkIO.ReadChunkVector3(chunkSize3)); } else { return(false); } return(true); }); } else if (id2 == Wad2Chunks.MeshVertexNormals) { chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshVertexNormal) { mesh.VerticesNormals.Add(chunkIO.ReadChunkVector3(chunkSize3)); } else { return(false); } return(true); }); } else if (id2 == Wad2Chunks.MeshVertexShades) { chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshVertexShade) { mesh.VerticesShades.Add(chunkIO.ReadChunkShort(chunkSize3)); } else { return(false); } return(true); }); } else if (id2 == Wad2Chunks.MeshPolygons) { chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshQuad || id3 == Wad2Chunks.MeshTriangle) { var polygon = new WadPolygon(); polygon.Shape = id3 == Wad2Chunks.MeshQuad ? WadPolygonShape.Quad : WadPolygonShape.Triangle; polygon.Index0 = LEB128.ReadInt(chunkIO.Raw); polygon.Index1 = LEB128.ReadInt(chunkIO.Raw); polygon.Index2 = LEB128.ReadInt(chunkIO.Raw); if (id3 == Wad2Chunks.MeshQuad) { polygon.Index3 = LEB128.ReadInt(chunkIO.Raw); } polygon.ShineStrength = LEB128.ReadByte(chunkIO.Raw); TextureArea textureArea = new TextureArea(); textureArea.Texture = textures[LEB128.ReadInt(chunkIO.Raw)]; textureArea.TexCoord0 = chunkIO.Raw.ReadVector2(); textureArea.TexCoord1 = chunkIO.Raw.ReadVector2(); textureArea.TexCoord2 = chunkIO.Raw.ReadVector2(); if (id3 == Wad2Chunks.MeshQuad) { textureArea.TexCoord3 = chunkIO.Raw.ReadVector2(); } else { textureArea.TexCoord3 = textureArea.TexCoord2; } textureArea.BlendMode = (BlendMode)LEB128.ReadLong(chunkIO.Raw); textureArea.DoubleSided = chunkIO.Raw.ReadBoolean(); polygon.Texture = textureArea; chunkIO.ReadChunks((id4, chunkSize4) => { return(false); }); mesh.Polys.Add(polygon); } else { return(false); } return(true); }); } else { return(false); } return(true); }); return(mesh); }
private static bool LoadStatics(ChunkReader chunkIO, ChunkId idOuter, Wad2 wad, /*Dictionary<long, WadMesh> meshes*/ Dictionary <long, WadTexture> textures) { if (idOuter != Wad2Chunks.Statics) { return(false); } chunkIO.ReadChunks((id, chunkSize) => { if (id != Wad2Chunks.Static) { return(false); } var s = new WadStatic(new WadStaticId(LEB128.ReadUInt(chunkIO.Raw))); //s.Mesh = meshes[LEB128.ReadInt(chunkIO.Raw)]; s.Flags = LEB128.ReadShort(chunkIO.Raw); s.LightingType = (WadMeshLightingType)LEB128.ReadShort(chunkIO.Raw); chunkIO.ReadChunks((id2, chunkSize2) => { if (id2 == Wad2Chunks.StaticVisibilityBox) { var min = Vector3.Zero; var max = Vector3.Zero; chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshBoundingBoxMin) { min = chunkIO.ReadChunkVector3(chunkSize3); } else if (id3 == Wad2Chunks.MeshBoundingBoxMax) { max = chunkIO.ReadChunkVector3(chunkSize3); } else { return(false); } return(true); }); s.VisibilityBox = new BoundingBox(min, max); } else if (id2 == Wad2Chunks.StaticCollisionBox) { var min = Vector3.Zero; var max = Vector3.Zero; chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.MeshBoundingBoxMin) { min = chunkIO.ReadChunkVector3(chunkSize3); } else if (id3 == Wad2Chunks.MeshBoundingBoxMax) { max = chunkIO.ReadChunkVector3(chunkSize3); } else { return(false); } return(true); }); s.CollisionBox = new BoundingBox(min, max); } else if (id2 == Wad2Chunks.Mesh) { s.Mesh = LoadMesh(chunkIO, chunkSize2, textures); } else if (id2 == Wad2Chunks.StaticAmbientLight) { s.AmbientLight = chunkIO.ReadChunkShort(chunkSize2); } else if (id2 == Wad2Chunks.StaticLight) { var light = new WadLight(); chunkIO.ReadChunks((id3, chunkSize3) => { if (id3 == Wad2Chunks.StaticLightPosition) { light.Position = chunkIO.ReadChunkVector3(chunkSize3); } else if (id3 == Wad2Chunks.StaticLightRadius) { light.Radius = chunkIO.ReadChunkFloat(chunkSize3); } else if (id3 == Wad2Chunks.StaticLightIntensity) { light.Intensity = chunkIO.ReadChunkFloat(chunkSize3); } else { return(false); } return(true); }); s.Lights.Add(light); } else { return(false); } return(true); }); wad.Statics.Add(s.Id, s); return(true); }); return(true); }