chore: Added Initial Engine Code
This commit is contained in:
62
Engine.Core/GameManager.cs
Normal file
62
Engine.Core/GameManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Core.Factory;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public class GameManager
|
||||
{
|
||||
public Game Game { get; private set; } = null!;
|
||||
private IList<IGameObject> _gameObjects = new List<IGameObject>(Constants.GAME_OBJECTS_SIZE_INITIAL);
|
||||
|
||||
private GameObjectFactory _gameObjectFactory = null!;
|
||||
private GameObjectFactory GameObjectFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_gameObjectFactory is null)
|
||||
_gameObjectFactory = new GameObjectFactory();
|
||||
return _gameObjectFactory;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<IGameObject> GameObjects => _gameObjects;
|
||||
|
||||
public void RegisterGameObject(IGameObject gameObject)
|
||||
{
|
||||
if (_gameObjects.Contains(gameObject))
|
||||
throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is already registered to the {nameof(GameManager)}.");
|
||||
|
||||
_gameObjects.Add(gameObject);
|
||||
}
|
||||
|
||||
public T InstantiateGameObject<T>() where T : class, IGameObject
|
||||
{
|
||||
T gameObject = GameObjectFactory.Instantiate<T>();
|
||||
_gameObjects.Add(gameObject);
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
// public TGameObject RegisterGameObject<TGameObject, TTransform, TBehaviourController, TStateEnable>()
|
||||
// where TGameObject : class, IGameObject
|
||||
// where TTransform : class, ITransform
|
||||
// where TBehaviourController : class, IBehaviourController
|
||||
// where TStateEnable : class, IStateEnable
|
||||
// {
|
||||
// TGameObject gameObject = Factory.GameObjectFactory.Get<TGameObject>();
|
||||
// _gameObjects.Add(gameObject);
|
||||
// return gameObject;
|
||||
// }
|
||||
|
||||
public void RemoveGameObject(IGameObject gameObject)
|
||||
{
|
||||
if (!_gameObjects.Contains(gameObject))
|
||||
throw new Exception($"{nameof(IGameComponent)} named {gameObject.Name} is not registered to the {nameof(GameManager)}.");
|
||||
|
||||
_gameObjects.Remove(gameObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user