working on actors

This commit is contained in:
2025-07-03 05:52:25 +02:00
parent dca9f8883a
commit c39b87ed44
16 changed files with 975 additions and 165 deletions

View File

@@ -27,7 +27,7 @@ namespace RebootKit.Engine.Main {
[ConfigVar("con.write_log", 1, "Enables writing game log to console output")]
static ConfigVar s_writeLogToConsole;
[ConfigVar("sv.tick_rate", 60, "Server tick rate in Hz")]
[ConfigVar("sv.tick_rate", 24, "Server tick rate in Hz")]
public static ConfigVar TickRate;
internal static EngineConfigAsset EngineConfig;
@@ -37,6 +37,9 @@ namespace RebootKit.Engine.Main {
static AsyncOperationHandle<SceneInstance> s_mainMenuSceneHandle;
static NetworkSystem s_networkSystemPrefab;
internal static NetworkSystem NetworkSystemInstance;
internal static ConsoleService Console { get; private set; }
public static InputService Input { get; private set; }
public static WorldService World { get; private set; }
@@ -60,7 +63,7 @@ namespace RebootKit.Engine.Main {
s_Logger.Info("Initializing");
s_servicesBag = new DisposableBag();
s_disposableBag = new DisposableBag();
s_Logger.Info("Registering core services");
Console = CreateService(EngineConfig.coreServices.consoleService);
Input = CreateService(EngineConfig.coreServices.inputService);
@@ -68,11 +71,14 @@ namespace RebootKit.Engine.Main {
await InitializeAssetsAsync(cancellationToken);
await SteamManager.InitializeAsync(cancellationToken);
// await SteamManager.InitializeAsync(cancellationToken);
}
// @NOTE: This method is called after the main scene is loaded.
internal static async UniTask RunAsync(CancellationToken cancellationToken) {
s_networkSystemPrefab =
Resources.Load<NetworkSystem>(RConsts.k_CoreNetworkGameSystemsResourcesPath);
NetworkManager.Singleton.OnConnectionEvent += OnConnectionEvent;
NetworkManager.Singleton.OnServerStarted += OnServerStarted;
NetworkManager.Singleton.OnServerStopped += OnServerStopped;
@@ -111,7 +117,7 @@ namespace RebootKit.Engine.Main {
NetworkManager.Singleton.OnServerStopped -= OnServerStopped;
}
SteamManager.Shutdown();
// SteamManager.Shutdown();
s_servicesBag.Dispose();
s_disposableBag.Dispose();
@@ -138,7 +144,7 @@ namespace RebootKit.Engine.Main {
WorldConfigAsset worldConfig =
s_WorldConfigsAssets.Find(asset => asset.Config.name.Equals(name, StringComparison.Ordinal));
if (!worldConfig) {
if (worldConfig is null) {
throw new KeyNotFoundException($"World config '{name}' not found");
}
@@ -187,7 +193,29 @@ namespace RebootKit.Engine.Main {
return;
}
GameInstance.SetCurrentWorldServerRpc(worldID);
NetworkSystemInstance.SetCurrentWorld(worldID);
}
public static void SpawnActor(AssetReferenceGameObject assetReference,
Vector3 position,
Quaternion rotation) {
if (!IsServer()) {
s_Logger.Error("Cannot spawn actor. Not a server instance.");
return;
}
if (NetworkSystemInstance is null) {
s_Logger.Error("NetworkSystemInstance is not initialized. Cannot spawn actor.");
return;
}
if (!assetReference.RuntimeKeyIsValid()) {
s_Logger.Error("Asset reference is not valid. Cannot spawn actor.");
return;
}
s_Logger.Info($"Spawning actor from asset reference: {assetReference.RuntimeKey}");
NetworkSystemInstance.Actors.SpawnActor(assetReference, position, rotation);
}
// Service API
@@ -343,8 +371,6 @@ namespace RebootKit.Engine.Main {
TickCount++;
}
World.Tick(deltaTime);
}
static void OnConnectionEvent(NetworkManager network, ConnectionEventData data) {
@@ -356,6 +382,9 @@ namespace RebootKit.Engine.Main {
GameInstance = Object.Instantiate(EngineConfig.gamePrefab);
GameInstance.NetworkObject.Spawn();
NetworkSystemInstance = Object.Instantiate(s_networkSystemPrefab);
NetworkSystemInstance.NetworkObject.Spawn();
}
static void OnServerStopped(bool obj) {
@@ -363,10 +392,13 @@ namespace RebootKit.Engine.Main {
if (GameInstance is not null) {
GameInstance.NetworkObject.Despawn();
Object.Destroy(GameInstance.gameObject);
GameInstance = null;
}
if (NetworkSystemInstance is not null) {
NetworkSystemInstance.NetworkObject.Despawn();
NetworkSystemInstance = null;
}
GameInstance = null;
}
// Console Commands