Change To OpenGL

This commit is contained in:
Mueller Wayan
2025-08-15 10:44:29 +02:00
parent 1862530728
commit a36789dd7e
101 changed files with 2981 additions and 1027 deletions
+55 -13
View File
@@ -1,10 +1,7 @@
using Firebird2D.Datatypes;
using Firebird2D.DataypesAndInterfaces.Datatypes;
using Firebird2D.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Firebird2D.EventPipelines
{
@@ -15,11 +12,15 @@ namespace Firebird2D.EventPipelines
{
// Dictionary that stores various pipelines for specific FirebirdEvents.
// The key is the event, and the value is the corresponding pipeline.
private Dictionary<FirebirdEvent, IPipelineBase> pipelines = new();
private readonly Dictionary<FirebirdEventId, IPipelineBase> pipelines = [];
// Dictionary that stores a list of callbacks for each FirebirdEvent.
// These callbacks will be invoked when the event's pipeline is build.
private Dictionary<FirebirdEvent, List<Action<IPipelineBase>>> pendingHooks = new();
private readonly Dictionary<FirebirdEventId, List<Action<IPipelineBase>>> pendingHooks = [];
private readonly HashSet<FirebirdEventId> pipelineReservations = [];
private readonly Mutex reservationMutex = new();
/// <summary>
/// Registers a callback (hook) for a specific event. The callback will be invoked when the pipeline for this event is built.
@@ -27,7 +28,7 @@ namespace Firebird2D.EventPipelines
/// <param name="callback">The function to be called when the pipeline for the event is built.</param>
/// <param name="type">The event for which the callback should be registered.</param>
/// <exception cref="ArgumentNullException">Thrown when the callback is null.</exception>
public void OnPipelineIsBuild(Action<IPipelineBase> callback, FirebirdEvent type)
public void OnPipelineIsBuild(Action<IPipelineBase> callback, FirebirdEventId type)
{
if (callback == null) throw new ArgumentNullException(nameof(callback));
@@ -48,15 +49,13 @@ namespace Firebird2D.EventPipelines
/// <param name="type">The event for which the pipeline should be created or retrieved.</param>
/// <param name="master">The master object used when creating the pipeline.</param>
/// <returns>The pipeline for the given event.</returns>
public IPipeline<T> GetOrBuildPipeline<T>(FirebirdEvent type, object master) where T : EventArgs
public IPipeline<T> GetOrBuildPipeline<T>(FirebirdEventId type, object master) where T : EventArgs
{
if (pipelines.TryGetValue(type, out var pipeline)) return (IPipeline<T>)pipeline;
var pipelineInstance = new Pipeline<T>(master);
pipelines[type] = pipelineInstance;
if (pendingHooks.TryGetValue(type, out var hookList)) return pipelineInstance;
if (hookList == null) return pipelineInstance;
if (!pendingHooks.TryGetValue(type, out var hookList)) return pipelineInstance;
foreach (Action<IPipelineBase> hook in hookList)
{
@@ -71,7 +70,7 @@ namespace Firebird2D.EventPipelines
/// </summary>
/// <param name="type">The event for which the pipeline should be retrieved.</param>
/// <returns>The pipeline for the event, or null if it does not exist.</returns>
public IPipelineBase? GetPipeline(FirebirdEvent type)
public IPipelineBase? GetPipeline(FirebirdEventId type)
{
if (!pipelines.TryGetValue(type, out var pipeline)) return null;
return pipeline;
@@ -83,11 +82,54 @@ namespace Firebird2D.EventPipelines
/// <param name="type">The event for which the pipeline should be destroyed.</param>
/// <param name="master">The master object that has permission to destroy the pipeline.</param>
/// <exception cref="InvalidDataException">Thrown when a non-authorized user attempts to destroy the pipeline.</exception>
public void DestroyPipeline(FirebirdEvent type, object master)
public void DestroyPipeline(FirebirdEventId type, object master)
{
if (!pipelines.ContainsKey(type)) return;
if (!pipelines[type].PipelineMaster.Equals(master)) throw new InvalidDataException("Only the pipeline master is allowed to delete this pipeline.");
pipelines.Remove(type);
}
/// <summary>
/// Finds the first Free Pipeline Key
/// </summary>
/// <returns>Pipeline Key that can bee used</returns>
public FirebirdEventId ReserveFreePipeline()
{
reservationMutex.WaitOne();
FirebirdEventId i = (FirebirdEventId)((int)FirebirdSystemEventInfo.MaxValue + 1);
while (pipelines.ContainsKey(i) || pipelineReservations.Contains(i))
{
i++;
}
pipelineReservations.Add(i);
reservationMutex.ReleaseMutex();
return i;
}
/// <summary>
/// Finds a number of Free Pipeline Keys and reserves it
/// </summary>
/// <param name="numberOfPipelines">Number of keys that has to be reserved</param>
/// <returns></returns>
public FirebirdEventId[] ReserveFreePipelines(int numberOfPipelines)
{
FirebirdEventId[] returnArray = new FirebirdEventId[numberOfPipelines];
for(int i = 0; i < returnArray.Length; i++)
{
returnArray[i] = ReserveFreePipeline();
}
return returnArray;
}
/// <summary>
/// Frees the reservation of a given Pipeline Key
/// </summary>
/// <param name="PipelineKey">The Pipline key on which the Reservation should be cancled</param>
public void CancleReservationOnPipeline(FirebirdEventId PipelineKey)
{
pipelineReservations.Remove(PipelineKey);
}
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ namespace Firebird2D.EventPipelines
{
if (sender == null || args == null) throw new ArgumentNullException(nameof(sender));
if (args is not T) throw new ArgumentException($"Invalid EventArgs type. Expected {typeof(T)}");
if (sender.Equals(PipelineMaster)) throw new InvalidDataException("Only the pipeline master is allowed to send events through this pipeline.");
if (!sender.Equals(PipelineMaster)) throw new InvalidDataException("Only the pipeline master is allowed to send events through this pipeline.");
OnEvent?.Invoke(sender, args);