Skip to content

Commit

Permalink
Merge branch 'feature/breaking-api-changes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
chaifoxes committed Feb 5, 2024
2 parents 0cae4f1 + 5421229 commit 5fea011
Show file tree
Hide file tree
Showing 41 changed files with 303 additions and 442 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@
- Added `UnorderedList` collection.
- Added `GetArea()`, `GetSignedArea()`, `IsClockwise()` methods to `GameMath`.
- Added new collision system.
- Added new drawing methods.

### Changed

- **BREAKING CHANGE:** `ResourceInfoMgr` now accepts wildcards instead of directory names. For example, `ResourceInfoMgr.GetResourcePaths("Graphics/Trees");` should now be replaced with `ResourceInfoMgr.GetResourcePaths("Graphics/Trees/*");`
- **BREAKING CHANGE:** Renamed `GetSafeNormalize()` to `SafeNormalize()`.
- **BREAKING CHANGE:** Removed instances of `Width` and `Height` in `Sprite`, `Frame`, `WindowMgr`, `Camera`, `Surface`, and replaced them with `Size`.
- **BREAKING CHANGE:** Changed boolean `isOutline` to `ShapeFill` enum for shapes.

### Fixed

- Fixed `AddComponent<>()` not taking generic type into account.
- `DirectoryResourceBox` now ignores non-xnb files properly.
- Fixed division by zero in dampers.

### Removed

- **BREAKING CHANGE:** Removed camera layer filters.
- **BREAKING CHANGE:** Removed `Drawable` class and non-static shape fields and methods.

## [v2.2.0] - *17.09.2022*

Expand Down
4 changes: 2 additions & 2 deletions Installer/packInstaller.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


!define APPNAME "Monofoxe"
!define APPVERSION "v2"
!define INSTALLERVERSION "2.2.0.0"
!define APPVERSION "v3-dev"
!define INSTALLERVERSION "3.0.0.0-dev.1"

!define MUI_ICON "pics\icon.ico"
!define MUI_UNICON "pics\icon.ico"
Expand Down
22 changes: 11 additions & 11 deletions Monofoxe/Monofoxe.Engine/Cameras/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public int Priority
/// <summary>
/// View size.
/// </summary>
public Vector2 Size => new Vector2(Surface.Width, Surface.Height);
public Vector2 Size => Surface.Size;

/// <summary>
/// Camera offset.
Expand Down Expand Up @@ -150,7 +150,7 @@ public PostprocessingMode PostprocessingMode

if (_postprocessingMode != PostprocessingMode.None)
{
_postprocessorBuffer = new Surface(Surface.Width, Surface.Height);
_postprocessorBuffer = new Surface(Surface.Size);
}
else
{
Expand All @@ -160,7 +160,7 @@ public PostprocessingMode PostprocessingMode

if (_postprocessingMode == PostprocessingMode.CameraAndLayers)
{
_postprocessorLayerBuffer = new Surface(Surface.Width, Surface.Height);
_postprocessorLayerBuffer = new Surface(Surface.Size);
}
else
{
Expand All @@ -177,24 +177,24 @@ public PostprocessingMode PostprocessingMode
internal Surface _postprocessorLayerBuffer;


public Camera(int w, int h, int priority = 0)
public Camera(Vector2 size, int priority = 0)
{
Surface = new Surface(w, h);
Surface = new Surface(size);

Priority = priority; // Also adds camera to camera list.
}

public event Action<int, int> OnResize;
public event Action<Vector2> OnResize;

/// <summary>
/// Resizes the view.
/// </summary>
public void Resize(int w, int h)
public void Resize(Vector2 size)
{
Surface.Resize(w, h);
_postprocessorBuffer?.Resize(w, h);
_postprocessorLayerBuffer?.Resize(w, h);
OnResize?.Invoke(w, h);
Surface.Resize(size);
_postprocessorBuffer?.Resize(size);
_postprocessorLayerBuffer?.Resize(size);
OnResize?.Invoke(size);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Monofoxe/Monofoxe.Engine/Cameras/Camera2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Vector2 Position2D
}


public Camera2D(int w, int h, int priority = 0) : base(w, h, priority)
public Camera2D(Vector2 size, int priority = 0) : base(size, priority)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public float Length

set
{
var e = (_line.RelativeVertices[1] - _line.RelativeVertices[0]).GetSafeNormalize();
var e = (_line.RelativeVertices[1] - _line.RelativeVertices[0]).SafeNormalize();
_line.RelativeVertices[1] = _line.RelativeVertices[0] + e * value;
}
}
Expand Down
27 changes: 5 additions & 22 deletions Monofoxe/Monofoxe.Engine/Drawing/CircleShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,13 @@ namespace Monofoxe.Engine.Drawing
/// <summary>
/// Drawable circle shape. Can be drawn by using static methods or be instantiated.
/// </summary>
public class CircleShape : Drawable
public static class CircleShape
{

public float Radius = 1;

/// <summary>
/// If false, circle will be filled with solid color. If true, only outline will be drawn.
/// </summary>
public bool IsOutline = false;

public Color Color = Color.White;

public float ZDepth = 0;

static CircleShape()
{
CircleVerticesCount = 16;
}

public override void Draw() =>
Draw(Position, Radius, IsOutline, Color, ZDepth);



/// <summary>
/// Amount of vertices in one circle.
/// </summary>
Expand Down Expand Up @@ -69,14 +52,14 @@ public static int CircleVerticesCount
/// <summary>
/// Draws a circle.
/// </summary>
public static void Draw(Vector2 p, float r, bool isOutline) =>
Draw(p, r, isOutline, GraphicsMgr.CurrentColor);
public static void Draw(Vector2 p, float r, ShapeFill fill) =>
Draw(p, r, fill, GraphicsMgr.CurrentColor);


/// <summary>
/// Draws a circle.
/// </summary>
public static void Draw(Vector2 p, float r, bool isOutline, Color color, float zDepth = 0)
public static void Draw(Vector2 p, float r, ShapeFill fill, Color color, float zDepth = 0)
{

for(var i = 0; i < _circleVerticesCount; i += 1)
Expand All @@ -89,7 +72,7 @@ public static void Draw(Vector2 p, float r, bool isOutline, Color color, float z
_circleVertices[i].Color = color;
}
GraphicsMgr.VertexBatch.Texture = null;
if (isOutline)
if (fill == ShapeFill.Outline)
{
GraphicsMgr.VertexBatch.AddPrimitive(PrimitiveType.LineList, _circleVertices, _outlineCircleIndices);
}
Expand Down
20 changes: 0 additions & 20 deletions Monofoxe/Monofoxe.Engine/Drawing/Drawable.cs

This file was deleted.

21 changes: 8 additions & 13 deletions Monofoxe/Monofoxe.Engine/Drawing/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ namespace Monofoxe.Engine.Drawing
/// <summary>
/// Drawable frame.
/// </summary>
public class Frame : Drawable, ICloneable
public class Frame : ICloneable
{
public Vector2 Position;

/// <summary>
/// Texture atlas where frame is stored.
/// </summary>
Expand All @@ -21,16 +23,9 @@ public class Frame : Drawable, ICloneable
public readonly RectangleF TexturePosition;

/// <summary>
/// Width of the frame.
/// </summary>
public float Width => TexturePosition.Width;

/// <summary>
/// Height of the frame.
/// Size of the frame.
/// </summary>
public float Height => TexturePosition.Height;


public Vector2 Size => TexturePosition.Size;

public Vector2 Scale = Vector2.One;

Expand Down Expand Up @@ -67,7 +62,7 @@ public Frame(Texture2D texture, RectangleF texturePosition, Vector2 origin)
Origin = origin;
}

public override void Draw() =>
public void Draw() =>
Draw(Position, Origin, Scale, Rotation, Color, ZDepth);


Expand Down Expand Up @@ -111,14 +106,14 @@ public void Draw(Vector2 position, Vector2 origin, Vector2 scale, Angle rotation
{
flipFlags = flipFlags | SpriteFlipFlags.FlipHorizontally;
scale.X *= -1;
origin.X = Width - origin.X;
origin.X = Size.X - origin.X;
}

if (scale.Y < 0)
{
flipFlags = flipFlags | SpriteFlipFlags.FlipVertically;
scale.Y *= -1;
origin.Y = Height - origin.Y;
origin.Y = Size.Y - origin.Y;
}
// Proper negative scaling.

Expand Down
18 changes: 7 additions & 11 deletions Monofoxe/Monofoxe.Engine/Drawing/GraphicsMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public static void Update(GameTime gameTime)
{
CanvasMatrix = Matrix.CreateScale(
new Vector3(
windowManager.PreferredBackBufferWidth / (float)windowManager.CanvasWidth,
windowManager.PreferredBackBufferHeight / (float)windowManager.CanvasHeight,
windowManager.PreferredBackBufferWidth / windowManager.CanvasSize.X,
windowManager.PreferredBackBufferHeight / windowManager.CanvasSize.Y,
1
)
);
Expand All @@ -113,26 +113,22 @@ public static void Update(GameTime gameTime)
// Scales display to match canvas, but keeps aspect ratio.
if (windowManager.CanvasMode == CanvasMode.KeepAspectRatio)
{
var backbufferSize = new Vector2(
windowManager.PreferredBackBufferWidth,
windowManager.PreferredBackBufferHeight
);
float ratio,
offsetX = 0,
offsetY = 0;

float backbufferRatio = windowManager.PreferredBackBufferWidth / (float)windowManager.PreferredBackBufferHeight;
float canvasRatio = windowManager.CanvasWidth / (float)windowManager.CanvasHeight;
float canvasRatio = windowManager.CanvasSize.X / windowManager.CanvasSize.Y;

if (canvasRatio > backbufferRatio)
{
ratio = windowManager.PreferredBackBufferWidth / (float)windowManager.CanvasWidth;
offsetY = (windowManager.PreferredBackBufferHeight - (windowManager.CanvasHeight * ratio)) / 2f;
ratio = windowManager.PreferredBackBufferWidth / windowManager.CanvasSize.X;
offsetY = (windowManager.PreferredBackBufferHeight - (windowManager.CanvasSize.Y * ratio)) / 2f;
}
else
{
ratio = windowManager.PreferredBackBufferHeight / (float)windowManager.CanvasHeight;
offsetX = (windowManager.PreferredBackBufferWidth - (windowManager.CanvasWidth * ratio)) / 2f;
ratio = windowManager.PreferredBackBufferHeight / windowManager.CanvasSize.Y;
offsetX = (windowManager.PreferredBackBufferWidth - (windowManager.CanvasSize.X * ratio)) / 2f;
}

CanvasMatrix = Matrix.CreateScale(new Vector3(ratio, ratio, 1)) * Matrix.CreateTranslation(new Vector3(offsetX, offsetY, 0));
Expand Down
27 changes: 2 additions & 25 deletions Monofoxe/Monofoxe.Engine/Drawing/LineShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,13 @@
namespace Monofoxe.Engine.Drawing
{
/// <summary>
/// Drawable line shape. Can be drawn by using static methods or be instantiated.
/// Drawable line shape.
/// NOTE: The line has no width.
/// </summary>
public class LineShape : Drawable
public static class LineShape
{
/// <summary>
/// First line point.
/// NOTE: all line points treat position as an origin point;
/// </summary>
public Vector2 Point1;

/// <summary>
/// Second line point.
/// NOTE: all line points treat position as an origin point;
/// </summary>
public Vector2 Point2;

public Color Color = Color.White;

public float ZDepth = 0;

private static VertexPositionColorTexture[] _lineVertices = new VertexPositionColorTexture[2];
private static short[] _lineIndices = { 0, 1 };


public override void Draw() =>
Draw(Point1 + Position, Point2 + Position, Color, Color, ZDepth);


/// <summary>
/// Draws a line.
Expand All @@ -53,7 +32,5 @@ public static void Draw(Vector2 p1, Vector2 p2, Color c1, Color c2, float zDepth
GraphicsMgr.VertexBatch.Texture = null;
GraphicsMgr.VertexBatch.AddPrimitive(PrimitiveType.LineList, _lineVertices, _lineIndices);
}


}
}
10 changes: 5 additions & 5 deletions Monofoxe/Monofoxe.Engine/Drawing/Primitive2D.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Monofoxe.Engine.Utils;

namespace Monofoxe.Engine.Drawing
{
/// <summary>
/// Base 2D primitive class. Can be used to create other types of primitives.
/// </summary>
public abstract class Primitive2D : Drawable
public abstract class Primitive2D
{
public Vector2 Position;

/// <summary>
/// List of all primitive's vertices.
/// NOTE: all vertices treat position as an origin point;
Expand Down Expand Up @@ -103,7 +103,7 @@ protected VertexPositionColorTexture[] GetConvertedVertices()
}


public override void Draw()
public void Draw()
{
GraphicsMgr.VertexBatch.Texture = _texture;
GraphicsMgr.VertexBatch.AddPrimitive(_primitiveType, GetConvertedVertices(), GetIndices());
Expand Down
Loading

0 comments on commit 5fea011

Please sign in to comment.