예제 #1
0
        private BspMipTexture[] ReadMipTextures(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_TEXTURES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            int numberOfTextures = reader.ReadInt32();

            int[] mipTexturesOffset = new int[numberOfTextures];

            for (int i = 0; i < numberOfTextures; i++)
            {
                mipTexturesOffset[i] = (entitiesLump.Offset + reader.ReadInt32());
            }

            var mipTextures = new List <BspMipTexture>();

            for (int i = 0; i < numberOfTextures; i++)
            {
                int textureOffset = mipTexturesOffset[i];
                reader.BaseStream.Seek(textureOffset, SeekOrigin.Begin);

                mipTextures.Add(new BspMipTexture {
                    Name = reader.ReadString(16), Width = reader.ReadUInt32(), Height = reader.ReadUInt32(), Offsets = reader.ReadUInt32Array(4)
                });
            }

            return(mipTextures.ToArray());
        }
예제 #2
0
        private byte[] ReadVisData(BinaryReader reader, int length)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_VISIBILITY];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            byte[] vis = reader.ReadBytes(length);

            return(vis);
        }
예제 #3
0
        private BspVisData ReadVisData(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_VISIBILITY];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            byte[] vis = reader.ReadBytes(entitiesLump.Length);

            return(new BspVisData {
                CompressedVis = vis
            });
        }
예제 #4
0
        private Entities ReadEntities(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_ENTITIES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            var    bytes       = reader.ReadBytes(entitiesLump.Length);
            string rawEntities = Encoding.ASCII.GetString(bytes);

            var parser   = new EntityParser(bytes);
            var entities = parser.Parse();

            return(entities);
        }
예제 #5
0
        private short[] ReadMarkSurfaces(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_MARKSURFACES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numMarkSurfaces = entitiesLump.Length / 2;

            var markSurfaces = new List <short>();

            for (int i = 0; i < numMarkSurfaces; i++)
            {
                markSurfaces.Add(reader.ReadInt16());
            }

            return(markSurfaces.ToArray());
        }
예제 #6
0
        private int[] ReadSurfEdges(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_SURFEDGES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numSurfedges = entitiesLump.Length / 4;

            var surfedges = new List <int>();

            for (int i = 0; i < numSurfedges; i++)
            {
                surfedges.Add(reader.ReadInt32());
            }

            return(surfedges.ToArray());
        }
예제 #7
0
        private BspPlane[] ReadPlanes(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_PLANES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numPlanes = entitiesLump.Length / BspPlane.SizeInBytes;

            var planes = new List <BspPlane>();

            for (int i = 0; i < numPlanes; i++)
            {
                planes.Add(new BspPlane {
                    Normal = reader.ReadSingleArray(), Distance = reader.ReadSingle(), Type = reader.ReadInt32()
                });
            }

            return(planes.ToArray());
        }
예제 #8
0
        private BspFace[] ReadFaces(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_FACES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numFaces = entitiesLump.Length / BspFace.SizeInBytes;

            var faces = new List <BspFace>();

            for (int i = 0; i < numFaces; i++)
            {
                faces.Add(new BspFace {
                    PlaneId = reader.ReadInt16(), PlaneSide = reader.ReadInt16(), FirstEdge = reader.ReadInt32(), NumEdges = reader.ReadInt16(), TextureInfo = reader.ReadInt16(), Styles = reader.ReadBytes(4), LightmapOffset = reader.ReadInt32()
                });
            }

            return(faces.ToArray());
        }
예제 #9
0
        private BspVertex[] ReadVertices(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_VERTEXES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numVertices = entitiesLump.Length / BspVertex.SizeInBytes;

            var vertices = new List <BspVertex>();

            for (int i = 0; i < numVertices; i++)
            {
                vertices.Add(new BspVertex {
                    Point = reader.ReadSingleArray()
                });
            }

            return(vertices.ToArray());
        }
예제 #10
0
        private BspEdge[] ReadEdges(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_EDGES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numEdges = entitiesLump.Length / BspEdge.SizeInBytes;

            var edges = new List <BspEdge>();

            for (int i = 0; i < numEdges; i++)
            {
                edges.Add(new BspEdge {
                    Vertices = reader.ReadUInt16Array()
                });
            }

            return(edges.ToArray());
        }
예제 #11
0
        private BspLeaf[] ReadLeafs(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_LEAFS];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numLeafs = entitiesLump.Length / BspLeaf.SizeInBytes;

            var leafs = new List <BspLeaf>();

            for (int i = 0; i < numLeafs; i++)
            {
                leafs.Add(new BspLeaf {
                    Contents = reader.ReadInt32(), VisOffset = reader.ReadInt32(), Mins = reader.ReadInt16Array(), Maxs = reader.ReadInt16Array(), FirstMarkSurface = reader.ReadUInt16(), NumMarkSurfaces = reader.ReadUInt16(), AmbientLevels = reader.ReadBytes(4)
                });
            }

            return(leafs.ToArray());
        }
예제 #12
0
        private BspNode[] ReadNodes(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_NODES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numNodes = entitiesLump.Length / BspNode.SizeInBytes;

            var nodes = new List <BspNode>();

            for (int i = 0; i < numNodes; i++)
            {
                nodes.Add(new BspNode {
                    PlaneId = reader.ReadInt32(), Children = reader.ReadInt16Array(2), Mins = reader.ReadInt16Array(), Maxs = reader.ReadInt16Array(), FirstFace = reader.ReadUInt16(), NumFaces = reader.ReadUInt16()
                });
            }

            return(nodes.ToArray());
        }
예제 #13
0
        private BspClipNode[] ReadClipNodes(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_CLIPNODES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numClipNodes = entitiesLump.Length / BspClipNode.SizeInBytes;

            var clipNodes = new List <BspClipNode>();

            for (int i = 0; i < numClipNodes; i++)
            {
                clipNodes.Add(new BspClipNode {
                    PlaneId = reader.ReadInt32(), Children = reader.ReadInt16Array(2)
                });
            }

            return(clipNodes.ToArray());
        }
예제 #14
0
        private BspModel[] ReadModels(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_MODELS];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);
            int numModels = entitiesLump.Length / 64;

            var models = new List <BspModel>();

            for (int i = 0; i < numModels; i++)
            {
                models.Add(new BspModel {
                    Mins = reader.ReadSingleArray(), Maxs = reader.ReadSingleArray(), Origin = reader.ReadSingleArray(), Nodes = reader.ReadInt32Array(), NumLeafs = reader.ReadInt32(), FirstFace = reader.ReadInt32(), NumFaces = reader.ReadInt32()
                });
            }

            return(models.ToArray());
        }
예제 #15
0
        private BspTextureHeader ReadTextureHeader(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_TEXTURES];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            int numberOfTextures = reader.ReadInt32();

            int[] mipTexturesOffsets = new int[numberOfTextures];

            for (int i = 0; i < numberOfTextures; i++)
            {
                mipTexturesOffsets[i] = reader.ReadInt32();
            }

            return(new BspTextureHeader {
                NumberMipTextures = numberOfTextures, Offsets = mipTexturesOffsets
            });
        }
예제 #16
0
        private BspTextureInfo[] ReadTextureInfos(BinaryReader reader)
        {
            BspLump entitiesLump = _header.Lumps[BspDefs.LUMP_TEXINFO];

            reader.BaseStream.Seek(entitiesLump.Offset, SeekOrigin.Begin);

            int numTextureInfos = entitiesLump.Length / 40;

            var textureInfos = new List <BspTextureInfo>();

            for (int i = 0; i < numTextureInfos; i++)
            {
                textureInfos.Add(new BspTextureInfo {
                    Vec3s = reader.ReadSingleArray(), SShift = reader.ReadSingle(), Vec3t = reader.ReadSingleArray(), TShift = reader.ReadSingle(), MipTex = reader.ReadUInt32(), Flags = reader.ReadUInt32()
                });
            }

            return(textureInfos.ToArray());
        }