BREAKING CHANGE: Removed MonoGame Package

This commit is contained in:
Syntriax 2024-01-22 22:45:40 +03:00
parent 1c884d49bb
commit 81f9ef10bf
16 changed files with 53 additions and 296 deletions

View File

@ -1,26 +0,0 @@
using System;
namespace Syntriax.Engine.Core.Abstract;
/// <summary>
/// Indicates the object is an <see cref="IAssignable"/> with an assignable <see cref="ISprite"/> field.
/// </summary>
public interface IAssignableSprite : IAssignable
{
/// <summary>
/// Callback triggered when the <see cref="ISprite"/> value has has been assigned a new value.
/// </summary>
Action<IAssignableSprite>? OnSpriteAssigned { get; set; }
/// <inheritdoc cref="ISprite" />
ISprite Sprite { get; }
/// <summary>
/// Assign a value to the <see cref="ISprite"/> field of this object
/// </summary>
/// <param name="sprite">New <see cref="ISprite"/> to assign.</param>
/// <returns>
/// <see cref="true"/>, if the value given assigned successfully assigned, <see cref="false"/> if not.
/// </returns>
bool Assign(ISprite sprite);
}

View File

@ -2,8 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
namespace Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core.Abstract;
/// <summary> /// <summary>
@ -12,18 +10,18 @@ namespace Syntriax.Engine.Core.Abstract;
public interface IBehaviourController : IAssignableGameObject public interface IBehaviourController : IAssignableGameObject
{ {
/// <summary> /// <summary>
/// Callback triggered when the <see cref="Update(GameTime)"/> is called but right before the <see cref="OnUpdate"/> action is triggered. /// Callback triggered when the <see cref="Update()"/> is called but right before the <see cref="OnUpdate"/> action is triggered.
/// </summary> /// </summary>
Action<IBehaviourController, GameTime>? OnPreUpdate { get; set; } Action<IBehaviourController>? OnPreUpdate { get; set; }
/// <summary> /// <summary>
/// Callback triggered when the <see cref="Update(GameTime)"/> is called. /// Callback triggered when the <see cref="Update()"/> is called.
/// </summary> /// </summary>
Action<IBehaviourController, GameTime>? OnUpdate { get; set; } Action<IBehaviourController>? OnUpdate { get; set; }
/// <summary> /// <summary>
/// Callback triggered when the <see cref="OnPreDraw(GameTime)"/> is called. /// Callback triggered when the <see cref="OnPreDraw()"/> is called.
/// </summary> /// </summary>
Action<IBehaviourController, GameTime>? OnPreDraw { get; set; } Action<IBehaviourController>? OnPreDraw { get; set; }
/// <summary> /// <summary>
@ -84,12 +82,12 @@ public interface IBehaviourController : IAssignableGameObject
/// <summary> /// <summary>
/// To be called in every frame of the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that a new frame is happening. /// To be called in every frame of the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that a new frame is happening.
/// </summary> /// </summary>
/// <param name="gameTime"><see cref="GameTime"/> information from the game.</param> /// <param name=""><see cref=""/> information from the game.</param>
void Update(GameTime gameTime); void Update();
/// <summary> /// <summary>
/// To be called before every draw call from the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that the engine is about to start drawing into the screen. /// To be called before every draw call from the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that the engine is about to start drawing into the screen.
/// </summary> /// </summary>
/// <param name="gameTime"><see cref="GameTime"/> information from the game.</param> /// <param name=""><see cref=""/> information from the game.</param>
void UpdatePreDraw(GameTime gameTime); void UpdatePreDraw();
} }

View File

@ -1,23 +1,11 @@
using System; using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core.Abstract;
public interface ICamera public interface ICamera : IAssignableTransform
{ {
Action<ICamera>? OnMatrixTransformChanged { get; set; }
Action<ICamera>? OnViewportChanged { get; set; }
Action<ICamera>? OnPositionChanged { get; set; }
Action<ICamera>? OnRotationChanged { get; set; }
Action<ICamera>? OnZoomChanged { get; set; } Action<ICamera>? OnZoomChanged { get; set; }
Matrix MatrixTransform { get; }
Viewport Viewport { get; set; }
Vector2 Position { get; set; }
float Rotation { get; set; }
float Zoom { get; set; } float Zoom { get; set; }
void Update(); void Update();

View File

@ -1,8 +0,0 @@
using Microsoft.Xna.Framework.Graphics;
namespace Syntriax.Engine.Core.Abstract;
public interface IDisplayable
{
public void Draw(SpriteBatch spriteBatch);
}

View File

@ -1,12 +1,10 @@
using System; using System;
using Microsoft.Xna.Framework;
namespace Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core.Abstract;
public interface IGameObject : IEntity, IAssignableTransform, IAssignableBehaviourController, INameable, IInitialize public interface IGameObject : IEntity, IAssignableTransform, IAssignableBehaviourController, INameable, IInitialize
{ {
Action<IGameObject, GameTime>? OnUpdated { get; set; } Action<IGameObject>? OnUpdated { get; set; }
void Update(GameTime time); void Update();
} }

View File

@ -1,13 +0,0 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Syntriax.Engine.Core.Abstract;
// TODO Probably gonna have to rethink this
public interface ISprite
{
Action<ISprite>? OnTextureChanged { get; set; }
Texture2D Texture2D { get; set; }
}

View File

@ -1,7 +1,5 @@
using System; using System;
using Microsoft.Xna.Framework;
namespace Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core.Abstract;
public interface ITransform public interface ITransform
@ -10,8 +8,8 @@ public interface ITransform
Action<ITransform>? OnScaleChanged { get; set; } Action<ITransform>? OnScaleChanged { get; set; }
Action<ITransform>? OnRotationChanged { get; set; } Action<ITransform>? OnRotationChanged { get; set; }
Vector2 Position { get; set; } Vector2D Position { get; set; }
Vector2 Scale { get; set; } Vector2D Scale { get; set; }
float Rotation { get; set; } float Rotation { get; set; }
} }

View File

@ -2,17 +2,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
public class BehaviourController : IBehaviourController public class BehaviourController : IBehaviourController
{ {
public Action<IBehaviourController, GameTime>? OnPreUpdate { get; set; } public Action<IBehaviourController>? OnPreUpdate { get; set; }
public Action<IBehaviourController, GameTime>? OnUpdate { get; set; } = null; public Action<IBehaviourController>? OnUpdate { get; set; } = null;
public Action<IBehaviourController, GameTime>? OnPreDraw { get; set; } = null; public Action<IBehaviourController>? OnPreDraw { get; set; } = null;
public Action<IBehaviourController, IBehaviour>? OnBehaviourAdded { get; set; } = null; public Action<IBehaviourController, IBehaviour>? OnBehaviourAdded { get; set; } = null;
public Action<IBehaviourController, IBehaviour>? OnBehaviourRemoved { get; set; } = null; public Action<IBehaviourController, IBehaviour>? OnBehaviourRemoved { get; set; } = null;
@ -115,21 +113,21 @@ public class BehaviourController : IBehaviourController
return true; return true;
} }
public void Update(GameTime gameTime) public void Update()
{ {
if (!GameObject.StateEnable.Enabled) if (!GameObject.StateEnable.Enabled)
return; return;
OnPreUpdate?.Invoke(this, gameTime); OnPreUpdate?.Invoke(this);
OnUpdate?.Invoke(this, gameTime); OnUpdate?.Invoke(this);
} }
public void UpdatePreDraw(GameTime gameTime) public void UpdatePreDraw()
{ {
if (!GameObject.StateEnable.Enabled) if (!GameObject.StateEnable.Enabled)
return; return;
OnPreDraw?.Invoke(this, gameTime); OnPreDraw?.Invoke(this);
} }
public BehaviourController() { } public BehaviourController() { }

View File

@ -1,5 +1,3 @@
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
@ -41,49 +39,49 @@ public abstract class BehaviourOverride : Behaviour
OnFinalize(); OnFinalize();
} }
protected virtual void OnPreUpdatePreEnabledCheck(GameTime time) { } protected virtual void OnPreUpdatePreEnabledCheck() { }
protected virtual void OnPreUpdate(GameTime time) { } protected virtual void OnPreUpdate() { }
private void PreUpdate(IBehaviourController _, GameTime time) private void PreUpdate(IBehaviourController _)
{ {
OnPreUpdatePreEnabledCheck(time); OnPreUpdatePreEnabledCheck();
if (!StateEnable.Enabled) if (!StateEnable.Enabled)
return; return;
if (isInitializedThisFrame) if (isInitializedThisFrame)
FirstActiveFrame(time); FirstActiveFrame();
OnPreUpdate(time); OnPreUpdate();
} }
protected virtual void OnFirstActiveFrame(GameTime time) { } protected virtual void OnFirstActiveFrame() { }
private void FirstActiveFrame(GameTime time) private void FirstActiveFrame()
{ {
OnFirstActiveFrame(time); OnFirstActiveFrame();
isInitializedThisFrame = false; isInitializedThisFrame = false;
} }
protected virtual void OnUpdatePreEnabledCheck(GameTime time) { } protected virtual void OnUpdatePreEnabledCheck() { }
protected virtual void OnUpdate(GameTime time) { } protected virtual void OnUpdate() { }
private void Update(IBehaviourController _, GameTime time) private void Update(IBehaviourController _)
{ {
OnUpdatePreEnabledCheck(time); OnUpdatePreEnabledCheck();
if (!StateEnable.Enabled) if (!StateEnable.Enabled)
return; return;
OnUpdate(time); OnUpdate();
} }
protected virtual void OnPreDrawPreEnabledCheck(GameTime time) { } protected virtual void OnPreDrawPreEnabledCheck() { }
protected virtual void OnPreDraw(GameTime time) { } protected virtual void OnPreDraw() { }
private void PreDraw(IBehaviourController _, GameTime time) private void PreDraw(IBehaviourController _)
{ {
OnPreDrawPreEnabledCheck(time); OnPreDrawPreEnabledCheck();
if (!StateEnable.Enabled) if (!StateEnable.Enabled)
return; return;
OnPreDraw(time); OnPreDraw();
} }
} }

View File

@ -1,98 +0,0 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core;
public class CameraBehaviour : BehaviourOverride, ICamera
{
public Action<ICamera>? OnPositionChanged { get; set; } = null;
public Action<ICamera>? OnMatrixTransformChanged { get; set; } = null;
public Action<ICamera>? OnViewportChanged { get; set; } = null;
public Action<ICamera>? OnRotationChanged { get; set; } = null;
public Action<ICamera>? OnZoomChanged { get; set; } = null;
private Matrix _matrixTransform = Matrix.Identity;
private Viewport _viewport = default;
private float _zoom = 1f;
public Matrix MatrixTransform
{
get => _matrixTransform;
set
{
if (_matrixTransform == value)
return;
_matrixTransform = value;
OnMatrixTransformChanged?.Invoke(this);
}
}
public Vector2 Position
{
get => Transform.Position;
set => Transform.Position = value;
}
public Viewport Viewport
{
get => _viewport;
set
{
if (_viewport.Equals(value))
return;
_viewport = value;
OnViewportChanged?.Invoke(this);
}
}
public float Zoom
{
get => _zoom;
set
{
float newValue = value >= .1f ? value : .1f;
if (_zoom == newValue)
return;
_zoom = newValue;
OnZoomChanged?.Invoke(this);
}
}
public float Rotation
{
get => Transform.Rotation;
set => Transform.Rotation = value;
}
public void Update()
{
MatrixTransform =
Matrix.CreateTranslation(new Vector3(-Position.X, Position.Y, 0f)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(new Vector3(_viewport.Width * .5f, _viewport.Height * .5f, 0f));
}
protected override void OnInitialize()
{
Transform.OnRotationChanged += OnTransformRotationChanged;
Transform.OnPositionChanged += OnTransformPositionChanged;
}
protected override void OnFinalize()
{
Transform.OnRotationChanged -= OnTransformRotationChanged;
Transform.OnPositionChanged -= OnTransformPositionChanged;
}
private void OnTransformRotationChanged(ITransform _) => OnRotationChanged?.Invoke(this);
private void OnTransformPositionChanged(ITransform _) => OnPositionChanged?.Invoke(this);
}

View File

@ -5,8 +5,4 @@
<ImplicitUsings>false</ImplicitUsings> <ImplicitUsings>false</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
</ItemGroup>
</Project> </Project>

View File

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Core.Exceptions; using Syntriax.Engine.Core.Exceptions;
using Syntriax.Engine.Core.Factory; using Syntriax.Engine.Core.Factory;
@ -20,7 +17,6 @@ public class GameManager : IEntity
private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL); private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL);
private IList<IDisplayable> _drawables = new List<IDisplayable>(Constants.DRAWABLE_OBJECTS_SIZE_INITIAL);
private IStateEnable _stateEnable = null!; private IStateEnable _stateEnable = null!;
private GameObjectFactory _gameObjectFactory = null!; private GameObjectFactory _gameObjectFactory = null!;
@ -137,51 +133,31 @@ public class GameManager : IEntity
return true; return true;
} }
public void Update(GameTime time) public void Update()
{ {
foreach (var gameObject in GameObjects) foreach (var gameObject in GameObjects)
gameObject.BehaviourController.Update(time); gameObject.BehaviourController.Update();
} }
public void PreDraw(GameTime time) public void PreDraw()
{ {
foreach (var gameObject in GameObjects) foreach (var gameObject in GameObjects)
gameObject.BehaviourController.UpdatePreDraw(time); gameObject.BehaviourController.UpdatePreDraw();
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin(SpriteSortMode.Deferred, transformMatrix: Camera.MatrixTransform);
foreach (var drawable in _drawables)
drawable.Draw(spriteBatch);
spriteBatch.End();
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
private void Unregister(IGameObject gameObject) private void Unregister(IGameObject gameObject)
{ {
gameObject.BehaviourController.OnBehaviourAdded -= OnBehaviourAdd;
gameObject.BehaviourController.OnBehaviourRemoved -= OnBehaviourRemove;
gameObject.OnFinalized -= OnGameObjectFinalize; gameObject.OnFinalized -= OnGameObjectFinalize;
if (gameObject.BehaviourController.TryGetBehaviour<IDisplayable>(out var drawable))
_drawables.Remove(drawable);
_gameObjects.Remove(gameObject); _gameObjects.Remove(gameObject);
} }
private void Register(IGameObject gameObject) private void Register(IGameObject gameObject)
{ {
gameObject.BehaviourController.OnBehaviourAdded += OnBehaviourAdd;
gameObject.BehaviourController.OnBehaviourRemoved += OnBehaviourRemove;
gameObject.OnFinalized += OnGameObjectFinalize; gameObject.OnFinalized += OnGameObjectFinalize;
if (gameObject.BehaviourController.TryGetBehaviour<IDisplayable>(out var drawable))
_drawables.Add(drawable);
_gameObjects.Add(gameObject); _gameObjects.Add(gameObject);
} }
@ -190,16 +166,4 @@ public class GameManager : IEntity
if (initialize is IGameObject gameObject) if (initialize is IGameObject gameObject)
Unregister(gameObject); Unregister(gameObject);
} }
private void OnBehaviourAdd(IBehaviourController controller, IBehaviour behaviour)
{
if (behaviour is IDisplayable drawable)
_drawables.Add(drawable);
}
private void OnBehaviourRemove(IBehaviourController controller, IBehaviour behaviour)
{
if (behaviour is IDisplayable drawable)
_drawables.Remove(drawable);
}
} }

View File

@ -1,7 +1,5 @@
using System; using System;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Core.Exceptions; using Syntriax.Engine.Core.Exceptions;
@ -19,7 +17,7 @@ public class GameObject : IGameObject
public Action<IInitialize>? OnInitialized { get; set; } = null; public Action<IInitialize>? OnInitialized { get; set; } = null;
public Action<IInitialize>? OnFinalized { get; set; } = null; public Action<IInitialize>? OnFinalized { get; set; } = null;
public Action<IGameObject, GameTime>? OnUpdated { get; set; } = null; public Action<IGameObject>? OnUpdated { get; set; } = null;
private ITransform _transform = null!; private ITransform _transform = null!;
@ -74,12 +72,12 @@ public class GameObject : IGameObject
return true; return true;
} }
public void Update(GameTime time) public void Update()
{ {
if (!_stateEnable.Enabled) if (!_stateEnable.Enabled)
return; return;
OnUpdated?.Invoke(this, time); OnUpdated?.Invoke(this);
} }
public bool Finalize() public bool Finalize()

View File

@ -1,29 +0,0 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core;
// TODO Probably gonna have to rethink this
public class Sprite : ISprite
{
public Action<ISprite>? OnTextureChanged { get; set; }
private Texture2D _texture = null!;
public Texture2D Texture2D
{
get => _texture;
set
{
if (_texture == value)
return;
_texture = value;
OnTextureChanged?.Invoke(this);
}
}
}

View File

@ -1,6 +1,3 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
internal static class Constants internal static class Constants

View File

@ -1,7 +1,5 @@
using System; using System;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
@ -12,11 +10,11 @@ public class Transform : ITransform
public Action<ITransform>? OnScaleChanged { get; set; } = null; public Action<ITransform>? OnScaleChanged { get; set; } = null;
public Action<ITransform>? OnRotationChanged { get; set; } = null; public Action<ITransform>? OnRotationChanged { get; set; } = null;
private Vector2 _position = Vector2.Zero; private Vector2D _position = Vector2D.Zero;
private Vector2 _scale = Vector2.One; private Vector2D _scale = Vector2D.One;
private float _rotation = 0f; private float _rotation = 0f;
public Vector2 Position public Vector2D Position
{ {
get => _position; get => _position;
set set
@ -29,7 +27,7 @@ public class Transform : ITransform
} }
} }
public Vector2 Scale public Vector2D Scale
{ {
get => _scale; get => _scale;
set set