Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-59: ECS Migration #13

Merged
merged 36 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65f7d03
refactor: components migration
cherrynik Oct 27, 2023
248121e
refactor: entities migration
cherrynik Oct 27, 2023
6d6168b
chore: ref replace
cherrynik Oct 27, 2023
735d83f
feat(tests): player entity
cherrynik Oct 31, 2023
b8d90bb
refactor: base entities & di structure migration
cherrynik Oct 31, 2023
a013d92
chore(git): imguinet added as a submodule
cherrynik Oct 31, 2023
46c0eb0
chore: imguinet is ran only on debug
cherrynik Oct 31, 2023
10a559d
feat: imguinet entities list debug menu
cherrynik Oct 31, 2023
6fe29c0
feat: animated movement system
cherrynik Oct 31, 2023
5911f5a
refactor: systems, movement, impl & render
cherrynik Oct 31, 2023
e70358f
refactor: camera system & impls
cherrynik Nov 8, 2023
bfd03b2
feat: ui
cherrynik Nov 10, 2023
1a7761f
refactor: feature abstract class for code maintaining
cherrynik Nov 16, 2023
336217f
refactor: feature handling with morpeh & systems
cherrynik Nov 17, 2023
bd6936b
chore: update pkgs
cherrynik Nov 17, 2023
b42a961
refactor: recursive features handled correctly
cherrynik Nov 18, 2023
1436abd
refactor: imgui debug & code maintenance
cherrynik Nov 19, 2023
b7240c1
chore(e2e): integration test example
cherrynik Nov 19, 2023
b9d065d
refactor: basic di for root feature
cherrynik Nov 19, 2023
8297353
refactor(test): moq & input scanner
cherrynik Nov 20, 2023
3f40305
refactor: ui factory
cherrynik Nov 21, 2023
3ebce03
chore(workflow): submodule recursive checkout & secret
cherrynik Nov 21, 2023
2d1e58a
fix: Scellecs.Morpeh.Extended.csproj depended on MG
cherrynik Nov 21, 2023
3dd3c29
chore(.net): targeting 8.0, 7.0, 6.0
cherrynik Nov 21, 2023
1d759df
chore(workflow): .net version specified
cherrynik Nov 21, 2023
01f221b
chore: deleted dotnet-tools.json from game project
cherrynik Nov 21, 2023
0c53439
chore: targeting net6.0
cherrynik Nov 21, 2023
bc381e0
chore: targeting net8.0
cherrynik Nov 21, 2023
3101ced
chore: added badge
cherrynik Nov 21, 2023
8c102f7
chore(workflow): spacing in yml
cherrynik Nov 21, 2023
63fa4a3
fix(workflow): framework targeting & etc
cherrynik Nov 21, 2023
40d21e7
refactor: targeting only 8.0
cherrynik Nov 21, 2023
0844e66
refactor: game infra & debug ui
cherrynik Nov 21, 2023
462dba8
refactor: game entry class
cherrynik Nov 22, 2023
9b9ec13
refactor: components & debug structure
cherrynik Feb 24, 2024
848ceb9
refactor: updated imgui.net
cherrynik Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading