This commit is contained in:
2025-07-17 06:36:37 +02:00
parent 4ec3dedd42
commit 1054061d91
52 changed files with 804 additions and 704 deletions

View File

@@ -259,25 +259,35 @@ namespace RebootKit.Engine.Simulation {
public bool IsDataDirty { get; protected internal set; }
internal ActorsManager Manager;
internal DateTime LastCoreStateSyncTime = DateTime.MinValue;
//
// @MARK: Unity callbacks
//
void OnValidate() {
if (ActorID == 0) {
ActorID = UniqueID.NewULongFromGuid();
}
}
//
// @MARK: Callbacks to override in derived classes
//
protected abstract IActorData CreateActorData();
// Override this method to implement server-side logic
public virtual void ServerTick(float deltaTime) { }
// Override this method to implement client-side logic
public virtual void ClientTick(float deltaTime) { }
// @NOTE: Server-side method to handle actor commands
// @MARK: Server side
public virtual void OnServerTick(float deltaTime) { }
protected virtual void OnActorCommandServer(ActorCommand actorCommand) { }
// @NOTE: Client-side method to handle actor events
// Override this method to implement client-side logic
public virtual void OnClientTick(float deltaTime) { }
protected virtual void OnActorEventClient(ActorEvent actorEvent) { }
protected virtual void OnClientFinishedInitialSync() { }
//
// @MARK: Server API
//
public void SetHidden(bool hidden) {
if (!RR.IsServer()) {
s_ActorLogger.Error($"Only the server can set actor visibility. Actor: {name} (ID: {ActorID})");
@@ -383,7 +393,9 @@ namespace RebootKit.Engine.Simulation {
Manager.SynchronizeActorCoreStateWithOther(this);
}
//
// @MARK: Common API
//
public bool IsHidden() {
return !gameObject.activeSelf;
}
@@ -457,7 +469,9 @@ namespace RebootKit.Engine.Simulation {
return false;
}
// @MARK: Internal API
//
// @MARK: Internal
//
internal ActorCoreStateSnapshot GetCoreStateSnapshot() {
ActorCoreStateSnapshot snapshot = new ActorCoreStateSnapshot();
snapshot.Timestamp = DateTime.UtcNow;
@@ -637,7 +651,11 @@ namespace RebootKit.Engine.Simulation {
internal IActorData InternalCreateActorData() {
return CreateActorData();
}
internal void InitialSyncFinished() {
OnClientFinishedInitialSync();
}
internal void HandleActorCommand(ActorCommand actorCommand) {
if (!RR.IsServer()) {
s_ActorLogger.Error($"Only the server can handle actor commands. Actor: {name} (ID: {ActorID})");
@@ -672,13 +690,5 @@ namespace RebootKit.Engine.Simulation {
OnActorEventClient(actorEvent);
}
// @MARK: Unity lifecycle methods
void OnValidate() {
if (ActorID == 0) {
ActorID = UniqueID.NewULongFromGuid();
}
}
}
}