Refactor project structure and update documentation. Replace PixiJS with plain DOM for UI rendering, enhance README with game features, and revise protocol documentation for HTTP API. Remove unused files and streamline client code for better maintainability.
This commit is contained in:
@@ -4,9 +4,9 @@ using System.Threading.Channels;
|
||||
namespace HSchool.Server.Net;
|
||||
|
||||
/// <summary>
|
||||
/// One connected browser. Frames are queued instead of written inline so a slow client
|
||||
/// can never stall the game loop; when the outbox overflows the oldest snapshot is dropped,
|
||||
/// which is exactly what you want for state that is resent 20 times a second.
|
||||
/// One connected browser. Frames are queued instead of written inline so a slow client can never
|
||||
/// stall the game loop; when the outbox overflows the oldest frame is dropped, which is right for
|
||||
/// a clock that is resent 20 times a second.
|
||||
/// </summary>
|
||||
internal sealed class GameClient(uint playerId, WebSocket socket)
|
||||
{
|
||||
@@ -21,19 +21,33 @@ internal sealed class GameClient(uint playerId, WebSocket socket)
|
||||
});
|
||||
|
||||
private bool _ready;
|
||||
private int _openSchoolId;
|
||||
|
||||
public uint PlayerId { get; } = playerId;
|
||||
|
||||
public WebSocket Socket { get; } = socket;
|
||||
|
||||
public string Name { get; set; } = $"player-{playerId}";
|
||||
|
||||
/// <summary>
|
||||
/// Set once the welcome frame is out. Snapshots are only queued for ready clients, so a
|
||||
/// connection never sees world state before it knows its own entity id.
|
||||
/// Set once the welcome frame is out. Clock frames are only queued for ready clients, so a
|
||||
/// connection never sees game state before the handshake finished.
|
||||
/// </summary>
|
||||
public bool IsReady => Volatile.Read(ref _ready);
|
||||
|
||||
/// <summary>
|
||||
/// School this connection is watching, or <c>null</c> in the menu. Written by the loop thread,
|
||||
/// read by the connection thread on disconnect.
|
||||
/// </summary>
|
||||
public int? OpenSchoolId
|
||||
{
|
||||
get
|
||||
{
|
||||
// School ids start at 1, so 0 stands for "this client is in the menu".
|
||||
var id = Volatile.Read(ref _openSchoolId);
|
||||
return id == 0 ? null : id;
|
||||
}
|
||||
set => Volatile.Write(ref _openSchoolId, value ?? 0);
|
||||
}
|
||||
|
||||
public void MarkReady() => Volatile.Write(ref _ready, true);
|
||||
|
||||
/// <summary>Queues a frame. Returns false once the connection is shutting down.</summary>
|
||||
|
||||
Reference in New Issue
Block a user