/ContentSystem/Rendering/ImageAnimationData.cs
C# | 209 lines | 108 code | 15 blank | 86 comment | 4 complexity | f074e561105a859ce7e4eec68cc11cc8 MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using Delta.Utilities.Graphics;
- using Delta.Utilities.Helpers;
-
- namespace Delta.ContentSystem.Rendering
- {
- /// <summary>
- /// Helper class for accessing image animations, which is just a collection
- /// of images, but with all important meta data for them. All images are
- /// just children and can be accessed easily with this class.
- /// <para />
- /// Please note that Image Animations just contain images and have no data
- /// own their own (just meta data).
- /// </summary>
- public class ImageAnimationData : Content
- {
- #region Get (Static)
- /// <summary>
- /// Get and load content based on the content name. This method makes sure
- /// we do not load the same content twice (the constructor is protected).
- /// </summary>
- /// <param name="contentName">Content name we want to load, this is
- /// passed onto the Content System, which will do the actual loading with
- /// help of the Load method in this class.</param>
- /// <returns>The loaded Content object, always unique for the same
- /// name, this helps comparing data.</returns>
- public static ImageAnimationData Get(string contentName)
- {
- return Get<ImageAnimationData>(contentName,
- ContentType.ImageAnimation);
- }
- #endregion
-
- #region Images (Public)
- /// <summary>
- /// List of images that are children to this ImageAnimation content node.
- /// </summary>
- public string[] Images
- {
- get;
- protected set;
- }
- #endregion
-
- #region AnimationSpeed (Public)
- /// <summary>
- /// Animation speed in FPS. 30 means we got 30 animations per second, 12
- /// means we only have 12 animations that are played per second (default).
- /// Used for 2D animated image sequences, but also for 3D Models using
- /// animations. The default value is 30 and usually used for all animated
- /// content unless it is optimized for 15 fps or less to save memory.
- /// Note: Not used if each of the images has its own AnimationLengthInMs!
- /// </summary>
- public float AnimationSpeed
- {
- get
- {
- return data.AnimationSpeed;
- }
- }
- #endregion
-
- #region AnimationIndicesAndMs (Public)
- /// <summary>
- /// Animation frame indices and their lengths in milliseconds for whatever
- /// crazy animation logic you want to build. Usually unused (0), but if
- /// this is used for all animated images in a sequence, you can control
- /// how quickly each part of the animation is played back. You are not
- /// forced to play the animation in order and you can repeat frames as
- /// many times as you like and make the animation as long as you want (see
- /// TotalAnimationLengthMs). AnimationSpeed (see above) is also ignored,
- /// you need to set each of these frame length times yourself.
- /// </summary>
- public int[] AnimationIndicesAndMs
- {
- get
- {
- return data.AnimationIndicesAndMs;
- }
- }
- #endregion
-
- #region PixelSize (Public)
- /// <summary>
- /// Size of the images in this animation in pixels. Each animation image
- /// can have its own PixelSize, but this is the important size used for
- /// displaying this image animation (children can be bigger or smaller).
- /// </summary>
- public Size PixelSize
- {
- get
- {
- return data.PixelSize;
- }
- }
- #endregion
-
- #region BlendMode (Public)
- /// <summary>
- /// Blend mode used for all images, set in data and can't be changed.
- /// This is important for the MaterialManager sorting logic!
- /// </summary>
- public BlendMode BlendMode
- {
- get
- {
- return data.BlendMode;
- }
- }
- #endregion
-
- #region UseLinearFiltering (Public)
- /// <summary>
- /// Helper property to determinate if we need to enable filtering for
- /// rendering this images (usually in a shader). True is the default and
- /// means we are going to use Trilinear filtering, false means no
- /// filtering, which is often called Nearest or Point filtering.
- /// Note: For fonts and the default image (4x4 pixels) this is
- /// automatically set to false for more accurate and sharp rendering.
- /// </summary>
- public bool UseLinearFiltering
- {
- get
- {
- return data.UseFiltering;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create image animation instance, which just holds some meta data and
- /// the list of images for this animation (see Images property).
- /// Use the static Get method to call this.
- /// </summary>
- /// <param name="setImageAnimationName">
- /// Name for this content object, should not contain any path, project,
- /// scene or any special character! If this is empty or starts with an
- /// > character, we assume this is code generated content
- /// (e.g. ">IntroScene<" or "") and no loading will happen!
- /// </param>
- protected ImageAnimationData(string setImageAnimationName)
- : base(setImageAnimationName, ContentType.ImageAnimation)
- {
- // In Load Images are set (this way it works with content updates)!
- }
- #endregion
-
- #region ToString (Public)
- /// <summary>
- /// To string, will display the image animation images list.
- /// </summary>
- /// <returns>
- /// A <see cref="System.String"/> that represents this ImageAnimationData
- /// instance with the list of image names.
- /// </returns>
- public override string ToString()
- {
- return GetType().GetClassName() + " " + Name + ": " +
- "Images=" + Images.Write();
- }
- #endregion
-
- #region Methods (Private)
-
- #region Load
- /// <summary>
- /// Load animated image content data, will just set the Images property.
- /// </summary>
- /// <param name="alreadyLoadedNativeData">
- /// Ignored here, can't be cloned.
- /// </param>
- protected override void Load(Content alreadyLoadedNativeData)
- {
- // Initialize a new list for all the children and grab all their names
- List<string> ret = new List<string>();
- // Note: Only direct image children nodes are allowed, nothing else!
- foreach (ContentMetaData childrenData in data.Children)
- {
- if (childrenData.Type != ContentType.Image ||
- childrenData.Children.Count > 0)
- {
- Log.Warning("Invalid children node for " + this + " found, only " +
- "Image nodes and no extra children are allowed: " +
- childrenData);
- // Skip this, maybe other data works
- continue;
- }
-
- // Note: We just add names, we don't want to load the images right away,
- // only when they need to be displayed they will be loaded (in the
- // Material class).
- ret.Add(childrenData.Name);
- }
-
- if (ret.Count == 0)
- {
- Log.Warning("No images found for " + this);
- }
-
- Images = ret.ToArray();
- }
- #endregion
-
- #endregion
- }
- }