From 5a813f212c68efd4c00126fc74c38ba2e67d3a68 Mon Sep 17 00:00:00 2001 From: Brajanowski Date: Tue, 24 Jun 2025 14:45:45 +0200 Subject: [PATCH] working on multiplayer --- .../Engine/Code/{Services => }/Console.meta | 0 .../{Services => }/Console/ConsoleService.cs | 42 ++-- .../Console/ConsoleService.cs.meta | 0 .../Console/ConsoleServiceAsset.cs | 0 .../Console/ConsoleServiceAsset.cs.meta | 0 .../Engine/Code/{Services => }/ConsoleUI.meta | 0 .../ConsoleUI/ConsoleUIService.cs | 0 .../ConsoleUI/ConsoleUIService.cs.meta | 0 .../{Services => }/ConsoleUI/ConsoleVC.cs | 0 .../ConsoleUI/ConsoleVC.cs.meta | 0 .../Engine/Code/{Services => }/Crosshair.meta | 0 .../Crosshair/CrosshairService.cs | 24 +- .../Crosshair/CrosshairService.cs.meta | 0 .../Code/{Services => }/Development.meta | 0 .../Development/DebugOverlayView.cs | 0 .../Development/DebugOverlayView.cs.meta | 0 .../Development/DevToolsService.cs | 98 ++++---- .../Development/DevToolsService.cs.meta | 0 Runtime/Engine/Code/EngineConfigAsset.cs | 3 + .../Engine/Code/{Services => }/GameMode.meta | 0 .../GameMode/GameModesService.cs | 0 .../GameMode/GameModesService.cs.meta | 0 .../Code/{Services => }/GameMode/IGameMode.cs | 34 +-- .../{Services => }/GameMode/IGameMode.cs.meta | 0 Runtime/Engine/Code/{Services => }/Input.meta | 0 .../Code/{Services => }/Input/InputService.cs | 0 .../{Services => }/Input/InputService.cs.meta | 0 .../{Services => }/Input/InputServiceAsset.cs | 0 .../Input/InputServiceAsset.cs.meta | 0 .../Input/ScriptableInputAction.cs | 0 .../Input/ScriptableInputAction.cs.meta | 0 Runtime/Engine/Code/Main/RR.cs | 107 ++++++--- Runtime/Engine/Code/Multiplayer.meta | 3 + Runtime/Engine/Code/Multiplayer/GameLobby.cs | 7 + .../Engine/Code/Multiplayer/GameLobby.cs.meta | 3 + .../Code/Multiplayer/INetworkTransport.cs | 24 ++ .../Multiplayer/INetworkTransport.cs.meta | 3 + .../Engine/Code/Multiplayer/NetworkPacket.cs | 4 + .../Code/Multiplayer/NetworkPacket.cs.meta | 3 + Runtime/Engine/Code/Services.meta | 3 - .../Code/{Services => }/Simulation.meta | 0 .../Code/{Services => }/Simulation/Actor.cs | 0 .../{Services => }/Simulation/Actor.cs.meta | 0 .../{Services => }/Simulation/Characters.meta | 0 .../Characters/CharacterLocomotion.cs | 0 .../Characters/CharacterLocomotion.cs.meta | 0 .../Simulation/Interactors.meta | 0 .../Simulation/Interactors/IInteractor.cs | 0 .../Interactors/IInteractor.cs.meta | 0 .../Simulation/PhysicsObjectDragger.cs | 0 .../Simulation/PhysicsObjectDragger.cs.meta | 0 .../{Services => }/Simulation/Sensors.meta | 0 .../Simulation/Sensors/ISensor.cs | 0 .../Simulation/Sensors/ISensor.cs.meta | 0 .../Simulation/Sensors/RaycastSensor.cs | 0 .../Simulation/Sensors/RaycastSensor.cs.meta | 0 .../Simulation/WorldConfigAsset.cs | 0 .../Simulation/WorldConfigAsset.cs.meta | 0 .../{Services => }/Simulation/WorldService.cs | 0 .../Simulation/WorldService.cs.meta | 0 .../Simulation/WorldServiceAsset.cs | 0 .../Simulation/WorldServiceAsset.cs.meta | 0 Runtime/Engine/Code/Steam.meta | 3 + Runtime/Engine/Code/Steam/SteamManager.cs | 50 +++++ .../Engine/Code/Steam/SteamManager.cs.meta | 3 + .../Code/Steam/SteamNetworkTransport.cs | 209 ++++++++++++++++++ .../Code/Steam/SteamNetworkTransport.cs.meta | 3 + 67 files changed, 499 insertions(+), 127 deletions(-) rename Runtime/Engine/Code/{Services => }/Console.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Console/ConsoleService.cs (90%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Console/ConsoleService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Console/ConsoleServiceAsset.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Console/ConsoleServiceAsset.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/ConsoleUI.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/ConsoleUI/ConsoleUIService.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/ConsoleUI/ConsoleUIService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/ConsoleUI/ConsoleVC.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/ConsoleUI/ConsoleVC.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Crosshair.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Crosshair/CrosshairService.cs (95%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Crosshair/CrosshairService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Development.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Development/DebugOverlayView.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Development/DebugOverlayView.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Development/DevToolsService.cs (96%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Development/DevToolsService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/GameMode.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/GameMode/GameModesService.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/GameMode/GameModesService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/GameMode/IGameMode.cs (95%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/GameMode/IGameMode.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/InputService.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/InputService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/InputServiceAsset.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/InputServiceAsset.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/ScriptableInputAction.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Input/ScriptableInputAction.cs.meta (100%) mode change 100755 => 100644 create mode 100644 Runtime/Engine/Code/Multiplayer.meta create mode 100644 Runtime/Engine/Code/Multiplayer/GameLobby.cs create mode 100644 Runtime/Engine/Code/Multiplayer/GameLobby.cs.meta create mode 100644 Runtime/Engine/Code/Multiplayer/INetworkTransport.cs create mode 100644 Runtime/Engine/Code/Multiplayer/INetworkTransport.cs.meta create mode 100644 Runtime/Engine/Code/Multiplayer/NetworkPacket.cs create mode 100644 Runtime/Engine/Code/Multiplayer/NetworkPacket.cs.meta delete mode 100755 Runtime/Engine/Code/Services.meta rename Runtime/Engine/Code/{Services => }/Simulation.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Actor.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Actor.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Characters.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Characters/CharacterLocomotion.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Characters/CharacterLocomotion.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Interactors.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Interactors/IInteractor.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Interactors/IInteractor.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/PhysicsObjectDragger.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/PhysicsObjectDragger.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Sensors.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Sensors/ISensor.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Sensors/ISensor.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Sensors/RaycastSensor.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/Sensors/RaycastSensor.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldConfigAsset.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldConfigAsset.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldService.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldService.cs.meta (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldServiceAsset.cs (100%) mode change 100755 => 100644 rename Runtime/Engine/Code/{Services => }/Simulation/WorldServiceAsset.cs.meta (100%) mode change 100755 => 100644 create mode 100644 Runtime/Engine/Code/Steam.meta create mode 100644 Runtime/Engine/Code/Steam/SteamManager.cs create mode 100644 Runtime/Engine/Code/Steam/SteamManager.cs.meta create mode 100644 Runtime/Engine/Code/Steam/SteamNetworkTransport.cs create mode 100644 Runtime/Engine/Code/Steam/SteamNetworkTransport.cs.meta diff --git a/Runtime/Engine/Code/Services/Console.meta b/Runtime/Engine/Code/Console.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Console.meta rename to Runtime/Engine/Code/Console.meta diff --git a/Runtime/Engine/Code/Services/Console/ConsoleService.cs b/Runtime/Engine/Code/Console/ConsoleService.cs old mode 100755 new mode 100644 similarity index 90% rename from Runtime/Engine/Code/Services/Console/ConsoleService.cs rename to Runtime/Engine/Code/Console/ConsoleService.cs index dbfc593..6360ded --- a/Runtime/Engine/Code/Services/Console/ConsoleService.cs +++ b/Runtime/Engine/Code/Console/ConsoleService.cs @@ -29,7 +29,7 @@ namespace RebootKit.Engine.Services.Console { public string description; public Action action; } - + readonly List m_ConsoleCommands = new List(); FileStream m_LogFileStream; @@ -39,10 +39,16 @@ namespace RebootKit.Engine.Services.Console { public ConsoleService() { ConfigVar.StateChanged += OnCVarStateChanged; - - m_LogFileStream = new FileStream(Application.persistentDataPath + "/rr_logs.txt", FileMode.Append, FileAccess.Write); + +#if UNITY_EDITOR + string logFilePath = Application.persistentDataPath + "/rr_logs_editor.txt"; +#else + string logFilePath = Application.persistentDataPath + "/rr_logs.txt"; +#endif + + m_LogFileStream = new FileStream(logFilePath, FileMode.Append, FileAccess.Write); m_LogFileWriter = new StreamWriter(m_LogFileStream); - + m_LogFileWriter.WriteLine("============================"); m_LogFileWriter.WriteLine("Starting new log"); m_LogFileWriter.WriteLine($" > Game: {Application.productName}"); @@ -52,7 +58,7 @@ namespace RebootKit.Engine.Services.Console { m_LogFileWriter.Flush(); s_logger.Info("Waking up"); - + Load(); RegisterCommands(); @@ -146,12 +152,16 @@ namespace RebootKit.Engine.Services.Console { public static ConsoleCommand[] GenerateCommandsToRegister() { IEnumerable methods = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) - .SelectMany(type => type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)) - .Where(method => method.GetCustomAttributes(typeof(RCCMD), false).Length > 0); + .SelectMany(type => type.GetMethods(BindingFlags.NonPublic | + BindingFlags.Public | + BindingFlags.Static)) + .Where(method => method.GetCustomAttributes(typeof(RCCMD), false) + .Length > + 0); List commands = new List(); foreach (MethodInfo method in methods) { - RCCMD attribute = (RCCMD)method.GetCustomAttributes(typeof(RCCMD), false)[0]; + RCCMD attribute = (RCCMD) method.GetCustomAttributes(typeof(RCCMD), false)[0]; if (!method.IsStatic) { s_logger.Error($"Command `{attribute.name}` is not static, skipping"); @@ -162,13 +172,13 @@ namespace RebootKit.Engine.Services.Console { s_logger.Error($"Command `{attribute.name}` has invalid number of parameters, skipping"); continue; } - + if (method.GetParameters()[0].ParameterType != typeof(string[])) { s_logger.Error($"Command `{attribute.name}` has invalid parameter type, skipping"); continue; } - - Action action = (Action)Delegate.CreateDelegate(typeof(Action), method); + + Action action = (Action) Delegate.CreateDelegate(typeof(Action), method); commands.Add(new ConsoleCommand { name = attribute.name, @@ -176,17 +186,17 @@ namespace RebootKit.Engine.Services.Console { action = action }); } - + return commands.ToArray(); } - + public void RegisterCommands() { ConsoleCommand[] commands = GenerateCommandsToRegister(); foreach (ConsoleCommand command in commands) { RegisterCommand(command.name, command.description, command.action); } } - + bool IsCommandRegistered(string name) { foreach (ConsoleCommand command in m_ConsoleCommands) { if (command.name.Equals(name)) { @@ -221,7 +231,7 @@ namespace RebootKit.Engine.Services.Console { RR.Console.WriteToOutput(message.ToString()); } - + [RCCMD("cvars", "Prints all cvars")] public static void PrintCVars(string[] args) { StringBuilder message = new StringBuilder(); @@ -235,7 +245,7 @@ namespace RebootKit.Engine.Services.Console { void Save() { string path = Application.persistentDataPath + "/" + RConsts.k_CVarsFilename; - + s_logger.Info("Saving cvars to file: " + path); StringBuilder sb = new StringBuilder(); diff --git a/Runtime/Engine/Code/Services/Console/ConsoleService.cs.meta b/Runtime/Engine/Code/Console/ConsoleService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Console/ConsoleService.cs.meta rename to Runtime/Engine/Code/Console/ConsoleService.cs.meta diff --git a/Runtime/Engine/Code/Services/Console/ConsoleServiceAsset.cs b/Runtime/Engine/Code/Console/ConsoleServiceAsset.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Console/ConsoleServiceAsset.cs rename to Runtime/Engine/Code/Console/ConsoleServiceAsset.cs diff --git a/Runtime/Engine/Code/Services/Console/ConsoleServiceAsset.cs.meta b/Runtime/Engine/Code/Console/ConsoleServiceAsset.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Console/ConsoleServiceAsset.cs.meta rename to Runtime/Engine/Code/Console/ConsoleServiceAsset.cs.meta diff --git a/Runtime/Engine/Code/Services/ConsoleUI.meta b/Runtime/Engine/Code/ConsoleUI.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/ConsoleUI.meta rename to Runtime/Engine/Code/ConsoleUI.meta diff --git a/Runtime/Engine/Code/Services/ConsoleUI/ConsoleUIService.cs b/Runtime/Engine/Code/ConsoleUI/ConsoleUIService.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/ConsoleUI/ConsoleUIService.cs rename to Runtime/Engine/Code/ConsoleUI/ConsoleUIService.cs diff --git a/Runtime/Engine/Code/Services/ConsoleUI/ConsoleUIService.cs.meta b/Runtime/Engine/Code/ConsoleUI/ConsoleUIService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/ConsoleUI/ConsoleUIService.cs.meta rename to Runtime/Engine/Code/ConsoleUI/ConsoleUIService.cs.meta diff --git a/Runtime/Engine/Code/Services/ConsoleUI/ConsoleVC.cs b/Runtime/Engine/Code/ConsoleUI/ConsoleVC.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/ConsoleUI/ConsoleVC.cs rename to Runtime/Engine/Code/ConsoleUI/ConsoleVC.cs diff --git a/Runtime/Engine/Code/Services/ConsoleUI/ConsoleVC.cs.meta b/Runtime/Engine/Code/ConsoleUI/ConsoleVC.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/ConsoleUI/ConsoleVC.cs.meta rename to Runtime/Engine/Code/ConsoleUI/ConsoleVC.cs.meta diff --git a/Runtime/Engine/Code/Services/Crosshair.meta b/Runtime/Engine/Code/Crosshair.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Crosshair.meta rename to Runtime/Engine/Code/Crosshair.meta diff --git a/Runtime/Engine/Code/Services/Crosshair/CrosshairService.cs b/Runtime/Engine/Code/Crosshair/CrosshairService.cs old mode 100755 new mode 100644 similarity index 95% rename from Runtime/Engine/Code/Services/Crosshair/CrosshairService.cs rename to Runtime/Engine/Code/Crosshair/CrosshairService.cs index c03a52c..47245ce --- a/Runtime/Engine/Code/Services/Crosshair/CrosshairService.cs +++ b/Runtime/Engine/Code/Crosshair/CrosshairService.cs @@ -1,13 +1,13 @@ -using RebootKit.Engine.Foundation; - -namespace RebootKit.Engine.Services.Crosshair { - public class CrosshairService : IService { - - public CrosshairService() { - - } - - public void Dispose() { - } - } +using RebootKit.Engine.Foundation; + +namespace RebootKit.Engine.Services.Crosshair { + public class CrosshairService : IService { + + public CrosshairService() { + + } + + public void Dispose() { + } + } } \ No newline at end of file diff --git a/Runtime/Engine/Code/Services/Crosshair/CrosshairService.cs.meta b/Runtime/Engine/Code/Crosshair/CrosshairService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Crosshair/CrosshairService.cs.meta rename to Runtime/Engine/Code/Crosshair/CrosshairService.cs.meta diff --git a/Runtime/Engine/Code/Services/Development.meta b/Runtime/Engine/Code/Development.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Development.meta rename to Runtime/Engine/Code/Development.meta diff --git a/Runtime/Engine/Code/Services/Development/DebugOverlayView.cs b/Runtime/Engine/Code/Development/DebugOverlayView.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Development/DebugOverlayView.cs rename to Runtime/Engine/Code/Development/DebugOverlayView.cs diff --git a/Runtime/Engine/Code/Services/Development/DebugOverlayView.cs.meta b/Runtime/Engine/Code/Development/DebugOverlayView.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Development/DebugOverlayView.cs.meta rename to Runtime/Engine/Code/Development/DebugOverlayView.cs.meta diff --git a/Runtime/Engine/Code/Services/Development/DevToolsService.cs b/Runtime/Engine/Code/Development/DevToolsService.cs old mode 100755 new mode 100644 similarity index 96% rename from Runtime/Engine/Code/Services/Development/DevToolsService.cs rename to Runtime/Engine/Code/Development/DevToolsService.cs index 8b8a0d4..bd1784a --- a/Runtime/Engine/Code/Services/Development/DevToolsService.cs +++ b/Runtime/Engine/Code/Development/DevToolsService.cs @@ -1,50 +1,50 @@ -using System; -using RebootKit.Engine.Foundation; -using RebootKit.Engine.Services.Console; -using UnityEngine; -using UnityEngine.InputSystem; - -namespace RebootKit.Engine.Services.Development { - static class DebugConfig { - [ConfigVar("debug.overlay", 0, "Controls overlay visibility. 0 - hidden, 1 - visible")] public static ConfigVar s_OverlayMode; - } - - public class DevToolsService : ServiceMonoBehaviour { - [SerializeField] DebugOverlayView m_DebugOverlayView; - - IDisposable m_CVarChangedListener; - - void Start() { - ConfigVar.StateChanged += OnCVarChanged; - OnCVarChanged(DebugConfig.s_OverlayMode); - } - - void OnDisable() { - Dispose(); - } - - public override void Dispose() { - ConfigVar.StateChanged -= OnCVarChanged; - } - - void Update() { - if (InputSystem.GetDevice().f3Key.wasReleasedThisFrame) { - DebugConfig.s_OverlayMode.Set(DebugConfig.s_OverlayMode.IndexValue == 1 ? 0 : 1); - } - } - - void OnOverlayModeChanged(int mode) { - if (mode == 1) { - m_DebugOverlayView.gameObject.SetActive(true); - } else { - m_DebugOverlayView.gameObject.SetActive(false); - } - } - - void OnCVarChanged(ConfigVar cvar) { - if (cvar == DebugConfig.s_OverlayMode) { - OnOverlayModeChanged(cvar.IndexValue); - } - } - } +using System; +using RebootKit.Engine.Foundation; +using RebootKit.Engine.Services.Console; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace RebootKit.Engine.Services.Development { + static class DebugConfig { + [ConfigVar("debug.overlay", 0, "Controls overlay visibility. 0 - hidden, 1 - visible")] public static ConfigVar s_OverlayMode; + } + + public class DevToolsService : ServiceMonoBehaviour { + [SerializeField] DebugOverlayView m_DebugOverlayView; + + IDisposable m_CVarChangedListener; + + void Start() { + ConfigVar.StateChanged += OnCVarChanged; + OnCVarChanged(DebugConfig.s_OverlayMode); + } + + void OnDisable() { + Dispose(); + } + + public override void Dispose() { + ConfigVar.StateChanged -= OnCVarChanged; + } + + void Update() { + if (InputSystem.GetDevice().f3Key.wasReleasedThisFrame) { + DebugConfig.s_OverlayMode.Set(DebugConfig.s_OverlayMode.IndexValue == 1 ? 0 : 1); + } + } + + void OnOverlayModeChanged(int mode) { + if (mode == 1) { + m_DebugOverlayView.gameObject.SetActive(true); + } else { + m_DebugOverlayView.gameObject.SetActive(false); + } + } + + void OnCVarChanged(ConfigVar cvar) { + if (cvar == DebugConfig.s_OverlayMode) { + OnOverlayModeChanged(cvar.IndexValue); + } + } + } } \ No newline at end of file diff --git a/Runtime/Engine/Code/Services/Development/DevToolsService.cs.meta b/Runtime/Engine/Code/Development/DevToolsService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Development/DevToolsService.cs.meta rename to Runtime/Engine/Code/Development/DevToolsService.cs.meta diff --git a/Runtime/Engine/Code/EngineConfigAsset.cs b/Runtime/Engine/Code/EngineConfigAsset.cs index 909b023..5d2cd71 100755 --- a/Runtime/Engine/Code/EngineConfigAsset.cs +++ b/Runtime/Engine/Code/EngineConfigAsset.cs @@ -9,5 +9,8 @@ namespace RebootKit.Engine { public EngineCoreServicesAsset coreServices; public GameAsset gameAsset; + + // @NOTE: Spacewar, change as needed + public uint steamAppID = 480; } } diff --git a/Runtime/Engine/Code/Services/GameMode.meta b/Runtime/Engine/Code/GameMode.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/GameMode.meta rename to Runtime/Engine/Code/GameMode.meta diff --git a/Runtime/Engine/Code/Services/GameMode/GameModesService.cs b/Runtime/Engine/Code/GameMode/GameModesService.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/GameMode/GameModesService.cs rename to Runtime/Engine/Code/GameMode/GameModesService.cs diff --git a/Runtime/Engine/Code/Services/GameMode/GameModesService.cs.meta b/Runtime/Engine/Code/GameMode/GameModesService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/GameMode/GameModesService.cs.meta rename to Runtime/Engine/Code/GameMode/GameModesService.cs.meta diff --git a/Runtime/Engine/Code/Services/GameMode/IGameMode.cs b/Runtime/Engine/Code/GameMode/IGameMode.cs old mode 100755 new mode 100644 similarity index 95% rename from Runtime/Engine/Code/Services/GameMode/IGameMode.cs rename to Runtime/Engine/Code/GameMode/IGameMode.cs index 94298c5..9c8e309 --- a/Runtime/Engine/Code/Services/GameMode/IGameMode.cs +++ b/Runtime/Engine/Code/GameMode/IGameMode.cs @@ -1,18 +1,18 @@ -using System; -using System.Threading; -using Cysharp.Threading.Tasks; -using RebootKit.Engine.Foundation; - -namespace RebootKit.Engine.Services.GameMode { - public interface IGameMode : IDisposable { - UniTask OnInit(CancellationToken cancellationToken); - - void OnStart(); - void OnStop(); - - void OnTick(); - } - - public abstract class GameModeAsset : FactoryAsset { - } +using System; +using System.Threading; +using Cysharp.Threading.Tasks; +using RebootKit.Engine.Foundation; + +namespace RebootKit.Engine.Services.GameMode { + public interface IGameMode : IDisposable { + UniTask OnInit(CancellationToken cancellationToken); + + void OnStart(); + void OnStop(); + + void OnTick(); + } + + public abstract class GameModeAsset : FactoryAsset { + } } \ No newline at end of file diff --git a/Runtime/Engine/Code/Services/GameMode/IGameMode.cs.meta b/Runtime/Engine/Code/GameMode/IGameMode.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/GameMode/IGameMode.cs.meta rename to Runtime/Engine/Code/GameMode/IGameMode.cs.meta diff --git a/Runtime/Engine/Code/Services/Input.meta b/Runtime/Engine/Code/Input.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input.meta rename to Runtime/Engine/Code/Input.meta diff --git a/Runtime/Engine/Code/Services/Input/InputService.cs b/Runtime/Engine/Code/Input/InputService.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/InputService.cs rename to Runtime/Engine/Code/Input/InputService.cs diff --git a/Runtime/Engine/Code/Services/Input/InputService.cs.meta b/Runtime/Engine/Code/Input/InputService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/InputService.cs.meta rename to Runtime/Engine/Code/Input/InputService.cs.meta diff --git a/Runtime/Engine/Code/Services/Input/InputServiceAsset.cs b/Runtime/Engine/Code/Input/InputServiceAsset.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/InputServiceAsset.cs rename to Runtime/Engine/Code/Input/InputServiceAsset.cs diff --git a/Runtime/Engine/Code/Services/Input/InputServiceAsset.cs.meta b/Runtime/Engine/Code/Input/InputServiceAsset.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/InputServiceAsset.cs.meta rename to Runtime/Engine/Code/Input/InputServiceAsset.cs.meta diff --git a/Runtime/Engine/Code/Services/Input/ScriptableInputAction.cs b/Runtime/Engine/Code/Input/ScriptableInputAction.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/ScriptableInputAction.cs rename to Runtime/Engine/Code/Input/ScriptableInputAction.cs diff --git a/Runtime/Engine/Code/Services/Input/ScriptableInputAction.cs.meta b/Runtime/Engine/Code/Input/ScriptableInputAction.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Input/ScriptableInputAction.cs.meta rename to Runtime/Engine/Code/Input/ScriptableInputAction.cs.meta diff --git a/Runtime/Engine/Code/Main/RR.cs b/Runtime/Engine/Code/Main/RR.cs index 7696a17..53c94d9 100755 --- a/Runtime/Engine/Code/Main/RR.cs +++ b/Runtime/Engine/Code/Main/RR.cs @@ -4,19 +4,18 @@ using System.Threading; using Cysharp.Threading.Tasks; using R3; using RebootKit.Engine.Foundation; +using RebootKit.Engine.Multiplayer; using RebootKit.Engine.Services.Console; using RebootKit.Engine.Services.GameMode; using RebootKit.Engine.Services.Input; using RebootKit.Engine.Services.Simulation; +using RebootKit.Engine.Steam; +using Unity.Collections; using UnityEngine; using UnityEngine.AddressableAssets; using Assert = UnityEngine.Assertions.Assert; using Logger = RebootKit.Engine.Foundation.Logger; -// RR -// Game -// GameMode - namespace RebootKit.Engine.Main { public interface IGame : IDisposable { UniTask InitAsync(CancellationToken cancellationToken); @@ -33,56 +32,60 @@ namespace RebootKit.Engine.Main { [ConfigVar("con.write_log", 1, "Enables writing game log to console output")] static ConfigVar s_writeLogToConsole; - static EngineConfigAsset s_engineConfigAsset; + internal static EngineConfigAsset EngineConfig; static DisposableBag s_disposableBag; static DisposableBag s_servicesBag; - static ConsoleService s_consoleService; - static GameModesService s_gameModesService; - static InputService s_inputService; - static WorldService s_worldService; - - public static ConsoleService Console => s_consoleService; - public static InputService Input => s_inputService; - public static WorldService World => s_worldService; - public static GameModesService GameModes => s_gameModesService; + public static ConsoleService Console { get; private set; } + public static InputService Input { get; private set; } + public static WorldService World { get; private set; } + public static GameModesService GameModes { get; private set; } public static Camera MainCamera { get; internal set; } static IGame s_game; - public static async UniTask InitAsync(EngineConfigAsset configAsset, CancellationToken cancellationToken) { + // Core + internal static async UniTask InitAsync(EngineConfigAsset configAsset, CancellationToken cancellationToken) { Assert.IsNotNull(configAsset, "Config asset is required"); Assert.IsNotNull(configAsset.gameAsset, "Game asset is required"); - s_engineConfigAsset = configAsset; + EngineConfig = configAsset; s_Logger.Info("Initializing"); s_servicesBag = new DisposableBag(); s_disposableBag = new DisposableBag(); s_Logger.Debug("Registering core services"); - s_consoleService = CreateService(s_engineConfigAsset.coreServices.consoleService); - s_inputService = CreateService(s_engineConfigAsset.coreServices.inputService); - s_worldService = CreateService(s_engineConfigAsset.coreServices.worldService); - s_gameModesService = CreateService(); + Console = CreateService(EngineConfig.coreServices.consoleService); + Input = CreateService(EngineConfig.coreServices.inputService); + World = CreateService(EngineConfig.coreServices.worldService); + GameModes = CreateService(); await InitializeAssetsAsync(cancellationToken); + + await SteamManager.InitializeAsync(cancellationToken); + + if (SteamManager.IsInitialized) { + s_networkTransport = SteamManager.NetworkTransport; + } s_Logger.Debug("Creating game"); - s_game = s_engineConfigAsset.gameAsset.CreateGame(); + s_game = EngineConfig.gameAsset.CreateGame(); await s_game.InitAsync(cancellationToken); } - public static void Shutdown() { + internal static void Shutdown() { + SteamManager.Shutdown(); + s_Logger.Info("Shutting down"); s_servicesBag.Dispose(); s_disposableBag.Dispose(); } - public static void Run() { + internal static void Run() { s_game.Run(); #if UNITY_EDITOR @@ -145,12 +148,13 @@ namespace RebootKit.Engine.Main { // Game API public static void StartGameMode(GameModeAsset gameMode, WorldConfig world) { - if (gameMode is null) { - throw new ArgumentNullException(nameof(gameMode)); + if (!IsClient() || !IsHost()) { + s_Logger.Error("Cannot start game mode: you must be connected to a server and be the host"); + return; } - + s_Logger.Info($"Starting game mode: {gameMode.name} in world: {world.name}"); - s_gameModesService.Start(gameMode, world); + GameModes.Start(gameMode, world); } public static TGame Game() where TGame : IGame { @@ -182,17 +186,17 @@ namespace RebootKit.Engine.Main { public static void Log(string message) { Debug.Log(message); - s_consoleService?.WriteToOutput(message); + Console?.WriteToOutput(message); } public static void LogWarning(string message) { Debug.LogWarning(message); - s_consoleService?.WriteToOutput(message); + Console?.WriteToOutput(message); } public static void LogError(string message) { Debug.LogError(message); - s_consoleService?.WriteToOutput(message); + Console?.WriteToOutput(message); } // CVar API @@ -228,5 +232,48 @@ namespace RebootKit.Engine.Main { ConfigVarsContainer.Register(cvar); return cvar; } + + // Network API + static GameLobby s_gameLobby; + static INetworkTransport s_networkTransport; + + public static bool IsHost() { + return s_networkTransport.IsServer(); + } + + public static bool IsClient() { + return s_networkTransport.IsClient(); + } + + public static int GetPing() { + return -1; + } + + public static void HostServer(bool offline = false) { + s_networkTransport.StartServer(); + } + + public static void ConnectToLobby() { + s_networkTransport.Connect(Steamworks.SteamNetworkingSockets.Identity.SteamId); + } + + public static void Disconnect() { + s_networkTransport.Disconnect(); + } + + internal static void OnConnected(GameLobby lobby) { + } + + internal static void OnDisconnected() { + } + + internal static void OnServerDataReceived(byte[] data) { + s_Logger.Debug($"[SERVER] Data received: {data.Length} bytes"); + + } + + internal static void OnClientDataReceived(byte[] data) { + s_Logger.Debug($"[CLIENT] Data received: {data.Length} bytes"); + } } } \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer.meta b/Runtime/Engine/Code/Multiplayer.meta new file mode 100644 index 0000000..be0188b --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 83d5dc53310c40caab8b7732b9cecbdc +timeCreated: 1750615656 \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/GameLobby.cs b/Runtime/Engine/Code/Multiplayer/GameLobby.cs new file mode 100644 index 0000000..7d5aedc --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/GameLobby.cs @@ -0,0 +1,7 @@ +namespace RebootKit.Engine.Multiplayer { + public class GameLobby { + public string GameModeID { get; private set; } + public string WorldID { get; private set; } + + } +} \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/GameLobby.cs.meta b/Runtime/Engine/Code/Multiplayer/GameLobby.cs.meta new file mode 100644 index 0000000..ef18829 --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/GameLobby.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cf39e9785e4e4ad0a7ebb8b19c882b2a +timeCreated: 1750628631 \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs b/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs new file mode 100644 index 0000000..0695a3e --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs @@ -0,0 +1,24 @@ +using System; + +namespace RebootKit.Engine.Multiplayer { + public enum SendMode { + Reliable, + Unreliable + } + + public interface INetworkTransport { + void Initialize(); + void Shutdown(); + + bool IsServer(); + bool IsClient(); + + bool StartServer(); + void StopServer(); + + bool Connect(ulong serverID); + void Disconnect(); + + void Send(ulong clientID, ArraySegment data, SendMode mode); + } +} \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs.meta b/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs.meta new file mode 100644 index 0000000..ab6100d --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/INetworkTransport.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 702059b29fda4edc80caf8b22cd8c0d7 +timeCreated: 1750759626 \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs b/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs new file mode 100644 index 0000000..746d5d4 --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs @@ -0,0 +1,4 @@ +namespace RebootKit.Engine.Multiplayer { + + +} \ No newline at end of file diff --git a/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs.meta b/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs.meta new file mode 100644 index 0000000..ffd148f --- /dev/null +++ b/Runtime/Engine/Code/Multiplayer/NetworkPacket.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 34d66ac5d1c443e8992a84edd5eb796e +timeCreated: 1750628495 \ No newline at end of file diff --git a/Runtime/Engine/Code/Services.meta b/Runtime/Engine/Code/Services.meta deleted file mode 100755 index 709b8a2..0000000 --- a/Runtime/Engine/Code/Services.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ac31ad3431a84354ab7c73a84039be3f -timeCreated: 1741791385 \ No newline at end of file diff --git a/Runtime/Engine/Code/Services/Simulation.meta b/Runtime/Engine/Code/Simulation.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation.meta rename to Runtime/Engine/Code/Simulation.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Actor.cs b/Runtime/Engine/Code/Simulation/Actor.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Actor.cs rename to Runtime/Engine/Code/Simulation/Actor.cs diff --git a/Runtime/Engine/Code/Services/Simulation/Actor.cs.meta b/Runtime/Engine/Code/Simulation/Actor.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Actor.cs.meta rename to Runtime/Engine/Code/Simulation/Actor.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Characters.meta b/Runtime/Engine/Code/Simulation/Characters.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Characters.meta rename to Runtime/Engine/Code/Simulation/Characters.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Characters/CharacterLocomotion.cs b/Runtime/Engine/Code/Simulation/Characters/CharacterLocomotion.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Characters/CharacterLocomotion.cs rename to Runtime/Engine/Code/Simulation/Characters/CharacterLocomotion.cs diff --git a/Runtime/Engine/Code/Services/Simulation/Characters/CharacterLocomotion.cs.meta b/Runtime/Engine/Code/Simulation/Characters/CharacterLocomotion.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Characters/CharacterLocomotion.cs.meta rename to Runtime/Engine/Code/Simulation/Characters/CharacterLocomotion.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Interactors.meta b/Runtime/Engine/Code/Simulation/Interactors.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Interactors.meta rename to Runtime/Engine/Code/Simulation/Interactors.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Interactors/IInteractor.cs b/Runtime/Engine/Code/Simulation/Interactors/IInteractor.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Interactors/IInteractor.cs rename to Runtime/Engine/Code/Simulation/Interactors/IInteractor.cs diff --git a/Runtime/Engine/Code/Services/Simulation/Interactors/IInteractor.cs.meta b/Runtime/Engine/Code/Simulation/Interactors/IInteractor.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Interactors/IInteractor.cs.meta rename to Runtime/Engine/Code/Simulation/Interactors/IInteractor.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/PhysicsObjectDragger.cs b/Runtime/Engine/Code/Simulation/PhysicsObjectDragger.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/PhysicsObjectDragger.cs rename to Runtime/Engine/Code/Simulation/PhysicsObjectDragger.cs diff --git a/Runtime/Engine/Code/Services/Simulation/PhysicsObjectDragger.cs.meta b/Runtime/Engine/Code/Simulation/PhysicsObjectDragger.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/PhysicsObjectDragger.cs.meta rename to Runtime/Engine/Code/Simulation/PhysicsObjectDragger.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Sensors.meta b/Runtime/Engine/Code/Simulation/Sensors.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Sensors.meta rename to Runtime/Engine/Code/Simulation/Sensors.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Sensors/ISensor.cs b/Runtime/Engine/Code/Simulation/Sensors/ISensor.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Sensors/ISensor.cs rename to Runtime/Engine/Code/Simulation/Sensors/ISensor.cs diff --git a/Runtime/Engine/Code/Services/Simulation/Sensors/ISensor.cs.meta b/Runtime/Engine/Code/Simulation/Sensors/ISensor.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Sensors/ISensor.cs.meta rename to Runtime/Engine/Code/Simulation/Sensors/ISensor.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/Sensors/RaycastSensor.cs b/Runtime/Engine/Code/Simulation/Sensors/RaycastSensor.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Sensors/RaycastSensor.cs rename to Runtime/Engine/Code/Simulation/Sensors/RaycastSensor.cs diff --git a/Runtime/Engine/Code/Services/Simulation/Sensors/RaycastSensor.cs.meta b/Runtime/Engine/Code/Simulation/Sensors/RaycastSensor.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/Sensors/RaycastSensor.cs.meta rename to Runtime/Engine/Code/Simulation/Sensors/RaycastSensor.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/WorldConfigAsset.cs b/Runtime/Engine/Code/Simulation/WorldConfigAsset.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldConfigAsset.cs rename to Runtime/Engine/Code/Simulation/WorldConfigAsset.cs diff --git a/Runtime/Engine/Code/Services/Simulation/WorldConfigAsset.cs.meta b/Runtime/Engine/Code/Simulation/WorldConfigAsset.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldConfigAsset.cs.meta rename to Runtime/Engine/Code/Simulation/WorldConfigAsset.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/WorldService.cs b/Runtime/Engine/Code/Simulation/WorldService.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldService.cs rename to Runtime/Engine/Code/Simulation/WorldService.cs diff --git a/Runtime/Engine/Code/Services/Simulation/WorldService.cs.meta b/Runtime/Engine/Code/Simulation/WorldService.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldService.cs.meta rename to Runtime/Engine/Code/Simulation/WorldService.cs.meta diff --git a/Runtime/Engine/Code/Services/Simulation/WorldServiceAsset.cs b/Runtime/Engine/Code/Simulation/WorldServiceAsset.cs old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldServiceAsset.cs rename to Runtime/Engine/Code/Simulation/WorldServiceAsset.cs diff --git a/Runtime/Engine/Code/Services/Simulation/WorldServiceAsset.cs.meta b/Runtime/Engine/Code/Simulation/WorldServiceAsset.cs.meta old mode 100755 new mode 100644 similarity index 100% rename from Runtime/Engine/Code/Services/Simulation/WorldServiceAsset.cs.meta rename to Runtime/Engine/Code/Simulation/WorldServiceAsset.cs.meta diff --git a/Runtime/Engine/Code/Steam.meta b/Runtime/Engine/Code/Steam.meta new file mode 100644 index 0000000..5930378 --- /dev/null +++ b/Runtime/Engine/Code/Steam.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b72bb6331ad3466d9c3da0c63c300d1a +timeCreated: 1750601845 \ No newline at end of file diff --git a/Runtime/Engine/Code/Steam/SteamManager.cs b/Runtime/Engine/Code/Steam/SteamManager.cs new file mode 100644 index 0000000..7c51ba6 --- /dev/null +++ b/Runtime/Engine/Code/Steam/SteamManager.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading; +using Cysharp.Threading.Tasks; +using R3; +using RebootKit.Engine.Main; +using RebootKit.Engine.Multiplayer; +using Steamworks; +using Logger = RebootKit.Engine.Foundation.Logger; + +namespace RebootKit.Engine.Steam { + static class SteamManager { + static readonly Logger s_Logger = new Logger(nameof(SteamManager)); + + public static bool IsInitialized { get; private set; } = false; + + public static INetworkTransport NetworkTransport { get; private set; } = new SteamNetworkTransport(); + + internal static async UniTask InitializeAsync(CancellationToken cancellationToken = default) { + s_Logger.Info("Initializing Steam Manager..."); + IsInitialized = false; + + try { + SteamClient.Init(RR.EngineConfig.steamAppID, true); + } catch (Exception ex) { + s_Logger.Error($"Failed to initialize Steam Client: {ex.Message}"); + return; + } + + NetworkTransport.Initialize(); + + IsInitialized = true; + + await UniTask.Yield(cancellationToken); + } + + internal static void Shutdown() { + if (!IsInitialized) { + s_Logger.Error("Steam Manager is not initialized. Skipping operation."); + return; + } + + s_Logger.Info("Shutting down Steam Manager..."); + + NetworkTransport.Shutdown(); + SteamClient.Shutdown(); + + IsInitialized = false; + } + } +} \ No newline at end of file diff --git a/Runtime/Engine/Code/Steam/SteamManager.cs.meta b/Runtime/Engine/Code/Steam/SteamManager.cs.meta new file mode 100644 index 0000000..13be069 --- /dev/null +++ b/Runtime/Engine/Code/Steam/SteamManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 692a7bd3511b4e79b29944f1439556a0 +timeCreated: 1750601849 \ No newline at end of file diff --git a/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs b/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs new file mode 100644 index 0000000..a5de7b8 --- /dev/null +++ b/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs @@ -0,0 +1,209 @@ +using System; +using R3; +using RebootKit.Engine.Foundation; +using RebootKit.Engine.Main; +using RebootKit.Engine.Multiplayer; +using Steamworks; +using Steamworks.Data; +using Logger = RebootKit.Engine.Foundation.Logger; + +namespace RebootKit.Engine.Steam { + class SteamNetworkTransport : INetworkTransport { + static readonly Logger s_Logger = new Logger(nameof(SteamNetworkTransport)); + + const int k_DefaultPort = 420; + + ServerCallbacks m_SocketManager; + ClientCallbacks m_ConnectionManager; + IDisposable m_TickDisposable; + + SteamId m_HostSteamID; + + public void Initialize() { + m_TickDisposable = Observable.EveryUpdate() + .Subscribe(_ => Tick()); + + SteamNetworkingUtils.DebugLevel = NetDebugOutput.Debug; + + SteamNetworkingSockets.OnConnectionStatusChanged += OnConnectionStatusChanged; + SteamNetworkingUtils.OnDebugOutput += OnSteamNetworkDebugOutput; + + SteamNetworkingUtils.InitRelayNetworkAccess(); + } + + public void Shutdown() { + Disconnect(); + + SteamNetworkingUtils.OnDebugOutput -= OnSteamNetworkDebugOutput; + SteamNetworkingSockets.OnConnectionStatusChanged -= OnConnectionStatusChanged; + + m_TickDisposable.Dispose(); + } + + public bool IsServer() { + return m_SocketManager != null; + } + + public bool IsClient() { + return m_ConnectionManager != null; + } + + public bool StartServer() { + Disconnect(); + + s_Logger.Info("Creating server..."); + + try { + m_HostSteamID = SteamNetworkingSockets.Identity.SteamId; + + m_SocketManager = SteamNetworkingSockets.CreateRelaySocket(k_DefaultPort); + m_ConnectionManager = SteamNetworkingSockets.ConnectRelay(m_HostSteamID, k_DefaultPort); + } catch (Exception e) { + s_Logger.Error($"Failed to create server: {e.Message}"); + m_SocketManager = null; + m_ConnectionManager = null; + + return false; + } + + return true; + } + + public void StopServer() { + Disconnect(); + } + + public bool Connect(ulong serverID) { + if (IsServer()) { + s_Logger.Error("Cannot connect to a server while running as a server."); + return false; + } + + Disconnect(); + + s_Logger.Info("Connecting to server with steam ID: " + serverID); + try { + m_ConnectionManager = SteamNetworkingSockets.ConnectRelay(serverID, k_DefaultPort); + m_HostSteamID = serverID; + } catch (Exception e) { + s_Logger.Error($"Failed to connect to server with ID {serverID}: {e.Message}"); + m_ConnectionManager = null; + + return false; + } + + return true; + } + + public void Disconnect() { + if (m_ConnectionManager != null) { + s_Logger.Info("Disconnecting from the server..."); + m_ConnectionManager.Close(); + m_ConnectionManager = null; + } + + if (m_SocketManager != null) { + s_Logger.Info("Shutting down the server..."); + m_SocketManager.Close(); + m_SocketManager = null; + } + } + + public void Send(ulong clientID, ArraySegment data, SendMode mode) { + if (clientID == 0) { + clientID = m_HostSteamID; + } + + } + + void OnSteamNetworkDebugOutput(NetDebugOutput level, string message) { + LogLevel logLevel = level switch { + NetDebugOutput.Debug => LogLevel.Debug, + NetDebugOutput.Msg => LogLevel.Info, + NetDebugOutput.Warning => LogLevel.Warning, + NetDebugOutput.Error => LogLevel.Error, + _ => LogLevel.Info + }; + + s_Logger.Log(logLevel, message); + } + + void Tick() { + m_SocketManager?.Receive(); + m_ConnectionManager?.Receive(); + } + + void OnConnectionStatusChanged(Connection connection, ConnectionInfo info) { + s_Logger.Info($"OnConnectionStatusChanged: {connection.Id} - {info.Identity} - Status: {info.State}"); + } + + class ServerCallbacks : SocketManager { + public override void OnConnecting(Connection connection, ConnectionInfo data) { + base.OnConnecting(connection, data); + connection.Accept(); + + s_Logger.Info($"OnConnecting: {connection.Id} - {data.Identity}"); + } + + public override void OnConnected(Connection connection, ConnectionInfo data) { + base.OnConnected(connection, data); + + s_Logger.Info($"OnConnected: {connection.Id} - {data.Identity}"); + + connection.SendMessage(new byte[] { + 0xBE, + 0xFE, + 0x00, + 0x00 + }, 0, 4, 0); + } + + public override void OnDisconnected(Connection connection, ConnectionInfo data) { + base.OnDisconnected(connection, data); + + s_Logger.Info($"OnDisconnected: {connection.Id} - {data.Identity}"); + } + + public override void OnMessage(Connection connection, + NetIdentity identity, + IntPtr data, + int size, + long messageNum, + long recvTime, + int channel) { + base.OnMessage(connection, identity, data, size, messageNum, recvTime, channel); + + byte[] buffer = new byte[size]; + System.Runtime.InteropServices.Marshal.Copy(data, buffer, 0, size); + RR.OnServerDataReceived(buffer); + + s_Logger.Info($"OnMessage: {connection.Id} - {identity} - Size: {size} - Channel: {channel}"); + } + } + + class ClientCallbacks : ConnectionManager { + public override void OnConnected(ConnectionInfo info) { + base.OnConnected(info); + s_Logger.Info("ConnectionOnConnected"); + } + + public override void OnConnecting(ConnectionInfo info) { + base.OnConnecting(info); + s_Logger.Info("ConnectionOnConnecting"); + } + + public override void OnDisconnected(ConnectionInfo info) { + base.OnDisconnected(info); + s_Logger.Info("ConnectionOnDisconnected"); + } + + public override void OnMessage(IntPtr data, int size, long messageNum, long recvTime, int channel) { + byte[] buffer = new byte[size]; + System.Runtime.InteropServices.Marshal.Copy(data, buffer, 0, size); + RR.OnClientDataReceived(buffer); + + s_Logger.Info($"OnMessage: Size: {size} - Channel: {channel}"); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs.meta b/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs.meta new file mode 100644 index 0000000..3553cfa --- /dev/null +++ b/Runtime/Engine/Code/Steam/SteamNetworkTransport.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 71b7467a62944868972778b3326a153a +timeCreated: 1750615670 \ No newline at end of file