Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

ExtendedContentManager

The ExtendedContentManager inherits from the ContentManager class in order to provide additional functionality not found in the ContentManager alone. It provides one additional overload to the Load<> method that allows the developer to specify weather or not to load a game asset fron disk again or use the default load behavior that will cache the loaded object for future use. This is useful in situations where you need to load the asset from disk again but want to get back a new object rather then a pre loaded cached object.

   1:  public class ExtendedContentManager : ContentManager
   2:  {
   3:      public ExtendedContentManager(IServiceProvider serviceProvider)
   4:          : base(serviceProvider)
   5:      {
   6:      }
   7:   
   8:      public virtual T Load<T>(string assetName, bool doNotCache)
   9:      {
  10:          if (doNotCache)
  11:          {
  12:              return ReadAsset<T>(assetName, null);
  13:          }
  14:   
  15:          return base.Load<T>(assetName);
  16:      }
  17:  }

The fallowing code is a extention method that extends any ContentManager class and determines if the class is a ContentManager class or an inherited ExtendedContentManager class. If it is not a ExtendedContentManager class it will use the default Load<> method. But if it is a ExtendedContentManager class it will use the overloaded Load<> method to load the content asset from disk again rather then returning a pre existing cache of that content.

   1:  public static T Load<T>(this ContentManager manager, string assetName, bool doNotCache)
   2:  {
   3:      if (manager is ExtendedContentManager)
   4:      {
   5:          return ((ExtendedContentManager)manager).Load<T>(assetName, doNotCache);
   6:      }
   7:   
   8:      return manager.Load<T>(assetName);
   9:  }

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume