quantum-space-buddies/QSB/WorldSync/RequestInitialStatesMessage.cs

32 lines
795 B
C#
Raw Normal View History

2022-04-06 18:35:40 +00:00
using QSB.Messaging;
using QSB.Utility;
2022-04-06 18:30:15 +00:00
using System;
2022-03-03 03:46:33 +00:00
namespace QSB.WorldSync;
/// <summary>
/// sent to the host to get initial object states.
/// <para/>
/// world objects will be ready on both sides at this point
/// </summary>
public class RequestInitialStatesMessage : QSBMessage
{
2022-03-03 03:46:33 +00:00
public RequestInitialStatesMessage() => To = 0;
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
2022-03-03 03:46:33 +00:00
private static void SendInitialStates(uint to)
{
2022-04-06 18:30:15 +00:00
SendInitialState?.SafeInvoke(to);
2022-03-14 12:13:12 +00:00
DebugLog.DebugWrite($"sent initial states to {to}");
}
2022-04-06 18:30:15 +00:00
2022-05-28 20:49:18 +00:00
/// <summary>
/// called on the host.
/// use this to send initial states to whoever is asking for it.
/// </summary>
2022-04-06 18:30:15 +00:00
public static event Action<uint> SendInitialState;
}