Skip to content

Commit

Permalink
Added basic network protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaMeinhold committed May 24, 2024
1 parent 2333afc commit 1c07068
Show file tree
Hide file tree
Showing 55 changed files with 3,106 additions and 235 deletions.
3 changes: 2 additions & 1 deletion App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using HexaEngine;
using HexaEngine.Core;
using HexaEngine.Core.Audio;
using HexaEngine.Core.Graphics;
using HexaEngine.Windows;

Expand All @@ -12,7 +13,7 @@ public static class Program
/// </summary>
public static void Main()
{
Application.Boot(GraphicsBackend.D3D11);
Application.Boot(GraphicsBackend.D3D11, AudioBackend.Auto);
Window window = new();
Platform.Init(window);
Application.Run(window);
Expand Down
2 changes: 1 addition & 1 deletion CrashReporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using HexaEngine.Core.Graphics;

ShaderCache.DisableCache = true;
Application.Boot(GraphicsBackend.D3D11, true);
Application.Boot(GraphicsBackend.D3D11, HexaEngine.Core.Audio.AudioBackend.Auto, true);
CrashWindow window = new();
Platform.Init(window, true);
Application.Run(window);
Expand Down
3 changes: 2 additions & 1 deletion Editor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
{
using HexaEngine;
using HexaEngine.Core;
using HexaEngine.Core.Audio;
using HexaEngine.Core.Graphics;

public class Program
{
public static void Main(string[] args)
{
Application.Boot(GraphicsBackend.D3D11);
Application.Boot(GraphicsBackend.D3D11, AudioBackend.Auto);
EditorWindow window = new();
Platform.Init(window, true);
Application.Run(window);
Expand Down
21 changes: 18 additions & 3 deletions HexaEngine.Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ public static unsafe class Application
/// </summary>
public static GraphicsBackend GraphicsBackend
{
get; set;
get; private set;
}

/// <summary>
/// Gets or sets the audio backend used by the application.
/// </summary>
public static AudioBackend AudioBackend
{
get; private set;
}

/// <summary>
Expand Down Expand Up @@ -188,6 +196,11 @@ public static EditorPlayState EditorPlayState
/// </summary>
public static bool GraphicsDebugging { get; set; }

/// <summary>
/// Gets or sets a value indicating whether graphics is disabled.
/// </summary>
public static bool GraphicsDisabled => GraphicsBackend == GraphicsBackend.Disabled;

/// <summary>
/// Occurs when the editor mode state of the application changes.
/// </summary>
Expand Down Expand Up @@ -271,9 +284,11 @@ public static string GetFolder(SpecialFolder folder)
/// <summary>
/// Initializes the application and necessary subsystems.
/// </summary>
public static void Boot(GraphicsBackend backend, bool disableLogging = false)
public static void Boot(GraphicsBackend graphicsBackend, AudioBackend audioBackend, bool disableLogging = false)
{
GraphicsBackend = backend;
GraphicsBackend = graphicsBackend;
AudioBackend = audioBackend;

#if DEBUG
GraphicsDebugging = true;
#endif
Expand Down
11 changes: 8 additions & 3 deletions HexaEngine.Core/Audio/AudioBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
/// </summary>
public enum AudioBackend
{
/// <summary>
/// Disables the audio sub system.
/// </summary>
Disabled = -1,

/// <summary>
/// Automatically select the most suitable audio backend based on the platform.
/// </summary>
Auto,
Auto = 0,

/// <summary>
/// Use the OpenAL audio backend for audio processing.
/// </summary>
OpenAL,
OpenAL = 1,

/// <summary>
/// Use the XAudio2 audio backend for audio processing.
/// </summary>
XAudio2,
XAudio2 = 2,
}
}
2 changes: 1 addition & 1 deletion HexaEngine.Core/Debugging/CrashLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class CrashLogger
/// <summary>
/// Gets the file log writer used for crash logging.
/// </summary>
public static readonly FileLogWriter FileLogWriter = new("logs");
public static readonly LogFileWriter FileLogWriter = new("logs");

#nullable disable
private static HardwareInfo info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// <summary>
/// A log writer that appends log messages to a file.
/// </summary>
public class FileLogWriter : ILogWriter
public class LogFileWriter : ILogWriter
{
private const int MaxLogFileCount = 5;
private readonly BufferedStream stream;
Expand All @@ -20,10 +20,10 @@ public class FileLogWriter : ILogWriter
private bool disposedValue;

/// <summary>
/// Initializes a new instance of the <see cref="FileLogWriter"/> class and creates or opens the specified log file.
/// Initializes a new instance of the <see cref="LogFileWriter"/> class and creates or opens the specified log file.
/// </summary>
/// <param name="folder">The path to the log folder.</param>
public FileLogWriter(string folder)
public LogFileWriter(string folder)
{
string fileName = $"app-{DateTime.Now:yyyy-dd-M--HH-mm-ss}.log";
string file = Path.Combine(folder, fileName);
Expand Down Expand Up @@ -127,7 +127,7 @@ public Task WriteAsync(string message)
}

/// <summary>
/// Releases the resources used by the <see cref="FileLogWriter"/> instance.
/// Releases the resources used by the <see cref="LogFileWriter"/> instance.
/// </summary>
/// <param name="disposing">True if the method is called directly, false if called by the finalizer.</param>
protected virtual void Dispose(bool disposing)
Expand All @@ -144,7 +144,7 @@ protected virtual void Dispose(bool disposing)
}

/// <summary>
/// Releases the resources used by the <see cref="FileLogWriter"/> instance.
/// Releases the resources used by the <see cref="LogFileWriter"/> instance.
/// </summary>
public void Dispose()
{
Expand Down
5 changes: 5 additions & 0 deletions HexaEngine.Core/Graphics/RenderBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public enum GraphicsBackend
{
/// <summary>
/// Disables the graphics sub system. (aka headless)
/// </summary>
Disabled = -1,

/// <summary>
/// Automatically select the most appropriate graphics backend.
/// </summary>
Expand Down
14 changes: 7 additions & 7 deletions HexaEngine.Core/Unsafes/StdWString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public StdWString(string s)
var byteCount = Encoding.Unicode.GetByteCount(s) / sizeof(char);
data = AllocT<char>(byteCount + 1);
capacity = size = s.Length;
Encoding.Unicode.GetBytes(s, new Span<byte>(data, byteCount));
Encoding.Unicode.GetBytes(s, new Span<byte>(data, byteCount * sizeof(char)));
data[size] = '\0';
}

Expand Down Expand Up @@ -156,10 +156,6 @@ public void Resize(int size)
{
EnsureCapacity(size);
this.size = size;
for (int i = size; i < capacity + 1; i++)
{
data[i] = '\0';
}
}

/// <summary>
Expand Down Expand Up @@ -781,8 +777,12 @@ public void Swap(ref StdWString other)
/// </summary>
public void Release()
{
Free(data);
data = null;
if (data != null)
{
Free(data);
data = null;
}

capacity = 0;
size = 0;
}
Expand Down
24 changes: 23 additions & 1 deletion HexaEngine.Editor/Hotkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using HexaEngine.Core.Input;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

public class Hotkey
{
private string? cache;
private readonly List<Key> keys = new();
private readonly List<Key> defaults = new();
private readonly HashSet<Hotkey> conflicts = new();
public readonly string Name;

[JsonIgnore]
Expand All @@ -18,6 +20,9 @@ public class Hotkey
[JsonIgnore]
public Action Callback;

[JsonIgnore]
public HashSet<Hotkey> Conflicts => conflicts;

public List<Key> Keys { get; private set; }

public List<Key> Defaults => defaults;
Expand Down Expand Up @@ -48,8 +53,25 @@ public Hotkey(string name, Action callback, IEnumerable<Key> defaults)
Keys = new(keys);
}

public bool IsConflicting(Hotkey other)
public void AddConflictingHotkey(Hotkey hotkey)
{
conflicts.Add(hotkey);
hotkey.conflicts.Add(this);
}

public void RemoveConflictingHotkey(Hotkey hotkey)
{
conflicts.Remove(hotkey);
hotkey.conflicts.Remove(this);
}

public bool IsConflicting(Hotkey other, bool useHashSet = true)
{
if (useHashSet)
{
return conflicts.Contains(other);
}

if (Keys.Count != other.Keys.Count)
{
return false;
Expand Down
32 changes: 30 additions & 2 deletions HexaEngine.Editor/HotkeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

public static class HotkeyManager
{
private static readonly List<Key> keys = new();
private static readonly List<Hotkey> hotkeys = new();
private static readonly List<Key> keys = [];
private static readonly List<Hotkey> hotkeys = [];
private const string Filename = "hotkeys.json";

static HotkeyManager()
Expand Down Expand Up @@ -75,6 +75,17 @@ public static bool TryFind(string name, [NotNullWhen(true)] out Hotkey? hotkey)
return hotkey != null;
}

private static IEnumerable<Hotkey> FindConflicts(Hotkey hotkey)
{
foreach (Hotkey other in hotkeys)
{
if (hotkey.IsConflicting(other, false))
{
yield return other;
}
}
}

public static Hotkey Register(string name, Action callback)
{
lock (hotkeys)
Expand All @@ -87,6 +98,11 @@ public static Hotkey Register(string name, Action callback)
{
hotkey = new(name, callback);
hotkeys.Add(hotkey);

foreach (var conflict in FindConflicts(hotkey))
{
hotkey.AddConflictingHotkey(conflict);
}
}

Save();
Expand All @@ -107,6 +123,11 @@ public static Hotkey Register(string name, Action callback, params Key[] default
{
hotkey = new(name, callback, defaults);
hotkeys.Add(hotkey);

foreach (var conflict in FindConflicts(hotkey))
{
hotkey.AddConflictingHotkey(conflict);
}
}

Save();
Expand All @@ -125,6 +146,13 @@ public static void Unregister(string name)
return;
}

var hotkey = hotkeys[index];

foreach (var conflict in hotkey.Conflicts)
{
hotkey.RemoveConflictingHotkey(conflict);
}

hotkeys.RemoveAt(index);
}

Expand Down
6 changes: 3 additions & 3 deletions HexaEngine.Editor/Widgets/HierarchyWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class HierarchyWidget : EditorWindow
private bool showHidden;
private bool focused;

private uint[] levelColorPalette =
{// 0xAABBGGRR
private readonly uint[] levelColorPalette =
[// 0xAABBGGRR
0x8F0000FF,
0x8F00FF00,
0x8FFF0000,
Expand All @@ -39,7 +39,7 @@ public class HierarchyWidget : EditorWindow
0x8F00FFFF,
0x8F800080,
0x8F008080,
};
];

private enum HierarchyLevelColoring
{
Expand Down
1 change: 1 addition & 0 deletions HexaEngine/HexaEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@
<Folder Include="assets\shared\shaders\forward\sun\" />
<Folder Include="assets\shared\shaders\tools\mesh\shaded\" />
<Folder Include="assets\shared\shaders\tools\mesh\textured\" />
<Folder Include="Physics\Network\" />
</ItemGroup>


Expand Down
Loading

0 comments on commit 1c07068

Please sign in to comment.