something

This commit is contained in:
2025-06-17 23:39:51 +02:00
parent 76b2c8c1bf
commit 518fd29d75
29 changed files with 118 additions and 101 deletions

View File

@@ -45,9 +45,9 @@ namespace RebootKit.Engine.Foundation {
}
public static class ConfigVarsContainer {
static readonly Logger s_logger = new(nameof(ConfigVarsContainer));
static readonly Logger s_logger = new Logger(nameof(ConfigVarsContainer));
static readonly List<ConfigVar> s_configVars = new();
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))) {
@@ -106,7 +106,7 @@ namespace RebootKit.Engine.Foundation {
s_logger.Info("Saving cvars to file: " + path);
StringBuilder sb = new();
StringBuilder sb = new StringBuilder();
foreach (ConfigVar cvar in All()) {
if (!cvar.flags.HasFlag(CVarFlags.ReadOnly)) {

View File

@@ -13,10 +13,10 @@ namespace RebootKit.Engine.Foundation {
const BindingFlags k_fieldsBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
const BindingFlags k_methodsBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
static readonly Logger s_logger = new(nameof(DIContext));
static readonly Logger s_logger = new Logger(nameof(DIContext));
readonly Dictionary<Type, object> m_BindingsMaps = new();
readonly List<IFieldInjector> m_FieldInjectors = new();
readonly Dictionary<Type, object> m_BindingsMaps = new Dictionary<Type, object>();
readonly List<IFieldInjector> m_FieldInjectors = new List<IFieldInjector>();
public DIContext() {
Bind(this);

View File

@@ -13,7 +13,7 @@ namespace RebootKit.Engine.Foundation {
public class ControllersManager<TController> : IDisposable where TController : IController {
readonly CancellationToken _cancellationToken;
readonly List<TController> _controllers = new();
readonly List<TController> _controllers = new List<TController>();
bool _isRunning;
public ControllersManager(CancellationToken cancellationToken) {

View File

@@ -12,7 +12,7 @@ namespace RebootKit.Engine.Foundation {
[DefaultExecutionOrder(-1000)]
public class SceneContext : MonoBehaviour {
static readonly Logger s_logger = new(nameof(SceneContext));
static readonly Logger s_logger = new Logger(nameof(SceneContext));
[SerializeField] SceneDependencyInstaller[] m_Installers;

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace RebootKit.Engine.Foundation {
[Serializable]
public struct SerializableGuid : IEquatable<SerializableGuid> {
public static SerializableGuid Zero = new(0, 0, 0, 0);
public static SerializableGuid Zero = new SerializableGuid(0, 0, 0, 0);
[SerializeField, HideInInspector] public uint A;
[SerializeField, HideInInspector] public uint B;

View File

@@ -1,12 +1,13 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Main;
using UnityEngine;
namespace RebootKit.Engine.Graphics {
public class MainCameraService : ServiceMonoBehaviour {
public class MainCameraSetter : MonoBehaviour {
[field: SerializeField]
public Camera Camera { get; private set; }
public override void Dispose() {
void Awake() {
RR.MainCamera = Camera;
}
}
}

View File

@@ -7,7 +7,7 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Main {
public static class EntryPoint {
static readonly Logger s_logger = new(nameof(EntryPoint));
static readonly Logger s_logger = new Logger(nameof(EntryPoint));
static CancellationTokenSource s_cancellationTokenSource;

View File

@@ -28,7 +28,7 @@ namespace RebootKit.Engine.Main {
}
public static class RR {
static readonly Logger s_logger = new("RR");
static readonly Logger s_Logger = new Logger("RR");
[ConfigVar("con.write_log", 1, "Enables writing game log to console output")]
static ConfigVar s_writeLogToConsole;
@@ -48,6 +48,8 @@ namespace RebootKit.Engine.Main {
public static WorldService World => s_worldService;
public static GameModesService GameModes => s_gameModesService;
public static Camera MainCamera { get; internal set; }
static IGame s_game;
public static async UniTask InitAsync(EngineConfigAsset configAsset, CancellationToken cancellationToken) {
@@ -56,11 +58,11 @@ namespace RebootKit.Engine.Main {
s_engineConfigAsset = configAsset;
s_logger.Info("Initializing");
s_Logger.Info("Initializing");
s_servicesBag = new DisposableBag();
s_disposableBag = new DisposableBag();
s_logger.Debug("Registering core services");
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);
@@ -68,14 +70,14 @@ namespace RebootKit.Engine.Main {
await InitializeAssetsAsync(cancellationToken);
s_logger.Debug("Creating game");
s_Logger.Debug("Creating game");
s_game = s_engineConfigAsset.gameAsset.CreateGame();
await s_game.InitAsync(cancellationToken);
}
public static void Shutdown() {
s_logger.Info("Shutting down");
s_Logger.Info("Shutting down");
s_servicesBag.Dispose();
s_disposableBag.Dispose();
}
@@ -85,11 +87,11 @@ namespace RebootKit.Engine.Main {
#if UNITY_EDITOR
string scriptContent = UnityEditor.EditorPrefs.GetString("RebootKitEditor.OnGameRunScriptContent", "");
s_logger.Info($"Executing script: {scriptContent}");
s_Logger.Info($"Executing script: {scriptContent}");
if (!string.IsNullOrEmpty(scriptContent)) {
foreach (string cmd in scriptContent.Split('\n')) {
s_logger.Info($"Executing command: {cmd}");
s_Logger.Info($"Executing command: {cmd}");
Console.Execute(cmd);
}
}
@@ -97,8 +99,8 @@ namespace RebootKit.Engine.Main {
}
// Assets API
static readonly List<GameModeAsset> s_gameModesAssets = new();
static readonly List<WorldConfigAsset> s_worldConfigsAssets = new();
static readonly List<GameModeAsset> s_gameModesAssets = new List<GameModeAsset>();
static readonly List<WorldConfigAsset> s_worldConfigsAssets = new List<WorldConfigAsset>();
public static IReadOnlyList<GameModeAsset> GameModesAssets => s_gameModesAssets;
public static IReadOnlyList<WorldConfigAsset> WorldConfigsAssets => s_worldConfigsAssets;
@@ -107,10 +109,10 @@ namespace RebootKit.Engine.Main {
s_gameModesAssets.Clear();
s_worldConfigsAssets.Clear();
s_logger.Info("Loading game assets");
s_Logger.Info("Loading game assets");
await Addressables.LoadAssetsAsync<GameModeAsset>("game_mode", asset => { s_gameModesAssets.Add(asset); }).ToUniTask(cancellationToken: cancellationToken);
s_logger.Info($"Loaded {s_gameModesAssets.Count} game modes");
s_Logger.Info($"Loaded {s_gameModesAssets.Count} game modes");
await Addressables.LoadAssetsAsync<WorldConfigAsset>("world", asset => { s_worldConfigsAssets.Add(asset); }).ToUniTask(cancellationToken: cancellationToken);
}
@@ -121,7 +123,7 @@ namespace RebootKit.Engine.Main {
throw new ArgumentNullException(nameof(gameMode));
}
s_logger.Info($"Starting game mode: {gameMode.name} in world: {world.name}");
s_Logger.Info($"Starting game mode: {gameMode.name} in world: {world.name}");
s_gameModesService.Start(gameMode, world);
}

View File

@@ -22,7 +22,7 @@ namespace RebootKit.Engine.Services.Console {
}
public class ConsoleService : IService {
static readonly Logger s_logger = new(nameof(ConsoleService));
static readonly Logger s_logger = new Logger(nameof(ConsoleService));
public struct ConsoleCommand {
public string name;
@@ -30,7 +30,7 @@ namespace RebootKit.Engine.Services.Console {
public Action<string[]> action;
}
readonly List<ConsoleCommand> m_ConsoleCommands = new();
readonly List<ConsoleCommand> m_ConsoleCommands = new List<ConsoleCommand>();
FileStream m_LogFileStream;
TextWriter m_LogFileWriter;
@@ -149,7 +149,7 @@ namespace RebootKit.Engine.Services.Console {
.SelectMany(type => type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
.Where(method => method.GetCustomAttributes(typeof(RCCMD), false).Length > 0);
List<ConsoleCommand> commands = new();
List<ConsoleCommand> commands = new List<ConsoleCommand>();
foreach (MethodInfo method in methods) {
RCCMD attribute = (RCCMD)method.GetCustomAttributes(typeof(RCCMD), false)[0];
@@ -199,7 +199,7 @@ namespace RebootKit.Engine.Services.Console {
[RCCMD("help", "Prints help message with all commands and cvars")]
public static void PrintHelpCommand(string[] args) {
StringBuilder message = new();
StringBuilder message = new StringBuilder();
message.AppendLine("Available commands:");
foreach (ConsoleCommand command in RR.Console.m_ConsoleCommands) {
@@ -224,7 +224,7 @@ namespace RebootKit.Engine.Services.Console {
[RCCMD("cvars", "Prints all cvars")]
public static void PrintCVars(string[] args) {
StringBuilder message = new();
StringBuilder message = new StringBuilder();
foreach (ConfigVar cvar in ConfigVarsContainer.All()) {
message.AppendLine($"{cvar.name} - {cvar}");
@@ -238,7 +238,7 @@ namespace RebootKit.Engine.Services.Console {
s_logger.Info("Saving cvars to file: " + path);
StringBuilder sb = new();
StringBuilder sb = new StringBuilder();
foreach (ConfigVar cvar in ConfigVarsContainer.All()) {
if (!cvar.flags.HasFlag(CVarFlags.ReadOnly)) {

View File

@@ -5,10 +5,10 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.Console {
[CreateAssetMenu(menuName = RConsts.k_ServiceAssetMenu + "Console")]
public class ConsoleServiceAsset : ServiceAsset<ConsoleService> {
static readonly Logger s_logger = new(nameof(ConsoleServiceAsset));
static readonly Logger s_logger = new Logger(nameof(ConsoleServiceAsset));
public override ConsoleService Create() {
ConsoleService service = new();
ConsoleService service = new ConsoleService();
return service;
}
}

View File

@@ -8,12 +8,12 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.ConsoleUI {
public class ConsoleUIService : ServiceMonoBehaviour {
static readonly Logger s_logger = new(nameof(ConsoleUIService));
static readonly Logger s_logger = new Logger(nameof(ConsoleUIService));
[SerializeField] ConsoleVC m_ConsoleVC;
[SerializeField] ScriptableInputAction m_ToggleAction;
readonly StringBuilder m_Content = new();
readonly StringBuilder m_Content = new StringBuilder();
public bool IsVisible => m_ConsoleVC.gameObject.activeSelf;

View File

@@ -5,7 +5,7 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.ConsoleUI {
public class ConsoleVC : MonoBehaviour {
static readonly Logger s_logger = new(nameof(ConsoleVC));
static readonly Logger s_logger = new Logger(nameof(ConsoleVC));
[SerializeField] UIDocument m_Document;

View File

@@ -7,15 +7,15 @@ using RebootKit.Engine.Services.Simulation;
namespace RebootKit.Engine.Services.GameMode {
public class GameModesService : IService {
static readonly Logger s_logger = new(nameof(GameModesService));
static readonly Logger s_logger = new Logger(nameof(GameModesService));
[Inject] DIContext m_DIContext;
GameModeAsset m_GameModeAsset;
readonly CancellationTokenSource m_DestroyCancellationTokenSource = new();
readonly CancellationTokenSource m_DestroyCancellationTokenSource = new CancellationTokenSource();
DisposableBag m_ActiveGameModeDisposableBag;
readonly ReactiveProperty<IGameMode> m_ActiveGameMode = new(null);
readonly ReactiveProperty<IGameMode> m_ActiveGameMode = new ReactiveProperty<IGameMode>(null);
public ReadOnlyReactiveProperty<IGameMode> ActiveGameMode => m_ActiveGameMode;

View File

@@ -7,7 +7,7 @@ namespace RebootKit.Engine.Services.Input {
[SerializeField] InputService.Config m_Config;
public override InputService Create() {
InputService instance = new(m_Config);
InputService instance = new InputService(m_Config);
return instance;
}
}

View File

@@ -12,7 +12,7 @@ namespace RebootKit.Engine.Services.Simulation.Interactors {
}
public class GroupInteractor<TInteractable> : IInteractor<TInteractable> {
readonly List<IInteractor<TInteractable>> m_Interactors = new();
readonly List<IInteractor<TInteractable>> m_Interactors = new List<IInteractor<TInteractable>>();
public void Interact(TInteractable target) {
foreach (IInteractor<TInteractable> interactor in m_Interactors) interactor.Interact(target);

View File

@@ -5,14 +5,18 @@ using Cysharp.Threading.Tasks;
using RebootKit.Engine.Foundation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Assertions;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.Simulation {
public interface IWorldContext {
}
public class WorldService : IService {
static readonly Logger s_logger = new(nameof(WorldService));
static readonly Logger s_Logger = new Logger(nameof(WorldService));
enum WorldState {
Unloaded,
@@ -23,8 +27,10 @@ namespace RebootKit.Engine.Services.Simulation {
WorldState m_WorldState = WorldState.Unloaded;
WorldConfig m_Config;
AsyncOperationHandle<SceneInstance> m_SceneInstance;
public IWorldContext Context { get; private set; }
readonly List<Actor> m_Actors = new();
readonly List<Actor> m_Actors = new List<Actor>();
public void Dispose() {
Unload();
@@ -45,6 +51,11 @@ namespace RebootKit.Engine.Services.Simulation {
SceneManager.SetActiveScene(m_SceneInstance.Result.Scene);
foreach (GameObject root in m_SceneInstance.Result.Scene.GetRootGameObjects()) {
if (root.TryGetComponent(out IWorldContext worldContext)) {
Assert.IsNull(Context, "WorldContext is already set. There should be only one WorldContext in the scene.");
Context = worldContext;
}
foreach (Actor actor in root.GetComponentsInChildren<Actor>()) {
RegisterActor(actor);
}
@@ -58,7 +69,7 @@ namespace RebootKit.Engine.Services.Simulation {
TRequiredActor actor = m_Actors.FirstOrDefault(t => t is TRequiredActor) as TRequiredActor;
if (actor is null) {
s_logger.Error($"Actor of type {typeof(TRequiredActor)} not found in the scene");
s_Logger.Error($"Actor of type {typeof(TRequiredActor)} not found in the scene");
return null;
}
@@ -74,6 +85,7 @@ namespace RebootKit.Engine.Services.Simulation {
}
m_WorldState = WorldState.Unloaded;
Context = null;
}
public async UniTask<TActor> SpawnActor<TActor>(AssetReferenceT<GameObject> asset, CancellationToken cancellationToken) where TActor : Actor {

View File

@@ -15,7 +15,7 @@ namespace RebootKit.Engine.UI {
}
public class VisualElementBuilder : IVisualElementBuilder {
readonly List<string> m_ClassNames = new();
readonly List<string> m_ClassNames = new List<string>();
Color? m_BackgroundColor;
float2? m_Size;
@@ -47,7 +47,7 @@ namespace RebootKit.Engine.UI {
}
public VisualElement Build() {
VisualElement element = new();
VisualElement element = new VisualElement();
element.AddToClassList(Classes.k_Base);
foreach (string className in m_ClassNames) {
@@ -79,12 +79,12 @@ namespace RebootKit.Engine.UI {
}
public VisualElement Build() {
Label label = new(m_Text);
Label label = new Label(m_Text);
label.AddToClassList(Classes.k_Base);
label.AddToClassList(Classes.k_Label);
return label;
}
public static LabelBuilder New(string text) => new(text);
public static LabelBuilder New(string text) => new LabelBuilder(text);
}
}

View File

@@ -5,7 +5,7 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.UI {
public abstract class UIDocumentView : MonoBehaviour, IView, IVisualElementBuilder {
static readonly Logger s_logger = new(nameof(UIDocumentView));
static readonly Logger s_logger = new Logger(nameof(UIDocumentView));
[SerializeField] UIDocument m_Document;