示例#1
0
        /// <summary>
        /// Finds all of the <see cref="GrhData"/>s that reference a texture that does not exist.
        /// </summary>
        /// <returns>IEnumerable of all of the <see cref="GrhData"/>s that reference a texture that does not exist.</returns>
        public static IEnumerable <StationaryGrhData> FindMissingTextures()
        {
            var nonanimated     = GrhDatas.OfType <StationaryGrhData>();
            var invalidTextures = nonanimated.Where(x => !x.TextureName.ContentExists());

            return(invalidTextures);
        }
示例#2
0
文件: GrhInfo.cs 项目: wtfcolt/game
 /// <summary>
 /// Gets a <see cref="IContentManager"/>.
 /// </summary>
 /// <returns>A <see cref="IContentManager"/>.</returns>
 static IContentManager GetContentManager()
 {
     return(GrhDatas.OfType <StationaryGrhData>().First(x => x.ContentManager != null).ContentManager);
 }
示例#3
0
文件: GrhInfo.cs 项目: wtfcolt/game
        /// <summary>
        /// Deletes a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData"><see cref="GrhData"/> to delete.</param>
        /// <exception cref="ArgumentNullException"><paramref name="grhData" /> is <c>null</c>.</exception>
        public static void Delete(GrhData grhData)
        {
            if (grhData == null)
            {
                throw new ArgumentNullException("grhData");
            }

            var grhIndex = grhData.GrhIndex;

            if (grhIndex.IsInvalid)
            {
                return;
            }

            // Insure the index is valid
            if (!_grhDatas.CanGet((int)grhIndex))
            {
                const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` could not be acquired.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, grhIndex);
                }
                Debug.Fail(string.Format(errmsg, grhData, grhIndex));
                return;
            }

            // Make sure we are deleting the correct GrhData
            var i = (int)grhIndex;

            if (_grhDatas[i] != grhData)
            {
                const string errmsg =
                    "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` is already in use by" +
                    " a different GrhData `{2}`. Most likely, the GrhData we tried to delete is already deleted, and" +
                    " the GrhIndex has been recycled to a new GrhData. Stop trying to delete dead stuff, will ya!?";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, grhIndex, _grhDatas[i]);
                }
                Debug.Fail(string.Format(errmsg, grhData, grhIndex, _grhDatas[i]));
                return;
            }

            // Remove the GrhData from the collection
            _grhDatas.RemoveAt((int)grhIndex);

            // If a stationary GrhData and auto-size is set, delete the texture, too
            try
            {
                var sgd = grhData as StationaryGrhData;
                if (sgd != null && sgd.AutomaticSize)
                {
                    // Make sure no other GrhData is using the texture
                    var origTexture = sgd.GetOriginalTexture();
                    if (GrhDatas.OfType <StationaryGrhData>().All(x => origTexture != x.GetOriginalTexture()))
                    {
                        // Dispose of the texture then recycle the file
                        origTexture.Dispose();
                        try
                        {
                            sgd.TextureName.RecycleFile();
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to recycle texture file for GrhData `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, ex);
                }
                Debug.Fail(string.Format(errmsg, grhData, ex));
            }
        }