_lagdriver fixes
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Cooker / Cook (Mac) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Cooker / Cook (Mac) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled
This commit is contained in:
@@ -97,11 +97,15 @@ bool NetworkLagDriver::PopEvent(NetworkEvent& eventPtr)
|
||||
if (!_driver)
|
||||
return false;
|
||||
|
||||
const auto delta2 = Time::Current != nullptr ? Time::Current->UnscaledDeltaTime : Time::Update.UnscaledDeltaTime;
|
||||
// Try to pop lagged event from the queue
|
||||
for (int32 i = 0; i < _events.Count(); i++)
|
||||
{
|
||||
auto& e = _events[i];
|
||||
if (e.Lag > 0.0)
|
||||
e.LagTime -= delta2;
|
||||
//if (e.Lag > 0.0)
|
||||
// continue;
|
||||
if (e.LagTime > 0)
|
||||
continue;
|
||||
|
||||
eventPtr = e.Event;
|
||||
@@ -117,6 +121,7 @@ bool NetworkLagDriver::PopEvent(NetworkEvent& eventPtr)
|
||||
|
||||
auto& e = _events.AddOne();
|
||||
e.Lag = (double)Lag;
|
||||
e.LagTime = /*Time::Current->UnscaledTime + */TimeSpan::FromMilliseconds(Lag);
|
||||
e.Event = eventPtr;
|
||||
}
|
||||
return false;
|
||||
@@ -130,8 +135,10 @@ void NetworkLagDriver::SendMessage(const NetworkChannelType channelType, const N
|
||||
return;
|
||||
}
|
||||
|
||||
//const auto tick = Time::Current->TicksCount;
|
||||
auto& msg = _messages.AddOne();
|
||||
msg.Lag = (double)Lag;
|
||||
msg.LagTime = /*Time::Current->UnscaledTime +*/ TimeSpan::FromMilliseconds(Lag);
|
||||
msg.ChannelType = channelType;
|
||||
msg.Type = 0;
|
||||
msg.MessageData.Set(message.Buffer, message.Length);
|
||||
@@ -148,6 +155,7 @@ void NetworkLagDriver::SendMessage(NetworkChannelType channelType, const Network
|
||||
|
||||
auto& msg = _messages.AddOne();
|
||||
msg.Lag = (double)Lag;
|
||||
msg.LagTime = /*Time::Current->UnscaledTime +*/ TimeSpan::FromMilliseconds(Lag);
|
||||
msg.ChannelType = channelType;
|
||||
msg.Type = 1;
|
||||
msg.Target = target;
|
||||
@@ -165,6 +173,7 @@ void NetworkLagDriver::SendMessage(const NetworkChannelType channelType, const N
|
||||
|
||||
auto& msg = _messages.AddOne();
|
||||
msg.Lag = (double)Lag;
|
||||
msg.LagTime = /*Time::Current->UnscaledTime +*/ TimeSpan::FromMilliseconds(Lag);
|
||||
msg.ChannelType = channelType;
|
||||
msg.Type = 2;
|
||||
msg.Targets = targets;
|
||||
@@ -192,14 +201,20 @@ void NetworkLagDriver::OnUpdate()
|
||||
return;
|
||||
|
||||
// Update all pending messages and events
|
||||
const double deltaTime = Time::Update.UnscaledDeltaTime.GetTotalMilliseconds();
|
||||
const auto delta2 = Time::Current != nullptr ? Time::Current->UnscaledDeltaTime : Time::Update.UnscaledDeltaTime;
|
||||
for (int32 i = 0; i < _messages.Count(); i++)
|
||||
{
|
||||
auto& msg = _messages[i];
|
||||
msg.Lag -= deltaTime;
|
||||
if (msg.Lag > 0.0)
|
||||
//msg.Lag -= deltaTime;
|
||||
//if (msg.Lag > 0.0)
|
||||
// continue;
|
||||
|
||||
msg.LagTime -= delta2;
|
||||
if (msg.LagTime > 0)
|
||||
continue;
|
||||
|
||||
auto missed = (-msg.LagTime).GetTotalMilliseconds();
|
||||
|
||||
// Use this helper message as a container to send the stored data and length to the ENet driver
|
||||
NetworkMessage message;
|
||||
message.Buffer = msg.MessageData.Get();
|
||||
@@ -222,6 +237,7 @@ void NetworkLagDriver::OnUpdate()
|
||||
for (int32 i = 0; i < _events.Count(); i++)
|
||||
{
|
||||
auto& e = _events[i];
|
||||
e.Lag -= deltaTime;
|
||||
//e.Lag -= deltaTime;
|
||||
e.LagTime -= delta2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user