Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5937e026eb | |||
| 7c3a2dab89 | |||
| 5dd6aad913 |
@@ -49,7 +49,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 8.0.x
|
dotnet-version: 9.0.x
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ internal class RoomListHandler: IHandler
|
|||||||
{
|
{
|
||||||
var roomCount = reader.ReadUShort();
|
var roomCount = reader.ReadUShort();
|
||||||
var roomList = new RagonRoomInformation[roomCount];
|
var roomList = new RagonRoomInformation[roomCount];
|
||||||
|
|
||||||
for (int i = 0; i < roomCount; i++)
|
for (int i = 0; i < roomCount; i++)
|
||||||
{
|
{
|
||||||
var id = reader.ReadString();
|
var id = reader.ReadString();
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ namespace Ragon.Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_changesCache.Clear();
|
||||||
_localChanges.Clear();
|
_localChanges.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -40,7 +41,7 @@ namespace Ragon.Relay
|
|||||||
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
|
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
|
||||||
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
||||||
|
|
||||||
INetworkServer networkServer = new ENetServer();
|
INetworkServer networkServer;
|
||||||
IServerPlugin plugin = new RelayServerPlugin();
|
IServerPlugin plugin = new RelayServerPlugin();
|
||||||
|
|
||||||
switch (serverType)
|
switch (serverType)
|
||||||
@@ -51,6 +52,9 @@ namespace Ragon.Relay
|
|||||||
case ServerType.WEBSOCKET:
|
case ServerType.WEBSOCKET:
|
||||||
networkServer = new WebSocketServer();
|
networkServer = new WebSocketServer();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
networkServer = new ENetServer();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverConfiguration = new RagonServerConfiguration()
|
var serverConfiguration = new RagonServerConfiguration()
|
||||||
@@ -70,10 +74,27 @@ namespace Ragon.Relay
|
|||||||
|
|
||||||
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
||||||
relay.Start();
|
relay.Start();
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
var tickRateMs = 1000.0 / configuration.ServerTickRate;
|
||||||
|
var nextTickMs = tickRateMs;
|
||||||
|
|
||||||
while (relay.IsRunning)
|
while (relay.IsRunning)
|
||||||
{
|
{
|
||||||
relay.Tick();
|
relay.Tick();
|
||||||
Thread.Sleep(1);
|
|
||||||
|
var sleepTime = nextTickMs - sw.Elapsed.TotalMilliseconds;
|
||||||
|
if (sleepTime > 0)
|
||||||
|
{
|
||||||
|
Thread.Sleep((int)sleepTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
nextTickMs += tickRateMs;
|
||||||
|
|
||||||
|
if (nextTickMs < sw.Elapsed.TotalMilliseconds)
|
||||||
|
{
|
||||||
|
nextTickMs = sw.Elapsed.TotalMilliseconds + tickRateMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
relay.Dispose();
|
relay.Dispose();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class RagonLobbyDispatcher
|
|||||||
{
|
{
|
||||||
writer.Clear();
|
writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.ROOM_LIST_UPDATED);
|
writer.WriteOperation(RagonOperation.ROOM_LIST_UPDATED);
|
||||||
|
|
||||||
var rooms = _lobby.Rooms;
|
var rooms = _lobby.Rooms;
|
||||||
|
|
||||||
if (projectId > 0)
|
if (projectId > 0)
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
private readonly Dictionary<ushort, RagonContext> _contextsByConnection;
|
private readonly Dictionary<ushort, RagonContext> _contextsByConnection;
|
||||||
private readonly Dictionary<string, RagonContext> _contextsByPlayerId;
|
private readonly Dictionary<string, RagonContext> _contextsByPlayerId;
|
||||||
private readonly ProjectRegistry _projectRegistry;
|
private readonly ProjectRegistry _projectRegistry;
|
||||||
private readonly Stopwatch _timer;
|
|
||||||
private readonly RagonLobbyDispatcher _lobbySerializer;
|
private readonly RagonLobbyDispatcher _lobbySerializer;
|
||||||
private readonly long _tickRate = 0;
|
|
||||||
private bool _isRunning = false;
|
private bool _isRunning = false;
|
||||||
|
|
||||||
public bool IsRunning => _isRunning;
|
public bool IsRunning => _isRunning;
|
||||||
@@ -66,13 +64,12 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_scheduler = new RagonScheduler();
|
_scheduler = new RagonScheduler();
|
||||||
_reader = new RagonBuffer();
|
_reader = new RagonBuffer();
|
||||||
_writer = new RagonBuffer();
|
_writer = new RagonBuffer();
|
||||||
_tickRate = 1000 / _configuration.ServerTickRate;
|
|
||||||
_timer = new Stopwatch();
|
|
||||||
|
|
||||||
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
|
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
|
||||||
_scheduler.Run(new RagonActionTimer(SendRoomList, 2.0f));
|
_scheduler.Run(new RagonActionTimer(SendRoomList, 2.0f));
|
||||||
_scheduler.Run(new RagonActionTimer(SendPlayerUserData, 0.1f));
|
_scheduler.Run(new RagonActionTimer(SendPlayerUserData, 0.1f));
|
||||||
_scheduler.Run(new RagonActionTimer(SendRoomUserData, 0.1f));
|
_scheduler.Run(new RagonActionTimer(SendRoomUserData, 0.1f));
|
||||||
|
_scheduler.Run(new RagonActionTimer(SendTimestamp, 1.0f / _configuration.ServerTickRate));
|
||||||
|
|
||||||
_serverPlugin.OnAttached(this);
|
_serverPlugin.OnAttached(this);
|
||||||
|
|
||||||
@@ -98,19 +95,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
}
|
}
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
if (_timer.ElapsedMilliseconds > _tickRate * 2)
|
var deltaTime = 1.0f / _configuration.ServerTickRate;
|
||||||
{
|
_scheduler.Update(deltaTime);
|
||||||
_logger.Warning($"Slow performance: {_timer.ElapsedMilliseconds}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_timer.ElapsedMilliseconds > _tickRate)
|
|
||||||
{
|
|
||||||
_timer.Restart();
|
|
||||||
_scheduler.Update(_timer.ElapsedMilliseconds / 1000.0f);
|
|
||||||
|
|
||||||
SendTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
_server.Update();
|
_server.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,8 +115,6 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_server.Listen(this, networkConfiguration);
|
_server.Listen(this, networkConfiguration);
|
||||||
_serverPlugin.OnAttached(this);
|
_serverPlugin.OnAttached(this);
|
||||||
|
|
||||||
_timer.Start();
|
|
||||||
|
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,8 +148,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
|||||||
RagonTarget targetMode
|
RagonTarget targetMode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner &&
|
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner && _bufferedEvents.Count < _limitBufferedEvents)
|
||||||
_bufferedEvents.Count < _limitBufferedEvents)
|
|
||||||
{
|
{
|
||||||
_bufferedEvents.Add(evnt);
|
_bufferedEvents.Add(evnt);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user