chore: Added Initial Engine Code

This commit is contained in:
2023-11-23 22:07:49 +03:00
parent a47586851c
commit 5fcf63c5a7
40 changed files with 1773 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
namespace Syntriax.Engine.Core.Abstract;
/// <summary>
/// Indicates the class implementing it has Assignable fields that are necessary for the engine to work properly.
/// </summary>
public interface IAssignable { }

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,26 @@
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

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

View File

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

View File

@@ -0,0 +1,19 @@
using System;
namespace Syntriax.Engine.Core.Abstract;
/// <summary>
/// Responsible for every behaviour an object in the game might have, controlled by <see cref="IBehaviourController"/>.
/// </summary>
public interface IBehaviour : IEntity, IAssignableBehaviourController, IAssignableStateEnable, IInitialize
{
/// <summary>
/// Callback triggered when the <see cref="Priority"/> has changed.
/// </summary>
Action<IBehaviour>? OnPriorityChanged { get; set; }
/// <summary>
/// Call priority of the <see cref="IBehaviour"/>.
/// </summary>
int Priority { get; set; }
}

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
namespace Syntriax.Engine.Core.Abstract;
/// <summary>
/// Responsible for controlling <see cref="IBehaviour"/>s and notify them accordingly about the engine's updates. Connected to an <see cref="IGameObject"/>.
/// </summary>
public interface IBehaviourController : IAssignableGameObject
{
/// <summary>
/// Callback triggered when the <see cref="Update(GameTime)"/> is called.
/// </summary>
Action<IBehaviourController, GameTime>? OnUpdate { get; set; }
/// <summary>
/// Callback triggered when the <see cref="OnPreDraw(GameTime)"/> is called.
/// </summary>
Action<IBehaviourController, GameTime>? OnPreDraw { get; set; }
/// <summary>
/// Callback triggered when the <see cref="IBehaviourController"/> has been registered a new <see cref="IBehaviour"/>.
/// </summary>
Action<IBehaviourController, IBehaviour>? OnBehaviourAdded { get; set; }
/// <summary>
/// Callback triggered when the <see cref="IBehaviourController"/> has been removed an existing <see cref="IBehaviour"/>.
/// </summary>
Action<IBehaviourController, IBehaviour>? OnBehaviourRemoved { get; set; }
/// <summary>
/// Registers the provided <see cref="IBehaviour"/> to be controlled by the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="behaviour">Uninitialized <see cref="IBehaviour"/> to be registered.</param>
/// <typeparam name="T">An implemented class of <see cref="IBehaviour"/></typeparam>
/// <returns>The provided <see cref="IBehaviour"/> class after initialization.</returns>
T AddBehaviour<T>(T behaviour) where T : class, IBehaviour;
/// <summary>
/// Instantiates the provided <see cref="IBehaviour"/> type and registers it to the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="args">Constructor parameters for the given <see cref="IBehaviour"/> class.</param>
/// <typeparam name="T">An implemented class of <see cref="IBehaviour"/></typeparam>
/// <returns>The instantiated <see cref="IBehaviour"/> class after initialization.</returns>
T AddBehaviour<T>(params object?[]? args) where T : class, IBehaviour;
/// <summary>
/// Looks up and tries to get the <see cref="IBehaviour"/> that is controlled by the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="behaviour">If return value is <see cref="true"/> outputs the class found in the <see cref="IBehaviourController"/>. If the return value is falls, this parameter is <see cref="null"/></param>
/// <typeparam name="T">An implemented class or <see cref="interface"/></typeparam>
/// <returns>
/// <see cref="true"/>, if the type of <see cref="IBehaviour"/> is present in the <see cref="IBehaviourController"/>, <see cref="false"/> if not.
/// </returns>
bool TryGetBehaviour<T>([NotNullWhen(returnValue: true)] out T? behaviour);
/// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
/// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
IList<T> GetBehaviours<T>() where T : IBehaviour;
/// <summary>
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
/// </summary>
/// <param name="removeAll">If all of the instances of the given Type is to be removed or not.</param>
/// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
void RemoveBehaviour<T>(bool removeAll = false) where T : IBehaviour;
/// <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.
/// </summary>
/// <param name="gameTime"><see cref="GameTime"/> information from the game.</param>
void Update(GameTime gameTime);
/// <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.
/// </summary>
/// <param name="gameTime"><see cref="GameTime"/> information from the game.</param>
void UpdatePreDraw(GameTime gameTime);
}

View File

@@ -0,0 +1,5 @@
namespace Syntriax.Engine.Core.Abstract;
public interface IEntity : IAssignableStateEnable
{
}

View File

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

View File

@@ -0,0 +1,13 @@
using System;
namespace Syntriax.Engine.Core.Abstract;
public interface IInitialize : IEntity
{
Action<IInitialize>? OnInitialized { get; set; }
Action<IInitialize>? OnFinalized { get; set; }
bool Initialized { get; }
bool Initialize();
bool Finalize();
}

View File

@@ -0,0 +1,9 @@
using System;
namespace Syntriax.Engine.Core.Abstract;
public interface INameable
{
Action<IEntity>? OnNameChanged { get; set; }
string Name { get; set; }
}

View File

@@ -0,0 +1,17 @@
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; }
Action<ISprite>? OnColorChanged { get; set; }
Action<ISprite>? OnDepthChanged { get; set; }
Texture2D Texture2D { get; set; }
Color Color { get; set; }
float Depth { get; set; }
}

View File

@@ -0,0 +1,9 @@
using System;
namespace Syntriax.Engine.Core.Abstract;
public interface IStateEnable : IAssignableEntity
{
Action<IStateEnable>? OnEnabledChanged { get; set; }
bool Enabled { get; set; }
}

View File

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