public void LoadBSP(BinaryReader br)
        {
            int cnt;

            this.header = new dheader_t(br);
            //Loading planes
            cnt    = (this.header.lumps [(int)lumpTypes.LUMP_PLANES].filelen) / STRUCT_PLANE_SIZE;
            planes = new dplane_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_PLANES].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                planes [i] = new dplane_t(br);
            }
            //Loading BSP nodes
            cnt      = (this.header.lumps [(int)lumpTypes.LUMP_NODES].filelen) / STRUCT_BSPNODE_SIZE;
            bspnodes = new dnode_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_NODES].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                bspnodes [i] = new dnode_t(br);
            }
            //Loading BSP leaves
            cnt       = (this.header.lumps [(int)lumpTypes.LUMP_LEAFS].filelen) / STRUCT_BSPLEAF_SIZE;
            bspleaves = new dleaf_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_LEAFS].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                bspleaves [i] = new dleaf_t(br);
            }
            //Loading texinfo
            cnt      = (this.header.lumps [(int)lumpTypes.LUMP_TEXINFO].filelen) / STRUCT_TEXINFO_SIZE;
            texinfos = new texinfo_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXINFO].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                texinfos [i] = new texinfo_t(br);
            }

            //Loading texdata
            cnt     = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA].filelen) / STRUCT_TEXDATA_SIZE;
            texdata = new dtexdata_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                texdata [i] = new dtexdata_t(br);
            }
            //Loading TexdataStringTable
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_TABLE].filelen) / 4;
            TexdataStringTable = new int[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_TABLE].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < cnt; i++)
            {
                TexdataStringTable [i] = br.ReadInt32();
            }
            //Loading TexdataStringData
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_DATA].filelen) / 1;
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_DATA].fileofs, SeekOrigin.Begin);
            TexdataStringData = br.ReadChars(cnt);
        }
Beispiel #2
0
        public virtual void Mod_LoadNodes(lump_t l)
        {
            Int32 i, j, count, p;

            qfiles.dnode_t in_renamed;
            mnode_t[]      out_renamed;
            if ((l.filelen % qfiles.dnode_t.SIZE) != 0)
            {
                Com.Error(Defines.ERR_DROP, "MOD_LoadBmodel: funny lump size in " + loadmodel.name);
            }
            count              = l.filelen / qfiles.dnode_t.SIZE;
            out_renamed        = new mnode_t[count];
            loadmodel.nodes    = out_renamed;
            loadmodel.numnodes = count;
            ByteBuffer bb = ByteBuffer.Wrap(mod_base, l.fileofs, l.filelen);

            bb.Order = ByteOrder.LittleEndian;
            for (i = 0; i < count; i++)
            {
                out_renamed[i] = new mnode_t();
            }
            for (i = 0; i < count; i++)
            {
                in_renamed = new dnode_t(bb);
                for (j = 0; j < 3; j++)
                {
                    out_renamed[i].mins[j] = in_renamed.mins[j];
                    out_renamed[i].maxs[j] = in_renamed.maxs[j];
                }

                p = in_renamed.planenum;
                out_renamed[i].plane        = loadmodel.planes[p];
                out_renamed[i].firstsurface = in_renamed.firstface;
                out_renamed[i].numsurfaces  = in_renamed.numfaces;
                out_renamed[i].contents     = -1;
                for (j = 0; j < 2; j++)
                {
                    p = in_renamed.children[j];
                    if (p >= 0)
                    {
                        out_renamed[i].children[j] = loadmodel.nodes[p];
                    }
                    else
                    {
                        out_renamed[i].children[j] = loadmodel.leafs[-1 - p];
                    }
                }
            }

            Mod_SetParent(loadmodel.nodes[0], null);
        }
Beispiel #3
0
        static void LoadNodesAndLeafs(BinaryReader br, Header header)
        {
            // Read nodes
            br.BaseStream.Seek(header.lumps[5].fileofs, SeekOrigin.Begin);
            int nNodes = header.lumps[5].filelen / 32;
            if (header.lumps[5].filelen % 32 > 0)
            {
                Common.Instance.Error("LoadNodesAndLeafs: Weird node lumpsize");
            }
            world.nodes = new dnode_t[nNodes];
            for (int i = 0; i < nNodes; i++)
            {
                dnode_t node = new dnode_t();
                node.planenum = br.ReadInt32();
                node.children = new int[] { br.ReadInt32(), br.ReadInt32() };
                node.mins = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16())); // 3 For frustrum culling
                node.maxs = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16())); // 3
                node.firstface = br.ReadUInt16(); // index into face array
                node.numfaces = br.ReadUInt16(); ;  // counting both sides
                node.area = br.ReadInt16(); ;    // If all leaves below this node are in the same area, then
                // this is the area index. If not, this is -1.
                node.paddding = br.ReadInt16(); ;	 // pad to 32 bytes length

                node.plane = world.planes[node.planenum];

                world.nodes[i] = node;
            }

            // Determine size
            int leafSize = 56;
            if (header.version == 20 || header.version == 17)
            {
                if (header.lumps[10].filelen % 32 == 0)
                    leafSize = 32;
                else
                    System.Console.WriteLine("Problem reading leafs..");
            }

            world.numLeafs = header.lumps[10].filelen / leafSize;
            world.leafs = new dleaf_t[world.numLeafs];
            br.BaseStream.Seek(header.lumps[10].fileofs, SeekOrigin.Begin);
            for (int i = 0; i < world.numLeafs; i++)
            {
                //
                dleaf_t leaf = new dleaf_t();
                leaf.contents = br.ReadInt32();
                leaf.cluster = br.ReadInt16();
                if (leaf.cluster > world.numClusters)
                    world.numClusters = leaf.cluster + 1;
                ushort packed = br.ReadUInt16();
                leaf.area = (short)((ushort)(packed << 7) >> 7);
                leaf.flags = (short)(packed >> 9);
                if (packed > 0)
                {
                    int test = 2;
                }
                leaf.mins = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16()));  // 3 For frustrum culling
                leaf.maxs = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16())); // 3

                leaf.firstleafface = br.ReadUInt16();
                leaf.numleaffaces = br.ReadUInt16();
                leaf.firstleafbrush = br.ReadUInt16();
                leaf.numleafbrushes = br.ReadUInt16();
                leaf.leafWaterDataID = br.ReadInt16();
                leaf.ambientLighting = new CompressedLightCube();
                if (leafSize > 32)
                {
                    leaf.ambientLighting.Color = new Vector3[6];
                    for (int j = 0; j < 6; j++)
                    {
                        RGBExp color = new RGBExp();
                        color.r = br.ReadByte();
                        color.g = br.ReadByte();
                        color.b = br.ReadByte();
                        color.exp = br.ReadSByte();
                        float r = SourceParser.TexLightToLinear((int)color.r, color.exp);
                        float g = SourceParser.TexLightToLinear((int)color.g, color.exp);
                        float b = SourceParser.TexLightToLinear((int)color.b, color.exp);
                        leaf.ambientLighting.Color[j] = new Vector3(r, g, b);
                    }
                }
                else
                {
                    if (world.LightGrid != null && world.LightGrid.Length > i)
                        leaf.ambientLighting = world.LightGrid[i];
                }
                leaf.padding = br.ReadInt16();
                leaf.staticProps = new List<SourceProp>();
                world.leafs[i] = leaf;
            }
        }
        public void LoadBSP(BinaryReader br)
        {
            int cnt;
            this.header = new dheader_t (br);
            //Loading planes
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_PLANES].filelen) / STRUCT_PLANE_SIZE;
            planes=new dplane_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_PLANES].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                planes [i] = new dplane_t (br);
            }
            //Loading BSP nodes
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_NODES].filelen) / STRUCT_BSPNODE_SIZE;
            bspnodes=new dnode_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_NODES].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                bspnodes [i] = new dnode_t (br);
            }
            //Loading BSP leaves
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_LEAFS].filelen) / STRUCT_BSPLEAF_SIZE;
            bspleaves=new dleaf_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_LEAFS].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                bspleaves [i] = new dleaf_t (br);
            }
            //Loading texinfo
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXINFO].filelen) / STRUCT_TEXINFO_SIZE;
            texinfos=new texinfo_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXINFO].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                texinfos [i] = new texinfo_t (br);
            }

            //Loading texdata
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA].filelen) / STRUCT_TEXDATA_SIZE;
            texdata=new dtexdata_t[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                texdata [i] = new dtexdata_t (br);
            }
            //Loading TexdataStringTable
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_TABLE].filelen) / 4;
            TexdataStringTable=new int[cnt];
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_TABLE].fileofs, SeekOrigin.Begin);
            for(int i=0 ; i<cnt ; i++) {
                TexdataStringTable [i] = br.ReadInt32();
            }
            //Loading TexdataStringData
            cnt = (this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_DATA].filelen) / 1;
            br.BaseStream.Seek(this.header.lumps [(int)lumpTypes.LUMP_TEXDATA_STRING_DATA].fileofs, SeekOrigin.Begin);
            TexdataStringData=br.ReadChars(cnt);
        }
Beispiel #5
0
 private void SetParentRef(ref dnode_t parent, ref object newparent)
 {
     parent.lastVisibleCount = VisCount;
     parent = (dnode_t)newparent;
 }
Beispiel #6
0
        // Sets parents for nodes and leafs, allowing a backwards trace
        private void SetParent(ref dnode_t node, ref dnode_t parent)
        {
            node.parent = parent;
            if (node.children[0] >= 0)
            {
                SetParent(ref world.nodes[node.children[0]], ref node);
            }
            else
            {
                world.leafs[-(node.children[0] + 1)].parent = node;
            }

            if (node.children[1] >= 0)
                SetParent(ref world.nodes[node.children[1]], ref node);
            else
                world.leafs[-(node.children[1] + 1)].parent = node;
        }
Beispiel #7
0
        void ReadNodes(Header header, BinaryReader br)
        {
            // Read nodes
            br.BaseStream.Seek(header.lumps[5].fileofs, SeekOrigin.Begin);
            int nNodes = header.lumps[5].filelen / 32;
            nodes = new dnode_t[nNodes];
            for (int i = 0; i < nNodes; i++)
            {
                dnode_t node = new dnode_t();
                node.planenum = br.ReadInt32();
                node.children = new int[] { br.ReadInt32(), br.ReadInt32() };
                node.mins = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16())); // 3 For frustrum culling
                node.maxs = SourceParser.SwapZY(new Vector3(br.ReadInt16(), br.ReadInt16(), br.ReadInt16())); // 3
                node.firstface = br.ReadUInt16(); // index into face array
                node.numfaces = br.ReadUInt16();  // counting both sides
                node.area = br.ReadInt16();     // If all leaves below this node are in the same area, then
                // this is the area index. If not, this is -1.
                node.paddding = br.ReadInt16(); 	 // pad to 32 bytes length

                node.plane = planes[node.planenum];

                nodes[i] = node;
            }
        }