Skip to content

Commit

Permalink
Separate eventbus
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Aug 15, 2024
1 parent 770ec9f commit 8fdaee2
Show file tree
Hide file tree
Showing 73 changed files with 155 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Audio.Events;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Hypercube.Client.Audio.Events;
using Hypercube.Client.Audio.Loading;
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Resources.Manager;
using Hypercube.Shared.Runtimes.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Graphics.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/Events/MainWindowClosedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Graphics.Windowing;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Graphics.Windowing;

namespace Hypercube.Client.Graphics.Events;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Events/RenderDrawingEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Graphics.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/Events/WindowClosed.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Graphics.Windowing;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Graphics.Windowing;

namespace Hypercube.Client.Graphics.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/Events/WindowFocusChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Graphics.Windowing;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Graphics.Windowing;

namespace Hypercube.Client.Graphics.Events;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/ImGui/Events/ImGuiRenderEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Graphics.ImGui.Events;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/ImGui/ImGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Hypercube.Client.Graphics.ImGui.Events;
using Hypercube.Client.Graphics.Rendering;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.ImGui;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Runtimes.Loop.Event;
using JetBrains.Annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Hypercube.Client.Graphics.Windows;
using Hypercube.Client.Graphics.Windows.Realisation.Glfw;
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Resources.Container;
using Hypercube.Shared.Resources.Manager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Hypercube.Client.Input.Events.Windowing;
using Hypercube.EventBus.Events;
using Hypercube.Input;
using Hypercube.OpenGL.Utilities.Helpers;
using Hypercube.Shared.EventBus.Events;
using OpenTK.Windowing.GraphicsLibraryFramework;

using GlfwKeyModifiers = OpenTK.Windowing.GraphicsLibraryFramework.KeyModifiers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Hypercube.Client.Graphics.Rendering;
using Hypercube.Client.Input.Handler;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Graphics.Windowing;
using Hypercube.Math.Vectors;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Logging;
using OpenTK.Windowing.GraphicsLibraryFramework;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Input/Events/KeyHandledEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Input;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Input;

namespace Hypercube.Client.Input.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Input/Events/MouseButtonHandledEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Input;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Input;

namespace Hypercube.Client.Input.Events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Input.Events.Windowing;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Input;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Input;

namespace Hypercube.Client.Input.Events.Windowing;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Input;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Input;

namespace Hypercube.Client.Input.Events.Windowing;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;

namespace Hypercube.Client.Input.Events.Windowing;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Input/Handler/IInputHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Client.Graphics.Windows;
using Hypercube.EventBus;
using Hypercube.Input;
using Hypercube.Shared.EventBus;

namespace Hypercube.Client.Input.Handler;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Input/Handler/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Hypercube.Client.Input.Events;
using Hypercube.Client.Input.Events.Windowing;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Input;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Runtimes.Loop.Event;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Runtimes/Loop/RuntimeLoop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Runtimes.Loop;
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Shared.Timing;
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Runtimes/Runtime.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Client.Graphics.Events;
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Runtimes;
using Hypercube.Shared.Runtimes.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using System.Runtime.CompilerServices;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Utilities.Ref;
using Hypercube.Utilities.Units;
using JetBrains.Annotations;

namespace Hypercube.Shared.EventBus;
namespace Hypercube.EventBus;

/// <summary>
/// EventBus providing interaction between loosely coupled
/// components according to the principle of "event publisher -> event subscriber".
/// </summary>
[PublicAPI]
public sealed class EventBus : IEventBus
{
private readonly Dictionary<Type, HashSet<EventSubscription>> _eventRegistration = new();
Expand Down
8 changes: 8 additions & 0 deletions Hypercube.EventBus/EventRefHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Hypercube.EventBus.Events;
using JetBrains.Annotations;

namespace Hypercube.EventBus;

[PublicAPI]
public delegate void EventRefHandler<T>(ref T args)
where T : IEventArgs;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Hypercube.Utilities.Ref;
using JetBrains.Annotations;

namespace Hypercube.Shared.EventBus;
namespace Hypercube.EventBus;

[PublicAPI]
public sealed class EventSubscription : IEquatable<EventSubscription>
{
public RefHandler Handler { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Hypercube.Shared.EventBus.Events;
using JetBrains.Annotations;

namespace Hypercube.EventBus.Events;

[PublicAPI]
public abstract class CancellableEventArgs : EventArgs
{
public bool Cancelled { get; private set; }
Expand All @@ -9,7 +12,7 @@ public void Cancel()
Cancelled = true;
}

public void UnCancel()
public void Uncancel()
{
Cancelled = false;
}
Expand Down
6 changes: 6 additions & 0 deletions Hypercube.EventBus/Events/EventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using JetBrains.Annotations;

namespace Hypercube.EventBus.Events;

[PublicAPI]
public abstract class EventArgs : IEventArgs;
6 changes: 6 additions & 0 deletions Hypercube.EventBus/Events/IEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using JetBrains.Annotations;

namespace Hypercube.EventBus.Events;

[PublicAPI]
public interface IEventArgs;
17 changes: 17 additions & 0 deletions Hypercube.EventBus/Hypercube.EventBus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Hypercube.Utilities\Hypercube.Utilities.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using JetBrains.Annotations;

namespace Hypercube.Shared.EventBus;
namespace Hypercube.EventBus;

/// <summary>
/// EventBus providing interaction between loosely coupled
/// components according to the principle of "event publisher -> event subscriber".
/// </summary>
[PublicAPI]
public interface IEventBus
{
void Raise<T>(ref T eventArgs) where T : IEventArgs;
Expand Down
6 changes: 6 additions & 0 deletions Hypercube.EventBus/IEventSubscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using JetBrains.Annotations;

namespace Hypercube.EventBus;

[PublicAPI]
public interface IEventSubscriber;
2 changes: 1 addition & 1 deletion Hypercube.Example.Client/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using Hypercube.Client.Graphics.Rendering;
using Hypercube.Client.Graphics.Viewports;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Example.Client.Controls;
using Hypercube.Math.Vectors;
using Hypercube.Shared.Entities.Realisation.Manager;
using Hypercube.Shared.Entities.Systems.Physics;
using Hypercube.Shared.Entities.Systems.Transform.Coordinates;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Physics;
using Hypercube.Shared.Physics.Shapes;
using Hypercube.Shared.Resources;
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Example.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;

namespace Hypercube.Example.Client;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Example.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;

namespace Hypercube.Example.Server;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Server/Runtimes/Loop/RuntimeLoop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Runtimes.Loop;
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Shared.Timing;
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Server/Runtimes/Runtime.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Dependencies;
using Hypercube.Shared.EventBus;
using Hypercube.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Runtimes;
using Hypercube.Shared.Runtimes.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Shared.Entities.Realisation.Components;
using Hypercube.EventBus.Events;
using Hypercube.Shared.Entities.Realisation.Components;
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;
using Hypercube.Shared.EventBus.Events;

namespace Hypercube.Shared.Entities.Realisation.Events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Shared.Entities.Realisation.Components;
using Hypercube.EventBus.Events;
using Hypercube.Shared.Entities.Realisation.Components;
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;
using Hypercube.Shared.EventBus.Events;

namespace Hypercube.Shared.Entities.Realisation.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Shared/Entities/Realisation/Events/EntityAdded.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;
using Hypercube.EventBus.Events;
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;
using Hypercube.Shared.Entities.Systems.Transform.Coordinates;
using Hypercube.Shared.EventBus.Events;

namespace Hypercube.Shared.Entities.Realisation.Events;

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Shared/Entities/Realisation/Events/EntityRemoved.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;
using Hypercube.Shared.EventBus.Events;
using Hypercube.EventBus.Events;
using Hypercube.Shared.Entities.Realisation.EventBus.EventArgs;

namespace Hypercube.Shared.Entities.Realisation.Events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Frozen;
using System.Reflection;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Shared.Entities.Realisation.Components;
using Hypercube.Shared.Entities.Realisation.EventBus;
using Hypercube.Shared.Entities.Realisation.Events;
using Hypercube.Shared.Entities.Systems.MetaData;
using Hypercube.Shared.Entities.Systems.Transform;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Runtimes.Event;
using Hypercube.Utilities.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Shared.Entities.Realisation.Events;
using Hypercube.Shared.Entities.Systems.Transform.Coordinates;
using Hypercube.Shared.EventBus;

namespace Hypercube.Shared.Entities.Realisation.Manager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Frozen;
using Hypercube.Dependencies;
using Hypercube.EventBus;
using Hypercube.Shared.Entities.Realisation.Systems;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Runtimes.Event;
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Utilities.Helpers;
Expand Down
Loading

0 comments on commit 8fdaee2

Please sign in to comment.