Beispiel #1
0
 public void LoadTextures(GraphicsDevice graphicsDevice, string basepath)
 {
     foreach (var index in Textureids)
     {
         var texture = _rsmRoot.LoadAndCacheTexture(index, graphicsDevice, basepath);
         TextureCache.Add(index, texture);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Loads a texture from file.
        /// If Texture has been loaded before it will pull it from a Texture Cache
        /// </summary>
        /// <param name="textureFile">Path to the file.</param>
        /// <returns>Texture from a TextureCache</returns>
        private Texture2D LoadTexture(String textureFile)
        {
            if (!TextureCache.Keys.Contains(textureFile))
            {
                TextureCache.Add(textureFile, m_game.Content.Load <Texture2D>(textureFile));
            }

            return(TextureCache[textureFile]);
        }
        /// <summary>
        ///  <para>Loads a Texture from given Zip-File and Entry.</para>
        /// </summary>
        private Texture LoadTextureFrom(ZipFile zipFile, ZipEntry imageEntry)
        {
            string ResourceName = Path.GetFileNameWithoutExtension(imageEntry.Name).ToLowerInvariant();

            if (TextureCache.Textures.ContainsKey(ResourceName))
            {
                return(TextureCache.Textures[ResourceName].Texture);
            }

            var byteBuffer = new byte[zipBufferSize];

            try
            {
                Stream zipStream = zipFile.GetInputStream(imageEntry);
                var    memStream = new MemoryStream();

                StreamUtils.Copy(zipStream, memStream, byteBuffer);
                memStream.Position = 0;

                Image img = new Image(memStream);
                bool[,] opacityMap = new bool[img.Size.X, img.Size.Y];
                for (int y = 0; y < img.Size.Y; y++)
                {
                    for (int x = 0; x < img.Size.X; x++)
                    {
                        Color pColor = img.GetPixel(Convert.ToUInt32(x), Convert.ToUInt32(y));
                        if (pColor.A > Limits.ClickthroughLimit)
                        {
                            opacityMap[x, y] = true;
                        }
                        else
                        {
                            opacityMap[x, y] = false;
                        }
                    }
                }

                Texture     loadedImg = new Texture(memStream);
                TextureInfo tmp       = new TextureInfo(loadedImg, img, opacityMap);
                TextureCache.Add(ResourceName, tmp);
                _textureToKey.Add(TextureCache.Textures[ResourceName].Texture, ResourceName);

                memStream.Close();
                zipStream.Close();
                memStream.Dispose();
                zipStream.Dispose();
                return(loadedImg);
            }
            catch (Exception I)
            {
                System.Console.WriteLine("Failed to load " + imageEntry.Name + ": " + I.ToString());
            }

            return(null);
        }
Beispiel #4
0
        public Halo()
        {
            if (!TextureCache.Contains(CacheKey))
            {
                var bmp    = Bitmap.CreateBitmap(RADIUS * 2, RADIUS * 2, Bitmap.Config.Argb8888);
                var canvas = new Canvas(bmp);
                var paint  = new Paint();

                paint.Color = Android.Graphics.Color.Argb(0xFF, 0xFF, 0xFF, 0xFF);
                canvas.DrawCircle(RADIUS, RADIUS, RADIUS * 0.75f, paint);
                paint.Color = Android.Graphics.Color.Argb(0x88, 0xFF, 0xFF, 0xFF);
                canvas.DrawCircle(RADIUS, RADIUS, RADIUS, paint);
                TextureCache.Add(CacheKey, new SmartTexture(bmp));
            }

            Texture(CacheKey);

            Origin.Set(RADIUS);
        }
Beispiel #5
0
        // WARNING: SFML jumps around the stream position while loading the image.
        // As such, streams that don't support seeking don't work (zip streams...)
        public Texture LoadTextureFrom(string name, Stream stream)
        {
            if (!stream.CanSeek || !stream.CanRead)
            {
                throw new ArgumentException("Stream must be read and seekable.", nameof(stream));
            }
            if (TextureCache.Textures.ContainsKey(name))
            {
                return(TextureCache.Textures[name].Texture);
            }

            var         img     = new Image(stream);
            var         texture = new Texture(img);
            TextureInfo tmp     = new TextureInfo(texture, img);

            TextureCache.Add(name, tmp);
            _textureToKey.Add(texture, name);

            return(texture);
        }
Beispiel #6
0
    private void RemoveTile(Dictionary <long, MapTile> map, List <MapTile> list, int index)
    {
        MapTile tile = list[index];
        long    id   = tile.Id.ToId();

        // Remove tile from list
        map.Remove(id);
        int last = list.Count - 1;

        list[index] = list[last];
        list.RemoveAt(last);

        // Update the texture cache
        textureCache.Add(id, tile.GetTexture());

        tile.Hide();

        // Put it back to the unused tiles stack
        unusedTiles.Push(tile);
        tile.name = "unused";
    }
Beispiel #7
0
        public static void LoadTexture(string filePath, GameObject referenceImage, bool reverseTexture = false)
        {
            if (!File.Exists(filePath))
            {
                Debug.Log("LoadTexture does not exist filePath=" + filePath);
                referenceImage.SetActive(false);
                return;
            }
            Texture2D tex = new Texture2D(1, 1);

            tex.LoadImage(File.ReadAllBytes(filePath));
            if (reverseTexture)
            {
                tex = FlipTextureHorizontal(FlipTextureVertical(tex));
            }
            Debug.Log("LoadTexture filePath=" + filePath + ", width=" + tex.width + ", height=" + tex.height);
            referenceImage.transform.localScale = new Vector3(Ratio.SolveForD(tex.height, tex.width, defaultScale), defaultScale, defaultScale);
            referenceImage.GetComponent <MeshRenderer>().materials[0].mainTexture = tex;

            Selectable selectable = referenceImage.GetComponent <Selectable>();

            selectable.Initialize();
            UnityEngine.Material[] unselectedMaterials = new UnityEngine.Material[1] {
                referenceImage.GetComponent <MeshRenderer>().materials[0]
            };
            Debug.Log("unselectedMaterials.Length=" + unselectedMaterials.Length);
            for (int i = 0; i < unselectedMaterials.Length; i++)
            {
                unselectedMaterials[i]             = GameObject.Instantiate(unselectedMaterials[i]);
                unselectedMaterials[i].mainTexture = tex;
            }
            int textureCacheId = TextureCache.Add(tex);

            selectable.renderMesh          = false;
            selectable.textureCacheId      = textureCacheId;
            selectable.unselectedMaterial  = null;
            selectable.unselectedMaterials = unselectedMaterials;
            selectable.UpdateSelectedMaterials();
        }
        // WARNING: SFML jumps around the stream position while loading the image.
        // As such, streams that don't support seeking don't work (zip streams...)
        public Texture LoadTextureFrom(string name, Stream stream)
        {
            if (!stream.CanSeek || !stream.CanRead)
            {
                throw new ArgumentException("Stream must be read and seekable.", nameof(stream));
            }
            if (TextureCache.Textures.ContainsKey(name))
            {
                return(TextureCache.Textures[name].Texture);
            }

            Image img = new Image(stream);

            bool[,] opacityMap = new bool[img.Size.X, img.Size.Y];
            for (int y = 0; y < img.Size.Y; y++)
            {
                for (int x = 0; x < img.Size.X; x++)
                {
                    Color pColor = img.GetPixel(Convert.ToUInt32(x), Convert.ToUInt32(y));
                    if (pColor.A > Limits.ClickthroughLimit)
                    {
                        opacityMap[x, y] = true;
                    }
                    else
                    {
                        opacityMap[x, y] = false;
                    }
                }
            }

            Texture     texture = new Texture(img);
            TextureInfo tmp     = new TextureInfo(texture, img, opacityMap);

            TextureCache.Add(name, tmp);
            _textureToKey.Add(texture, name);

            return(texture);
        }
Beispiel #9
0
 internal override bool Startup()
 {
     TextureID_ = TextureCache.Add("1.jpg");
     return(true);
 }
Beispiel #10
0
    //****************************************************************************************************
    //
    //****************************************************************************************************

    private IEnumerator RequestMap()
    {
        if (m_request != null)
        {
            string url = string.Empty;

            switch (m_map.source)
            {
            case WebMap.SOURCE.GOOGLE: url = GetGoogleMapRequestURL(m_request.@params); break;

            case WebMap.SOURCE.ESRI: url = GetESRIMapRequestURL(m_request.@params); break;
            }

            Texture texture = (m_cacheDisabled == false) ? m_cache.Get(url) : null;

            if (texture != null)
            {
                CORE.UTILS.Log("USING CACHE FOR " + url);

                if (object.ReferenceEquals(m_request.texture, texture) == false)
                {
                    m_request.texture = texture;
                }

                DropCurRequest(WebMapRequest.DROP_REASON.COMPLETED);

                yield break;
            }



            CORE.UTILS.Log("LOADING > " + m_map.source.ToString() + " > " + url);

            WWW HTTPSReq = (m_logOnly == false) ? new WWW(url) : null;

            while ((HTTPSReq != null) && (HTTPSReq.isDone == false))
            {
                if (m_request.canceled || m_request.@new)
                {
                    DropCurRequest(WebMapRequest.DROP_REASON.CONTEXT_CHANGED);

                    yield break;
                }

                yield return(HTTPSReq);
            }


            if ((HTTPSReq != null) && (HTTPSReq.error != null))
            {
                DropCurRequest(WebMapRequest.DROP_REASON.CANCELED);

                yield break;
            }


            texture = (HTTPSReq != null) ? HTTPSReq.texture : null;

            if (texture != null)
            {
                CORE.UI.ClampTexture(texture, FilterMode.Bilinear);

                texture.name = url;

                m_cache.Add(url, texture);

                m_request.texture = texture;
            }

            DropCurRequest(WebMapRequest.DROP_REASON.COMPLETED);
        }
    }
Beispiel #11
0
 public FogTexture(int width2, int height2)
     : base(Android.Graphics.Bitmap.CreateBitmap(width2, height2, Android.Graphics.Bitmap.Config.Argb8888))
 {
     Filter(Linear, Linear);
     TextureCache.Add(typeof(FogOfWar), this);
 }