mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-10 03:40:01 +00:00
finished wake up
This commit is contained in:
parent
d0a77ae25e
commit
37ffecdd06
@ -1,4 +1,5 @@
|
||||
using QSB.Messaging;
|
||||
using QSB.TimeSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -14,9 +15,15 @@ namespace QSB.Events
|
||||
{
|
||||
GlobalMessenger<float, int>.AddListener("QSBServerTime", (time, count) => SendEvent(
|
||||
new WakeUpMessage {
|
||||
SenderId = PlayerRegistry.LocalPlayer.NetId,
|
||||
ServerTime = time,
|
||||
LoopCount = count
|
||||
}));
|
||||
}
|
||||
|
||||
public override void OnReceive(WakeUpMessage message)
|
||||
{
|
||||
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public class WakeUpMessage : QSBMessage
|
||||
public class WakeUpMessage : PlayerMessage
|
||||
{
|
||||
public float ServerTime { get; set; }
|
||||
public int LoopCount { get; set; }
|
||||
|
@ -7,6 +7,8 @@ namespace QSB.TimeSync
|
||||
{
|
||||
public class WakeUpSync : NetworkBehaviour
|
||||
{
|
||||
public static WakeUpSync LocalInstance { get; private set; }
|
||||
|
||||
private const float TimeThreshold = 0.5f;
|
||||
private const float MaxFastForwardSpeed = 60f;
|
||||
private const float MaxFastForwardDiff = 20f;
|
||||
@ -15,8 +17,6 @@ namespace QSB.TimeSync
|
||||
private enum State { NotLoaded, Loaded, FastForwarding, Pausing }
|
||||
private State _state = State.NotLoaded;
|
||||
|
||||
private MessageHandler<WakeUpMessage> _wakeUpHandler;
|
||||
|
||||
private float _sendTimer;
|
||||
private float _serverTime;
|
||||
private float _timeScale;
|
||||
@ -24,6 +24,11 @@ namespace QSB.TimeSync
|
||||
private int _localLoopCount;
|
||||
private int _serverLoopCount;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!isLocalPlayer)
|
||||
@ -31,9 +36,6 @@ namespace QSB.TimeSync
|
||||
return;
|
||||
}
|
||||
|
||||
_wakeUpHandler = new MessageHandler<WakeUpMessage>(MessageType.WakeUp);
|
||||
_wakeUpHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
||||
|
||||
var sceneName = SceneManager.GetActiveScene().name;
|
||||
if (sceneName == "SolarSystem" || sceneName == "EyeOfTheUniverse")
|
||||
{
|
||||
@ -85,15 +87,10 @@ namespace QSB.TimeSync
|
||||
|
||||
private void SendServerTime()
|
||||
{
|
||||
var message = new WakeUpMessage
|
||||
{
|
||||
ServerTime = Time.timeSinceLevelLoad,
|
||||
LoopCount = _localLoopCount
|
||||
};
|
||||
_wakeUpHandler.SendToAll(message);
|
||||
GlobalMessenger<float, int>.FireEvent("QSBServerTime", Time.timeSinceLevelLoad, _localLoopCount);
|
||||
}
|
||||
|
||||
private void OnClientReceiveMessage(WakeUpMessage message)
|
||||
public void OnClientReceiveMessage(WakeUpMessage message)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user