Beispiel #1
0
 public SourceProp(StaticPropLump_t prop_t)
     : base(null, null)
 {
     this.DontOptimize = true;
     this.prop_t = prop_t;
     Vector3 lightOrigin = Vector3.Zero;
     if ((prop_t.Flags & 2) == 2)
     {
         lightOrigin = prop_t.LightingOrigin;
     }
     else
     {
         lightOrigin = GetIlluminationPoint(srcModel, prop_t.Origin, prop_t.Angles);
     }
     //modelMatrix = Matrix.Translation(prop_t.Origin);
 }
Beispiel #2
0
        static void LoadGameAndProps(BinaryReader br, Header header)
        {
            // Game Lump
            dgamelumpheader_t gameheader = new dgamelumpheader_t();
            br.BaseStream.Seek(header.lumps[35].fileofs, SeekOrigin.Begin);
            int gamelen = header.lumps[35].filelen;
            gameheader.lumpCount = br.ReadInt32();
            gameheader.gamelump = new dgamelump_t[gameheader.lumpCount];
            for (int i = 0; i < gameheader.lumpCount; i++)
            {
                dgamelump_t game = new dgamelump_t();
                game.id = br.ReadInt32();
                game.flags = br.ReadUInt16();
                game.version = br.ReadUInt16();
                game.fileofs = br.ReadInt32();
                game.filelen = br.ReadInt32();

                gameheader.gamelump[i] = game;
            }

            // Read Static Props
            foreach (dgamelump_t game in gameheader.gamelump)
            {
                if (game.id == 1936749168)
                {
                    // read prop dict
                    StaticPropDictLump_t dict = new StaticPropDictLump_t();
                    br.BaseStream.Seek(game.fileofs, SeekOrigin.Begin);
                    dict.dictEntries = br.ReadInt32();
                    dict.Name = new string[dict.dictEntries];
                    Dictionary<string, SourceModel> srcmodels = new Dictionary<string, SourceModel>();
                    for (int i = 0; i < dict.dictEntries; i++)
                    {
                        char[] name = br.ReadChars(128);
                        dict.Name[i] = new string(name);
                        // cut \0 chars
                        int dindex = -1;
                        if ((dindex = dict.Name[i].IndexOf('\0')) != -1)
                        {
                            dict.Name[i] = dict.Name[i].Substring(0, dindex);
                            if (MDLReader.ReadFile(dict.Name[i]))
                            {
                                MDLReader.srcModel.Name = dict.Name[i];
                                srcmodels.Add(MDLReader.srcModel.Name, MDLReader.srcModel);
                            }
                        }
                    }

                    // Read prop leafs
                    StaticPropLeafLump_t propleaf = new StaticPropLeafLump_t();
                    propleaf.leafEntries = br.ReadInt32();
                    propleaf.leaf = new ushort[propleaf.leafEntries];
                    for (int i = 0; i < propleaf.leafEntries; i++)
                    {
                        propleaf.leaf[i] = br.ReadUInt16();
                    }
                    world.propleafs = propleaf;

                    // read props
                    int nStaticProps = br.ReadInt32();
                    StaticPropLump_t[] props = new StaticPropLump_t[nStaticProps];
                    for (int i = 0; i < nStaticProps; i++)
                    {
                        StaticPropLump_t prop = new StaticPropLump_t();
                        prop.Origin = SwapZY(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        prop.Angles = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        prop.PropType = br.ReadUInt16();
                        prop.PropName = dict.Name[(int)prop.PropType];
                        prop.FirstLeaf = br.ReadUInt16();
                        prop.LeafCount = br.ReadUInt16();
                        prop.Solid = br.ReadByte();
                        prop.Flags = br.ReadByte();
                        prop.Skin = br.ReadInt32();
                        prop.FadeMinDist = br.ReadSingle();
                        prop.FadeMaxDist = br.ReadSingle();
                        prop.LightingOrigin = SwapZY(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        if (game.version == 5)
                            prop.ForcedFaceScale = br.ReadSingle();
                        else
                            prop.ForcedFaceScale = 1f;

                        props[i] = prop;
                        SourceProp sprop = new SourceProp(prop);
                        if (srcmodels.ContainsKey(prop.PropName))
                        {
                            sprop.srcModel = srcmodels[prop.PropName];

                            world.sourceProps.Add(sprop);
                        }

                        // Index into leaves
                        if (prop.LeafCount + prop.FirstLeaf < world.propleafs.leafEntries)
                        {
                            for (int j = 0; j < prop.LeafCount; j++)
                            {
                                ushort leafIndex = world.propleafs.leaf[prop.FirstLeaf + j];
                                if (leafIndex >= world.leafs.Length)
                                {
                                    int test = 2;
                                }
                                world.leafs[leafIndex].staticProps.Add(sprop);
                            }
                        }
                    }
                    world.props = props;

                    break;
                }
            }
        }