networking progress

This commit is contained in:
2023-04-06 21:12:04 +03:00
parent 59ef64fe3b
commit 7228c51dd7
32 changed files with 1084 additions and 261 deletions

View File

@@ -3,12 +3,13 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using FlaxEditor;
using FlaxEngine;
namespace Game
{
public class ConsoleLine
public struct ConsoleLine
{
public string content;
@@ -75,7 +76,7 @@ namespace Game
public static string LinePrefix => instance.LinePrefix;
public static IReadOnlyCollection<ConsoleLine> Lines => instance.Lines;
public static ReadOnlySpan<ConsoleLine> Lines => instance.Lines;
public static void Init()
{
@@ -220,7 +221,7 @@ namespace Game
public int DebugVerbosity { get; set; } = 1;
public string LinePrefix { get; internal set; } = "]";
public IReadOnlyCollection<ConsoleLine> Lines => consoleLines.AsReadOnly();
public ReadOnlySpan<ConsoleLine> Lines => CollectionsMarshal.AsSpan(consoleLines);
public void Dispose()
{
@@ -380,23 +381,14 @@ namespace Game
{
debugLastLine = text;
foreach (string line in text.Split('\n'))
{
ConsoleLine lineEntry = new ConsoleLine(line);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
PrintLine(text);
}
// Echoes warning text to Console
public void PrintWarning(string text)
{
foreach (string line in text.Split('\n'))
{
ConsoleLine lineEntry = new ConsoleLine(line);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
PrintLine(text);
}
// Echoes error text to Console
@@ -404,12 +396,7 @@ namespace Game
[DebuggerHidden]
public void PrintError(string text)
{
foreach (string line in text.Split('\n'))
{
ConsoleLine lineEntry = new ConsoleLine(line);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
PrintLine(text);
/*if (Debugger.IsAttached)
Debugger.Break();
@@ -417,6 +404,26 @@ namespace Game
throw new Exception(text);
}
private void PrintLine(string text)
{
if (text.IndexOf('\n') != -1)
{
// Avoid generating extra garbage in single-line cases
foreach (string line in text.Split('\n'))
{
ConsoleLine lineEntry = new ConsoleLine(line);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
}
else
{
ConsoleLine lineEntry = new ConsoleLine(text);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
}
public void PrintDebug(int verbosity, bool noRepeat, string text)
{
if (DebugVerbosity < verbosity)
@@ -428,12 +435,7 @@ namespace Game
debugLastLine = text;
foreach (string line in text.Split('\n'))
{
ConsoleLine lineEntry = new ConsoleLine(line);
consoleLines.Add(lineEntry);
OnPrint?.Invoke(text);
}
PrintLine(text);
}
// Opens the Console