示例#1
0
        /// <summary>
        /// Read all lump headers
        /// </summary>
        private static bsp_header_t ReadHeader(BinaryStreamReader src)
        {
            bsp_header_lump_t lump;
            bsp_header_t      header;

            // Read the magic number and the version
            header         = new bsp_header_t();
            header.tag     = src.ReadString(0, 4);
            header.version = src.ReadInt32(); //src.readULong();
            header.lumps   = new List <bsp_header_lump_t>();

            header.company = "GoldSrc"; // GoldSrc doesnt have a magic number

            if (header.tag.StartsWith("I"))
            {
                header.company = "iD Software";
            }
            else if (header.tag.StartsWith("V"))
            {
                header.company = "Valve Software";
            }

            // Read the lump headers
            for (int i = 0; i < 17; ++i)
            {
                lump = new bsp_header_lump_t();

                //lump.offset = (ulong)src.ReadInt32();
                //lump.length = (ulong)src.ReadInt32();

                //lump.offset = src.ReadUInt64();
                //lump.length = src.ReadUInt64();

                //lump.offset = src.ReadUInt64();
                //lump.length = src.ReadUInt64();

                lump.offset = src.ReadUInt32();
                lump.length = src.ReadUInt32();

                header.lumps.Add(lump);
            }

            return(header);
        }
示例#2
0
        /// <summary>
        /// Parses the BSP file
        /// </summary>
        public static void Parse(BinaryStreamReader src, int tesselationLevel, OnBspIncompatible onIncompatible)
        {
            bsp_header_t header = ReadHeader(src);

            // Check for appropriate format
            if (header.tag != "IBSP" || header.version != 46)
            {
                onIncompatible(header);

                return;
            }

            // info on different versions: https://github.com/zturtleman/bsp-sekai

            /*---- LUMP INDEX ----
             * Index       Lump Name         Description
             * 0           Entities          Game-related object descriptions.
             * 1           Textures          Surface descriptions (shaders).
             * 2           Planes            Planes used by map geometry.
             * 3           Nodes             BSP tree nodes.
             * 4           Leafs             BSP tree leaves.
             * 5           Leaffaces         Lists of face indices, one list per leaf.
             * 6           Leafbrushes       Lists of brush indices, one list per leaf.
             * 7           Models            Descriptions of rigid world geometry in map.
             * 8           Brushes           Convex polyhedra used to describe solid space.
             * 9           Brushsides        Brush surfaces.
             * 10          Vertexes          Vertices used to describe faces.
             * 11          Meshverts         Lists of offsets, one list per mesh.
             * 12          Effects           List of special map effects.
             * 13          Faces             Surface geometry.
             * 14          Lightmaps         Packed lightmap data.
             * 15          Lightvols         Local illumination data.
             * 16          Visdata           Cluster-cluster visibility data.*/


            // Read map entities
            bsp_parser_ibsp_v46.ReadEntities(header.lumps[0], src);

            /*  The entities lump stores game-related map information,
             *  including information about the map name, weapons, health, armor, triggers, spawn points,
             *  lights, and .md3 models to be placed in the map.
             *  The lump contains only one record, a string that describes all of the entities */

            bsp_tree        tree = new bsp_tree();
            List <shader_p> shaders;

            // Load visual map components
            tree.surfaces = shaders = bsp_parser_ibsp_v46.ReadShaders(header.lumps[1], src);
            List <lightmap_rect_t> lightmaps = bsp_parser_ibsp_v46.ReadLightmaps(header.lumps[14], src);
            List <Vertex>          verts     = bsp_parser_ibsp_v46.ReadVerts(header.lumps[10], src);
            List <int>             meshVerts = bsp_parser_ibsp_v46.ReadMeshVerts(header.lumps[11], src);
            List <Face>            faces     = bsp_parser_ibsp_v46.ReadFaces(header.lumps[13], src);



            // COMPILE MAP
            BspCompiler.CompileMap(verts, faces, meshVerts, lightmaps, shaders, tesselationLevel);

            //   postMessage2({
            //       "type": 'status',
            //"message": 'Geometry compiled, parsing collision tree...'
            //   },null);


            // Load bsp components
            tree.planes      = bsp_parser_ibsp_v46.ReadPlanes(header.lumps[2], src);
            tree.nodes       = bsp_parser_ibsp_v46.ReadNodes(header.lumps[3], src);
            tree.leaves      = bsp_parser_ibsp_v46.ReadLeaves(header.lumps[4], src);
            tree.leafFaces   = bsp_parser_ibsp_v46.ReadLeafFaces(header.lumps[5], src);
            tree.leafBrushes = bsp_parser_ibsp_v46.ReadLeafBrushes(header.lumps[6], src);
            tree.brushes     = bsp_parser_ibsp_v46.ReadBrushes(header.lumps[8], src);
            tree.brushSides  = bsp_parser_ibsp_v46.ReadBrushSides(header.lumps[9], src);
            VisData visData = bsp_parser_ibsp_v46.ReadVisData(header.lumps[16], src);

            tree.visBuffer = visData.buffer;
            tree.visSize   = visData.size;

            BspVisibilityChecking.visBuffer = visData.buffer;
            BspVisibilityChecking.visSize   = visData.size;

            //tree.visData = visData;

            q3bsp.onMessage(new MessageParams()
            {
                type = "bsp",
                bsp  = tree
            });
        }