feat: IGameManager
This commit is contained in:
parent
0461454793
commit
9853e0af36
|
@ -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,7 +9,7 @@ using Syntriax.Engine.Core.Factory;
|
|||
namespace Syntriax.Engine.Core;
|
||||
|
||||
[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;
|
||||
|
@ -21,7 +21,7 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||
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 GameObjectFactory _gameObjectFactory = null!;
|
||||
|
@ -39,7 +39,8 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||
}
|
||||
|
||||
public bool Initialized => _initialized;
|
||||
public IList<IGameObject> GameObjects => _gameObjects;
|
||||
public IReadOnlyList<IGameObject> GameObjects => _gameObjects;
|
||||
|
||||
public IStateEnable StateEnable
|
||||
{
|
||||
get
|
||||
|
@ -102,6 +103,7 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||
foreach (var gameObject in GameObjects)
|
||||
gameObject.Initialize();
|
||||
|
||||
_initialized = true;
|
||||
OnInitialized?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
@ -115,6 +117,7 @@ public class GameManager : IEntity, IEnumerable<IGameObject>
|
|||
GameObjects[i].Finalize();
|
||||
|
||||
OnFinalized?.Invoke(this);
|
||||
_initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue