removed r3

This commit is contained in:
2025-10-02 00:38:45 +02:00
parent f9fae63e01
commit fe7dea3c7c
7 changed files with 66 additions and 47 deletions

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
using UnityEngine;
namespace RebootKit.Engine.Foundation {
public class AppLoopManager : MonoBehaviour {
static readonly Logger s_Logger = new Logger(nameof(AppLoopManager));
public delegate void TickDelegate(float dt);
readonly List<TickDelegate> m_Delegates = new List<TickDelegate>();
void Update() {
float dt = Time.deltaTime;
foreach (TickDelegate tick in m_Delegates) {
tick(dt);
}
}
public void Add(TickDelegate tick) {
if (m_Delegates.Contains(tick)) {
s_Logger.Warning("Tick is already registered!");
}
m_Delegates.Add(tick);
}
public void Remove(TickDelegate tick) {
m_Delegates.Remove(tick);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 64a923b7732440d1ab5505b4dd250fc2
timeCreated: 1759181550

View File

@@ -4,7 +4,6 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
using ZLinq;
namespace RebootKit.Engine.Foundation { namespace RebootKit.Engine.Foundation {
[AttributeUsage(AttributeTargets.Field)] [AttributeUsage(AttributeTargets.Field)]
@@ -49,7 +48,7 @@ namespace RebootKit.Engine.Foundation {
static readonly List<ConfigVar> s_configVars = new List<ConfigVar>(); static readonly List<ConfigVar> s_configVars = new List<ConfigVar>();
public static void Register(ConfigVar cvar) { public static void Register(ConfigVar cvar) {
if (s_configVars.AsValueEnumerable().Any(c => c.name.Equals(cvar.name, StringComparison.Ordinal))) { if (Get(cvar.name) != null) {
throw new Exception($"CVar with name '{cvar.name}' already exists"); throw new Exception($"CVar with name '{cvar.name}' already exists");
} }
@@ -63,7 +62,13 @@ namespace RebootKit.Engine.Foundation {
} }
public static ConfigVar Get(string name) { public static ConfigVar Get(string name) {
return s_configVars.AsValueEnumerable().FirstOrDefault(c => c.name.Equals(name, StringComparison.Ordinal)); foreach (ConfigVar configVar in s_configVars) {
if (configVar.name.Equals(name, StringComparison.Ordinal)) {
return configVar;
}
}
return null;
} }
public static IEnumerable<ConfigVar> All() => s_configVars; public static IEnumerable<ConfigVar> All() => s_configVars;

View File

@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using R3;
using RebootKit.Engine.Console; using RebootKit.Engine.Console;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Foundation; using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input; using RebootKit.Engine.Input;
using RebootKit.Engine.Network; using RebootKit.Engine.Network;
@@ -32,10 +32,10 @@ namespace RebootKit.Engine.Main {
internal static EngineConfigAsset EngineConfig; internal static EngineConfigAsset EngineConfig;
static DisposableBag s_DisposableBag;
static DisposableBag s_ServicesBag;
static AsyncOperationHandle<SceneInstance> s_MainMenuSceneHandle; static AsyncOperationHandle<SceneInstance> s_MainMenuSceneHandle;
internal static GameObject SystemGameObject;
internal static AppLoopManager LoopManager;
internal static NetworkSystem Network; internal static NetworkSystem Network;
internal static byte NetworkProtocolVersion { internal static byte NetworkProtocolVersion {
@@ -62,14 +62,16 @@ namespace RebootKit.Engine.Main {
EngineConfig = configAsset; EngineConfig = configAsset;
s_Logger.Info("Initializing"); s_Logger.Info("Initializing");
s_ServicesBag = new DisposableBag();
s_DisposableBag = new DisposableBag();
s_Logger.Info("Registering core services"); s_Logger.Info("Registering core services");
Console = CreateService<ConsoleService>(); Console = new ConsoleService();
Input = new InputService(EngineConfig.inputConfig); Input = new InputService(EngineConfig.inputConfig);
s_ServicesBag.Add(Input); World = new WorldService();
World = CreateService<WorldService>();
SystemGameObject = new GameObject("__RebootReality__");
Object.DontDestroyOnLoad(SystemGameObject);
LoopManager = SystemGameObject.AddComponent<AppLoopManager>();
#if RR_STEAM #if RR_STEAM
await SteamManager.InitializeAsync(cancellationToken); await SteamManager.InitializeAsync(cancellationToken);
@@ -83,9 +85,7 @@ namespace RebootKit.Engine.Main {
// @NOTE: This method is called after the main scene is loaded. // @NOTE: This method is called after the main scene is loaded.
internal static async UniTask RunAsync(CancellationToken cancellationToken) { internal static async UniTask RunAsync(CancellationToken cancellationToken) {
Observable.EveryUpdate() LoopManager.Add(Tick);
.Subscribe(_ => Tick())
.AddTo(ref s_DisposableBag);
await OpenMainMenuAsync(cancellationToken); await OpenMainMenuAsync(cancellationToken);
@@ -116,9 +116,14 @@ namespace RebootKit.Engine.Main {
#if RR_STEAM #if RR_STEAM
SteamManager.Shutdown(); SteamManager.Shutdown();
#endif #endif
World.Dispose();
s_ServicesBag.Dispose(); Input.Dispose();
s_DisposableBag.Dispose(); Console.Dispose();
LoopManager = null;
if (SystemGameObject.OrNull() != null) {
Object.Destroy(SystemGameObject);
}
} }
// Assets API // Assets API
@@ -140,8 +145,7 @@ namespace RebootKit.Engine.Main {
throw new ArgumentException("World config name cannot be null or empty", nameof(name)); throw new ArgumentException("World config name cannot be null or empty", nameof(name));
} }
WorldConfigAsset worldConfig = WorldConfigAsset worldConfig = s_WorldConfigsAssets.Find(asset => asset.Config.name.Equals(name, StringComparison.Ordinal));
s_WorldConfigsAssets.Find(asset => asset.Config.name.Equals(name, StringComparison.Ordinal));
if (worldConfig is null) { if (worldConfig is null) {
throw new KeyNotFoundException($"World config '{name}' not found"); throw new KeyNotFoundException($"World config '{name}' not found");
} }
@@ -271,26 +275,6 @@ namespace RebootKit.Engine.Main {
} }
} }
//
// @MARK: Service API
// Services seems to be useless in the current architecture. Consider removing this API in the future.
//
public static TService CreateService<TService>(ServiceAsset<TService> asset) where TService : class, IService {
if (asset is null) {
throw new ArgumentNullException($"Null asset of type {typeof(TService)}");
}
TService service = asset.Create();
s_ServicesBag.Add(service);
return service;
}
public static TService CreateService<TService>() where TService : class, IService {
TService service = Activator.CreateInstance<TService>();
s_ServicesBag.Add(service);
return service;
}
// //
// @MARK: Logging API // @MARK: Logging API
// //
@@ -425,9 +409,8 @@ namespace RebootKit.Engine.Main {
throw new NotSupportedException("Cannot send chat message. Not connected to a server."); throw new NotSupportedException("Cannot send chat message. Not connected to a server.");
} }
static void Tick() { static void Tick(float dt) {
float deltaTime = Time.deltaTime; Network.Tick(dt);
Network.Tick(deltaTime);
} }
internal static void OnServerStarted() { internal static void OnServerStarted() {

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using R3;
using Unity.Collections; using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe; using Unity.Collections.LowLevel.Unsafe;
using Unity.Networking.Transport; using Unity.Networking.Transport;

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization; using System.Globalization;
using RebootKit.Engine.Foundation; using RebootKit.Engine.Foundation;
using RebootKit.Engine.Main; using RebootKit.Engine.Main;
@@ -280,7 +279,7 @@ namespace RebootKit.Engine.Simulation {
[Serializable] [Serializable]
public struct AttachmentSocket { public struct AttachmentSocket {
[MaxLength(32)] [InfoBox("Max length: 32")]
public string socketName; public string socketName;
public Transform root; public Transform root;

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Threading; using System.Threading;
using Cysharp.Threading.Tasks; using Cysharp.Threading.Tasks;
using R3;
using RebootKit.Engine.Main; using RebootKit.Engine.Main;
using Steamworks; using Steamworks;
using Logger = RebootKit.Engine.Foundation.Logger; using Logger = RebootKit.Engine.Foundation.Logger;