コード例 #1
0
ファイル: mapCreator.cs プロジェクト: eclipseanu/UnityDoom
    void UpdateSectorBounds(SECTORS sector, LINEDEFS line)
    {
        if (sector == null)
        {
            return;
        }
        int[] floorBounds = LineDefTypes.types[line.types].GetFloorMovementBound(reader.newWad, sector);
        sector.floorBounds[0] = Math.Min(sector.floorBounds[0], floorBounds[0]);
        sector.floorBounds[1] = Math.Max(sector.floorBounds[1], floorBounds[1]);

        int[] ceilingBounds = LineDefTypes.types[line.types].GetCeilingMovementBound(reader.newWad, sector);
        sector.ceilingBounds[0] = Math.Min(sector.ceilingBounds[0], ceilingBounds[0]);
        sector.ceilingBounds[1] = Math.Max(sector.ceilingBounds[1], ceilingBounds[1]);
    }
コード例 #2
0
        public static List <SubMesh> CreateUpperWalls(SECTORS sector, LINEDEFS line, WAD wad)            // uppertex
        {
            List <SubMesh> walls = new List <SubMesh>();

            SECTORS otherSector = (sector == line.getFrontSector()) ? line.getBackSector() : line.getFrontSector();

            // figure out how much extra height we have to add to a moving ceiling
            float[] addMovementHeight = new float[2];
            addMovementHeight[0] = Math.Min(Math.Min(sector.ceilingHeight, otherSector.ceilingHeight), sector.ceilingBounds[0]);
            addMovementHeight[1] = Math.Max(Math.Max(sector.ceilingHeight, otherSector.ceilingHeight), sector.ceilingBounds[1]);

            // figure out start and end heights
            float startHeight = sector.ceilingHeight;
            float endHeight   = Math.Max(otherSector.ceilingHeight, sector.ceilingHeight + (addMovementHeight[1] - addMovementHeight[0]));

            // this is an ugly hack in order to get DOOM2 MAP31 to have correct doors:
            bool backSectorDoor = line.getBackSector() != null && line.getBackSector().isMovingCeiling;

            // generate a wall for each textured side
            if (line.getBackSector() == sector && line.side1 != null && wad.textures.ContainsKey(line.side1.upTex))
            {
                walls.Add(CreateWall(line.getFrontSector(), line, wad.textures[line.side1.upTex], startHeight, endHeight, false, WallType.Upper));
            }

            if (line.getFrontSector() == sector && line.side2 != null && wad.textures.ContainsKey(line.side2.upTex) && !backSectorDoor)
            {
                walls.Add(CreateWall(line.getBackSector(), line, wad.textures[line.side2.upTex], startHeight, endHeight, true, WallType.Upper));
            }

            // generate skybox hole textures
            if (line.getFrontSector() == sector && line.side1 != null && !wad.textures.ContainsKey(line.side1.upTex))
            {
                if (line.getFrontSector().ceilingFlat.StartsWith("F_SKY") && line.getBackSector().ceilingFlat.StartsWith("F_SKY"))
                {
                    Material texture = wad.flats[sector.ceilingFlat];
                    walls.Add(CreateWall(line.getFrontSector(), line, texture, startHeight, endHeight, false, WallType.Upper));
                }
            }

            return(walls);
        }
コード例 #3
0
        public static List <SubMesh> CreateLowerWalls(SECTORS sector, LINEDEFS line, WAD wad)            // lowtex
        {
            List <SubMesh> walls = new List <SubMesh>();

            // figure out start and end heights
            SECTORS otherSector = (sector == line.getFrontSector()) ? line.getBackSector() : line.getFrontSector();
            float   startHeight = Math.Min(sector.floorHeight + sector.floorBounds[0] - sector.floorBounds[1], otherSector.floorHeight + otherSector.floorBounds[0] - otherSector.floorBounds[1]);
            float   endHeight   = sector.floorHeight;

            // generate a wall for each textured side
            if (line.getBackSector() == sector && line.side1 != null && wad.textures.ContainsKey(line.side1.lowTex))
            {
                walls.Add(CreateWall(line.getFrontSector(), line, wad.textures[line.side1.lowTex], startHeight, endHeight, false, WallType.Lower));
            }

            if (line.getFrontSector() == sector && line.side2 != null && wad.textures.ContainsKey(line.side2.lowTex))
            {
                walls.Add(CreateWall(line.getBackSector(), line, wad.textures[line.side2.lowTex], startHeight, endHeight, true, WallType.Lower));
            }

            return(walls);
        }
コード例 #4
0
        public static List <SubMesh> CreateMidWalls(SECTORS sector, LINEDEFS line, WAD wad)            // midtex
        {
            float startHeight = 0;
            float endHeight   = 0;

            // figure out start and end heights
            if (line.getFrontSector() != null && line.getBackSector() != null)
            {
                startHeight = Math.Max(line.getFrontSector().floorHeight, line.getBackSector().floorHeight);
                endHeight   = Math.Min(line.getFrontSector().ceilingHeight, line.getBackSector().ceilingHeight);
            }
            else if (line.getFrontSector() != null && line.getBackSector() == null)
            {
                SECTORS fSector = line.getFrontSector();
                startHeight = fSector.floorHeight;
                endHeight   = fSector.ceilingHeight;

                if (fSector.isMovingCeiling)
                {
                    endHeight = fSector.ceilingBounds[1];
                }

                if (fSector.isMovingFloor)
                {
                    startHeight = Math.Min(startHeight, fSector.floorBounds[0]);
                    endHeight   = Math.Max(endHeight, fSector.floorBounds[1]);
                }
            }
            else if (line.getFrontSector() == null && line.getBackSector() != null)
            {
                startHeight = line.getBackSector().floorHeight;
                endHeight   = line.getBackSector().ceilingHeight;
            }

            // generate a wall for each textured side
            List <SubMesh> walls = new List <SubMesh>();

            if (line.getFrontSector() == sector && line.side1 != null && wad.textures.ContainsKey(line.side1.midTex))
            {
                Material texture = wad.textures[line.side1.midTex];

                if (line.getFrontSector() != null && line.getBackSector() != null)
                {
                    endHeight = Math.Min(startHeight + texture.mainTexture.height, endHeight);  //dont tile middle textures with 2 sides
                }
                walls.Add(CreateWall(line.getFrontSector(), line, texture, startHeight, endHeight, false, WallType.Middle));
            }

            if (line.getBackSector() == sector && line.side2 != null && wad.textures.ContainsKey(line.side2.midTex))
            {
                Material texture = wad.textures[line.side2.midTex];

                if (line.getFrontSector() != null && line.getBackSector() != null)
                {
                    endHeight = Math.Min(startHeight + texture.mainTexture.height, endHeight);  //dont tile middle textures with 2 sides
                }
                walls.Add(CreateWall(line.getBackSector(), line, texture, startHeight, endHeight, true, WallType.Middle));
            }

            // generate skybox hole textures
            if (line.getFrontSector() == sector && line.side1 != null && !wad.textures.ContainsKey(line.side1.midTex) && sector.ceilingFlat.StartsWith("F_SKY"))
            {
                SECTORS bSector = line.getBackSector();
                if (bSector == null || (bSector.floorHeight == bSector.ceilingHeight && !bSector.isMovingCeiling && !bSector.isMovingFloor))
                {
                    Material texture = wad.flats[sector.ceilingFlat];
                    startHeight = line.getFrontSector().floorHeight;
                    endHeight   = line.getFrontSector().ceilingHeight;
                    walls.Add(CreateWall(line.getFrontSector(), line, texture, startHeight, endHeight, false, WallType.Middle));
                }
            }

            return(walls);
        }
コード例 #5
0
        public static SubMesh CreateWall(SECTORS sector, LINEDEFS line, Material texture, float startHeight, float endHeight, bool flipped, WallType wallType)
        {
            List <Vector3> tmpVerts = new List <Vector3>();
            List <Vector2> tmpUv    = new List <Vector2>();

            SubMesh sMesh = new SubMesh();

            sMesh.mesh = new Mesh();

            sMesh.mesh.vertices = new Vector3[4];
            sMesh.mesh.uv       = new Vector2[4];

            // create the vertices
            tmpVerts.Add(new Vector3(line.firstVert.x, startHeight, line.firstVert.z));
            tmpVerts.Add(new Vector3(line.firstVert.x, endHeight, line.firstVert.z));
            tmpVerts.Add(new Vector3(line.lastVert.x, endHeight, line.lastVert.z));
            tmpVerts.Add(new Vector3(line.lastVert.x, startHeight, line.lastVert.z));

            // remember things for uv generation
            SIDEDEFS side          = flipped ? line.side2 : line.side1;
            float    xOffset       = side.xOfs;
            float    yOffset       = side.yOfs;
            float    textureWidth  = texture.mainTexture.width;
            float    textureHeight = texture.mainTexture.height;
            float    wallHeight    = endHeight - startHeight;
            float    wallWidth     = line.getLength();

            // check upper and lower unpegged flags
            bool lowerUnpegged = (wallType == WallType.Upper) ? ((line.flags & 0x0008) == 0) : ((line.flags & 0x0010) != 0);

            // generate UVs
            if (lowerUnpegged)
            {
                if (wallType == WallType.Lower)
                {
                    float sectorHeight = sector.ceilingHeight - sector.floorHeight;
                    tmpUv.Add(new Vector2(xOffset / textureWidth, (sectorHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2(xOffset / textureWidth, (sectorHeight - wallHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (sectorHeight - wallHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (sectorHeight + yOffset) / textureHeight));
                }
                else
                {
                    tmpUv.Add(new Vector2(xOffset / textureWidth, (textureHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2(xOffset / textureWidth, (textureHeight - wallHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (textureHeight - wallHeight + yOffset) / textureHeight));
                    tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (textureHeight + yOffset) / textureHeight));
                }
            }
            else
            {
                tmpUv.Add(new Vector2(xOffset / textureWidth, (wallHeight + yOffset) / textureHeight));
                tmpUv.Add(new Vector2(xOffset / textureWidth, yOffset / textureHeight));
                tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, yOffset / textureHeight));
                tmpUv.Add(new Vector2((wallWidth + xOffset) / textureWidth, (wallHeight + yOffset) / textureHeight));
            }

            // set mesh data
            sMesh.mesh.uv       = tmpUv.ToArray();
            sMesh.mesh.vertices = tmpVerts.ToArray();
            sMesh.material      = texture;

            if (flipped)
            {
                sMesh.mesh.triangles = new int[6] {
                    2, 1, 0, 0, 3, 2
                };
                sMesh.mesh.normals = new Vector3[4] {
                    -line.frontVector(), -line.frontVector(), -line.frontVector(), -line.frontVector()
                };
            }
            else
            {
                sMesh.mesh.triangles = new int[6] {
                    0, 1, 2, 2, 3, 0
                };
                sMesh.mesh.normals = new Vector3[4] {
                    line.frontVector(), line.frontVector(), line.frontVector(), line.frontVector()
                };
            }

            return(sMesh);
        }
コード例 #6
0
    void ReadMAPEntries()
    {
        for (int i = 0; i < newWad.directory.Count - 1; i++)
        {
            if (newWad.directory[i + 1].name.Contains("THINGS") && newWad.directory[i].size == 0)
            {
                DoomMap   newMap   = new DoomMap();
                DrctEntry dirEntry = newWad.directory[i];


                newMap.name = dirEntry.name;

                //THINGS lump

                if (newWad.directory[i + 1].name.Contains("THINGS"))
                {
                    byte[] thingBytes = new byte[newWad.directory[i + 1].size];

                    wadOpener.Position = newWad.directory[i + 1].filepos;
                    wadOpener.Read(thingBytes, 0, thingBytes.Length);

                    for (int j = 0; j < newWad.directory[i + 1].size; j += 10)
                    {
                        THINGS newThing = new THINGS();

                        newThing.xPos         = BitConverter.ToInt16(thingBytes, j + 0);
                        newThing.yPos         = BitConverter.ToInt16(thingBytes, j + 2);
                        newThing.angle        = BitConverter.ToInt16(thingBytes, j + 4);
                        newThing.thingType    = BitConverter.ToInt16(thingBytes, j + 6);
                        newThing.thingOptions = BitConverter.ToInt16(thingBytes, j + 8);

                        newMap.things.Add(newThing);
                    }
                }

                //LINEDEEFS lump

                if (newWad.directory[i + 2].name.Contains("LINEDEFS"))
                {
                    byte[] lineDefBytes = new byte[newWad.directory[i + 2].size];

                    wadOpener.Position = newWad.directory[i + 2].filepos;
                    wadOpener.Read(lineDefBytes, 0, lineDefBytes.Length);
                    for (int j = 0; j < newWad.directory[i + 2].size; j += 14)
                    {
                        LINEDEFS newLineDef = new LINEDEFS();

                        newLineDef.firstVertIndex = BitConverter.ToInt16(lineDefBytes, j + 0);
                        newLineDef.lastVertIndex  = BitConverter.ToInt16(lineDefBytes, j + 2);
                        newLineDef.flags          = BitConverter.ToInt16(lineDefBytes, j + 4);
                        newLineDef.types          = BitConverter.ToInt16(lineDefBytes, j + 6);
                        newLineDef.tag            = BitConverter.ToInt16(lineDefBytes, j + 8);
                        newLineDef.side1Index     = BitConverter.ToInt16(lineDefBytes, j + 10);
                        newLineDef.side2Index     = BitConverter.ToInt16(lineDefBytes, j + 12);

                        newMap.linedefs.Add(newLineDef);
                    }
                }

                //SIDEDEFS lump

                if (newWad.directory[i + 3].name.Contains("SIDEDEFS"))
                {
                    byte[] sideDefBytes = new byte[newWad.directory[i + 3].size];

                    wadOpener.Position = newWad.directory[i + 3].filepos;
                    wadOpener.Read(sideDefBytes, 0, sideDefBytes.Length);

                    for (int j = 0; j < newWad.directory[i + 3].size; j += 30)
                    {
                        SIDEDEFS newSideDef = new SIDEDEFS();

                        newSideDef.xOfs   = BitConverter.ToInt16(sideDefBytes, j + 0);
                        newSideDef.yOfs   = BitConverter.ToInt16(sideDefBytes, j + 2);
                        newSideDef.upTex  = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 4, 8)).ToUpper();
                        newSideDef.lowTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 12, 8)).ToUpper();
                        newSideDef.midTex = new String(System.Text.Encoding.ASCII.GetChars(sideDefBytes, j + 20, 8)).ToUpper();
                        newSideDef.secNum = BitConverter.ToInt16(sideDefBytes, j + 28);

                        newSideDef.upTex  = newSideDef.upTex.Replace("\0", "");
                        newSideDef.lowTex = newSideDef.lowTex.Replace("\0", "");
                        newSideDef.midTex = newSideDef.midTex.Replace("\0", "");

                        newMap.sidedefs.Add(newSideDef);
                    }
                }

                //VERTEXES lump

                if (newWad.directory[i + 4].name.Contains("VERTEXES"))
                {
                    byte[] vertexBytes = new byte[newWad.directory[i + 4].size];

                    wadOpener.Position = newWad.directory[i + 4].filepos;
                    wadOpener.Read(vertexBytes, 0, vertexBytes.Length);

                    for (int j = 0; j < newWad.directory[i + 4].size; j += 4)
                    {
                        Vector3 newVertex = new Vector3(0, 0, 0);

                        newVertex.x = BitConverter.ToInt16(vertexBytes, j + 0);
                        newVertex.z = BitConverter.ToInt16(vertexBytes, j + 2);

                        newMap.vertexes.Add(newVertex);
                    }
                }

                //SECTORS lump

                if (newWad.directory[i + 8].name.Contains("SECTORS"))
                {
                    byte[] secBytes = new byte[newWad.directory[i + 8].size];

                    wadOpener.Position = newWad.directory[i + 8].filepos;
                    wadOpener.Read(secBytes, 0, secBytes.Length);

                    for (int j = 0; j < newWad.directory[i + 8].size; j += 26)
                    {
                        SECTORS newSec = new SECTORS();

                        newSec.floorHeight   = BitConverter.ToInt16(secBytes, j + 0);
                        newSec.ceilingHeight = BitConverter.ToInt16(secBytes, j + 2);
                        newSec.floorFlat     = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 4, 8));
                        newSec.ceilingFlat   = new String(System.Text.Encoding.ASCII.GetChars(secBytes, j + 12, 8));
                        newSec.lightLevel    = BitConverter.ToInt16(secBytes, j + 20);
                        newSec.specialSec    = BitConverter.ToInt16(secBytes, j + 22);
                        newSec.sectorTag     = BitConverter.ToInt16(secBytes, j + 24);

                        newSec.floorFlat   = newSec.floorFlat.Replace("\0", "");
                        newSec.ceilingFlat = newSec.ceilingFlat.Replace("\0", "");

                        newMap.sectors.Add(newSec);
                    }
                }

                //BLOCKMAPS lump

                if (newWad.directory[i + 10].name.Contains("BLOCKMAP"))
                {
                    byte[] blockBytes = new byte[newWad.directory[i + 10].size];

                    wadOpener.Position = newWad.directory[i + 10].filepos;
                    wadOpener.Read(blockBytes, 0, blockBytes.Length);

                    BLOCKMAP newBlockmap = new BLOCKMAP();

                    newBlockmap.xcoord     = BitConverter.ToInt16(blockBytes, 0);
                    newBlockmap.ycoord     = BitConverter.ToInt16(blockBytes, 2);
                    newBlockmap.numColumns = BitConverter.ToInt16(blockBytes, 4);
                    newBlockmap.numRows    = BitConverter.ToInt16(blockBytes, 6);

                    int N = newBlockmap.numColumns * newBlockmap.numRows;
                    //Offsets
                    for (int j = 8; j < (8 + (2 * (N - 1))); j += 2)                       // (8 + (2 * (N - 1))) IS DEFINITELY RIGHT
                    {
                        newBlockmap.Offsets.Add(BitConverter.ToUInt16(blockBytes, j) * 2); //multiply this times 2 so its right
                    }

                    foreach (int offset in newBlockmap.Offsets)
                    {
                        int line        = 0;
                        int blockOffset = offset;
                        // List<int> newBlock = new List<int>();
                        Block blk = new Block();
                        do
                        {
                            line = BitConverter.ToUInt16(blockBytes, blockOffset + 2);
                            //newBlock.Add(line);

                            if (line == 0xFFFF)
                            {
                                continue;
                            }

                            blk.lines.Add(newMap.linedefs[line]);

                            blockOffset += 2;
                        } while (line != 0xFFFF);

                        newBlockmap.blocks.Add(blk);
                    }

                    newMap.blockmap = newBlockmap;
                }

                newWad.maps.Add(newMap);     //Store the map in newWad
            }
        }
    }