void calculateXTDMemory() { ECFReader ecfR = new ECFReader(); string XTDName = Path.ChangeExtension(gameDirectory + @"\scenario\" + scnName, ".XTD"); if (!ecfR.openForRead(XTDName)) { return; } for (uint i = 0; i < ecfR.getNumChunks(); i++) { ECF.BECFChunkHeader chunkHeader = ecfR.getChunkHeader(i); eXTD_ChunkID id = (eXTD_ChunkID)chunkHeader.mID; switch (id) { case eXTD_ChunkID.cXTD_XTDHeader: break; case eXTD_ChunkID.cXTD_AOChunk: mMemEst.setOrAddMemoryElement("Terrain AO", chunkHeader.mSize, ScnMemoryEstimate.eMainCatagory.eCat_Terrain); break; case eXTD_ChunkID.cXTD_AtlasChunk: mMemEst.setOrAddMemoryElement("Terrain Verts & Normals", chunkHeader.mSize, ScnMemoryEstimate.eMainCatagory.eCat_Terrain); break; case eXTD_ChunkID.cXTD_TessChunk: mMemEst.setOrAddMemoryElement("Terrain Tessellation", chunkHeader.mSize, ScnMemoryEstimate.eMainCatagory.eCat_Terrain); break; case eXTD_ChunkID.cXTD_LightingChunk: mMemEst.setOrAddMemoryElement("Terrain Lighting", chunkHeader.mSize, ScnMemoryEstimate.eMainCatagory.eCat_Terrain); break; case eXTD_ChunkID.cXTD_AlphaChunk: mMemEst.setOrAddMemoryElement("Terrain Alpha", chunkHeader.mSize, ScnMemoryEstimate.eMainCatagory.eCat_Terrain); break; } } ecfR.close(); ecfR = null; }
public void buildAOFiles(string inputFilename, int numSections) { float [] AOVals = null; for (int i = 0; i < numSections; i++) { //work\scenario\development\coltTest\coltTest.AO0, .AO1, .AO2...., .AON string outFileName = Path.ChangeExtension(inputFilename, ".AO" + i); FileStream sr = File.Open(outFileName, FileMode.Open, FileAccess.Read); BinaryReader fr = new BinaryReader(sr); int majik = fr.ReadInt32(); if (majik != cMajik) { AOVals = null; sr.Close(); sr = null; fr.Close(); fr = null; return; } int numSectionsT = fr.ReadInt32(); Debug.Assert(numSectionsT == numSections); int mySecetion = fr.ReadInt32(); int numSamples = fr.ReadInt32(); int startSampleCount = fr.ReadInt32(); int endSampleCount = fr.ReadInt32(); int width = fr.ReadInt32(); int height = fr.ReadInt32(); if (AOVals == null) { AOVals = new float[width * height]; } for (int x = 0; x < width * height; x++) { AOVals[x] += fr.ReadSingle(); Debug.Assert(AOVals[x] > 1); } sr.Close(); sr = null; fr.Close(); fr = null; } //now that we have our AO data read from file and accumulated, open our XTD and write over the previous AO Values. //first we have to get the file pointer offset from reading the file... int AOOffset = 0; int AOHeaderAdlerOffset = 0; ECFReader ecfR = new ECFReader(); string XTDName = Path.ChangeExtension(inputFilename, ".XTD"); if (!ecfR.openForRead(XTDName)) { return; } int numXVerts = 0; for (uint i = 0; i < ecfR.getNumChunks(); i++) { ECF.BECFChunkHeader chunkHeader = ecfR.getChunkHeader(i); eXTD_ChunkID id = (eXTD_ChunkID)chunkHeader.mID; switch (id) { case eXTD_ChunkID.cXTD_XTDHeader: int version = Xbox_EndianSwap.endSwapI32(ecfR.readInt32()); numXVerts = Xbox_EndianSwap.endSwapI32(ecfR.readInt32()); break; case eXTD_ChunkID.cXTD_AOChunk: AOHeaderAdlerOffset = (int)(i * ECF.BECFChunkHeader.giveSize() + ECF.ECFHeader.giveSize()); AOHeaderAdlerOffset += sizeof(Int64) * 2; AOOffset = chunkHeader.mOfs; break; } } ecfR.close(); ecfR = null; //now that we have our offset into the file, open it for write //generate our data byte[] data = XTDExporter.packAOToDXT5A(AOVals, numXVerts); FileStream s = File.Open(XTDName, FileMode.Open, FileAccess.ReadWrite); BinaryWriter f = new BinaryWriter(s); //reset the ADLER32 for this chunk.. f.Seek(AOHeaderAdlerOffset, SeekOrigin.Begin); uint adler32 = (uint)Xbox_EndianSwap.endSwapI32((int)ECF.calcAdler32(data, 0, (uint)data.Length)); f.Write(adler32); f.Seek(AOOffset, SeekOrigin.Begin); for (int i = 0; i < data.Length; i++) { f.Write(data[i]); } data = null; f.Close(); f = null; s.Close(); s = null; //DONE! }