Compare commits

...

9 Commits

28 changed files with 107 additions and 1093 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

@ -0,0 +1,9 @@
using System;
namespace Syntriax.Engine.Core;
public record EngineTime
(
TimeSpan Total,
TimeSpan Elapsed
);

View File

@ -1,18 +1,19 @@
using System; using System;
using System.Collections;
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;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
public class GameManager : IEntity public class GameManager : IEntity, IEnumerable<IGameObject>
{ {
public Action<GameManager>? OnCameraChanged { get; set; } = null; public Action<GameManager>? OnCameraChanged { get; set; } = null;
public Action<GameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
public Action<GameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
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<IAssignable>? OnUnassigned { get; set; } = null; public Action<IAssignable>? OnUnassigned { get; set; } = null;
@ -20,7 +21,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,52 +137,35 @@ public class GameManager : IEntity
return true; return true;
} }
public void Update(GameTime time) public void Update(EngineTime time)
{ {
Time.SetTime(time);
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)
{
gameObject.BehaviourController.OnBehaviourAdded -= OnBehaviourAdd;
gameObject.BehaviourController.OnBehaviourRemoved -= OnBehaviourRemove;
gameObject.OnFinalized -= OnGameObjectFinalize;
if (gameObject.BehaviourController.TryGetBehaviour<IDisplayable>(out var drawable))
_drawables.Remove(drawable);
_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);
OnGameObjectRegistered?.Invoke(this, gameObject);
}
private void Unregister(IGameObject gameObject)
{
gameObject.OnFinalized -= OnGameObjectFinalize;
_gameObjects.Remove(gameObject);
OnGameObjectUnRegistered?.Invoke(this, gameObject);
} }
private void OnGameObjectFinalize(IInitialize initialize) private void OnGameObjectFinalize(IInitialize initialize)
@ -191,15 +174,8 @@ public class GameManager : IEntity
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) public IEnumerator<IGameObject> GetEnumerator() => _gameObjects.GetEnumerator();
{ IEnumerator IEnumerable.GetEnumerator() => _gameObjects.GetEnumerator();
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

13
Engine.Core/Time.cs Normal file
View File

@ -0,0 +1,13 @@
using System;
namespace Syntriax.Engine.Core;
public static class Time
{
private static EngineTime _engineTime = new(TimeSpan.Zero, TimeSpan.Zero);
public static TimeSpan Total => _engineTime.Total;
public static TimeSpan Elapsed => _engineTime.Elapsed;
public static void SetTime(EngineTime engineTime) => _engineTime = engineTime;
}

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

View File

@ -1,484 +0,0 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from `dotnet new gitignore`
# dotenv files
.env
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
.idea
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# Vim temporary swap files
*.swp

View File

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Engine.Graphics", "Engine.Graphics.csproj", "{79D95F74-10BD-4E69-90ED-CDFC1FB4F449}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{79D95F74-10BD-4E69-90ED-CDFC1FB4F449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79D95F74-10BD-4E69-90ED-CDFC1FB4F449}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79D95F74-10BD-4E69-90ED-CDFC1FB4F449}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79D95F74-10BD-4E69-90ED-CDFC1FB4F449}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67B7E3F7-18AE-4E39-B4C4-CFCD760729D5}
EndGlobalSection
EndGlobal

View File

@ -1,20 +0,0 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Graphics.TwoDimensional.Abstract;
public interface IDisplayableSprite : IDisplayable, IAssignableSprite
{
Action<IDisplayableSprite>? OnSpriteEffectsChanged { get; set; }
Action<IDisplayableSprite>? OnOriginChanged { get; set; }
Action<IDisplayableSprite>? OnColorChanged { get; set; }
Action<IDisplayableSprite>? OnDepthChanged { get; set; }
SpriteEffects SpriteEffects { get; set; }
Vector2 Origin { get; set; }
Color Color { get; set; }
float Depth { get; set; }
}

View File

@ -1,116 +0,0 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Graphics.TwoDimensional.Abstract;
namespace Syntriax.Engine.Graphics.TwoDimensional;
public class DisplayableSpriteBehaviour : Behaviour, IDisplayableSprite, IAssignableSprite
{
public Action<IAssignableSprite>? OnSpriteAssigned { get; set; } = null;
public Action<IDisplayableSprite>? OnSpriteEffectsChanged { get; set; } = null;
public Action<IDisplayableSprite>? OnOriginChanged { get; set; } = null;
public Action<IDisplayableSprite>? OnColorChanged { get; set; } = null;
public Action<IDisplayableSprite>? OnDepthChanged { get; set; } = null;
private ISprite _sprite = null!;
private Color _color = Color.White;
private float _depth = 0f;
private SpriteEffects _spriteEffects = SpriteEffects.None;
private Vector2 _origin = Vector2.One * .5f;
public ISprite Sprite => _sprite;
public SpriteEffects SpriteEffects
{
get => _spriteEffects;
set
{
if (_spriteEffects == value)
return;
_spriteEffects = value;
OnSpriteEffectsChanged?.Invoke(this);
}
}
public Vector2 Origin
{
get => _origin;
set
{
if (_origin == value)
return;
_origin = value;
OnOriginChanged?.Invoke(this);
}
}
public Color Color
{
get => _color;
set
{
if (_color == value)
return;
_color = value;
OnColorChanged?.Invoke(this);
}
}
public float Depth
{
get => _depth;
set
{
if (_depth == value)
return;
_depth = value;
OnDepthChanged?.Invoke(this);
}
}
public void Draw(SpriteBatch spriteBatch)
{
if (!BehaviourController.GameObject.StateEnable.Enabled || !StateEnable.Enabled)
return;
ITransform transform = BehaviourController.GameObject.Transform;
Vector2 position = transform.Position;
Vector2 scale = transform.Scale;
Rectangle rectangle = new Rectangle((int)position.X, -(int)position.Y, (int)(Sprite.Texture2D.Width * scale.X), (int)(Sprite.Texture2D.Height * scale.Y));
spriteBatch.Draw(Sprite.Texture2D, rectangle, null, Color, transform.Rotation, new Vector2(Sprite.Texture2D.Width, Sprite.Texture2D.Height) * Origin, SpriteEffects, Depth);
}
public bool Assign(ISprite sprite)
{
_sprite = sprite;
OnSpriteAssigned?.Invoke(this);
return true;
}
public DisplayableSpriteBehaviour() => OnUnassigned += OnUnassign;
public DisplayableSpriteBehaviour(
Color? color = null,
float? depth = null,
SpriteEffects? spriteEffects = null,
Vector2? origin = null)
{
OnUnassigned += OnUnassign;
_color = color ?? _color;
_depth = depth ?? _depth;
_spriteEffects = spriteEffects ?? _spriteEffects;
_origin = origin ?? _origin;
}
private void OnUnassign(IAssignable assignable) => _sprite = null!;
}

View File

@ -0,0 +1,14 @@
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Input;
public interface IButtonInputs<T> : IAssignableStateEnable
{
void RegisterOnPress(T button, Action<IButtonInputs<T>, T> callback);
void UnregisterOnPress(T button, Action<IButtonInputs<T>, T> callback);
void RegisterOnRelease(T button, Action<IButtonInputs<T>, T> callback);
void UnregisterOnRelease(T button, Action<IButtonInputs<T>, T> callback);
bool IsPressed(T button);
bool WasPressed(T button);
}

View File

@ -1,16 +0,0 @@
using Microsoft.Xna.Framework.Input;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Input;
public interface IKeyboardInputs : IAssignableStateEnable
{
void RegisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback);
void UnregisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback);
void RegisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback);
void UnregisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback);
bool IsPressed(Keys key);
bool WasPressed(Keys key);
}

View File

@ -6,10 +6,6 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" /> <ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,104 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Syntriax.Engine.Core;
namespace Syntriax.Engine.Input;
public class KeyboardInputsBehaviour : BehaviourOverride, IKeyboardInputs
{
private IDictionary<Keys, Action<IKeyboardInputs, Keys>> OnPressed = new Dictionary<Keys, Action<IKeyboardInputs, Keys>>(256);
private IDictionary<Keys, Action<IKeyboardInputs, Keys>> OnReleased = new Dictionary<Keys, Action<IKeyboardInputs, Keys>>(256);
private int cachePressedCurrentlyCount = 0;
private Keys[] cachePressedCurrently = new Keys[256];
private int cachePressedPreviouslyCount = 0;
private Keys[] cachePressedPreviously = new Keys[256];
public void RegisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback)
{
if (OnPressed.TryGetValue(key, out var action))
{
action += callback;
return;
}
OnPressed.Add(key, callback);
}
public void UnregisterOnPress(Keys key, Action<IKeyboardInputs, Keys> callback)
{
if (OnPressed.TryGetValue(key, out var action))
action -= callback;
}
public void RegisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback)
{
if (OnReleased.TryGetValue(key, out var action))
{
action += callback;
return;
}
OnReleased.Add(key, callback);
}
public void UnregisterOnRelease(Keys key, Action<IKeyboardInputs, Keys> callback)
{
if (OnReleased.TryGetValue(key, out var action))
action -= callback;
}
protected override void OnUpdate(GameTime time)
{
KeyboardState keyboardState = Keyboard.GetState();
keyboardState.GetPressedKeys(cachePressedCurrently);
cachePressedCurrentlyCount = keyboardState.GetPressedKeyCount();
for (int i = 0; i < cachePressedCurrentlyCount; i++)
{
Keys currentlyPressedKey = cachePressedCurrently[i];
if (!OnPressed.TryGetValue(currentlyPressedKey, out var action))
continue;
if (WasPressed(currentlyPressedKey))
continue;
action.Invoke(this, currentlyPressedKey);
}
for (int i = 0; i < cachePressedPreviouslyCount; i++)
{
Keys previouslyPressedKey = cachePressedPreviously[i];
if (!OnReleased.TryGetValue(previouslyPressedKey, out var action))
continue;
if (IsPressed(previouslyPressedKey))
continue;
action.Invoke(this, previouslyPressedKey);
}
Array.Copy(cachePressedCurrently, cachePressedPreviously, cachePressedCurrentlyCount);
cachePressedPreviouslyCount = cachePressedCurrentlyCount;
}
public bool IsPressed(Keys key)
{
for (int i = 0; i < cachePressedCurrentlyCount; i++)
if (cachePressedCurrently[i] == key)
return true;
return false;
}
public bool WasPressed(Keys key)
{
for (int i = 0; i < cachePressedPreviouslyCount; i++)
if (cachePressedPreviously[i] == key)
return true;
return false;
}
}

View File

@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Core", "Engine.Core\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Input", "Engine.Input\Engine.Input.csproj", "{12149E55-1EE8-45B4-A82E-15BA981B0C6A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Input", "Engine.Input\Engine.Input.csproj", "{12149E55-1EE8-45B4-A82E-15BA981B0C6A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Engine.Graphics", "Engine.Graphics\Engine.Graphics.csproj", "{F3CC78C2-A9A9-4C2F-8675-6A491B7D29E0}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -26,9 +24,5 @@ Global
{12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Release|Any CPU.Build.0 = Release|Any CPU {12149E55-1EE8-45B4-A82E-15BA981B0C6A}.Release|Any CPU.Build.0 = Release|Any CPU
{F3CC78C2-A9A9-4C2F-8675-6A491B7D29E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3CC78C2-A9A9-4C2F-8675-6A491B7D29E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3CC78C2-A9A9-4C2F-8675-6A491B7D29E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3CC78C2-A9A9-4C2F-8675-6A491B7D29E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal