Compare commits
5 Commits
d7d53e467a
...
4000e761a7
Author | SHA1 | Date | |
---|---|---|---|
4000e761a7 | |||
9768dbdded | |||
9853e0af36 | |||
0461454793 | |||
e7587a0827 |
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Syntriax.Engine.Core.Abstract;
|
|
||||||
|
|
||||||
public interface ICamera : IAssignableTransform
|
|
||||||
{
|
|
||||||
Action<ICamera>? OnZoomChanged { get; set; }
|
|
||||||
|
|
||||||
float Zoom { get; set; }
|
|
||||||
|
|
||||||
void Update();
|
|
||||||
}
|
|
21
Engine.Core/Abstract/IGameManager.cs
Normal file
21
Engine.Core/Abstract/IGameManager.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Syntriax.Engine.Core.Abstract;
|
||||||
|
|
||||||
|
public interface IGameManager : IEntity, IEnumerable<IGameObject>
|
||||||
|
{
|
||||||
|
Action<GameManager, IGameObject>? OnGameObjectRegistered { get; set; }
|
||||||
|
Action<GameManager, IGameObject>? OnGameObjectUnRegistered { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
IReadOnlyList<IGameObject> GameObjects { get; }
|
||||||
|
|
||||||
|
|
||||||
|
void RegisterGameObject(IGameObject gameObject);
|
||||||
|
T InstantiateGameObject<T>(params object?[]? args) where T : class, IGameObject;
|
||||||
|
IGameObject RemoveGameObject(IGameObject gameObject);
|
||||||
|
|
||||||
|
void Update(EngineTime time);
|
||||||
|
void PreDraw();
|
||||||
|
}
|
@@ -9,9 +9,8 @@ using Syntriax.Engine.Core.Factory;
|
|||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
|
[System.Diagnostics.DebuggerDisplay("GameObject Count: {_gameObjects.Count}")]
|
||||||
public class GameManager : IEntity, IEnumerable<IGameObject>
|
public class GameManager : IGameManager
|
||||||
{
|
{
|
||||||
public Action<GameManager>? OnCameraChanged { get; set; } = null;
|
|
||||||
public Action<GameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
|
public Action<GameManager, IGameObject>? OnGameObjectRegistered { get; set; } = null;
|
||||||
public Action<GameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
|
public Action<GameManager, IGameObject>? OnGameObjectUnRegistered { get; set; } = null;
|
||||||
|
|
||||||
@@ -21,12 +20,11 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||||||
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
|
public Action<IAssignableStateEnable>? OnStateEnableAssigned { get; set; } = null;
|
||||||
|
|
||||||
|
|
||||||
private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
private readonly List<IGameObject> _gameObjects = new(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||||
|
|
||||||
private IStateEnable _stateEnable = null!;
|
private IStateEnable _stateEnable = null!;
|
||||||
private GameObjectFactory _gameObjectFactory = null!;
|
private GameObjectFactory _gameObjectFactory = null!;
|
||||||
private bool _initialized = false;
|
private bool _initialized = false;
|
||||||
private ICamera _camera = null!;
|
|
||||||
|
|
||||||
private GameObjectFactory GameObjectFactory
|
private GameObjectFactory GameObjectFactory
|
||||||
{
|
{
|
||||||
@@ -39,7 +37,8 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool Initialized => _initialized;
|
public bool Initialized => _initialized;
|
||||||
public IList<IGameObject> GameObjects => _gameObjects;
|
public IReadOnlyList<IGameObject> GameObjects => _gameObjects;
|
||||||
|
|
||||||
public IStateEnable StateEnable
|
public IStateEnable StateEnable
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -55,19 +54,6 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICamera Camera
|
|
||||||
{
|
|
||||||
get => _camera;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_camera == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_camera = value;
|
|
||||||
OnCameraChanged?.Invoke(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RegisterGameObject(IGameObject gameObject)
|
public void RegisterGameObject(IGameObject gameObject)
|
||||||
{
|
{
|
||||||
if (_gameObjects.Contains(gameObject))
|
if (_gameObjects.Contains(gameObject))
|
||||||
@@ -102,6 +88,7 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||||||
foreach (var gameObject in GameObjects)
|
foreach (var gameObject in GameObjects)
|
||||||
gameObject.Initialize();
|
gameObject.Initialize();
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
OnInitialized?.Invoke(this);
|
OnInitialized?.Invoke(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -115,6 +102,7 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||||||
GameObjects[i].Finalize();
|
GameObjects[i].Finalize();
|
||||||
|
|
||||||
OnFinalized?.Invoke(this);
|
OnFinalized?.Invoke(this);
|
||||||
|
_initialized = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
@@ -11,24 +12,24 @@ public static class Math
|
|||||||
public const float PI = 3.1415926535897932f;
|
public const float PI = 3.1415926535897932f;
|
||||||
public const float Tau = 2f * PI;
|
public const float Tau = 2f * PI;
|
||||||
|
|
||||||
public static float Abs(float x) => MathF.Abs(x);
|
public static T Abs<T>(T x) where T : INumber<T> => x > T.Zero ? x : -x;
|
||||||
public static float Acos(float x) => MathF.Acos(x);
|
public static float Acos(float x) => MathF.Acos(x);
|
||||||
public static float Asin(float x) => MathF.Asin(x);
|
public static float Asin(float x) => MathF.Asin(x);
|
||||||
public static float Atan2(float y, float x) => MathF.Atan2(y, x);
|
public static float Atan2(float y, float x) => MathF.Atan2(y, x);
|
||||||
public static float Atanh(float x) => MathF.Atanh(x);
|
public static float Atanh(float x) => MathF.Atanh(x);
|
||||||
public static float Clamp(float x, float min, float max) => (x < min) ? min : (x > max) ? max : x;
|
public static T Clamp<T>(this T x, T min, T max) where T : INumber<T> => (x < min) ? min : (x > max) ? max : x;
|
||||||
public static float Ceiling(float x) => MathF.Ceiling(x);
|
public static float Ceiling(float x) => MathF.Ceiling(x);
|
||||||
public static float CopySign(float x, float y) => MathF.CopySign(x, y);
|
public static float CopySign(float x, float y) => MathF.CopySign(x, y);
|
||||||
public static float Floor(float x) => MathF.Floor(x);
|
public static float Floor(float x) => MathF.Floor(x);
|
||||||
public static float IEEERemainder(float x, float y) => MathF.IEEERemainder(x, y);
|
public static float IEEERemainder(float x, float y) => MathF.IEEERemainder(x, y);
|
||||||
public static float Log(float x, float y) => MathF.Log(x, y);
|
public static float Log(float x, float y) => MathF.Log(x, y);
|
||||||
public static float Max(float x, float y) => MathF.Max(x, y);
|
public static T Max<T>(T x, T y) where T : INumber<T> => (x > y) ? x : y;
|
||||||
public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y);
|
public static float MaxMagnitude(float x, float y) => MathF.MaxMagnitude(x, y);
|
||||||
public static float Min(float x, float y) => MathF.Min(x, y);
|
public static T Min<T>(T x, T y) where T : INumber<T> => (x < y) ? x : y;
|
||||||
public static float MinMagnitude(float x, float y) => MathF.MinMagnitude(x, y);
|
public static float MinMagnitude(float x, float y) => MathF.MinMagnitude(x, y);
|
||||||
public static float Pow(float x, float y) => MathF.Pow(x, y);
|
public static float Pow(float x, float y) => MathF.Pow(x, y);
|
||||||
public static float Round(float x, int digits, MidpointRounding mode) => MathF.Round(x, digits, mode);
|
public static float Round(float x, int digits, MidpointRounding mode) => MathF.Round(x, digits, mode);
|
||||||
public static float Sqr(float x) => x * x;
|
public static T Sqr<T>(T x) where T : INumber<T> => x * x;
|
||||||
public static float Sqrt(float x) => MathF.Sqrt(x);
|
public static float Sqrt(float x) => MathF.Sqrt(x);
|
||||||
public static float Truncate(float x) => MathF.Truncate(x);
|
public static float Truncate(float x) => MathF.Truncate(x);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user