Skip to content

Commit

Permalink
release v1.0.0
Browse files Browse the repository at this point in the history
- [feat] easy way to implement an ECS pattern program
- [feat] support concurrency/parallelism to boost performance
- [feat] purely asynchronous interfaces to ensure nothing blocks the thread (unless deadlock from user code)
  • Loading branch information
JasonXuDeveloper committed Jan 20, 2025
1 parent 866e4e3 commit 3d247c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
42 changes: 29 additions & 13 deletions EasyEcs.Core/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,39 @@ public async ValueTask Update(bool parallel = true)
if (_disposed)
throw new InvalidOperationException("Context disposed.");

// if empty, return
if (_executeSystems.Count == 0)
return;

// clear the cache of the groups
InvalidateGroupCache();
// execute the systems
_executeTasks.Clear();
// sort by priority
foreach (var system in _executeSystems.Values)
// group by priority
int remaining = _executeSystems.Count;
int index = 0;
while (remaining > 0)
{
_executeTasks.Add(parallel ? Task.Run(() => system.Update(this)) : system.Update(this));
}
// execute the systems with the same priority
_executeTasks.Clear();
ExecuteSystemWrapper system = _executeSystems.Values[index];
var currentPriority = system.Priority;
while (system.Priority == currentPriority && remaining > 0)
{
var systemWrapper = system;
_executeTasks.Add(parallel ? Task.Run(() => systemWrapper.Update(this)) : systemWrapper.Update(this));
index++;
if (--remaining > 0)
system = _executeSystems.Values[index];
}

try
{
await Task.WhenAll(_executeTasks);
}
catch (Exception e)
{
OnError?.Invoke(e);
// dispatch all tasks of the same priority
try
{
await Task.WhenAll(_executeTasks);
}
catch (Exception e)
{
OnError?.Invoke(e);
}
}

while (_removeList.TryDequeue(out var entity))
Expand Down
2 changes: 2 additions & 0 deletions EasyEcs.Core/ExecuteSystemWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal class ExecuteSystemWrapper
private readonly IExecuteSystem _system;
private int _counter;

internal int Priority => ((SystemBase)_system).Priority;

public ExecuteSystemWrapper(IExecuteSystem system)
{
_system = system;
Expand Down
5 changes: 5 additions & 0 deletions EasyEcs.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AReadOnlyCollection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4cfef46534ca7afeaf461953f17dc5b92a0173671794e94d93bbe487d37f4a_003FReadOnlyCollection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASocket_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F611efef9cc4db44681420ed548e67f2174d4f12bb94a911f6f81a4ba7ca_003FSocket_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASortedList_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fd08c4c7cd56e410ba2f228947c6bfcc349200_003F6d_003Fab004b16_003FSortedList_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ca59a3c6_002D1b78_002D4f89_002D9b6e_002Df9f35114ecb0/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="SimpleTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::FDA284F0-DE3A-4C46-A8B9-90324F25FCB0::net6.0::EasyEcs.UnitTest.SimpleTest&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String>


<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fabae239_002Dedef_002D47f4_002Da7cb_002D6b40f5828ca8/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Tests" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
Expand Down

0 comments on commit 3d247c1

Please sign in to comment.