Esempio n. 1
0
        private int writeBuildable()
        {
            ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder();
            chunkHolder.mDataMemStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream);


            BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep();

            // Write buildable
            bool[] landBuildable = simRep.getDataTiles().getSimLandBuildable();
            int    numTiles      = simRep.getNumXTiles();

            byte tru = 0xFF;
            byte fal = 0x00;

            for (int x = 0; x < numTiles; x++)
            {
                for (int z = 0; z < numTiles; z++)
                {
                    int index = (x * numTiles + z);

                    if (landBuildable[index])
                    {
                        binWriter.Write(tru);
                    }
                    else
                    {
                        binWriter.Write(fal);
                    }
                }
            }



            ExportTo360.mECF.addChunk((int)eXSD_ChunkID.cXSD_Buildable, chunkHolder, binWriter.BaseStream.Length);
            binWriter.Close();
            binWriter = null;
            chunkHolder.Close();
            chunkHolder = null;

            return(landBuildable.Length * sizeof(byte));
        }
Esempio n. 2
0
        void heightFieldAlphaToChunk(ref ExportResults results)
        {
            //i think for visual reasons, the resolution of this alpha data needs to match
            //the density of the terrain alpha..

            BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep();

            int width  = TerrainGlobals.getTerrain().getNumXVerts();
            int height = TerrainGlobals.getTerrain().getNumXVerts();

            if (width < 256 || height < 256)
            {
                return; //don't write for small maps..
            }
            byte[] AlphaVals = TerrainGlobals.getEditor().getAlphaValues();

            DXT3_1111 img = new DXT3_1111(width, height);


            //walk through all the terrain alpha values,
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int  index   = x * width + y;
                    bool visible = AlphaVals[index] > 0;// if it's invisible, so are we.

                    //walk through the sim rep. If it's passable, we're visible.
                    float normalizedX   = x / (float)width;
                    float normalizedZ   = y / (float)height;
                    bool  obstructsLand = simRep.getDataTiles().isLandObstructedComposite(normalizedX, normalizedZ);
                    visible |= !obstructsLand;


                    img.setValue(x, y, visible);
                }
            }


            ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder();
            chunkHolder.mDataMemStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream);

            int packedWidth = width >> 2;

            binWriter.Write(Xbox_EndianSwap.endSwapI32(packedWidth));
            binWriter.Write(Xbox_EndianSwap.endSwapI32(height));

            int numBlocks = img.getNumBlocks();

            //numXBlocks-1 + numXBlocks * numYBlocks
            int texelMemSize = numBlocks * sizeof(Int64);// (((width >> 4) - 1) + (width >> 4) * ((height >> 2) - 1)) * sizeof(Int64);

            binWriter.Write(Xbox_EndianSwap.endSwapI32(texelMemSize));


            for (int i = 0; i < numBlocks; i++)
            {
                binWriter.Write(img.getBlock(i));
            }

            ExportTo360.mECF.addChunk((int)eXTH_ChunkID.cXTH_TerrainHeightfieldAlpha, chunkHolder, binWriter.BaseStream.Length);
            binWriter.Close();
            binWriter = null;
            chunkHolder.Close();
            chunkHolder = null;

            results.terrainGPUHeighfieldMemory += texelMemSize;

            img = null;
        }
Esempio n. 3
0
        private int writeObstructions()
        {
            ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder();
            chunkHolder.mDataMemStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream);


            BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep();

            // Write obstructions
            bool[] landObstructions     = simRep.getDataTiles().getSimLandObstructions();
            int    numTiles             = simRep.getNumXTiles();
            int    obstructionArraySize = numTiles * numTiles;

            byte[] obstructionsFlags = new byte[obstructionArraySize];

            bool[] alreadyDone = new bool[numTiles * numTiles];
            for (int i = 0; i < numTiles * numTiles; i++)
            {
                alreadyDone[i] = false;
            }

            for (int x = 0; x < numTiles; x++)
            {
                for (int z = 0; z < numTiles; z++)
                {
                    int index = (x * numTiles + z);


                    bool obstructsLand   = simRep.getDataTiles().isLandObstructedComposite(x, z);
                    bool obstructsFlood  = simRep.getDataTiles().isFloodObstructed(x, z);
                    bool obstructsScarab = simRep.getDataTiles().isScarabObstructed(x, z);


                    obstructionsFlags[index] = 0;

                    if (obstructsLand && obstructsFlood && obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Flood_Scarab;
                    }
                    else if (obstructsLand && obstructsFlood && !obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Flood;
                    }
                    else if (obstructsLand && !obstructsFlood && obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Scarab;
                    }
                    else if (obstructsLand && !obstructsFlood && !obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land;
                    }
                    else if (!obstructsLand && obstructsFlood && obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Flood_Scarab;
                    }
                    else if (!obstructsLand && obstructsFlood && !obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Flood;
                    }
                    else if (!obstructsLand && !obstructsFlood && obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Scarab;
                    }
                    else if (!obstructsLand && !obstructsFlood && !obstructsScarab)
                    {
                        obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cNoObstruction;
                    }
                }
            }

            binWriter.Write(obstructionsFlags);

            ExportTo360.mECF.addChunk((int)eXSD_ChunkID.cXSD_Obstructions, chunkHolder, binWriter.BaseStream.Length);
            binWriter.Close();
            binWriter = null;
            chunkHolder.Close();
            chunkHolder = null;

            return(obstructionsFlags.Length);
        }