예제 #1
0
        /// <summary>
        /// Mod_LoadSpriteModel
        /// </summary>
        private void LoadSprite(SpriteModelData mod, Byte[] buffer)
        {
            mod.Load(mod.Name, buffer, (name, buf, width, height) =>
            {
                var texture = (Renderer.OpenGL.Textures.GLTexture)BaseTexture.FromBuffer(Host.Video.Device, name,
                                                                                         buf, width, height, hasMipMap: true, hasAlpha: true);

                SpriteTextures.Add(texture);

                return(texture.GLDesc.TextureNumber);
            });
        }
예제 #2
0
        /// <summary>
        /// Mod_LoadSpriteModel
        /// </summary>
        public void LoadSpriteModel(SpriteModelData mod, Byte[] buffer)
        {
            mod.Load(mod.Name, buffer, (n, b, w, h) =>
            {
                var texture = (Renderer.OpenGL.Textures.GLTexture)BaseTexture.FromBuffer(Host.Video.Device, n,
                                                                                         b, w, h, true, true);

                SpriteTextures.Add(texture);

                return(texture.GLDesc.TextureNumber);
            });
        }
예제 #3
0
        /// <summary>
        /// Mod_FindName
        /// </summary>
        private ModelData FindName(String name, ModelType type)
        {
            ModelData result = null;

            if (String.IsNullOrEmpty(name))
            {
                Utilities.Error("Mod_ForName: NULL name");
            }

            if (!Contains(name))
            {
                if (DictionaryItems.Count == ModelDef.MAX_MOD_KNOWN)
                {
                    Utilities.Error("mod_numknown == MAX_MOD_KNOWN");
                }

                switch (type)
                {
                case ModelType.Brush:
                    result = new BrushModelData(Host.Model.SubdivideSize, Host.RenderContext.NoTextureMip);
                    break;

                case ModelType.Sprite:
                    result = new AliasModelData(Host.RenderContext.NoTextureMip);
                    break;

                case ModelType.Alias:
                    result = new SpriteModelData(Host.RenderContext.NoTextureMip);
                    break;
                }

                result.Name           = name;
                result.IsLoadRequired = true;
                Add(result.Name, result);
            }
            else
            {
                result = Get(name);
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Mod_FindName
        /// </summary>
        public ModelData FindName(string name, ModelType type)
        {
            if (string.IsNullOrEmpty(name))
            {
                Utilities.Error("Mod_ForName: NULL name");
            }

            var mod = this.ModelCache.Where(m => m.Name == name).FirstOrDefault( );

            if (mod == null)
            {
                if (this.ModelCache.Count == ModelDef.MAX_MOD_KNOWN)
                {
                    Utilities.Error("mod_numknown == MAX_MOD_KNOWN");
                }

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

                case ModelType.mod_sprite:
                    mod = new AliasModelData(this.Host.RenderContext.NoTextureMip);
                    break;

                case ModelType.mod_alias:
                    mod = new SpriteModelData(this.Host.RenderContext.NoTextureMip);
                    break;
                }

                mod.Name           = name;
                mod.IsLoadRequired = true;
                this.ModelCache.Add(mod);
            }

            return(mod);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <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);
        }