Skip to content

Commit

Permalink
Merge pull request #41 from noverd/warn_kill
Browse files Browse the repository at this point in the history
Warn kill
  • Loading branch information
Tornado-Technology authored Aug 2, 2024
2 parents b876607 + ffceac1 commit 5412459
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 52 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.Hypercube/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/.idea.Hypercube/.idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Monitors/MonitorHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public MonitorHandle(int id, string name, int width, int height, int refreshRate

public override string ToString()
{
return $"MonitorHandle {Id.Value}, name: {Name}, size: {size}, rate: {refreshRate}, mode: ({videoModes.Length})";
return $"MonitorHandle {Id.Value}, name: {Name}, size: {Size}, rate: {RefreshRate}, mode: ({VideoModes.Length})";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ private bool InitMainWindow(ContextInfo? context, WindowCreateSettings settings)
return (null, result.Error);

var registration = result.Registration;

if (registration == null)
return (null, "registration is null");

_windowManager.MakeContextCurrent(registration);
_windows.Add(registration.Id, registration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public sealed unsafe partial class GlfwWindowManager : IWindowManager

private bool _initialized;
private bool _running;
private bool _disposed;

private int _nextWindowId = 1;

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Windows/WindowHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class WindowHandle(IRenderer renderer, WindowRegistration registration) :
public void Dispose()
{
// Destroy self in renderer
renderer.DestroyWindow(registration);
Renderer.DestroyWindow(Registration);
}
}
12 changes: 6 additions & 6 deletions Hypercube.Client/Input/KeyStateChangedArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public readonly struct KeyStateChangedArgs(Key key, bool pressed, bool repeat, KeyModifiers modifiers, int scanCode)
{
public bool Shift => modifiers.HasFlag(KeyModifiers.Shift);
public bool Control => modifiers.HasFlag(KeyModifiers.Control);
public bool Alt => modifiers.HasFlag(KeyModifiers.Alt);
public bool Super => modifiers.HasFlag(KeyModifiers.Super);
public bool CapsLock => modifiers.HasFlag(KeyModifiers.CapsLock);
public bool NumLock => modifiers.HasFlag(KeyModifiers.NumLock);
public bool Shift => Modifiers.HasFlag(KeyModifiers.Shift);
public bool Control => Modifiers.HasFlag(KeyModifiers.Control);
public bool Alt => Modifiers.HasFlag(KeyModifiers.Alt);
public bool Super => Modifiers.HasFlag(KeyModifiers.Super);
public bool CapsLock => Modifiers.HasFlag(KeyModifiers.CapsLock);
public bool NumLock => Modifiers.HasFlag(KeyModifiers.NumLock);

public readonly Key Key = key;
public readonly bool Pressed = pressed;
Expand Down
5 changes: 3 additions & 2 deletions Hypercube.Client/Preloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Hypercube.Shared.Resources.Container;
using Hypercube.Shared.Resources.Manager;
using Hypercube.Shared.Resources.Preloader;
using JetBrains.Annotations;

namespace Hypercube.Client;

Expand All @@ -19,7 +20,7 @@ public sealed class Preloader : IPreloader

private readonly ILogger _logger = new Logger("preloader");

[Preloading(typeof(GraphicsLibraryInitializedEvent))]
[Preloading(typeof(GraphicsLibraryInitializedEvent)), UsedImplicitly]
private void PreloadGraphics()
{
PreloadShaders();
Expand Down Expand Up @@ -73,7 +74,7 @@ private void PreloadShaders()
_logger.EngineInfo($"Preloaded {count} shaders in {stopwatch.Elapsed}");
}

[Preloading(typeof(AudioLibraryInitializedEvent))]
[Preloading(typeof(AudioLibraryInitializedEvent)), UsedImplicitly]
private void PreloadAudio()
{
_logger.EngineInfo("Preloading shaders...");
Expand Down
29 changes: 18 additions & 11 deletions Hypercube.Shared/Entities/Realisation/EntityUid.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
namespace Hypercube.Shared.Entities.Realisation;
using JetBrains.Annotations;

namespace Hypercube.Shared.Entities.Realisation;

public readonly struct EntityUid(int id)
{
/// <summary>
/// All Ids equals or less than -1 are Invalid.
/// </summary>
public static readonly EntityUid Invalid = new(-1);
[PublicAPI] public static readonly EntityUid Invalid = new(-1);

public bool Valid => Id > Invalid.Id;
public readonly int Id = id;
public bool Equals(EntityUid entityUid)

[PublicAPI] public readonly int Id = id;

private bool Equals(EntityUid entityUid)
{
return Id == entityUid.Id;
}

public override int GetHashCode()
{
return Id;
}

public override bool Equals(object? @object)
{
return @object is EntityUid id && Equals(id);
}

public override string ToString()
{
return $"Entity({Id})";
}

public static bool operator ==(EntityUid a, EntityUid b)
{
return a.Id == b.Id;
}

public static bool operator !=(EntityUid a, EntityUid b)
{
return a.Id != b.Id;
}

public static implicit operator int(EntityUid entityUid)
{
return entityUid.Id;
}

public static implicit operator EntityUid(int value)
{
return new EntityUid(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Hypercube.Shared.Entities.Realisation.Manager;

public sealed class EntitiesManager : IEntitiesManager
{
[Dependency] private readonly IEntitiesComponentManager _entitiesComponentManager = default!;
[Dependency] private readonly IEventBus _eventBus = default!;

private readonly HashSet<EntityUid> _entities = new();
Expand Down
33 changes: 14 additions & 19 deletions Hypercube.Shared/Entities/Realisation/Systems/EntitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,37 @@ public abstract class EntitySystem : IEntitySystem, IEventSubscriber
{
[Dependency] private readonly IEntitiesComponentManager _entitiesComponentManager = default!;
[Dependency] private readonly IEntitiesEventBus _entitiesEventBus = default!;
[Dependency] private readonly IEntitiesManager _entitiesManager = default!;
[Dependency] private readonly IEntitiesSystemManager _entitiesSystemManager = default!;

[Dependency] private readonly IEventBus _eventBus = default!;

protected readonly ILogger Logger;

protected EntitySystem()
{
Logger = LoggingManager.GetLogger(GetLoggerName());
}

public virtual void Initialize()
{

}

public virtual void Shutdown(RuntimeShutdownEvent args)
{

}

public virtual void FrameUpdate(UpdateFrameEvent args)
{

}

protected T AddComponent<T>(EntityUid entityUid) where T : IComponent
{
return _entitiesComponentManager.AddComponent<T>(entityUid);
}

protected T GetComponent<T>(EntityUid entityUid) where T : IComponent
{
return _entitiesComponentManager.GetComponent<T>(entityUid);
}

protected bool HasComponent<T>(EntityUid entityUid) where T : IComponent
{
return _entitiesComponentManager.HasComponent<T>(entityUid);
Expand All @@ -62,13 +56,14 @@ protected IEnumerable<Entity<T>> GetEntities<T>() where T : IComponent
{
return _entitiesComponentManager.GetEntities<T>();
}

protected IEnumerable<Entity<T1, T2>> GetEntities<T1, T2>() where T1 : IComponent where T2 : IComponent
{
return _entitiesComponentManager.GetEntities<T1, T2>();
}

protected IEnumerable<Entity<T1, T2, T3>> GetEntities<T1, T2, T3>() where T1 : IComponent where T2 : IComponent where T3 : IComponent

protected IEnumerable<Entity<T1, T2, T3>> GetEntities<T1, T2, T3>()
where T1 : IComponent where T2 : IComponent where T3 : IComponent
{
return _entitiesComponentManager.GetEntities<T1, T2, T3>();
}
Expand All @@ -77,40 +72,40 @@ protected void Subscribe<T>(EventRefHandler<T> callback) where T : IEventArgs
{
_eventBus.Subscribe(this, callback);
}

protected void Unsubscribe<T>(EventRefHandler<T> callback) where T : IEventArgs
{
_eventBus.Unsubscribe<T>(this);
}

protected void Subscribe<TComponent, TEvent>(EntitiesEventRefHandler<TComponent, TEvent> callback)
where TComponent : IComponent
where TEvent : IEntitiesEventArgs
{
_entitiesEventBus.Subscribe(this, callback);
}

protected void Raise<TComponent, TEvent>(EntityUid entityUid, TComponent component, TEvent args)
where TComponent : IComponent
where TEvent : IEntitiesEventArgs
{
_entitiesEventBus.Raise(entityUid, component, args);
}

protected void Raise<TComponent, TEvent>(Entity<TComponent> entity, TEvent args)
where TComponent : IComponent
where TEvent : IEntitiesEventArgs
{
_entitiesEventBus.Raise(entity, args);
}

protected void Raise<TComponent, TEvent>(Entity<TComponent> entity, ref TEvent args)
where TComponent : IComponent
where TEvent : IEntitiesEventArgs
{
_entitiesEventBus.Raise(entity, args);
}

private string GetLoggerName()
{
var name = GetType().Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Hypercube.Shared.Entities.Systems.MetaData;

public sealed class MetaDataComponent : Component
{
public string Name;
public string Name = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public readonly struct SceneCoordinates(SceneId scene, Vector2 position)
{
public static readonly SceneCoordinates Nullspace = new(SceneId.Nullspace, Vector2.Zero);

public float X => position.X;
public float Y => position.Y;
public float X => Position.X;
public float Y => Position.Y;

public readonly SceneId Scene = scene;
public readonly Vector2 Position = position;
Expand Down
9 changes: 5 additions & 4 deletions Hypercube.Shared/Hypercube.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0-2.final"/>
<PackageReference Include="YamlDotNet" Version="16.0.0"/>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0-2.final" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
</ItemGroup>

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

<ItemGroup>
<None Include="..\Resources\**" Link="Resources\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest"/>
<None Include="..\Resources\**" Link="Resources\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions Hypercube.Shared/Utilities/ArgumentsParser/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public class ArgumentParser(string[] args)
{
private readonly string[] Arguments = args;

public bool TryParse()
{
foreach (var arg in args)
Expand Down

0 comments on commit 5412459

Please sign in to comment.