removed r3
This commit is contained in:
31
Runtime/Engine/Code/Foundation/AppLoopManager.cs
Normal file
31
Runtime/Engine/Code/Foundation/AppLoopManager.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Runtime/Engine/Code/Foundation/AppLoopManager.cs.meta
Normal file
3
Runtime/Engine/Code/Foundation/AppLoopManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64a923b7732440d1ab5505b4dd250fc2
|
||||
timeCreated: 1759181550
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using ZLinq;
|
||||
|
||||
namespace RebootKit.Engine.Foundation {
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
@@ -49,7 +48,7 @@ namespace RebootKit.Engine.Foundation {
|
||||
static readonly List<ConfigVar> s_configVars = new List<ConfigVar>();
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -63,7 +62,13 @@ namespace RebootKit.Engine.Foundation {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -3,8 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using R3;
|
||||
using RebootKit.Engine.Console;
|
||||
using RebootKit.Engine.Extensions;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Input;
|
||||
using RebootKit.Engine.Network;
|
||||
@@ -32,11 +32,11 @@ namespace RebootKit.Engine.Main {
|
||||
|
||||
internal static EngineConfigAsset EngineConfig;
|
||||
|
||||
static DisposableBag s_DisposableBag;
|
||||
static DisposableBag s_ServicesBag;
|
||||
|
||||
static AsyncOperationHandle<SceneInstance> s_MainMenuSceneHandle;
|
||||
|
||||
internal static GameObject SystemGameObject;
|
||||
internal static AppLoopManager LoopManager;
|
||||
|
||||
internal static NetworkSystem Network;
|
||||
internal static byte NetworkProtocolVersion {
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -62,14 +62,16 @@ namespace RebootKit.Engine.Main {
|
||||
EngineConfig = configAsset;
|
||||
|
||||
s_Logger.Info("Initializing");
|
||||
s_ServicesBag = new DisposableBag();
|
||||
s_DisposableBag = new DisposableBag();
|
||||
|
||||
s_Logger.Info("Registering core services");
|
||||
Console = CreateService<ConsoleService>();
|
||||
Console = new ConsoleService();
|
||||
Input = new InputService(EngineConfig.inputConfig);
|
||||
s_ServicesBag.Add(Input);
|
||||
World = CreateService<WorldService>();
|
||||
World = new WorldService();
|
||||
|
||||
SystemGameObject = new GameObject("__RebootReality__");
|
||||
Object.DontDestroyOnLoad(SystemGameObject);
|
||||
|
||||
LoopManager = SystemGameObject.AddComponent<AppLoopManager>();
|
||||
|
||||
#if RR_STEAM
|
||||
await SteamManager.InitializeAsync(cancellationToken);
|
||||
@@ -83,9 +85,7 @@ namespace RebootKit.Engine.Main {
|
||||
|
||||
// @NOTE: This method is called after the main scene is loaded.
|
||||
internal static async UniTask RunAsync(CancellationToken cancellationToken) {
|
||||
Observable.EveryUpdate()
|
||||
.Subscribe(_ => Tick())
|
||||
.AddTo(ref s_DisposableBag);
|
||||
LoopManager.Add(Tick);
|
||||
|
||||
await OpenMainMenuAsync(cancellationToken);
|
||||
|
||||
@@ -116,9 +116,14 @@ namespace RebootKit.Engine.Main {
|
||||
#if RR_STEAM
|
||||
SteamManager.Shutdown();
|
||||
#endif
|
||||
World.Dispose();
|
||||
Input.Dispose();
|
||||
Console.Dispose();
|
||||
|
||||
s_ServicesBag.Dispose();
|
||||
s_DisposableBag.Dispose();
|
||||
LoopManager = null;
|
||||
if (SystemGameObject.OrNull() != null) {
|
||||
Object.Destroy(SystemGameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Assets API
|
||||
@@ -140,8 +145,7 @@ namespace RebootKit.Engine.Main {
|
||||
throw new ArgumentException("World config name cannot be null or empty", nameof(name));
|
||||
}
|
||||
|
||||
WorldConfigAsset worldConfig =
|
||||
s_WorldConfigsAssets.Find(asset => asset.Config.name.Equals(name, StringComparison.Ordinal));
|
||||
WorldConfigAsset worldConfig = s_WorldConfigsAssets.Find(asset => asset.Config.name.Equals(name, StringComparison.Ordinal));
|
||||
if (worldConfig is null) {
|
||||
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
|
||||
//
|
||||
@@ -425,9 +409,8 @@ namespace RebootKit.Engine.Main {
|
||||
throw new NotSupportedException("Cannot send chat message. Not connected to a server.");
|
||||
}
|
||||
|
||||
static void Tick() {
|
||||
float deltaTime = Time.deltaTime;
|
||||
Network.Tick(deltaTime);
|
||||
static void Tick(float dt) {
|
||||
Network.Tick(dt);
|
||||
}
|
||||
|
||||
internal static void OnServerStarted() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using R3;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Networking.Transport;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Main;
|
||||
@@ -280,7 +279,7 @@ namespace RebootKit.Engine.Simulation {
|
||||
|
||||
[Serializable]
|
||||
public struct AttachmentSocket {
|
||||
[MaxLength(32)]
|
||||
[InfoBox("Max length: 32")]
|
||||
public string socketName;
|
||||
public Transform root;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using R3;
|
||||
using RebootKit.Engine.Main;
|
||||
using Steamworks;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
Reference in New Issue
Block a user