mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Compare commits
No commits in common. "b5619db55cc67573662ca2542fac7572c5fbc2a5" and "6ac2ba615104e5a1f87a319acc83d8be2f3e4d88" have entirely different histories.
b5619db55c
...
6ac2ba6151
4 changed files with 11 additions and 76 deletions
|
@ -27,7 +27,6 @@ Improvements
|
|||
- Added trimming and AOT annotations and made MLEM trimmable
|
||||
- Allow specifying percentage-based padding for a NinePatch
|
||||
- Improved the way InputHandler down time calculation works
|
||||
- Allow explicitly specifying each region for extended auto tiles
|
||||
- **Drastically improved StaticSpriteBatch batching performance**
|
||||
- **Made GenericFont and TokenizedString support UTF-32 characters like emoji**
|
||||
|
||||
|
@ -77,7 +76,6 @@ Improvements
|
|||
- Made RuntimeTexturePacker restore texture region name and pivot when packing
|
||||
- Multi-target net452, making MLEM compatible with MonoGame for consoles
|
||||
- Added trimming and AOT annotations and made MLEM.Data trimmable
|
||||
- Store a RuntimeTexturePacker packed texture region's source region
|
||||
|
||||
Fixes
|
||||
- Fixed data texture atlases not allowing most characters in their region names
|
||||
|
|
|
@ -203,8 +203,7 @@ namespace MLEM.Data {
|
|||
var packedArea = request.PackedArea.Shrink(new Point(request.Padding, request.Padding));
|
||||
request.Result.Invoke(new TextureRegion(this.PackedTexture, packedArea) {
|
||||
Pivot = request.Texture.Pivot,
|
||||
Name = request.Texture.Name,
|
||||
Source = request.Texture
|
||||
Name = request.Texture.Name
|
||||
});
|
||||
if (this.disposeTextures)
|
||||
request.Texture.Texture.Dispose();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
@ -6,8 +5,8 @@ using MLEM.Textures;
|
|||
|
||||
namespace MLEM.Graphics {
|
||||
/// <summary>
|
||||
/// This class contains a <see cref="DrawAutoTile"/> method that allows users to easily draw a tile with automatic connections, as well as a more complex <see cref="DrawExtendedAutoTile(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Textures.TextureRegion,MLEM.Textures.TextureRegion,MLEM.Graphics.AutoTiling.ConnectsTo,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Nullable{Microsoft.Xna.Framework.Vector2},System.Nullable{Microsoft.Xna.Framework.Vector2},float,float)"/> method.
|
||||
/// Note that <see cref="StaticSpriteBatch"/> can also be used for drawing by using the <see cref="AddAutoTile"/> and <see cref="AddExtendedAutoTile(MLEM.Graphics.StaticSpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Textures.TextureRegion,MLEM.Textures.TextureRegion,MLEM.Graphics.AutoTiling.ConnectsTo,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Nullable{Microsoft.Xna.Framework.Vector2},System.Nullable{Microsoft.Xna.Framework.Vector2},float,float,System.Collections.Generic.ICollection{MLEM.Graphics.StaticSpriteBatch.Item})"/> methods instead.
|
||||
/// This class contains a <see cref="DrawAutoTile"/> method that allows users to easily draw a tile with automatic connections, as well as a more complex <see cref="DrawExtendedAutoTile"/> method.
|
||||
/// Note that <see cref="StaticSpriteBatch"/> can also be used for drawing by using the <see cref="AddAutoTile"/> and <see cref="AddExtendedAutoTile"/> methods instead.
|
||||
/// </summary>
|
||||
public static class AutoTiling {
|
||||
|
||||
|
@ -102,25 +101,7 @@ namespace MLEM.Graphics {
|
|||
batch.Draw(overlayTexture.Texture, pos, r4, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="DrawExtendedAutoTile(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Textures.TextureRegion,MLEM.Textures.TextureRegion,MLEM.Graphics.AutoTiling.ConnectsTo,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Nullable{Microsoft.Xna.Framework.Vector2},System.Nullable{Microsoft.Xna.Framework.Vector2},float,float)"/>
|
||||
public static void DrawExtendedAutoTile(SpriteBatch batch, Vector2 pos, TextureRegion backgroundTexture, Func<int, TextureRegion> overlayTextures, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, float overlayDepthOffset = 0) {
|
||||
var orig = origin ?? Vector2.Zero;
|
||||
var sc = scale ?? Vector2.One;
|
||||
var od = layerDepth + overlayDepthOffset;
|
||||
var (xUl, xUr, xDl, xDr) = AutoTiling.CalculateExtendedAutoTileOffsets(connectsTo);
|
||||
if (backgroundTexture != null)
|
||||
batch.Draw(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
|
||||
if (xUl >= 0)
|
||||
batch.Draw(overlayTextures(xUl), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
if (xUr >= 0)
|
||||
batch.Draw(overlayTextures(xUr), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
if (xDl >= 0)
|
||||
batch.Draw(overlayTextures(xDl), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
if (xDr >= 0)
|
||||
batch.Draw(overlayTextures(xDr), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="DrawExtendedAutoTile(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Textures.TextureRegion,MLEM.Textures.TextureRegion,MLEM.Graphics.AutoTiling.ConnectsTo,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Nullable{Microsoft.Xna.Framework.Vector2},System.Nullable{Microsoft.Xna.Framework.Vector2},float,float)"/>
|
||||
/// <inheritdoc cref="DrawExtendedAutoTile"/>
|
||||
public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, TextureRegion backgroundTexture, TextureRegion overlayTexture, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, float overlayDepthOffset = 0, ICollection<StaticSpriteBatch.Item> items = null) {
|
||||
var orig = origin ?? Vector2.Zero;
|
||||
var sc = scale ?? Vector2.One;
|
||||
|
@ -148,34 +129,6 @@ namespace MLEM.Graphics {
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="DrawExtendedAutoTile(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Textures.TextureRegion,Func{int,MLEM.Textures.TextureRegion},MLEM.Graphics.AutoTiling.ConnectsTo,Microsoft.Xna.Framework.Color,Microsoft.Xna.Framework.Color,System.Nullable{Microsoft.Xna.Framework.Vector2},System.Nullable{Microsoft.Xna.Framework.Vector2},float,float)"/>
|
||||
public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, TextureRegion backgroundTexture, Func<int, TextureRegion> overlayTextures, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, float overlayDepthOffset = 0, ICollection<StaticSpriteBatch.Item> items = null) {
|
||||
var orig = origin ?? Vector2.Zero;
|
||||
var sc = scale ?? Vector2.One;
|
||||
var od = layerDepth + overlayDepthOffset;
|
||||
var (xUl, xUr, xDl, xDr) = AutoTiling.CalculateExtendedAutoTileOffsets(connectsTo);
|
||||
if (backgroundTexture != null) {
|
||||
var background = batch.Add(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
|
||||
items?.Add(background);
|
||||
}
|
||||
if (xUl >= 0) {
|
||||
var o1 = batch.Add(overlayTextures(xUl), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
items?.Add(o1);
|
||||
}
|
||||
if (xUr >= 0) {
|
||||
var o2 = batch.Add(overlayTextures(xUr), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
items?.Add(o2);
|
||||
}
|
||||
if (xDl >= 0) {
|
||||
var o3 = batch.Add(overlayTextures(xDl), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
items?.Add(o3);
|
||||
}
|
||||
if (xDr >= 0) {
|
||||
var o4 = batch.Add(overlayTextures(xDr), pos, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||
items?.Add(o4);
|
||||
}
|
||||
}
|
||||
|
||||
private static (Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle) CalculateAutoTile(Vector2 pos, Rectangle textureRegion, ConnectsTo connectsTo, Vector2 scale) {
|
||||
var up = connectsTo(0, -1);
|
||||
var down = connectsTo(0, 1);
|
||||
|
@ -194,20 +147,15 @@ namespace MLEM.Graphics {
|
|||
new Vector2(pos.X + w2 * scale.X, pos.Y + h2 * scale.Y), new Rectangle(textureRegion.X + w2 + xDr * w, textureRegion.Y + h2, w2, h2));
|
||||
}
|
||||
|
||||
private static (int, int, int, int) CalculateExtendedAutoTileOffsets(ConnectsTo connectsTo) {
|
||||
private static (Rectangle, Rectangle, Rectangle, Rectangle) CalculateExtendedAutoTile(Rectangle textureRegion, ConnectsTo connectsTo) {
|
||||
var up = connectsTo(0, -1);
|
||||
var down = connectsTo(0, 1);
|
||||
var left = connectsTo(-1, 0);
|
||||
var right = connectsTo(1, 0);
|
||||
return (
|
||||
up && left ? connectsTo(-1, -1) ? -1 : 12 : left ? 0 : up ? 8 : 4,
|
||||
up && right ? connectsTo(1, -1) ? -1 : 13 : right ? 1 : up ? 9 : 5,
|
||||
down && left ? connectsTo(-1, 1) ? -1 : 14 : left ? 2 : down ? 10 : 6,
|
||||
down && right ? connectsTo(1, 1) ? -1 : 15 : right ? 3 : down ? 11 : 7);
|
||||
}
|
||||
|
||||
private static (Rectangle, Rectangle, Rectangle, Rectangle) CalculateExtendedAutoTile(Rectangle textureRegion, ConnectsTo connectsTo) {
|
||||
var (xUl, xUr, xDl, xDr) = AutoTiling.CalculateExtendedAutoTileOffsets(connectsTo);
|
||||
var xUl = up && left ? connectsTo(-1, -1) ? -1 : 12 : left ? 0 : up ? 8 : 4;
|
||||
var xUr = up && right ? connectsTo(1, -1) ? -1 : 13 : right ? 1 : up ? 9 : 5;
|
||||
var xDl = down && left ? connectsTo(-1, 1) ? -1 : 14 : left ? 2 : down ? 10 : 6;
|
||||
var xDr = down && right ? connectsTo(1, 1) ? -1 : 15 : right ? 3 : down ? 11 : 7;
|
||||
var (w, h) = (textureRegion.Width, textureRegion.Height);
|
||||
return (
|
||||
xUl < 0 ? Rectangle.Empty : new Rectangle(textureRegion.X + xUl * w, textureRegion.Y, w, h),
|
||||
|
|
|
@ -58,11 +58,6 @@ namespace MLEM.Textures {
|
|||
/// The name of this texture region. By default, this name is <see cref="string.Empty"/>.
|
||||
/// </summary>
|
||||
public string Name = string.Empty;
|
||||
/// <summary>
|
||||
/// A <see cref="TextureRegion"/> that this texture region was created from.
|
||||
/// This value is set in the various constructors that accept another <see cref="TextureRegion"/> to create sub-regions from, in <see cref="OffsetCopy"/>, as well as by MLEM.Data's <c>RuntimeTexturePacker</c>.
|
||||
/// </summary>
|
||||
public TextureRegion Source;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new texture region from a texture and a rectangle which defines the region's area
|
||||
|
@ -121,9 +116,7 @@ namespace MLEM.Textures {
|
|||
/// <param name="region">The texture region to create a sub-region of</param>
|
||||
/// <param name="uv">The top left corner of this area</param>
|
||||
/// <param name="size">The size of this area</param>
|
||||
public TextureRegion(TextureRegion region, Point uv, Point size) : this(region.Texture, region.Position + uv, size) {
|
||||
this.Source = region;
|
||||
}
|
||||
public TextureRegion(TextureRegion region, Point uv, Point size) : this(region.Texture, region.Position + uv, size) {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="TextureRegion"/> that has the same <see cref="Texture"/>, <see cref="Pivot"/> and <see cref="Size"/> as this texture, but the returned region's <see cref="Position"/> will be offset by <paramref name="offset"/>.
|
||||
|
@ -132,10 +125,7 @@ namespace MLEM.Textures {
|
|||
/// <param name="offset">The offset to apply to the <see cref="Position"/></param>
|
||||
/// <returns>An offset copy of this texture region</returns>
|
||||
public TextureRegion OffsetCopy(Point offset) {
|
||||
return new TextureRegion(this.Texture, this.Position + offset, this.Size) {
|
||||
Pivot = this.Pivot,
|
||||
Source = this
|
||||
};
|
||||
return new TextureRegion(this.Texture, this.Position + offset, this.Size) {Pivot = this.Pivot};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue