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

32 lines
795 B
C#
Raw Normal View History

2022-04-06 11:35:40 -07:00
using QSB.Messaging;
using QSB.Utility;
2022-04-06 11:30:15 -07:00
using System;
2022-03-02 19:46:33 -08: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-02 19:46:33 -08:00
public RequestInitialStatesMessage() => To = 0;
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady,
() => SendInitialStates(From));
2022-03-02 19:46:33 -08:00
private static void SendInitialStates(uint to)
{
2022-04-06 11:30:15 -07:00
SendInitialState?.SafeInvoke(to);
2022-03-14 05:13:12 -07:00
DebugLog.DebugWrite($"sent initial states to {to}");
}
2022-04-06 11:30:15 -07:00
2022-05-28 13:49:18 -07:00
/// <summary>
/// called on the host.
/// use this to send initial states to whoever is asking for it.
/// </summary>
2022-04-06 11:30:15 -07:00
public static event Action<uint> SendInitialState;
}