/// <summary> /// Mod_LoadModel /// Loads a model into the cache /// </summary> public ModelData LoadModel(ModelData mod, bool crash, ModelType type) { var name = mod.Name; if (mod.Type != type) { ModelData newMod = null; switch (type) { case ModelType.mod_brush: newMod = new BrushModelData(this.Host.Model.SubdivideSize, this.Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; case ModelType.mod_alias: newMod = new AliasModelData(this.Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; case ModelType.mod_sprite: newMod = new SpriteModelData(this.Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; } newMod.Name = mod.Name; this.ModelCache.RemoveAll(k => k.Name == name); mod = newMod; this.ModelCache.Add(mod); } if (!mod.IsLoadRequired) { if (mod.Type == ModelType.mod_alias) { if (this.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 // this.CurrentModel = mod; mod.IsLoadRequired = false; switch (BitConverter.ToUInt32(buf, 0)) // LittleLong(*(unsigned *)buf)) { case ModelDef.IDPOLYHEADER: this.LoadAliasModel(( AliasModelData )mod, buf); break; case ModelDef.IDSPRITEHEADER: this.LoadSpriteModel(( SpriteModelData )mod, buf); break; default: this.LoadBrushModel(( BrushModelData )mod, buf); break; } return(mod); }
/// <summary> /// Mod_LoadModel /// Loads a model into the cache /// </summary> private ModelData Load(ModelData mod, Boolean crash, ModelType type) { var name = mod.Name; if (mod.Type != type) { ModelData newMod = null; switch (type) { case ModelType.Brush: newMod = new BrushModelData(Host.Model.SubdivideSize, Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; case ModelType.Alias: newMod = new AliasModelData(Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; case ModelType.Sprite: newMod = new SpriteModelData(Host.RenderContext.NoTextureMip); newMod.CopyFrom(mod); break; } newMod.Name = mod.Name; Remove(name); mod = newMod; Add(mod.Name, mod); } if (!mod.IsLoadRequired) { if (mod.Type == ModelType.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 Allocate(mod, buf); return(mod); }