Updated KD and ModulLoader

This commit is contained in:
Mueller Wayan
2025-05-18 18:05:23 +02:00
parent 47ddfed9bc
commit 1862530728
38 changed files with 602 additions and 360 deletions
@@ -8,6 +8,7 @@
<ItemGroup>
<ProjectReference Include="..\Firebird2D.EventPipelines\Firebird2D.EventPipelines.csproj" />
<ProjectReference Include="..\Firebird2D.Requirement\Firebird2D.Requirement.csproj" />
</ItemGroup>
</Project>
+8 -6
View File
@@ -5,13 +5,15 @@ using System.Runtime.CompilerServices;
using System.Text.Json;
using Firebird2D.Interfaces;
using Firebird2D.Datatypes;
using Firebird2D.DataypesAndInterfaces.Interfaces;
using Firebird2D.Requirement;
namespace Firebird2D.KeyMapping
{
/// <summary>
/// Maps input events (keyboard, mouse, joystick) to custom Firebird events and manages their pipelines.
/// </summary>
public class KeyMapper
public class KeyMapper : IKeyMapper
{
private readonly IEventBus eventBus;
@@ -25,7 +27,7 @@ namespace Firebird2D.KeyMapping
private Dictionary<string, FirebirdEvent> inputMapping = [];
// Caches active pipelines for performance.
private Dictionary<FirebirdEvent, IPipeline> cachedPipelines = [];
private Dictionary<FirebirdEvent, IPipelineBase> cachedPipelines = [];
public KeyMapper(IEventBus eventBus)
{
@@ -72,7 +74,7 @@ namespace Firebird2D.KeyMapping
if (!inputMapping.TryGetValue(EventName, out var firebirdEvent)) return;
if (!eventTypes.TryGetValue(EventName, out var type)) return;
IPipeline? pipeline = eventBus.GetPipeline(firebirdEvent, type);
IPipelineBase pipeline = eventBus.GetPipeline(firebirdEvent);
if (pipeline != null)
{
@@ -94,7 +96,7 @@ namespace Firebird2D.KeyMapping
{
if (!eventTypes.TryGetValue(EventName, out var type)) return;
IPipeline pipeline = eventBus.GetOrBuildPipeline(eventNumber, type, this);
IPipeline<EventArgs> pipeline = eventBus.GetOrBuildPipeline<EventArgs>(eventNumber, this);
pipeline.Subscribe(inputEvents[EventName]);
}
@@ -146,12 +148,12 @@ namespace Firebird2D.KeyMapping
/// Retrieves a cached pipeline or fetches and caches it.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Pipeline<T>? GetOrCachePipeline<T>(FirebirdEvent fbEvent) where T : EventArgs
private IPipeline<T>? GetOrCachePipeline<T>(FirebirdEvent fbEvent) where T : EventArgs
{
if (cachedPipelines.TryGetValue(fbEvent, out var pipelineObj) && pipelineObj is Pipeline<T> cached)
return cached;
var pipeline = eventBus?.GetPipeline(fbEvent, typeof(T)) as Pipeline<T>;
var pipeline = eventBus?.GetPipeline(fbEvent) as Pipeline<T>;
if (pipeline != null)
cachedPipelines[fbEvent] = pipeline;