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! }
static public bool doExport(String terrainFileName, String scenarioFileName, String outputOverrideDir, ref ExportSettings expSettings, ref ExportResults results, bool doXTD, bool doXTT, bool doXTH, bool doXSD, bool doLRP, bool doDEP, bool doTAG, bool doXMB) { //This is now done outside using work topics //if (CoreGlobals.UsingPerforce == true) //{ // if (!checkPerforceFileAlloances(terrainFileName, scenarioFileName, // doXTD, doXTT, doXTH, doXSD, doLRP, doDEP, doTAG, doXMB)) // return false; //} init(); int maxValues = (doXTD?1:0) + (doXTT?1:0) + (doXTH?1:0) + (doXSD?1:0) + (doLRP?1:0) + (doDEP?1:0) + (doTAG?1:0) + (doXMB?1:0) + (expSettings.AmbientOcclusion != AmbientOcclusion.eAOQuality.cAO_Off?1:0) ; initOverrideDir(outputOverrideDir); mEPB.Init(maxValues); mEPB.setName(Path.GetFileNameWithoutExtension(terrainFileName)); mEPB.Show(); DateTime start = DateTime.Now; GC.Collect(); GC.WaitForPendingFinalizers(); mECF.clear(); mDEP.clear(); bool sofarSoGood = true; if (sofarSoGood && doXTT) { XTTExporter XTTexporter = new XTTExporter(); sofarSoGood &= XTTexporter.export_XTT(terrainFileName, expSettings, ref results); XTTexporter.destroy(); XTTexporter = null; ExportTo360.mECF.clear(); ExportProgressDialog.Increase(); } //From here on out we don't need textures in memory.. if (sofarSoGood && (expSettings.AmbientOcclusion != AmbientOcclusion.eAOQuality.cAO_Off || doXTH)) { BRenderDevice.getTextureManager().freeAllD3DTextureHandles(); } if (sofarSoGood && doXTD) { XTDExporter XTDexporter = new XTDExporter(); sofarSoGood &= XTDexporter.export_XTD(terrainFileName, expSettings, ref results); XTDexporter.destroy(); XTDexporter = null; ExportTo360.mECF.clear(); ExportProgressDialog.Increase(); } if (sofarSoGood && doXSD) { XSDExporter XSDexporter = new XSDExporter(); sofarSoGood &= XSDexporter.export_XSD(scenarioFileName, expSettings, ref results); XSDexporter.destroy(); if (sofarSoGood && doLRP) { sofarSoGood &= XSDexporter.CreateLRP(spliceFilenameWithOverride(scenarioFileName)); } XSDexporter = null; ExportTo360.mECF.clear(); ExportProgressDialog.Increase(); } if (sofarSoGood && doXTH) { XTHExporter XTHexporter = new XTHExporter(); sofarSoGood &= XTHexporter.export_XTH(terrainFileName, expSettings, ref results); XTHexporter.destroy(); XTHexporter = null; ExportTo360.mECF.clear(); ExportProgressDialog.Increase(); } // OVERRIDE! if ANY terrain files are changed, then generate a .TAG if (sofarSoGood && doTAG && (doXTT | doXTD | doXTH | doXSD)) { TAG mTAG = new TAG(); String[] extentions = new String[] { ".XTD", ".XTT", ".XTH", ".XSD", ".LRP" }; String desiredFilename = ""; for (int i = 0; i < extentions.Length - 1; i++) { desiredFilename = spliceFilenameWithOverride(Path.ChangeExtension(terrainFileName, extentions[i])); mTAG.addFile(desiredFilename); } //XSD desiredFilename = spliceFilenameWithOverride(Path.ChangeExtension(scenarioFileName, extentions[extentions.Length - 2])); mTAG.addFile(desiredFilename); desiredFilename = spliceFilenameWithOverride(Path.ChangeExtension(scenarioFileName, extentions[extentions.Length - 1])); mTAG.addFile(desiredFilename); mTAG.writeToFile(spliceFilenameWithOverride(Path.ChangeExtension(scenarioFileName, ".TAG"))); mTAG = null; ExportProgressDialog.Increase(); } if (sofarSoGood && doXTT && doDEP) //CLM XTT is the only one that marks dependents currently... { mDEP.writeToFile(spliceFilenameWithOverride(terrainFileName)); } if (sofarSoGood && doXMB) { string outputDir = null; if (mOutputOverrideDir != null) { outputDir = spliceFilenameWithOverride(terrainFileName); outputDir = Path.GetDirectoryName(outputDir); } if (File.Exists(Path.ChangeExtension(scenarioFileName, ".SCN"))) { XMBProcessor.CreateXMB(Path.ChangeExtension(scenarioFileName, ".SCN"), outputDir, false); } if (File.Exists(Path.ChangeExtension(scenarioFileName, ".GLS"))) { XMBProcessor.CreateXMB(Path.ChangeExtension(scenarioFileName, ".GLS"), outputDir, false); } if (File.Exists(Path.ChangeExtension(scenarioFileName, ".DEP"))) { XMBProcessor.CreateXMB(spliceFilenameWithOverride(Path.ChangeExtension(scenarioFileName, ".DEP")), false); } ExportProgressDialog.Increase(); } TimeSpan ts = DateTime.Now - start; results.totalTime = ts.TotalMinutes; destroy(); GC.Collect(); GC.WaitForPendingFinalizers(); //if we've cleared the textures, force them to reload.. if (expSettings.AmbientOcclusion != AmbientOcclusion.eAOQuality.cAO_Off || doXTH) { BRenderDevice.getTextureManager().reloadTexturesIfNeeded(true); } mOutputOverrideDir = null; return(sofarSoGood); }