1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Added the ability for UniformTextureAtlases to have padding for each region

This commit is contained in:
Ell 2022-11-19 17:12:57 +01:00
parent b5619db55c
commit 810406fb94
2 changed files with 15 additions and 4 deletions

View file

@ -16,6 +16,7 @@ Additions
- Added TokenizedString.Realign - Added TokenizedString.Realign
- Added GetFlags and GetUniqueFlags to EnumHelper - Added GetFlags and GetUniqueFlags to EnumHelper
- Added GetDownTime, GetUpTime, GetTimeSincePress, WasModifierDown and WasDown to Keybind and Combination - Added GetDownTime, GetUpTime, GetTimeSincePress, WasModifierDown and WasDown to Keybind and Combination
- Added the ability for UniformTextureAtlases to have padding for each region
- **Added the ability to find paths to one of multiple goals using AStar** - **Added the ability to find paths to one of multiple goals using AStar**
Improvements Improvements

View file

@ -32,6 +32,12 @@ namespace MLEM.Textures {
/// The height of reach region, based on the texture's height and the amount of regions /// The height of reach region, based on the texture's height and the amount of regions
/// </summary> /// </summary>
public readonly int RegionHeight; public readonly int RegionHeight;
/// <summary>
/// The padding that each texture region has around itself, in pixels, which will be taken away from each side of <see cref="TextureRegion"/> objects created and returned by this texture atlas.
/// Creating a texture atlas with padding can be useful if texture bleeding issues occur due to texture coordinate rounding.
/// </summary>
public readonly int RegionPadding;
/// <summary> /// <summary>
/// The texture to use for this atlas. /// The texture to use for this atlas.
/// Note that <see cref="Region"/> stores the actual area that we depend on. /// Note that <see cref="Region"/> stores the actual area that we depend on.
@ -68,10 +74,12 @@ namespace MLEM.Textures {
/// <param name="region">The texture region to use for this atlas</param> /// <param name="region">The texture region to use for this atlas</param>
/// <param name="regionAmountX">The amount of texture regions in the x direction</param> /// <param name="regionAmountX">The amount of texture regions in the x direction</param>
/// <param name="regionAmountY">The amount of texture regions in the y direction</param> /// <param name="regionAmountY">The amount of texture regions in the y direction</param>
public UniformTextureAtlas(TextureRegion region, int regionAmountX, int regionAmountY) { /// <param name="regionPadding">The padding that each texture region has around itself, in pixels, which will be taken away from each side of <see cref="TextureRegion"/> objects created and returned by this texture atlas.</param>
public UniformTextureAtlas(TextureRegion region, int regionAmountX, int regionAmountY, int regionPadding = 0) {
this.Region = region; this.Region = region;
this.RegionAmountX = regionAmountX; this.RegionAmountX = regionAmountX;
this.RegionAmountY = regionAmountY; this.RegionAmountY = regionAmountY;
this.RegionPadding = regionPadding;
this.RegionWidth = region.Width / regionAmountX; this.RegionWidth = region.Width / regionAmountX;
this.RegionHeight = region.Height / regionAmountY; this.RegionHeight = region.Height / regionAmountY;
} }
@ -82,14 +90,16 @@ namespace MLEM.Textures {
/// <param name="texture">The texture to use for this atlas</param> /// <param name="texture">The texture to use for this atlas</param>
/// <param name="regionAmountX">The amount of texture regions in the x direction</param> /// <param name="regionAmountX">The amount of texture regions in the x direction</param>
/// <param name="regionAmountY">The amount of texture regions in the y direction</param> /// <param name="regionAmountY">The amount of texture regions in the y direction</param>
public UniformTextureAtlas(Texture2D texture, int regionAmountX, int regionAmountY) : this(new TextureRegion(texture), regionAmountX, regionAmountY) {} /// <param name="regionPadding">The padding that each texture region has around itself, in pixels, which will be taken away from each side of <see cref="TextureRegion"/> objects created and returned by this texture atlas.</param>
public UniformTextureAtlas(Texture2D texture, int regionAmountX, int regionAmountY, int regionPadding = 0) :
this(new TextureRegion(texture), regionAmountX, regionAmountY, regionPadding) {}
private TextureRegion GetOrAddRegion(Rectangle rect) { private TextureRegion GetOrAddRegion(Rectangle rect) {
if (this.regions.TryGetValue(rect, out var region)) if (this.regions.TryGetValue(rect, out var region))
return region; return region;
region = new TextureRegion(this.Region, region = new TextureRegion(this.Region,
rect.X * this.RegionWidth, rect.Y * this.RegionHeight, rect.X * this.RegionWidth + this.RegionPadding, rect.Y * this.RegionHeight + this.RegionPadding,
rect.Width * this.RegionWidth, rect.Height * this.RegionHeight); rect.Width * this.RegionWidth - 2 * this.RegionPadding, rect.Height * this.RegionHeight - 2 * this.RegionPadding);
this.regions.Add(rect, region); this.regions.Add(rect, region);
return region; return region;
} }