Compare commits

..

5 Commits

Author SHA1 Message Date
edmand46 5937e026eb fix: user data changes not cleared 2025-12-28 20:12:21 +03:00
edmand46 7c3a2dab89 feat: optimize game server tick loop performance 2025-10-05 23:28:09 +03:00
edmand46 5dd6aad913 chore: update github actions 2025-10-04 17:45:14 +03:00
edmand46 9da397dd8c chore: update .net version 2025-10-04 17:43:57 +03:00
edmand46 6bb84daf03 chore: update Dockerfile 2025-10-04 17:41:02 +03:00
11 changed files with 40 additions and 33 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Build
shell: bash
run: |
@@ -17,6 +17,7 @@ internal class RoomListHandler: IHandler
{
var roomCount = reader.ReadUShort();
var roomList = new RagonRoomInformation[roomCount];
for (int i = 0; i < roomCount; i++)
{
var id = reader.ReadString();
+1
View File
@@ -98,6 +98,7 @@ namespace Ragon.Client
}
}
_changesCache.Clear();
_localChanges.Clear();
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env
WORKDIR /App
@@ -7,7 +7,7 @@ COPY . ./
RUN dotnet restore
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/runtime:7.0
FROM mcr.microsoft.com/dotnet/runtime:9.0
WORKDIR /App
+23 -2
View File
@@ -15,6 +15,7 @@
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
@@ -40,7 +41,7 @@ namespace Ragon.Relay
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
INetworkServer networkServer = new ENetServer();
INetworkServer networkServer;
IServerPlugin plugin = new RelayServerPlugin();
switch (serverType)
@@ -51,6 +52,9 @@ namespace Ragon.Relay
case ServerType.WEBSOCKET:
networkServer = new WebSocketServer();
break;
default:
networkServer = new ENetServer();
break;
}
var serverConfiguration = new RagonServerConfiguration()
@@ -70,10 +74,27 @@ namespace Ragon.Relay
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
relay.Start();
var sw = Stopwatch.StartNew();
var tickRateMs = 1000.0 / configuration.ServerTickRate;
var nextTickMs = tickRateMs;
while (relay.IsRunning)
{
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();
@@ -4,7 +4,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Ragon.ENet</RootNamespace>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Eduard Kargin</Copyright>
<Authors>Eduard Kargin</Authors>
@@ -15,6 +14,7 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@@ -4,7 +4,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Ragon.WebSockets</RootNamespace>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Copyright>Eduard Kargin</Copyright>
<Authors>Eduard Kargin</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -15,6 +14,7 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -14,7 +14,7 @@
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
<RepositoryType>Source</RepositoryType>
<LangVersion>10</LangVersion>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@@ -16,6 +16,7 @@ public class RagonLobbyDispatcher
{
writer.Clear();
writer.WriteOperation(RagonOperation.ROOM_LIST_UPDATED);
var rooms = _lobby.Rooms;
if (projectId > 0)
+3 -19
View File
@@ -42,9 +42,7 @@ public class RagonServer : IRagonServer, INetworkListener
private readonly Dictionary<ushort, RagonContext> _contextsByConnection;
private readonly Dictionary<string, RagonContext> _contextsByPlayerId;
private readonly ProjectRegistry _projectRegistry;
private readonly Stopwatch _timer;
private readonly RagonLobbyDispatcher _lobbySerializer;
private readonly long _tickRate = 0;
private bool _isRunning = false;
public bool IsRunning => _isRunning;
@@ -66,13 +64,12 @@ public class RagonServer : IRagonServer, INetworkListener
_scheduler = new RagonScheduler();
_reader = new RagonBuffer();
_writer = new RagonBuffer();
_tickRate = 1000 / _configuration.ServerTickRate;
_timer = new Stopwatch();
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
_scheduler.Run(new RagonActionTimer(SendRoomList, 2.0f));
_scheduler.Run(new RagonActionTimer(SendPlayerUserData, 0.1f));
_scheduler.Run(new RagonActionTimer(SendRoomUserData, 0.1f));
_scheduler.Run(new RagonActionTimer(SendTimestamp, 1.0f / _configuration.ServerTickRate));
_serverPlugin.OnAttached(this);
@@ -98,19 +95,8 @@ public class RagonServer : IRagonServer, INetworkListener
}
public void Tick()
{
if (_timer.ElapsedMilliseconds > _tickRate * 2)
{
_logger.Warning($"Slow performance: {_timer.ElapsedMilliseconds}");
}
if (_timer.ElapsedMilliseconds > _tickRate)
{
_timer.Restart();
_scheduler.Update(_timer.ElapsedMilliseconds / 1000.0f);
SendTimestamp();
}
var deltaTime = 1.0f / _configuration.ServerTickRate;
_scheduler.Update(deltaTime);
_server.Update();
}
@@ -129,8 +115,6 @@ public class RagonServer : IRagonServer, INetworkListener
_server.Listen(this, networkConfiguration);
_serverPlugin.OnAttached(this);
_timer.Start();
_isRunning = true;
}
+1 -2
View File
@@ -148,8 +148,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
RagonTarget targetMode
)
{
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner &&
_bufferedEvents.Count < _limitBufferedEvents)
if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner && _bufferedEvents.Count < _limitBufferedEvents)
{
_bufferedEvents.Add(evnt);
}