wip
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
namespace Ragon.Core.Time;
|
||||
|
||||
public interface IScheduleTask
|
||||
public interface IAction
|
||||
{
|
||||
public void Tick();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace Ragon.Core.Time;
|
||||
|
||||
public class Loop
|
||||
{
|
||||
private List<IAction> _tasks;
|
||||
|
||||
public Loop()
|
||||
{
|
||||
_tasks = new List<IAction>(35);
|
||||
}
|
||||
|
||||
public void Run(IAction task)
|
||||
{
|
||||
_tasks.Add(task);
|
||||
}
|
||||
|
||||
public void Stop(IAction task)
|
||||
{
|
||||
_tasks.Remove(task);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var task in _tasks)
|
||||
task.Tick();
|
||||
}
|
||||
}
|
||||
+12
-13
@@ -10,25 +10,24 @@ namespace Ragon.Core;
|
||||
|
||||
public class Application : INetworkListener
|
||||
{
|
||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private INetworkServer _server;
|
||||
private Thread _dedicatedThread;
|
||||
private Configuration _configuration;
|
||||
private HandlerRegistry _handlerRegistry;
|
||||
private ILobby _lobby;
|
||||
private Scheduler _scheduler;
|
||||
private Dictionary<ushort, PlayerContext> _contexts = new();
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly INetworkServer _server;
|
||||
private readonly Thread _dedicatedThread;
|
||||
private readonly Configuration _configuration;
|
||||
private readonly HandlerRegistry _handlerRegistry;
|
||||
private readonly ILobby _lobby;
|
||||
private readonly Loop _loop;
|
||||
private readonly Dictionary<ushort, PlayerContext> _contexts;
|
||||
|
||||
public Application(Configuration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_dedicatedThread = new Thread(Execute);
|
||||
_dedicatedThread.IsBackground = true;
|
||||
|
||||
_contexts = new Dictionary<ushort, PlayerContext>();
|
||||
_handlerRegistry = new HandlerRegistry();
|
||||
_lobby = new LobbyInMemory();
|
||||
_scheduler = new Scheduler();
|
||||
_loop = new Loop();
|
||||
|
||||
if (configuration.Socket == "enet")
|
||||
_server = new ENetServer();
|
||||
@@ -40,7 +39,7 @@ public class Application : INetworkListener
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_scheduler.Tick();
|
||||
_loop.Tick();
|
||||
_server.Poll();
|
||||
|
||||
Thread.Sleep((int) 1000.0f / _configuration.SendRate);
|
||||
@@ -71,7 +70,7 @@ public class Application : INetworkListener
|
||||
{
|
||||
var context = new PlayerContext(connection, new LobbyPlayer(connection));
|
||||
context.Lobby = _lobby;
|
||||
context.Scheduler = _scheduler;
|
||||
context.Loop = _loop;
|
||||
|
||||
_logger.Trace($"Connected {connection.Id}");
|
||||
_contexts.Add(connection.Id, context);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class Entity
|
||||
player.Connection.ReliableChannel.Send(sendData);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
public void Destroy(byte[] payload)
|
||||
{
|
||||
var room = Owner.Room;
|
||||
var serializer = room.Writer;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Ragon.Common;
|
||||
using Ragon.Core.Time;
|
||||
|
||||
namespace Ragon.Core.Game;
|
||||
|
||||
public class Room
|
||||
public class Room: IAction
|
||||
{
|
||||
public string Id { get; }
|
||||
public RoomInformation Info { get; }
|
||||
@@ -22,15 +23,12 @@ public class Room
|
||||
private RagonSerializer _writer;
|
||||
|
||||
public RagonSerializer Writer => _writer;
|
||||
public PluginBase Plugin { get; set; }
|
||||
|
||||
public Room(string roomId, RoomInformation info, PluginBase plugin)
|
||||
public Room(string roomId, RoomInformation info)
|
||||
{
|
||||
Id = roomId;
|
||||
Info = info;
|
||||
|
||||
Plugin = plugin;
|
||||
|
||||
Players = new Dictionary<ushort, RoomPlayer>(info.Max);
|
||||
WaitPlayersList = new List<RoomPlayer>(info.Max);
|
||||
ReadyPlayersList = new List<RoomPlayer>(info.Max);
|
||||
@@ -68,7 +66,7 @@ public class Room
|
||||
DynamicEntitiesList.Remove(entity);
|
||||
_entitiesDirtySet.Remove(entity);
|
||||
|
||||
entity.Destroy();
|
||||
entity.Destroy(payload);
|
||||
currentOwner.Entities.Remove(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed class HandlerRegistry
|
||||
_reader = new RagonSerializer(2048);
|
||||
_writer = new RagonSerializer(2048);
|
||||
|
||||
_authorizationHandler = new AuthHandler();
|
||||
_authorizationHandler = new AuthorizationHandler();
|
||||
_joinOrCreateHandler = new JoinOrCreateHandler();
|
||||
_sceneLoadedHandler = new SceneLoadedHandler();
|
||||
_createHandler = new CreateHandler();
|
||||
|
||||
@@ -4,7 +4,7 @@ using Ragon.Core.Lobby;
|
||||
|
||||
namespace Ragon.Core.Handlers;
|
||||
|
||||
public sealed class AuthHandler: IHandler
|
||||
public sealed class AuthorizationHandler: IHandler
|
||||
{
|
||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
@@ -50,7 +50,7 @@ public sealed class CreateHandler: IHandler
|
||||
var lobbyPlayer = context.LobbyPlayer;
|
||||
var roomPlayer = new RoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
|
||||
var room = new Room(roomId, information, new PluginBase());
|
||||
var room = new Room(roomId, information);
|
||||
room.AddPlayer(roomPlayer);
|
||||
|
||||
context.Room?.RemovePlayer(context.RoomPlayer);
|
||||
@@ -62,6 +62,8 @@ public sealed class CreateHandler: IHandler
|
||||
|
||||
JoinSuccess(roomPlayer, room, writer);
|
||||
|
||||
context.Loop.Run(room);
|
||||
|
||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed class JoinOrCreateHandler : IHandler
|
||||
Min = _roomParameters.Min,
|
||||
};
|
||||
|
||||
var room = new Room(roomId, information, new PluginBase());
|
||||
var room = new Room(roomId, information);
|
||||
context.Lobby.Persist(room);
|
||||
|
||||
var roomPlayer = new RoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
@@ -57,6 +57,8 @@ public sealed class JoinOrCreateHandler : IHandler
|
||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} {information}");
|
||||
|
||||
JoinSuccess(roomPlayer, room, writer);
|
||||
|
||||
context.Loop.Run(room);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Ragon.Core;
|
||||
public class PlayerContext: IDisposable
|
||||
{
|
||||
public INetworkConnection Connection { get; }
|
||||
public Scheduler Scheduler;
|
||||
public Loop Loop;
|
||||
public ILobby Lobby { get; set; }
|
||||
public LobbyPlayer LobbyPlayer { private set; get; }
|
||||
public Room? Room { get; set; }
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace Ragon.Core.Time;
|
||||
|
||||
public class Scheduler
|
||||
{
|
||||
private List<IScheduleTask> _tasks;
|
||||
|
||||
public Scheduler()
|
||||
{
|
||||
_tasks = new List<IScheduleTask>(35);
|
||||
}
|
||||
|
||||
public void Add(IScheduleTask task)
|
||||
{
|
||||
_tasks.Add(task);
|
||||
}
|
||||
|
||||
public void Remove(IScheduleTask task)
|
||||
{
|
||||
_tasks.Remove(task);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var task in _tasks)
|
||||
task.Tick();
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,6 @@ using Ragon.Core;
|
||||
|
||||
namespace Ragon.Relay
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct Serializer
|
||||
{
|
||||
[FieldOffset(0)] public Guid Uuid;
|
||||
[FieldOffset(0)] public long Long0;
|
||||
[FieldOffset(0)] public long Long1;
|
||||
}
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
|
||||
Reference in New Issue
Block a user