forked from Misaki/GhostEngine
Added a new static class `AssetsPath` for asset management. Added a new icon file (`icon-256.ico`) for UI representation. Added new package references to enhance functionality. Added internals visibility attributes for better testing. Added a new `EngineEditorViewModel` class for MVVM support. Added a new `GameObject` class for component management. Added a new `BitSet` class for efficient bit manipulation. Added various utility classes to support the new entity system. Changed the `ID` property in `ProjectInfo` to internal. Changed the `AddProjectAsync` method to return the created `ProjectInfo`. Changed the connection string retrieval method to use the new `Command` constant. Changed the `DataPath` class to use `readonly` fields for folder paths. Changed the `ActivationHandler` class to use new `DataPath` constants. Changed the `OpenProjectPage` layout and interaction for better UI. Updated the target framework to a newer version for compatibility. Updated the `ProjectService` to use new constants from `DataPath`. Updated the `World` class to improve entity management. Refactored the `ProjectRepository` class to encapsulate SQL commands. Refactored the `Transform` class to use properties for better encapsulation.
80 lines
1.6 KiB
C#
80 lines
1.6 KiB
C#
|
|
namespace Ghost.Engine.Services;
|
|
|
|
internal static class GameLoopService
|
|
{
|
|
private readonly static HashSet<GameObject> _gameObjects = new();
|
|
|
|
private static Timer? _timer;
|
|
private static bool _isRunning = false;
|
|
|
|
// TODO: Implement the actual time system
|
|
public static float fixedDeltaTime = 0.02f;
|
|
|
|
public static void RegisterGameObject(GameObject gameObject)
|
|
{
|
|
_gameObjects.Add(gameObject);
|
|
}
|
|
|
|
public static void UnregisterGameObject(GameObject gameObject)
|
|
{
|
|
_gameObjects.Remove(gameObject);
|
|
}
|
|
|
|
public static void Start()
|
|
{
|
|
if (_isRunning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var gameObject in _gameObjects)
|
|
{
|
|
if (!gameObject.isActive)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
gameObject.Start();
|
|
}
|
|
|
|
_timer ??= new Timer(FixedUpdate, null, 0, (int)(fixedDeltaTime * 1000));
|
|
|
|
while (_isRunning)
|
|
{
|
|
Update();
|
|
}
|
|
}
|
|
|
|
private static void Update()
|
|
{
|
|
foreach (var gameObject in _gameObjects)
|
|
{
|
|
if (!gameObject.isActive)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
gameObject.Update();
|
|
gameObject.LateUpdate();
|
|
}
|
|
}
|
|
|
|
private static void FixedUpdate(object? state)
|
|
{
|
|
foreach (var gameObject in _gameObjects)
|
|
{
|
|
if (!gameObject.isActive)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
gameObject.FixedUpdate();
|
|
}
|
|
}
|
|
|
|
public static void Stop()
|
|
{
|
|
_isRunning = false;
|
|
}
|
|
} |