Exemple #1
0
        /// <summary>
        /// Gets the original texture for this <see cref="StationaryGrhData"/>, bypassing any <see cref="TextureAtlas"/> being used.
        /// </summary>
        /// <returns>The original texture for this <see cref="StationaryGrhData"/>.</returns>
        public Image GetOriginalTexture()
        {
            if (!_isUsingAtlas)
            {
                return(Texture);
            }

            return(_cm.LoadImage(_textureName, GrhInfo.ContentLevelDecider(this)));
        }
Exemple #2
0
        /// <summary>
        /// Ensures that the texture is properly loaded.
        /// </summary>
        void ValidateTexture()
        {
            // If the texture is not set or is disposed, request a new one
            if (_texture != null)
            {
                return;
            }

            // Check that enough time has elapsed to try and load the texture
            if (_failedLoadAttempts > 0 && _nextLoadAttemptTime > TickCount.Now)
            {
                return;
            }

            // Try to load the texture
            const string errmsg = "Failed to load texture `{0}` for GrhData `{1}`: {2}";

            try
            {
                _texture = _cm.LoadImage(_textureName, GrhInfo.ContentLevelDecider(this));
            }
            catch (LoadingFailedException ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, _textureName, this, ex);
                }
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, _textureName, this, ex);
                }
                Debug.Fail(string.Format(errmsg, _textureName, this, ex));
            }

            // Update the failed loading information if the texture failed to load, or clear it if the texture
            // is valid
            if (_texture != null)
            {
                _failedLoadAttempts  = 0;
                _nextLoadAttemptTime = TickCount.MinValue;
            }
            else
            {
                _failedLoadAttempts++;
                _nextLoadAttemptTime = (TickCount)(TickCount.Now + GetLoadTextureTimeout(_failedLoadAttempts));
            }

            // If we were using an atlas, we'll have to remove it because the texture was reloaded
            _isUsingAtlas = false;
        }