Beispiel #1
0
        /// <summary>
        /// Mod_LoadModel
        /// Loads a model into the cache
        /// </summary>
        public ModelData LoadModel(ModelData mod, Boolean crash, ModelType type)
        {
            var name = mod.Name;

            if (mod.Type != type)
            {
                ModelData newMod = null;

                switch (type)
                {
                case ModelType.mod_brush:
                    newMod = new BrushModelData(Host.Model.SubdivideSize, Host.RenderContext.NoTextureMip);
                    newMod.CopyFrom(mod);
                    break;

                case ModelType.mod_alias:
                    newMod = new AliasModelData(Host.RenderContext.NoTextureMip);
                    newMod.CopyFrom(mod);
                    break;

                case ModelType.mod_sprite:
                    newMod = new SpriteModelData(Host.RenderContext.NoTextureMip);
                    newMod.CopyFrom(mod);
                    break;
                }

                newMod.Name = mod.Name;

                ModelCache.RemoveAll(k => k.Name == name);

                mod = newMod;

                ModelCache.Add(mod);
            }

            if (!mod.IsLoadRequired)
            {
                if (mod.Type == ModelType.mod_alias)
                {
                    if (Host.Cache.Check(mod.cache) != null)
                    {
                        return(mod);
                    }
                }
                else
                {
                    return(mod);         // not cached at all
                }
            }

            //
            // load the file
            //
            var buf = FileSystem.LoadFile(mod.Name);

            if (buf == null)
            {
                if (crash)
                {
                    Utilities.Error("Mod_NumForName: {0} not found", mod.Name);
                }
                return(null);
            }

            //
            // allocate a new model
            //
            CurrentModel = mod;

            mod.IsLoadRequired = false;

            switch (BitConverter.ToUInt32(buf, 0))    // LittleLong(*(unsigned *)buf))
            {
            case ModelDef.IDPOLYHEADER:
                LoadAliasModel(( AliasModelData )mod, buf);
                break;

            case ModelDef.IDSPRITEHEADER:
                LoadSpriteModel(( SpriteModelData )mod, buf);
                break;

            default:
                LoadBrushModel(( BrushModelData )mod, buf);
                break;
            }

            return(mod);
        }