Skip to content

Commit

Permalink
MG-59: ECS Migration (#13)
Browse files Browse the repository at this point in the history
* refactor: components migration

* refactor: entities migration

* chore: ref replace

* feat(tests): player entity

* refactor: base entities & di structure migration

* chore(git): imguinet added as a submodule

* chore: imguinet is ran only on debug

* feat: imguinet entities list debug menu

* feat: animated movement system

* refactor: systems, movement, impl & render

* refactor: camera system & impls

* feat: ui

- FPS counter
- UI Debugging
- refactor & things to cleanup yet, but still improving

* refactor: feature abstract class for code maintaining

* refactor: feature handling with morpeh & systems

- Grouping for rendering, fixed, late, etc systems update

* chore: update pkgs

* refactor: recursive features handled correctly

* refactor: imgui debug & code maintenance

* chore(e2e): integration test example

* refactor: basic di for root feature

* refactor(test): moq & input scanner

* refactor: ui factory

* chore(workflow): submodule recursive checkout & secret

- Removed Jenny generation for Entitas

* fix: Scellecs.Morpeh.Extended.csproj depended on MG

- Removed local paths

* chore(.net): targeting 8.0, 7.0, 6.0

* chore(workflow): .net version specified

* chore: deleted dotnet-tools.json from game project

* chore: targeting net6.0

* chore: targeting net8.0

* chore: added badge

* chore(workflow): spacing in yml

* fix(workflow): framework targeting & etc

* refactor: targeting only 8.0

* refactor: game infra & debug ui

* refactor: game entry class

- Cleaned-up warnings on build

* refactor: components & debug structure
- ignore dirty submodule

* refactor: updated imgui.net
  • Loading branch information
cherrynik authored Feb 24, 2024
1 parent 601f47c commit 9620e94
Show file tree
Hide file tree
Showing 141 changed files with 2,038 additions and 4,501 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Restore tools
run: dotnet tool restore

- name: Restore dependencies
run: dotnet restore

- name: Generate ECS files by Jenny
run: make gen

- name: Build
run: dotnet build --no-restore
env:
Expand All @@ -32,4 +39,4 @@ jobs:
run: dotnet test --no-build --verbosity normal

- name: Run
run: dotnet run --project ./src/Apps/GameDesktop/GameDesktop.csproj -c Release -p:DefineConstants=IS_CI
run: dotnet run --project ./src/Apps/GameDesktop/GameDesktop.csproj --framework net8.0 -c Release -p:DefineConstants=IS_CI
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "src/Libs/External/MonoGame.ImGuiNet"]
path = src/Libs/External/MonoGame.ImGuiNet
url = [email protected]:Mezo-hx/MonoGame.ImGuiNet.git
ignore = dirty
1 change: 0 additions & 1 deletion .idea/.idea.MonoGame/.idea/.name

This file was deleted.

28 changes: 21 additions & 7 deletions MonoGame.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "src\Libs\Comp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Systems", "src\Libs\Systems\Systems.csproj", "{CE9F6FF0-F117-4AFA-8758-EDA88BF4A642}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entitas.Extended", "src\Libs\External\Entitas.Extended\Entitas.Extended.csproj", "{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "External", "src\Libs\External", "{FE9CE932-6F98-4455-A80F-2A0CDB6DB46E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features", "src\Libs\Features\Features.csproj", "{F4C957C8-3B10-4614-99F4-E2F2398F38ED}"
Expand All @@ -33,6 +31,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Systems.Debugging", "src\Li
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features.Debugging", "src\Libs\Features.Debugging\Features.Debugging.csproj", "{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scellecs.Morpeh.Extended", "src\Libs\External\Scellecs.Morpeh.Extended\Scellecs.Morpeh.Extended.csproj", "{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.Entities", "src\UnitTests\UnitTests.Entities\UnitTests.Entities.csproj", "{57F0A75A-5AD6-4187-9DC6-3CBA44333061}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monogame.ImGuiNet", "src\Libs\External\MonoGame.ImGuiNet\Monogame.ImGuiNet.csproj", "{56FF7C50-4B5F-4480-A5BE-BA95925152A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -62,10 +66,6 @@ Global
{CE9F6FF0-F117-4AFA-8758-EDA88BF4A642}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE9F6FF0-F117-4AFA-8758-EDA88BF4A642}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE9F6FF0-F117-4AFA-8758-EDA88BF4A642}.Release|Any CPU.Build.0 = Release|Any CPU
{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B}.Release|Any CPU.Build.0 = Release|Any CPU
{F4C957C8-3B10-4614-99F4-E2F2398F38ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4C957C8-3B10-4614-99F4-E2F2398F38ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4C957C8-3B10-4614-99F4-E2F2398F38ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -82,6 +82,18 @@ Global
{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28}.Release|Any CPU.Build.0 = Release|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4}.Release|Any CPU.Build.0 = Release|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57F0A75A-5AD6-4187-9DC6-3CBA44333061}.Release|Any CPU.Build.0 = Release|Any CPU
{56FF7C50-4B5F-4480-A5BE-BA95925152A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56FF7C50-4B5F-4480-A5BE-BA95925152A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56FF7C50-4B5F-4480-A5BE-BA95925152A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56FF7C50-4B5F-4480-A5BE-BA95925152A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5E3B6238-A92E-4703-8527-1C2410D7906A} = {F5258F7E-B0BA-466D-8CF8-4DAB84722BE3}
Expand All @@ -93,10 +105,12 @@ Global
{3116D134-6362-41E8-8C18-EA0196F0C53F} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{CE9F6FF0-F117-4AFA-8758-EDA88BF4A642} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{FE9CE932-6F98-4455-A80F-2A0CDB6DB46E} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{6EEBFA40-2814-43D0-A9DC-4A98F4837A1B} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E}
{F4C957C8-3B10-4614-99F4-E2F2398F38ED} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{8232C7AA-E217-465B-95A3-C42D1000FA3B} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{7AD01EBF-370B-4F35-9AEC-172A889D643F} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{8E6812DB-F7B8-411D-BD15-4BCFA2BF6C28} = {7AE4DC46-59EB-4F69-9240-C7363F0778AA}
{5D45D0B2-6B53-4487-B9C2-3F685B2EC1E4} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E}
{57F0A75A-5AD6-4187-9DC6-3CBA44333061} = {FC0D63F3-9B01-46BD-9435-A7E26C905825}
{56FF7C50-4B5F-4480-A5BE-BA95925152A1} = {FE9CE932-6F98-4455-A80F-2A0CDB6DB46E}
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Getting Started
[![.NET](https://github.com/cherrynik/monogame/actions/workflows/dotnet.yml/badge.svg)](https://github.com/cherrynik/monogame/actions/workflows/dotnet.yml)

## Getting Started

- [Wiki](./docs/TableOfContent.md)
- [MonoGame repository](https://github.com/MonoGame/MonoGame)
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
}
36 changes: 0 additions & 36 deletions src/Apps/GameDesktop/.config/dotnet-tools.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using Components;
using Components.Data;
using Components.Render.Animation;
using Components.Render.Static;
using Components.Tags;
using GameDesktop.Resources.Internal;
using LightInject;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Aseprite.Sprites;
using Services.Math;

Expand All @@ -18,11 +20,50 @@ internal class ComponentsCompositionRoot : ICompositionRoot

public void Compose(IServiceRegistry serviceRegistry)
{
RegisterSpriteComponent(serviceRegistry);
RegisterMovementAnimationComponent(serviceRegistry);
RegisterCameraComponent(serviceRegistry);
RegisterTagComponents(serviceRegistry);
RegisterDataComponents(serviceRegistry);
RegisterStaticRenderComponents(serviceRegistry);
RegisterAnimatedRenderComponents(serviceRegistry);

// Removed camera as it's a system, existing globally and singly
}

private static void RegisterDataComponents(IServiceRegistry serviceRegistry)
{
RegisterTransformComponent(serviceRegistry);
RegisterRectangleCollisionComponent(serviceRegistry);
RegisterInventoryComponent(serviceRegistry);
}

private static void RegisterTagComponents(IServiceRegistry serviceRegistry)
{
RegisterCameraComponent(serviceRegistry);
RegisterPlayerMovementComponent(serviceRegistry);
}


private static void RegisterStaticRenderComponents(IServiceRegistry serviceRegistry)
{
RegisterSpriteComponent(serviceRegistry);
}

private static void RegisterAnimatedRenderComponents(IServiceRegistry serviceRegistry)
{
RegisterMovementAnimationsComponent(serviceRegistry);
RegisterCharacterAnimatorComponent(serviceRegistry);
}

private static void RegisterCameraComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(_ => new Viewport(0, 0, 800, 480), "CameraComponent");
serviceRegistry.RegisterSingleton(factory =>
new CameraComponent(factory.GetInstance<Viewport>("CameraComponent")));
}

private static void RegisterPlayerMovementComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(_ => new InputMovableComponent());
serviceRegistry.RegisterSingleton(_ => new MovableComponent());
}

private static void RegisterSpriteComponent(IServiceRegistry serviceRegistry)
Expand All @@ -33,42 +74,57 @@ private static void RegisterSpriteComponent(IServiceRegistry serviceRegistry)
var getAnimations =
factory.GetInstance<Func<string, string, Dictionary<Direction, AnimatedSprite>>>("Character");
Dictionary<Direction, AnimatedSprite> idle = getAnimations(PlayerSpriteSheetPath, "Idle");
var defaultSprite = idle[Direction.Down];
AnimatedSprite defaultSprite = idle[Direction.Down];

return new SpriteComponent(defaultSprite);
});
}

private static void RegisterMovementAnimationComponent(IServiceRegistry serviceRegistry)
private static void RegisterMovementAnimationsComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterTransient(factory =>
{
var getAnimations =
factory.GetInstance<Func<string, string, Dictionary<Direction, AnimatedSprite>>>("Character");

return new MovementAnimationComponent(getAnimations(PlayerSpriteSheetPath, "Idle"),
return new MovementAnimationsComponent(getAnimations(PlayerSpriteSheetPath, "Idle"),
getAnimations(PlayerSpriteSheetPath, "Walking"));
});
}, "PlayerEntity");
}

private static void RegisterCameraComponent(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterSingleton(_ => new CameraComponent { Size = new Rectangle(0, 0, 640, 480) });

// private static void RegisterCameraComponent(IServiceRegistry serviceRegistry) =>
// serviceRegistry.RegisterSingleton(_ => new CameraComponent { Size = new Rectangle(0, 0, 640, 480) });

private static void RegisterTransformComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(_ =>
{
return new TransformComponent { Position = new(316, 116) };
}, "Player");
new TransformComponent { Position = new(316, 116) }, "PlayerEntity");

serviceRegistry.RegisterSingleton(_ =>
{
return new TransformComponent { Position = new(300, 100) };
}, "StaticEntity");
new TransformComponent { Position = new(300, 100) }, "DummyEntity");
}

private static void RegisterRectangleCollisionComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterTransient(_ => new RectangleCollisionComponent { Size = new Rectangle(0, 0, 8, 8) });
serviceRegistry.RegisterTransient(_ =>
new RectangleCollisionComponent { Size = new(0, 0, 8, 8) });
}

private static void RegisterInventoryComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterTransient(_ =>
new InventoryComponent([]));
}

private static void RegisterCharacterAnimatorComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(factory =>
{
var movementAnimations = factory.GetInstance<MovementAnimationsComponent>("PlayerEntity");
const Direction facing = Direction.Right;

return new CharacterAnimatorComponent(facing, movementAnimations.IdleAnimations[facing]);
}, "PlayerEntity");
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
using System;
using Entitas;
using Features.Debugging;
using GameDesktop.Resources.Internal;
// using Features.Debugging;
using LightInject;
using Serilog;
using Systems.Debugging;
using MonoGame.ImGuiNet;

namespace GameDesktop.CompositionRoots.DebugFeatures;

internal class DebugRootFeatureCompositionRoot : ICompositionRoot
{
private static readonly IMatcher<GameEntity>[] Matchers = { GameMatcher.RectangleCollision, GameMatcher.Transform };

public void Compose(IServiceRegistry serviceRegistry)
{
RegisterSystems(serviceRegistry);
RegisterFeature(serviceRegistry);
// RegisterFeature(serviceRegistry);
}

private static void RegisterSystems(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(factory =>
{
var getGroup =
factory.GetInstance<Func<IMatcher<GameEntity>[], IGroup<GameEntity>>>(Matcher.AllOf);
IGroup<GameEntity> group = getGroup(Matchers);

return new DrawRectangleCollisionComponentsSystem(factory.GetInstance<Contexts>(), group,
factory.GetInstance<ILogger>());
});
// serviceRegistry.RegisterSingleton(factory =>
// {
// return new DrawRectangleCollisionComponentsSystem(factory.GetInstance<ILogger>());
// });
}

private static void RegisterFeature(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterSingleton<DebugRootFeature>();
// private static void RegisterFeature(IServiceRegistry serviceRegistry) =>
// serviceRegistry.RegisterSingleton<DebugRootFeature>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Components.Data;
using Components.Render.Animation;
using Components.Tags;
using Entities;
using Entities.Factories;
using Entities.Factories.Characters;
using LightInject;

namespace GameDesktop.CompositionRoots.Entities;
Expand All @@ -12,8 +16,13 @@ public void Compose(IServiceRegistry serviceRegistry)
}

private static void RegisterEntity(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterTransient(factory => new PlayerEntity(factory.GetInstance<Contexts>(),
factory.GetInstance<MovementAnimationComponent>(),
factory.GetInstance<TransformComponent>("Player"), factory.GetInstance<CameraComponent>(),
factory.GetInstance<RectangleCollisionComponent>()));
serviceRegistry.RegisterTransient(factory => new PlayerEntityFactory(
factory.GetInstance<InputMovableComponent>(),
factory.GetInstance<MovableComponent>(),
factory.GetInstance<TransformComponent>("PlayerEntity"),
factory.GetInstance<CameraComponent>(),
factory.GetInstance<RectangleCollisionComponent>(),
factory.GetInstance<MovementAnimationsComponent>(),
factory.GetInstance<CharacterAnimatorComponent>("PlayerEntity"),
factory.GetInstance<InventoryComponent>()));
}
Loading

0 comments on commit 9620e94

Please sign in to comment.