Exemplo n.º 1
0
        /// <summary>
        /// Unloads all textures. Take caution as it may cause serious damage.
        /// </summary>
        public void Clear()
        {
            for (int i = 0; i < textures.Count; i++)
            {
                TextureManagerItem it = GetTexture(i);

                if (it != null)
                {
                    it.Texture.Dispose();
                    textures[i] = null;
                }
            }

            textures.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the index of specified texture.
        /// </summary>
        /// <param name="FileName">Path to texture file. If not loaded yet, loads the texture.</param>
        /// <returns>Index of texture</returns>
        public int AddTexture(string FileName)
        {
            int idx = -1;

            for (int i = 0; i < textures.Count; i++)
            {
                if (textures[i] != null)
                {
                    if (((TextureManagerItem)textures[i]).Filename == FileName)                       // nalezen
                    {
                        idx = i;

                        break;
                    }
                }
            }

            if (idx == -1)               // nenalezen, zalozime
            {
                TextureManagerItem it = new TextureManagerItem(FileName);
                if (it != null)
                {
                    if (unloadedTextures.Count == 0)
                    {
                        // pridame na konec
                        textures.Add(it);
                        idx = textures.Count - 1;
                    }
                    else
                    {
                        // zalozime na predchozim pouzitem miste
                        textures[(int)unloadedTextures.Peek()] = it;
                        idx = (int)unloadedTextures.Pop();
                    }
                }
            }

            if (idx != -1)
            {
                GetTexture(idx).NewUser();
            }

            return(idx);
        }