Add plugin receive loop & remote player state

Add a networking receive loop and in-plugin remote-player storage. Introduces F4TRemotePlayerState (header + implementation) to track assigned playerId and remote player snapshots with thread-safe access. Expands F4TNetworking to start/stop a background receive thread, parse newline-separated JSON packets (welcome, transform, disconnect), validate fields, update remote state, throttle logs, and handle socket/thread synchronization. Add nlohmann_json to xmake and plugin build. Update docs and dev log to reflect the new receive behavior and current prototype scope.
This commit is contained in:
2026-05-31 20:10:41 +12:00
parent d724d7404c
commit 62635f4226
10 changed files with 581 additions and 70 deletions
+7 -6
View File
@@ -20,12 +20,13 @@ Current behavior:
broadcast to other connected clients.
- `disconnect` is sent by the server when a client disconnects.
The Fallout 4 plugin currently sends transform packets only. It does not yet
receive or process server packets.
The Fallout 4 plugin sends transform packets and receives `welcome`,
`transform`, and `disconnect` packets. Received transforms are stored as plain
remote-player state only.
## Working In Fake Client Only
## Current Receivers
`server/fake_client.py` currently receives:
The Fallout 4 plugin and `server/fake_client.py` currently receive:
```text
welcome
@@ -33,8 +34,8 @@ transform
disconnect
```
The fake client stores broadcast transform packets in an in-memory remote player
state table and removes entries when disconnect packets arrive.
The plugin and fake client store broadcast transform packets in in-memory remote
player state tables and remove entries when disconnect packets arrive.
## Planned Later
+16 -12
View File
@@ -40,8 +40,8 @@ playerId Server-assigned player ID for this connection.
serverTime Server timestamp when the welcome packet was created.
```
The Fallout 4 plugin does not yet read this packet. `server/fake_client.py`
currently receives and prints it.
The Fallout 4 plugin and `server/fake_client.py` receive this packet. The plugin
stores the assigned `playerId` for filtering its own future transform echoes.
### Transform Packet
@@ -117,20 +117,24 @@ playerId Server-assigned player ID that disconnected.
serverTime Server timestamp when the disconnect packet was created.
```
`server/fake_client.py` currently uses this packet to remove remote players from
its in-memory state table.
The Fallout 4 plugin and `server/fake_client.py` use this packet to remove
remote players from their in-memory state tables.
## Working In Fake Client Only
## Receiver Behavior
- Receiving `welcome` packets.
- Receiving broadcast `transform` packets from other clients.
- Storing remote player state by `playerId`.
- Removing remote player state when `disconnect` packets arrive.
The Fallout 4 plugin and fake client both receive:
```text
welcome
transform
disconnect
```
The plugin receive loop runs on a background networking thread. It stores plain
remote-player state only and does not spawn actors or touch Fallout 4 game
objects.
## Planned Later
- Fallout 4 plugin receive loop.
- Plugin-side parsing of `welcome`, `transform`, and `disconnect` packets.
- Plugin-side remote player state storage.
- Remote actor spawning.
- Gameplay synchronization.
+14 -19
View File
@@ -6,23 +6,24 @@ The current implementation is still a local networking prototype.
## Current Implemented Flow
```text
Fallout 4 Plugin
Fallout 4 Plugin ↔ Local Python Server ↔ Other Clients
↓
Local Python Server
↓
Fake Client Remote Player State
Plugin Remote Player State
```
The Fallout 4 plugin currently reads the local player's transform and sends it
to the local Python server. The server assigns a `playerId`, adds `serverTime`,
and broadcasts transform packets to other connected clients.
The Fallout 4 plugin does not yet receive remote transforms from the server.
The current receiver is `server/fake_client.py`.
The Fallout 4 plugin also receives server packets on a background networking
thread. It stores its assigned `playerId`, stores remote transform state by
remote `playerId`, and removes remote state when disconnect packets arrive.
`server/fake_client.py` remains a lightweight test receiver for the same packet
lifecycle.
## Current Remote Player State Model
The fake client stores remote players by `playerId`.
The plugin and fake client store remote players by `playerId`.
Each remote player state entry tracks:
@@ -40,13 +41,16 @@ serverTime
lastReceivedLocalTime
```
This model is a prototype for the eventual Fallout 4 receiving client. The goal
is to prove the data shape and lifecycle before adding a plugin receive loop or
spawning remote actors.
This model proves the data shape and lifecycle before spawning remote actors.
## Implemented
- The plugin sends local player transform packets.
- The plugin receives `welcome` packets and stores its assigned `playerId`.
- The plugin receives broadcast transform packets.
- The plugin ignores transform packets for its own assigned `playerId`.
- The plugin stores remote player state by `playerId`.
- The plugin receives `disconnect` packets and removes remote player state.
- The server assigns incrementing `playerId` values.
- The server sends `welcome` packets.
- The server adds `playerId` and `serverTime` to transform packets.
@@ -55,19 +59,10 @@ spawning remote actors.
- The server broadcasts `disconnect` packets.
- The fake client removes disconnected remote players from its state table.
## Working In Fake Client Only
- Receiving broadcast transform packets.
- Tracking remote player state.
- Handling disconnect cleanup.
No Fallout 4 remote actor is spawned yet.
## Planned Later
- Add a Fallout 4 plugin receive loop.
- Parse `welcome`, `transform`, and `disconnect` packets in the plugin.
- Store remote player state inside the plugin.
- Add interpolation or smoothing after plugin-side state exists.
- Spawn and move remote actors only after the receive loop is stable.