mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-05-02 02:23:56 +00:00
Remove obsolete docs
This commit is contained in:
parent
a9747dec11
commit
ff0593fd60
File diff suppressed because it is too large
Load Diff
@ -1,406 +0,0 @@
|
|||||||
# Phase 1: URL Rooms, Animation Triggers, and Svelte Overlay
|
|
||||||
|
|
||||||
## Context
|
|
||||||
|
|
||||||
The multiplayer backend works: Cloudflare Durable Objects relay, binary protocol (15Hz player state, world events), remote player rendering, host election. But there's no user-facing interface -- room ID is hardcoded to `"default"` in `ISLE/emscripten/config.cpp`, everyone auto-joins one room. The isle.pizza Svelte 5 frontend hosts the WASM game but has zero multiplayer screens.
|
|
||||||
|
|
||||||
The relay can be extended. No auth system.
|
|
||||||
|
|
||||||
## What We're Building
|
|
||||||
|
|
||||||
URL-based rooms + animation trigger system + Svelte overlay.
|
|
||||||
|
|
||||||
- **Room code in URL**: `isle.pizza/#r/brave-red-brick`
|
|
||||||
- **Configurable room size**: creator picks max players (up to a relay-enforced ceiling)
|
|
||||||
- **Svelte overlay** with buttons that trigger animations on the local player (presented as "emotes" in the UI, but internally just animation triggers)
|
|
||||||
- **Collapsible in-game overlay** -- panel can be minimized to stay out of the way
|
|
||||||
- **Room preview** on isle.pizza (player count before joining)
|
|
||||||
- **No text chat** -- emotes are the communication
|
|
||||||
- **Connection lifecycle handled by INI config** at startup (no `mp_connect`/`mp_disconnect` from Svelte)
|
|
||||||
|
|
||||||
### Animation Categories
|
|
||||||
|
|
||||||
The multiplayer UI supports three types of player animations:
|
|
||||||
|
|
||||||
1. **Walking animation** -- plays while the player is moving. Persistent setting (stays until changed).
|
|
||||||
2. **Idle animation** -- plays while stationary, after ~2.5s of not moving. Persistent setting (stays until changed).
|
|
||||||
3. **One-off emotes** -- plays one full cycle while stationary. Movement interrupts. After completing, returns to the 2.5s timeout → idle animation flow. Triggers an emoji popup in the local player's UI (similar to the debug menu activation feedback).
|
|
||||||
|
|
||||||
All three are selected by the player through the overlay UI. Internally, the protocol and C++ exports deal in animation name strings (e.g., `"CNs003xx"`) -- the Svelte overlay maps UI labels to these names.
|
|
||||||
|
|
||||||
## User Flow
|
|
||||||
|
|
||||||
```
|
|
||||||
isle.pizza → solo play (multiplayer disabled in INI)
|
|
||||||
isle.pizza/#r/brave-red-brick → auto-joins room brave-red-brick
|
|
||||||
```
|
|
||||||
|
|
||||||
To play together:
|
|
||||||
|
|
||||||
1. Click "Create Room" → configure max players → generates room name → navigates to `#r/NAME`
|
|
||||||
2. Share the URL with friends
|
|
||||||
3. Friends open URL → see room preview (player count) → auto-join the same room
|
|
||||||
|
|
||||||
When launching from the main page without a room hash, the multiplayer extension is disabled in the INI config before the game starts. This ensures solo play has zero multiplayer overhead.
|
|
||||||
|
|
||||||
## Room Name Generation
|
|
||||||
|
|
||||||
Room names are three-word phrases generated from curated Lego Island-themed word lists. Each component is drawn randomly:
|
|
||||||
|
|
||||||
```
|
|
||||||
[adjective] - [color/material] - [noun]
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
brave-red-brick
|
|
||||||
sneaky-chrome-pizza
|
|
||||||
turbo-sandy-surfer
|
|
||||||
```
|
|
||||||
|
|
||||||
**Word lists** (defined in the Svelte frontend):
|
|
||||||
|
|
||||||
- **Adjectives**: island/adventure tone (brave, sneaky, turbo, radical, mega, super, hyper, epic, wild, rogue, swift, mighty, ...)
|
|
||||||
- **Colors/Materials**: Lego-relevant descriptors (red, blue, chrome, sandy, mossy, golden, rusty, neon, crystal, painted, ...)
|
|
||||||
- **Nouns**: Lego Island objects, locations, and character name fragments drawn from the game's 66 characters (brick, pizza, pepper, mama, papa, nick, laura, brickster, studs, rhoda, snap, infoman, clickitt, rom, ding, legando, shrimp, hogg, funberg, surfer, racer, cop, skater, island, jetski, tower, chopper, minifig, ...)
|
|
||||||
|
|
||||||
Character name inspiration from `ActorDisplayNames` in isle.pizza: Pepper Roni, Mama/Papa Brickolini, Nick/Laura Brick, Infomaniac, Brickster, Studs Linkin, Rhoda Hogg, Valerie Stubbins, Snap Lockitt, Maggie Post, Buck Pounds, Ed Mail, Nubby Stevens, Nancy Nubbins, Dr. Clickitt, Captain D. Rom, Bill Ding, Brazilian Carmen, Gideon Worse, Red Greenbase, Polly Gone, Bradford Brickford, Shiney Doris, Glen/Dorothy Funberg, Brian Shrimp, Luke Tepid, Shorty Tails, Bumpy Kindergreen, Jack O'Trades.
|
|
||||||
|
|
||||||
Each list needs ~30-50 words to produce enough unique combinations (30^3 = 27,000 possible names). Words must be URL-safe (lowercase, no special characters). The generation happens client-side in Svelte -- no server round-trip needed.
|
|
||||||
|
|
||||||
## Configurable Room Size
|
|
||||||
|
|
||||||
### Creator-Side
|
|
||||||
|
|
||||||
When creating a room, the UI offers a max player count selector (e.g., dropdown or stepper). The chosen limit is sent to the relay when the room is created and stored as room metadata.
|
|
||||||
|
|
||||||
### Relay-Side
|
|
||||||
|
|
||||||
The relay enforces a **ceiling limit** -- a hard upper bound configured in the Cloudflare Worker environment (e.g., `MAX_PLAYERS_CEILING = 64`). The room's configured max players cannot exceed this ceiling. If a room is created with a limit above the ceiling, the relay clamps it down.
|
|
||||||
|
|
||||||
When a new WebSocket connection arrives:
|
|
||||||
|
|
||||||
1. Check `connections.size` against the room's configured max players
|
|
||||||
2. If full, reject the WebSocket upgrade with an appropriate error
|
|
||||||
3. The room preview endpoint returns both `players` and `maxPlayers` so the UI can show capacity
|
|
||||||
|
|
||||||
### Protocol
|
|
||||||
|
|
||||||
The max player count is set when the room is first created (first WebSocket connection, or via a creation endpoint). It persists for the lifetime of the Durable Object. Default if unspecified: 5 (for the 5 playable characters).
|
|
||||||
|
|
||||||
## In-Game Overlay
|
|
||||||
|
|
||||||
The overlay is **collapsible** -- a small tab/handle remains visible when collapsed so players can re-expand it.
|
|
||||||
|
|
||||||
```
|
|
||||||
┌──────────────── Game Canvas ─────────────────┐
|
|
||||||
│ │
|
|
||||||
│ │
|
|
||||||
│ ┌────────────────┐ │
|
|
||||||
│ │ Room: brave-.. │ │
|
|
||||||
│ │ Players: 3/5 │ │
|
|
||||||
│ │ [Copy Link] │ │
|
|
||||||
│ │ │ │
|
|
||||||
│ │ ── Emotes ── │ │
|
|
||||||
│ │ [emote buttons]│ │
|
|
||||||
│ │ [.............]│ │
|
|
||||||
│ │ [__] │ │ ← collapse handle
|
|
||||||
│ └────────────────┘ │
|
|
||||||
│ │
|
|
||||||
└──────────────────────────────────────────────┘
|
|
||||||
|
|
||||||
Collapsed:
|
|
||||||
┌──────────────── Game Canvas ─────────────────┐
|
|
||||||
│ [≡] │ ← expand handle
|
|
||||||
│ │
|
|
||||||
└──────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
Changing a walk/idle animation or triggering an emote broadcasts to all other players through the multiplayer protocol. Animations are **not played on the local player** -- they are only visible to remote players. This avoids interfering with the local player's path actor state and movement controls. One-off emotes show an emoji popup locally as feedback.
|
|
||||||
|
|
||||||
## Svelte → WASM Bridge
|
|
||||||
|
|
||||||
One-way, minimal. The C++ side exports only what the Svelte overlay needs:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
extern "C" {
|
|
||||||
// Set the walking animation for this player (persistent).
|
|
||||||
// Index into the walk animation table. Included in every PlayerStateMsg.
|
|
||||||
// Not played locally -- only visible to remote players.
|
|
||||||
EMSCRIPTEN_KEEPALIVE void mp_set_walk_animation(int index);
|
|
||||||
|
|
||||||
// Set the idle animation for this player (persistent).
|
|
||||||
// Index into the idle animation table. Included in every PlayerStateMsg.
|
|
||||||
// Not played locally -- only visible to remote players.
|
|
||||||
EMSCRIPTEN_KEEPALIVE void mp_set_idle_animation(int index);
|
|
||||||
|
|
||||||
// Trigger a one-off emote (plays one cycle on remote players).
|
|
||||||
// Index into the emote table. Not played locally.
|
|
||||||
EMSCRIPTEN_KEEPALIVE void mp_trigger_emote(int index);
|
|
||||||
|
|
||||||
// Room info -- for the overlay to display
|
|
||||||
EMSCRIPTEN_KEEPALIVE int mp_get_player_count();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
No `mp_connect` / `mp_disconnect` -- the connection is established at WASM startup based on the room name in the INI config.
|
|
||||||
|
|
||||||
## Room Configuration via INI
|
|
||||||
|
|
||||||
### Current State
|
|
||||||
|
|
||||||
Room name is set in `ISLE/emscripten/config.cpp` as a default INI override:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
iniparser_set(p_dictionary, "multiplayer:room", "default");
|
|
||||||
```
|
|
||||||
|
|
||||||
The extension reads it in `MultiplayerExt::Initialize()`:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
room = options["multiplayer:room"];
|
|
||||||
```
|
|
||||||
|
|
||||||
### Change
|
|
||||||
|
|
||||||
The isle.pizza frontend writes multiplayer settings directly into `isle.ini` via OPFS, using the same `saveConfig()` pattern already used for display, audio, and control settings in `opfs.js`.
|
|
||||||
|
|
||||||
When navigating to a room URL (`#r/brave-red-brick`):
|
|
||||||
|
|
||||||
1. Svelte reads the room name from the URL hash
|
|
||||||
2. Writes `multiplayer:room=brave-red-brick` and `extensions:multiplayer=YES` into `isle.ini` via OPFS
|
|
||||||
3. Game starts and reads the INI as normal
|
|
||||||
|
|
||||||
When launching without a room hash (solo play):
|
|
||||||
|
|
||||||
1. Svelte writes `extensions:multiplayer=NO` into `isle.ini` via OPFS
|
|
||||||
2. The multiplayer extension is not initialized at all -- zero overhead for solo play
|
|
||||||
|
|
||||||
The hardcoded `"default"` room override in `ISLE/emscripten/config.cpp` is removed. The INI file becomes the sole authority for room configuration.
|
|
||||||
|
|
||||||
### Connection Logic
|
|
||||||
|
|
||||||
- **`extensions:multiplayer=NO`** (or missing): multiplayer extension is not loaded
|
|
||||||
- **`extensions:multiplayer=YES`** with a room name: connect to relay at `/room/{roomName}` as currently implemented
|
|
||||||
- **Empty room name with multiplayer enabled**: extension loads but skips connection (current behavior when `room.empty()`)
|
|
||||||
|
|
||||||
## Available Animation Assets
|
|
||||||
|
|
||||||
### Animation System Overview
|
|
||||||
|
|
||||||
The game has two distinct animation playback mechanisms:
|
|
||||||
|
|
||||||
| Mechanism | How It Works | Remote Player Support |
|
|
||||||
|-----------|-------------|----------------------|
|
|
||||||
| `ApplyAnimationTransformation()` + ROI map | Directly applies bone transforms from a `LegoAnim` tree at a given time. Used for walk/idle/ride cycles. | **Working** -- already used for remote players |
|
|
||||||
| `StartEntityAction()` + presenter system | Loads animations from SI files via the action/presenter pipeline. Used for click animations, disassemble/reassemble. | **Not available** -- requires the full presenter infrastructure which remote players don't have |
|
|
||||||
|
|
||||||
All multiplayer animations use `ApplyAnimationTransformation()` since it already works for remote players.
|
|
||||||
|
|
||||||
### CNs### Animations (g_cycles)
|
|
||||||
|
|
||||||
The `g_cycles[11][17]` array in `legoanimationmanager.cpp` maps character types to animation names. Each character has character-specific variants (e.g., `CNs001Pe` for Pepper), but **generic `xx` versions exist that work on any character** since all characters share the same skeleton structure.
|
|
||||||
|
|
||||||
All are loaded as `LegoAnimPresenter` objects in the world and can be looked up via `world->Find("LegoAnimPresenter", "CNs003xx")`.
|
|
||||||
|
|
||||||
**Playback for remote players**: Same pattern already used for walk/idle -- call `BuildROIMap()` to map animation bones to the character's ROI, then `ApplyAnimationTransformation()` each frame with an advancing time value.
|
|
||||||
|
|
||||||
#### Walking Animations (looping, while moving)
|
|
||||||
|
|
||||||
| Name | UI Label | Description |
|
|
||||||
|------|----------|-------------|
|
|
||||||
| `CNs001xx` | Normal | Walking upright/straight (default) |
|
|
||||||
| `CNs002xx` | Joyful | Happy, energetic walk |
|
|
||||||
| `CNs003xx` | Gloomy | Sad, leaning forward, depressed |
|
|
||||||
| `CNs005xx` | Sneaky | Walking hunched forward |
|
|
||||||
| `CNs006xx` | Scared | Frightened walk |
|
|
||||||
| `CNs007xx` | Hyper | Super excited, head pops off |
|
|
||||||
|
|
||||||
`CNs004xx` appears identical to `CNs001xx` and is excluded.
|
|
||||||
|
|
||||||
#### Idle Animations (looping, after ~2.5s stationary)
|
|
||||||
|
|
||||||
| Name | UI Label | Description |
|
|
||||||
|------|----------|-------------|
|
|
||||||
| `CNs008xx` | Sway | Body swaying back and forth (default) |
|
|
||||||
| `CNs009xx` | Groove | Happy, body swaying side to side |
|
|
||||||
| `CNs010xx` | Excited | Swinging arms energetically |
|
|
||||||
|
|
||||||
#### One-Off Emotes (single cycle, must be stationary)
|
|
||||||
|
|
||||||
| Name | UI Label | Description |
|
|
||||||
|------|----------|-------------|
|
|
||||||
| `CNs011xx` | Wave | Waving hello with one hand |
|
|
||||||
| `CNs012xx` | Hat Tip | Taking off hat and waving with it |
|
|
||||||
|
|
||||||
### Other Animation Assets (Future)
|
|
||||||
|
|
||||||
These use the presenter system which isn't available for remote players yet:
|
|
||||||
|
|
||||||
- **Click/Customize body flip** (`CUSTOMIZE_ANIM_FILE`, IDs 10-13): Full body flip animation triggered by clicking NPCs. Uses `SUBST:actor_01:characterName` to work on any character. Would need extraction to `ApplyAnimationTransformation()` or presenter system extension.
|
|
||||||
- **Disassemble/Reassemble** (`BNsDis01`-`03` / `BNsAss01`-`03`, action IDs 228-233): Character falls apart into pieces then reassembles. Same presenter portability challenge.
|
|
||||||
- **Procedural flip**: Not animation data -- pure code in `LegoExtraActor::StepState()` (`RotateX`/`RotateZ` at 0.7 rad/frame for 2 seconds). Easiest to port since it's just transform math.
|
|
||||||
|
|
||||||
## Protocol: Animation Messages
|
|
||||||
|
|
||||||
### Walk/Idle: Carried in PlayerStateMsg
|
|
||||||
|
|
||||||
Walk and idle animation selections are **persistent state** -- they must survive player joins, reconnects, and packet loss. They are included in the existing 15Hz `PlayerStateMsg`:
|
|
||||||
|
|
||||||
```
|
|
||||||
struct PlayerStateMsg {
|
|
||||||
MessageHeader header;
|
|
||||||
float position[3];
|
|
||||||
float direction[3];
|
|
||||||
float up[3];
|
|
||||||
float speed;
|
|
||||||
int8_t vehicleType;
|
|
||||||
int32_t worldId;
|
|
||||||
uint8_t walkAnimId; // index into walk animation table (0 = default)
|
|
||||||
uint8_t idleAnimId; // index into idle animation table (0 = default)
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
Using a `uint8_t` index into a fixed animation table (rather than a string name) keeps the per-tick overhead minimal. The table mapping is shared between Svelte (UI labels) and C++ (CNs name lookup):
|
|
||||||
|
|
||||||
**Walk animation table:**
|
|
||||||
|
|
||||||
| Index | CNs Name | UI Label |
|
|
||||||
|-------|----------|----------|
|
|
||||||
| 0 | `CNs001xx` | Normal (default) |
|
|
||||||
| 1 | `CNs002xx` | Joyful |
|
|
||||||
| 2 | `CNs003xx` | Gloomy |
|
|
||||||
| 3 | `CNs005xx` | Leaning |
|
|
||||||
| 4 | `CNs006xx` | Scared |
|
|
||||||
| 5 | `CNs007xx` | Hyper |
|
|
||||||
|
|
||||||
**Idle animation table:**
|
|
||||||
|
|
||||||
| Index | CNs Name | UI Label |
|
|
||||||
|-------|----------|----------|
|
|
||||||
| 0 | `CNs008xx` | Sway (default) |
|
|
||||||
| 1 | `CNs009xx` | Groove |
|
|
||||||
| 2 | `CNs010xx` | Excited |
|
|
||||||
|
|
||||||
This way every `PlayerStateMsg` carries the current walk/idle setting. New players joining a room automatically receive the correct animations from the first state update -- no special join-time sync needed.
|
|
||||||
|
|
||||||
### Emotes: One-Shot Message
|
|
||||||
|
|
||||||
Emotes are discrete events, not persistent state. A separate message type:
|
|
||||||
|
|
||||||
```
|
|
||||||
MSG_EMOTE = 9
|
|
||||||
|
|
||||||
struct EmoteMsg {
|
|
||||||
MessageHeader header; // 9 bytes (type + peerId + sequence)
|
|
||||||
uint8_t emoteId; // 1 byte -- index into emote table
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
Total: 10 bytes per emote trigger.
|
|
||||||
|
|
||||||
**Emote table:**
|
|
||||||
|
|
||||||
| Index | CNs Name | UI Label |
|
|
||||||
|-------|----------|----------|
|
|
||||||
| 0 | `CNs011xx` | Wave |
|
|
||||||
| 1 | `CNs012xx` | Hat Tip |
|
|
||||||
|
|
||||||
The relay broadcasts it to all peers. The remote player must be stationary -- if a `PlayerStateMsg` arrives indicating movement (non-zero speed) during the emote, it is **immediately interrupted**. After the emote completes (or is interrupted), the remote player returns to the ~2.5s idle timeout → idle animation flow.
|
|
||||||
|
|
||||||
### Why This Split
|
|
||||||
|
|
||||||
- **Walk/idle in PlayerStateMsg**: persistent state that must be known by all peers at all times. Piggybacking on the existing 15Hz message means zero additional messages and automatic sync on join. 2 extra bytes per tick is negligible.
|
|
||||||
- **Emotes as one-shot messages**: discrete events with "fire once, play once" semantics. Don't belong in continuous state.
|
|
||||||
|
|
||||||
## Relay: Room Preview Endpoint
|
|
||||||
|
|
||||||
Add an HTTP response to the Durable Object for non-WebSocket requests, so the Svelte UI can show player count before joining:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// In GameRoom.fetch(), before WebSocket upgrade:
|
|
||||||
if (request.headers.get("Upgrade") !== "websocket") {
|
|
||||||
return new Response(JSON.stringify({
|
|
||||||
players: this.connections.size,
|
|
||||||
maxPlayers: this.maxPlayers // room-specific configured limit
|
|
||||||
}), {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Cross-Origin-Resource-Policy": "same-site"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `same-site` header is needed because isle.pizza serves `Cross-Origin-Embedder-Policy: require-corp` (required for SharedArrayBuffer / pthreads). WebSocket connections are unaffected by COEP; only HTTP fetch needs this header.
|
|
||||||
|
|
||||||
## Hosting: relay.isle.pizza
|
|
||||||
|
|
||||||
Works with the COOP/COEP setup:
|
|
||||||
|
|
||||||
- **WebSocket** (`wss://relay.isle.pizza/room/...`): unaffected by COEP
|
|
||||||
- **HTTP fetch** (`GET https://relay.isle.pizza/room/.../info`): needs `Cross-Origin-Resource-Policy: same-site` (relay and isle.pizza share the same registrable domain)
|
|
||||||
|
|
||||||
## C++ Implementation: Animation System
|
|
||||||
|
|
||||||
### Exports (Svelte → WASM)
|
|
||||||
|
|
||||||
All three exports affect remote players only -- nothing is played on the local player.
|
|
||||||
|
|
||||||
- `mp_set_walk_animation(index)`: stores the walk animation index, included in subsequent `PlayerStateMsg` broadcasts
|
|
||||||
- `mp_set_idle_animation(index)`: stores the idle animation index, included in subsequent `PlayerStateMsg` broadcasts
|
|
||||||
- `mp_trigger_emote(index)`: sends `MSG_EMOTE` to all peers
|
|
||||||
|
|
||||||
### Remote Player State Machine
|
|
||||||
|
|
||||||
The remote player's `UpdateAnimation()` currently has two states (moving → walk, stationary → idle). This extends to:
|
|
||||||
|
|
||||||
```
|
|
||||||
moving ──────────────────────────────► walk animation (from walkAnimId in PlayerStateMsg)
|
|
||||||
│ ▲
|
|
||||||
│ │ movement detected
|
|
||||||
▼ │
|
|
||||||
stationary ──(2.5s timeout)──► idle animation (from idleAnimId in PlayerStateMsg)
|
|
||||||
│ ▲
|
|
||||||
│ MSG_EMOTE received │ emote completed / movement detected
|
|
||||||
▼ │
|
|
||||||
emote playing ─────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Walk/idle changes**: when `walkAnimId` or `idleAnimId` in an incoming `PlayerStateMsg` differs from the current value, look up the new animation via `world->Find("LegoAnimPresenter", tableLookup(index))`, build ROI map (cache it), swap in as the active walk/idle animation.
|
|
||||||
- **Emote** (`MSG_EMOTE`): look up animation presenter from emote table, build ROI map if not cached, play for one `GetDuration()` cycle. If movement is detected during playback, interrupt immediately and return to walk. After completion, return to stationary state (2.5s timeout → idle).
|
|
||||||
|
|
||||||
**Animation ROI map caching**: ROI maps are lazily built on first use and cached per animation name. The cache must be invalidated on world change (the `LegoAnimPresenter` objects are world-specific and destroyed when switching worlds).
|
|
||||||
|
|
||||||
## Files Changed
|
|
||||||
|
|
||||||
| File | Change |
|
|
||||||
|------|--------|
|
|
||||||
| `extensions/include/extensions/multiplayer/protocol.h` | Add `walkAnimId`/`idleAnimId` to `PlayerStateMsg`, add `MSG_EMOTE` (9) and `EmoteMsg` struct |
|
|
||||||
| `extensions/src/multiplayer/networkmanager.cpp` | Include walk/idle IDs in state broadcasts, handle incoming `MSG_EMOTE`, add `SendEmote()` |
|
|
||||||
| `extensions/include/extensions/multiplayer/networkmanager.h` | Declare `SendEmote()`, walk/idle animation index storage |
|
|
||||||
| `extensions/src/multiplayer/remoteplayer.cpp` | Extended state machine: configurable walk/idle from PlayerStateMsg, emote playback with duration + interruption, animation ROI map caching |
|
|
||||||
| `extensions/include/extensions/multiplayer/remoteplayer.h` | Add animation state members (current walk/idle/emote anim, ROI maps, elapsed time, animation tables) |
|
|
||||||
| `extensions/src/multiplayer.cpp` | Add `mp_set_walk_animation()`, `mp_set_idle_animation()`, `mp_trigger_emote()`, `mp_get_player_count()` C exports |
|
|
||||||
| `ISLE/emscripten/config.cpp` | Remove hardcoded `"default"` room override |
|
|
||||||
| `CMakeLists.txt` | Add `_mp_set_walk_animation`, `_mp_set_idle_animation`, `_mp_trigger_emote`, `_mp_get_player_count` to `EXPORTED_FUNCTIONS` |
|
|
||||||
| `extensions/src/multiplayer/server/gameroom.ts` | Add HTTP room preview, configurable max players with ceiling enforcement, capacity check on WebSocket upgrade |
|
|
||||||
| `extensions/src/multiplayer/server/relay.ts` | Add `MAX_PLAYERS_CEILING` env config |
|
|
||||||
| isle.pizza `src/core/opfs.js` | Write `multiplayer:room` and `extensions:multiplayer` to INI |
|
|
||||||
| isle.pizza `src/App.svelte` | Read `#r/:name` from URL hash, write room config to INI before launch, mount overlay |
|
|
||||||
| isle.pizza: room creation UI | Max player selector, room name generation, navigate to `#r/NAME` |
|
|
||||||
| isle.pizza: new overlay component | Collapsible panel: walk/idle selectors, emote buttons with emoji popup, room info, copy link |
|
|
||||||
| isle.pizza: word lists module | Lego Island-themed adjective/color/noun word lists for room name generation |
|
|
||||||
|
|
||||||
## Implementation Priority
|
|
||||||
|
|
||||||
1. **Room name generation + URL routing** -- word lists, generate names in Svelte, read `#r/:name` from URL hash.
|
|
||||||
2. **INI config integration** -- write `multiplayer:room` and `extensions:multiplayer` to `isle.ini` via OPFS. Disable multiplayer for solo play. Remove hardcoded room from `config.cpp`.
|
|
||||||
3. **Configurable room size** -- max player selector in room creation UI, relay ceiling enforcement, capacity check on WebSocket upgrade.
|
|
||||||
4. **Animation protocol** -- add `walkAnimId`/`idleAnimId` fields to `PlayerStateMsg`, add `MSG_EMOTE` message type.
|
|
||||||
5. **Remote player animation state machine** -- extend `RemotePlayer::UpdateAnimation()` to read walk/idle IDs from state updates, emote playback with duration + interruption, animation ROI map caching.
|
|
||||||
6. **C++ exports** -- `mp_set_walk_animation()`, `mp_set_idle_animation()`, `mp_trigger_emote()`, `mp_get_player_count()` as WASM exports.
|
|
||||||
7. **Svelte overlay** -- collapsible panel with walk/idle animation selectors (persistent), emote buttons with emoji popup feedback, room info badge, copy link button.
|
|
||||||
8. **Room preview** -- relay HTTP endpoint returning player count and max, Svelte pre-join display.
|
|
||||||
|
|
||||||
## Open Questions
|
|
||||||
|
|
||||||
1. **Room capacity UX**: When a player tries to join a full room, the relay rejects the WebSocket upgrade. The game calls `exit()`, which triggers the existing page reload in isle.pizza (`Module.onExit`). The frontend shows a toast (using existing isle.pizza toast styles) informing the player the room is full. The toast must survive the page reload -- persist the error condition (e.g., in `sessionStorage`) before reload and display it after the page loads.
|
|
||||||
@ -1,261 +0,0 @@
|
|||||||
# Assessment: Sharing Overworld State in Multiplayer
|
|
||||||
|
|
||||||
## Context
|
|
||||||
|
|
||||||
The multiplayer extension syncs player character positions/animations (~52 bytes at 15 Hz per peer) and, as of the Tier 1 implementation, shared plant and building state. The remaining question is: what additional world state is worth syncing, and what are the trade-offs?
|
|
||||||
|
|
||||||
## The Short Answer
|
|
||||||
|
|
||||||
Tier 1 (plants + buildings) is **implemented**. The remaining tiers vary significantly in value. Tier 4 (vehicle world presence) is the highest-value next step but is complicated by autonomous vehicle coasting after exit. Tier 2 (NPC customization) has **low practical value** because NPCs are randomly spawned and pathed per-session -- players never see the same NPCs in the same locations. Tier 3 (vehicle colors + environment) is low-effort but low-value.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What State Exists to Share
|
|
||||||
|
|
||||||
| Category | Count | Bytes (serialized) | Mutation Frequency | Visual Impact |
|
|
||||||
|----------|-------|--------------------|--------------------|---------------|
|
|
||||||
| Plants | 81 | 972 | Click-driven (low) | HIGH - variant, color, height visible |
|
|
||||||
| Buildings | 16 | 161 | Click-driven (low) | MEDIUM - mood, animation |
|
|
||||||
| Characters (NPCs) | 66 | 1,056 | Click-driven (low) | MEDIUM - hat, colors |
|
|
||||||
| Vehicle colors | 43 | ~860 | Build-screen only | LOW |
|
|
||||||
| Environment | 2 | ~60 | Rare | LOW |
|
|
||||||
| **Total** | | **~3,100 bytes** | | |
|
|
||||||
|
|
||||||
The entire syncable world state fits in a single WebSocket frame. Bandwidth is a non-issue.
|
|
||||||
|
|
||||||
## The Core Problem: No Authority Model
|
|
||||||
|
|
||||||
The current system is fully symmetric -- all peers are equal, the relay server (`extensions/src/multiplayer/server/relay.ts`) just stamps peer IDs and broadcasts. For shared world state, exactly one peer must be the "source of truth."
|
|
||||||
|
|
||||||
### Recommended: Server-Assigned Host
|
|
||||||
|
|
||||||
The relay server already assigns peer IDs incrementally. Adding host tracking is ~40-60 lines of TypeScript:
|
|
||||||
|
|
||||||
- First peer to connect becomes host; server sends `MSG_HOST_ASSIGN`
|
|
||||||
- On host disconnect, lowest-ID remaining peer becomes host; server broadcasts new `MSG_HOST_ASSIGN`
|
|
||||||
- New peers receive `MSG_HOST_ASSIGN` on connect so they know who the host is
|
|
||||||
|
|
||||||
This is clearly better than client-side election (no race conditions, no timeout-based detection). The server is the one entity that knows the full connection set.
|
|
||||||
|
|
||||||
### Host Migration Risk
|
|
||||||
|
|
||||||
When the host disconnects, the new host has its own local copy of the world (which was being kept in sync). It immediately broadcasts a full snapshot to converge everyone. The data-loss window is tiny -- at most one unbroadcast click. For plants/buildings this is imperceptible.
|
|
||||||
|
|
||||||
## The Second Core Problem: Intercepting Mutations
|
|
||||||
|
|
||||||
This is where the real complexity lives. State mutations happen via direct function calls with no event system:
|
|
||||||
|
|
||||||
```
|
|
||||||
Player clicks plant -> LegoEntity::Notify() -> SwitchVariant()
|
|
||||||
-> PlantManager()->SwitchVariant(this) // directly mutates g_plantInfo[81]
|
|
||||||
```
|
|
||||||
|
|
||||||
The `Switch*` methods in `legoplantmanager.cpp`, `legobuildingmanager.cpp`, and `legocharactermanager.cpp` modify global arrays in-place. There is no observer pattern, no event bus, nothing to hook into.
|
|
||||||
|
|
||||||
### Recommended: Single Extension Hook in LegoEntity::Notify()
|
|
||||||
|
|
||||||
Add one `Extensions::Call()` invocation in `LegoEntity::Notify()` (in `legoentity.cpp`), following the established pattern already used in `LegoWorld::Enable()`. This is the natural chokepoint -- all click-driven mutations flow through here.
|
|
||||||
|
|
||||||
The extension hook would:
|
|
||||||
- **If host**: allow mutation locally, then broadcast a `MSG_WORLD_EVENT` (12 bytes: entity type, index, change type, actor ID)
|
|
||||||
- **If non-host**: block the local mutation, send a `MSG_WORLD_EVENT_REQUEST` (same 12-byte format as `MSG_WORLD_EVENT`) to the host via the relay, wait for the host's broadcast to apply it
|
|
||||||
|
|
||||||
Non-host click latency would be one relay round trip (20-100ms depending on region) -- imperceptible for clicking on plants.
|
|
||||||
|
|
||||||
**Important edge case: host outside the Isle world.** The host may not be in the Isle world when a non-host's `MSG_WORLD_EVENT_REQUEST` arrives (e.g., the host is in a building interior). The host's `m_entity` pointers are also NULL in this case, so the host cannot call `Switch*` methods either. The host must apply the mutation to its data arrays directly (same increment/cycle logic as the `Switch*` methods, without the ROI visual update), then broadcast the change-type event. This works because the data arrays (`g_plantInfo[]`, `g_buildingInfo[]`) persist across world unloads.
|
|
||||||
|
|
||||||
**Why change-type events, not value-based events:** The `Switch*` methods are increment/cycle operations (e.g., `SwitchColor` does `color = (color + 1) % 5`), and they combine the data mutation with the visual update (ROI/LOD swap) in a single call. If `MSG_WORLD_EVENT` carried a resulting value like "color = RED", receivers couldn't easily use the existing `Switch*` methods -- they'd need separate visual-update-only helpers that don't exist today.
|
|
||||||
|
|
||||||
Instead, `MSG_WORLD_EVENT` carries a **change type** (e.g., "cycle color on plant 42"). Since WebSocket/TCP guarantees in-order delivery and all peers start from the same snapshot, applying the same sequence of change-type events keeps everyone in sync:
|
|
||||||
- **In-world peers**: call the same `Switch*` method, which increments the data AND updates the ROI
|
|
||||||
- **Out-of-world peers**: apply the same increment logic to the data arrays directly (no visual update needed; `LoadWorldInfo()` rebuilds visuals from the data when re-entering the Isle world)
|
|
||||||
- **Host outside the Isle world**: same as out-of-world peers -- apply data increment, then broadcast the event
|
|
||||||
|
|
||||||
## Synchronization: Hybrid Approach
|
|
||||||
|
|
||||||
**On join**: New peer requests a snapshot from the host. Host serializes using the *existing* `PlantManager::Write()` / `BuildingManager::Write()` / `CharacterManager::Write()` methods via the existing `LegoMemory` class (a `LegoStorage` subclass at `legostorage.h:194` that reads/writes to a `uint8_t*` buffer -- no new adapter class needed). New peer deserializes using the existing `Read()` methods. This reuses all existing serialization code.
|
|
||||||
|
|
||||||
**During play**: Individual mutations broadcast as 12-byte `MSG_WORLD_EVENT` messages. Receiving peers that are currently in the Isle world call the same `Switch*` methods locally to get both data mutation and visual update in one step. Peers that are NOT in the Isle world (in Act 2, a building, etc.) instead write the changed field directly to the `g_plantInfo[]` / `g_buildingInfo[]` arrays -- the visual update happens automatically when they re-enter the Isle world and `LoadWorldInfo()` rebuilds entities from the updated data.
|
|
||||||
|
|
||||||
**Late joiner edge case**: Queue any `MSG_WORLD_EVENT` messages that arrive between snapshot request and snapshot response, apply them after the snapshot.
|
|
||||||
|
|
||||||
## Protocol Changes
|
|
||||||
|
|
||||||
```
|
|
||||||
New message types needed:
|
|
||||||
MSG_HOST_ASSIGN (13 bytes) - server -> all, announces host peer ID
|
|
||||||
MSG_REQUEST_SNAPSHOT (9 bytes) - client -> host, request full world state
|
|
||||||
MSG_WORLD_SNAPSHOT (~3.1 KB) - host -> client, full world state blob
|
|
||||||
MSG_WORLD_EVENT (12 bytes) - host -> all, single state mutation (change type, not value)
|
|
||||||
MSG_WORLD_EVENT_REQUEST (12 bytes) - non-host -> host, request a mutation (same format)
|
|
||||||
```
|
|
||||||
|
|
||||||
Steady-state bandwidth addition: essentially zero (events are click-driven, ~0.1 Hz). Snapshot is a one-time 3 KB message on join.
|
|
||||||
|
|
||||||
## Tiered Implementation
|
|
||||||
|
|
||||||
### Tier 1: Plants + Buildings ~~IMPLEMENTED~~
|
|
||||||
- **Status**: Complete. Host election, snapshot sync, event-based deltas, mutation interception hook, and visual state application are all working.
|
|
||||||
- This established the authority model (server-assigned host), the hybrid sync pattern (snapshot on join + change-type events during play), and the extension hook in `LegoEntity::Notify()`. All subsequent tiers build on this foundation.
|
|
||||||
|
|
||||||
### Tier 2: NPC Character Customization ~~LOW VALUE -- DEPRIORITIZE~~
|
|
||||||
- **Value**: **LOW** (downgraded from MEDIUM)
|
|
||||||
- **Effort**: ~150-200 additional lines
|
|
||||||
- **Risk**: Character customization involves LOD cloning and texture swapping (`legocharactermanager.cpp:807-858`). Remote triggering could have subtle visual bugs.
|
|
||||||
- **Problem**: NPCs are **randomly spawned and autonomously pathed per-session**, making customization sync nearly meaningless in practice:
|
|
||||||
- NPCs spawn on randomized `LegoPathBoundary` paths. The walking mode is selected via a global counter (`g_pathWalkingModeSelector++`) combined with `SDL_rand()` calls for edge selection.
|
|
||||||
- NPC speeds are randomized (`0.9f + 1.5f * SDL_randf()` for walking).
|
|
||||||
- NPC **positions are never saved** -- only customization data (hats, colors, mood) persists across world loads. On every world load, NPCs are recreated at different boundaries with different paths.
|
|
||||||
- This means players will never see the same NPCs in the same places. If Player A customizes "pepper" with a red hat, Player B would need to find "pepper" somewhere in their own world to notice -- but "pepper" is on a completely different path walking in a different direction.
|
|
||||||
- The only way NPC customization sync would have visible impact is if NPC positions/paths were also synced, which would require deterministic spawning, synchronized pathfinding, and shared random seeds -- a massive undertaking far beyond this tier's scope.
|
|
||||||
|
|
||||||
### Tier 3: Vehicle Colors + Environment
|
|
||||||
- **Value**: LOW -- vehicle colors are rarely changed during gameplay, environment changes are cosmetic
|
|
||||||
- **Effort**: ~100-150 additional lines
|
|
||||||
|
|
||||||
### Tier 4: Vehicle World Presence (placement, enter/exit, visibility, coasting)
|
|
||||||
- **Value**: HIGH -- without this, each player sees all 7 vehicles sitting idle in the world even when another player is driving one. When Player A enters the helicopter, Player B should see it disappear (it's "in use"), and when Player A exits, it should reappear at the exit location for everyone.
|
|
||||||
- **Effort**: ~500-800 additional lines (**HIGH** complexity)
|
|
||||||
- **Scope**:
|
|
||||||
- Sync vehicle enter/exit events so vehicles disappear/reappear for all peers
|
|
||||||
- Sync vehicle positions during post-exit coasting (see below)
|
|
||||||
- Sync vehicle final resting position
|
|
||||||
- Sync custom textures for built vehicles (helicopter windshield, jetski front, etc.)
|
|
||||||
|
|
||||||
**How vehicles work:**
|
|
||||||
|
|
||||||
There are 7 vehicles in the Isle world: motorcycle, bike, skateboard, helicopter, jetski, dunebuggy, racecar. Their world state is stored in `Act1State` as `LegoNamedPlane` structs (76 bytes each: name + position + direction + up vector). Built vehicles (helicopter, jetski, dunebuggy, racecar) also have custom textures (`LegoNamedTexture*`).
|
|
||||||
|
|
||||||
**Vehicle enter/exit lifecycle:**
|
|
||||||
1. **Idle**: Vehicle is visible in the world via `m_roi->SetVisibility(TRUE)`
|
|
||||||
2. **Enter** (`IslePathActor::Enter()`): `m_roi->SetVisibility(FALSE)` -- vehicle disappears, player takes control
|
|
||||||
3. **Active**: Vehicle is invisible; dashboard UI is shown; vehicle is the `UserActor`
|
|
||||||
4. **Exit** (`IslePathActor::Exit()`): `m_roi->SetVisibility(TRUE)` -- vehicle reappears at exit position **and continues moving autonomously**
|
|
||||||
|
|
||||||
**Autonomous vehicle coasting (critical finding):**
|
|
||||||
|
|
||||||
Vehicles do **NOT** stop when a player exits them. `IslePathActor::Exit()` sets `m_userNavFlag = FALSE` and `m_actorState = c_initial`, but **never resets `m_worldSpeed`**. The vehicle retains whatever velocity it had at the moment of exit and continues following its path boundary:
|
|
||||||
|
|
||||||
1. `LegoAnimActor::Animate()` is called every frame. It checks `m_actorState == c_initial && !m_userNavFlag && m_worldSpeed <= 0` to decide whether to idle. Since `m_worldSpeed > 0`, this condition is FALSE, so it calls `LegoPathActor::Animate()`.
|
|
||||||
2. `LegoPathActor::Animate()` calls `CalculateTransform()` in a while-loop until caught up to the current time.
|
|
||||||
3. `CalculateTransform()` sees `m_worldSpeed > 0` with `m_userNavFlag = FALSE` and continues advancing the vehicle along the spline path, evaluating `m_spline.Evaluate(m_traveledDistance / m_BADuration, ...)` with the retained speed.
|
|
||||||
4. The vehicle coasts along path boundaries, potentially transitioning between boundaries, until speed depletes or it reaches a dead end.
|
|
||||||
|
|
||||||
None of the 7 vehicle `Exit()` methods reset `m_worldSpeed` -- they all delegate to `IslePathActor::Exit()`.
|
|
||||||
|
|
||||||
**Sync approach (revised):**
|
|
||||||
- `MSG_WORLD_EVENT` with `EVENT_VEHICLE_ENTER` / `EVENT_VEHICLE_EXIT` types
|
|
||||||
- On enter: host broadcasts which vehicle was entered; all peers call `SetVisibility(FALSE)` on that vehicle's ROI
|
|
||||||
- On exit: host broadcasts the vehicle exit event; all peers call `SetVisibility(TRUE)`. **But the vehicle is now coasting**, so one of two approaches is needed:
|
|
||||||
- **Option A: Periodic position sync while coasting.** The host periodically broadcasts the coasting vehicle's position/orientation (similar to player position sync but at a lower frequency, e.g., 5 Hz) until the vehicle stops (`m_worldSpeed <= 0`). Then a final position is broadcast. This is simpler but adds bandwidth during coasting.
|
|
||||||
- **Option B: Deterministic path replay.** Sync the path state (boundary ID, spline distance, speed) and let each client simulate independently. Much harder -- requires all clients to have identical path data and deterministic spline evaluation, and boundary transitions would need to match exactly. Fragile and not recommended.
|
|
||||||
- On snapshot: include which vehicles are currently "in use" (a bitmask, 1 byte) plus the saved `LegoNamedPlane` for each parked vehicle, plus coasting state for any currently-coasting vehicles
|
|
||||||
|
|
||||||
**Simplified Tier 4a (enter/exit visibility only):** As a stepping stone, only sync enter/exit visibility (hide when entered, show when exited) without syncing the coasting position. The vehicle would "teleport" to its final resting position when it stops. This removes the worst artifact (seeing idle vehicles that are being driven) with much less complexity (~300 lines). Position sync during coasting could be added later.
|
|
||||||
|
|
||||||
**Key complexity**: Built vehicles have custom textures that are serialized as bitmap data (variable size, potentially several KB each). For Tier 4, syncing textures on join would require including them in the snapshot. An alternative is to skip texture sync initially and use default textures for remote players' built vehicles -- visually imperfect but functional.
|
|
||||||
|
|
||||||
**Out-of-world handling**: Vehicle state is managed by `Act1State`, which persists across world transitions. `RemoveActors()` calls `UpdatePlane()` to save positions when leaving the Isle; `PlaceActors()` restores them on re-entry. The same direct-write approach from Tier 1 applies: update the `LegoNamedPlane` data in `Act1State` when the receiving peer is outside the Isle world.
|
|
||||||
|
|
||||||
**Data size:**
|
|
||||||
| Component | Size |
|
|
||||||
|-----------|------|
|
|
||||||
| 7 vehicle planes | ~532 bytes (7 x 76) |
|
|
||||||
| Vehicle-in-use bitmask | 1 byte |
|
|
||||||
| Custom textures (optional) | 0-50+ KB (bitmap data) |
|
|
||||||
| 43 vehicle color strings | ~500-1,000 bytes |
|
|
||||||
|
|
||||||
## Estimated Effort Summary
|
|
||||||
|
|
||||||
| Component | New Lines | Difficulty | Status |
|
|
||||||
|-----------|-----------|------------|--------|
|
|
||||||
| ~~Tier 1: Plants + Buildings~~ | ~~750-1,250~~ | ~~Hard~~ | **DONE** |
|
|
||||||
| Tier 2: NPC Customization | 150-200 | Medium | Deprioritized (low value) |
|
|
||||||
| Tier 3: Vehicle Colors + Environment | 100-150 | Easy | |
|
|
||||||
| Tier 4a: Vehicle enter/exit visibility only | ~300 | Medium | |
|
|
||||||
| Tier 4b: + coasting position sync | 200-500 | **Hard** (path system integration) | |
|
|
||||||
| **Total (Tier 4a)** | **~300** | | |
|
|
||||||
| **Total (Tier 4a+4b)** | **~500-800** | | |
|
|
||||||
|
|
||||||
**Recommended priority order:**
|
|
||||||
1. **Tier 4a** (vehicle visibility) -- highest visual impact for moderate effort
|
|
||||||
2. **Tier 4b** (coasting sync) -- incremental on top of 4a, hardest remaining piece
|
|
||||||
3. **Tier 3** (vehicle colors + environment) -- small incremental work
|
|
||||||
4. ~~**Tier 2**~~ (NPC customization) -- deprioritized, near-zero perceptible benefit without NPC position sync
|
|
||||||
|
|
||||||
## Open Questions and Risks
|
|
||||||
|
|
||||||
1. **Sound on remote mutations**: `ClickSound()` uses 3D positional audio via `Lego3DSound`. Sounds are anchored to the entity's world position and naturally attenuate with distance (min 15, max 100 units; effectively silent beyond ~100 units). This means **sounds should be played on remote peers** -- a player clicking a plant far away from you will be quiet or silent. The 3D sound system handles this correctly without any special networking logic. The `ClickAnimation()` visual effect should also play for the same reason.
|
|
||||||
|
|
||||||
2. **Conflict resolution**: Two players click the same plant simultaneously. With host authority, the host processes them sequentially -- the second click advances from the state the first click left it in. Both players see the same result. No special handling needed.
|
|
||||||
|
|
||||||
3. **State sync for players not in the Isle world** (IMPORTANT): When a player leaves the Isle world (enters Act 2, a building interior, etc.), `PlantManager()->Reset()` and `BuildingManager()->Reset()` set all `m_entity` pointers to NULL. Several `Switch*` methods access `m_entity->GetROI()` without NULL checks and will **crash** if called when the entity doesn't exist:
|
|
||||||
- **CRASHES outside Isle**: `SwitchColor()`, `SwitchVariant()`, `DecrementCounter()` (both plant and building) -- access `m_entity->GetROI()` which is NULL
|
|
||||||
- **NO-OPS outside Isle**: `SwitchSound()`, `SwitchMove()`, `SwitchMood()` -- these use `GetInfo(p_entity)` which searches `g_plantInfo[].m_entity` for a matching pointer. When entities are NULL, the search finds nothing and returns NULL, so the method does nothing. They don't crash, but they also **don't apply the data change**.
|
|
||||||
|
|
||||||
**Solution**: When receiving state updates from other players while not in the Isle world, **ALL methods require direct array writes** -- not just the crash-prone ones. The data fields (variant, color, mood, sound, move, counter) persist across world unloads. When the player re-enters the Isle world, `LoadWorldInfo()` → `CreatePlant()` / `CreateBuilding()` reads these fields to create entities with the correct appearance. The receiving code must check `info->m_entity != NULL` and branch accordingly: if non-NULL, call the `LegoEntity::Switch*` method (which handles data + visual + sound + animation); if NULL, write the field directly to the data array by index.
|
|
||||||
|
|
||||||
4. **Testing**: Requires testing late-joiner sync, host migration, simultaneous clicks, snapshot + queued events ordering, and state application when players are in different worlds. The existing `relay.ts` dev server (via `wrangler dev`) helps, but automated multi-client testing would need a new test harness.
|
|
||||||
|
|
||||||
5. **World reload**: When a player leaves and re-enters the Isle world, `PlantManager::LoadWorldInfo()` re-creates plants from `g_plantInfo[]`. As noted in point 3, if the data arrays have been kept in sync via direct writes, the re-created entities will have the correct appearance. This is confirmed to work because `CreatePlant()` reads `g_plantInfo[index].m_variant` and `g_plantInfo[index].m_color` to select the correct LOD list.
|
|
||||||
|
|
||||||
## Verified Findings & Additional Gotchas (code review)
|
|
||||||
|
|
||||||
The following were discovered by cross-checking every claim against the actual source code:
|
|
||||||
|
|
||||||
6. **`LegoMemory` already exists** (`legostorage.h:194`): The plan proposed creating a "MemoryStorage adapter" but `LegoMemory` is already a `LegoStorage` subclass that reads/writes to a `uint8_t*` buffer with position tracking. This eliminates ~50-80 lines of estimated work.
|
|
||||||
|
|
||||||
7. **`BuildingManager::SwitchVariant()` is disabled by default**: `g_buildingManagerConfig` is initialized to 1 (`legobuildingmanager.cpp:222`), and `SwitchVariant()` returns TRUE immediately when `g_buildingManagerConfig <= 1`. Building variant switching only works if this config is explicitly set to > 1 (via a registry/config setting from the original game). This means building variant sync may be a no-op in practice.
|
|
||||||
|
|
||||||
8. **`BuildingManager::SwitchVariant()` creates a new entity**: Unlike plant mutations (which swap LOD lists), `SwitchVariant()` at line 474 calls `CreateBuilding(HAUS1_INDEX, CurrentWorld())`, which requires the Isle world to be loaded. This mutation **cannot be applied via direct array writes** for out-of-world peers -- you can write `m_variant` to the data array, but the visual swap requires `CreateBuilding()`. For out-of-world peers, the data write is sufficient; `LoadWorldInfo()` will create the correct variant on re-entry.
|
|
||||||
|
|
||||||
9. **`ClickAnimation()` blocks rapid clicks**: `ClickAnimation()` sets `m_interaction |= c_disabled` (`legoentity.cpp:340`), preventing further clicks until the animation finishes. Both `ClickSound()` and `ClickAnimation()` check `!IsInteraction(c_disabled)` and skip if set. If a remote world event arrives while an entity is already animating, the data mutation (via the manager's `Switch*` method) still applies correctly, but the sound and animation for that remote event will be silently skipped. This is consistent with single-player behavior but means rapid multiplayer clicks may have fewer visual/audio effects than expected.
|
|
||||||
|
|
||||||
10. **Every mutation decrements the interaction counter**: `ClickAnimation()` triggers `ScheduleAnimation()`, which calls `AdjustCounter(-1)` for plants and `AdjustCounter(-2)` for buildings. This means every click-driven mutation decrements the entity's counter as a side effect through the animation system. When the counter reaches 0, the entity sinks and disappears. This is already correctly captured when calling `LegoEntity::SwitchVariant()` etc. (which call `ClickAnimation()` internally), but it means **the receiving side must call the full `LegoEntity::Switch*` method (not just the manager method)** to get the counter decrement and animation.
|
|
||||||
|
|
||||||
11. **Plant `Write()` / `Read()` asymmetry**: `Write()` saves `m_initialCounter` but `Read()` reads into `m_counter` (then copies to `m_initialCounter` and calls `AdjustHeight()`). The snapshot sender must be aware that what gets written is `initialCounter`, not the current `counter`. This matters if a plant has been partially decremented -- the snapshot should send the current state, not the initial state. The snapshot serialization should either use the existing `Write()`/`Read()` pair as-is (which saves/restores `initialCounter` and adjusts heights accordingly), or use a custom serialization that captures `m_counter` directly.
|
|
||||||
|
|
||||||
12. **Snapshot `Read()` doesn't update visual positions**: `PlantManager::Read()` calls `AdjustHeight()` which modifies `g_plantInfo[].m_position[1]` (Y coordinate) but does NOT call `SetLocation()` on the entity. If a snapshot is received while in the Isle world, the entity's visual position won't update until the player leaves and re-enters. An additional `SetLocation()` call per entity is needed after applying a snapshot in-world. Same issue applies to buildings via `AdjustHeight()` in `BuildingManager::Read()`.
|
|
||||||
|
|
||||||
13. **PlayerStateMsg is 52 bytes, not 48**: Header(9) + actorId(1) + worldId(1) + vehicleType(1) + position(12) + direction(12) + up(12) + speed(4) = 52 bytes. The bandwidth estimate changes negligibly (from 720 to 780 bytes/s per peer at 15 Hz).
|
|
||||||
|
|
||||||
## Impact Assessment of Verified Findings
|
|
||||||
|
|
||||||
None of the verified findings above are architectural blockers. Summary:
|
|
||||||
|
|
||||||
- **#6 (LegoMemory exists)**: Positive — reduces work.
|
|
||||||
- **#7 (SwitchVariant disabled)**: Neutral — less to sync; already handled if config changes.
|
|
||||||
- **#8 (CreateBuilding for SwitchVariant)**: Already handled — out-of-world peers use direct array writes; `LoadWorldInfo()` creates the correct variant on re-entry.
|
|
||||||
- **#9 (ClickAnimation blocks rapid clicks)**: Matches single-player behavior — data still applies, only sound/animation skipped. Prevents audio spam.
|
|
||||||
- **#10 (Counter decrement side effect)**: Most important finding. Receiving peers **must call `LegoEntity::Switch*()` methods** (not `PlantManager::Switch*()` directly) to get the full effect chain (data + visual + sound + animation + counter decrement). For out-of-world peers, direct array writes must also decrement `m_counter` and call `AdjustHeight()`.
|
|
||||||
- **#11 (Write/Read asymmetry)**: Manageable — use existing `Write()`/`Read()` pair as-is for snapshots. The sequence "snapshot (initial state) + queued change-type events" produces the correct final state.
|
|
||||||
- **#12 (Snapshot Read doesn't update visuals)**: Minor — add a `SetLocation()` loop (~10 lines) after applying a snapshot in-world.
|
|
||||||
- **#13 (52 bytes not 48)**: Cosmetic correction, no design impact.
|
|
||||||
|
|
||||||
## Opinion
|
|
||||||
|
|
||||||
With Tier 1 implemented, the authority model, hybrid sync pattern, and mutation interception architecture are all proven. The remaining tiers build on this foundation.
|
|
||||||
|
|
||||||
**Tier 4 (vehicles) is the clear next priority** -- seeing idle vehicles that another player is driving is the most visible remaining multiplayer artifact. The enter/exit visibility sync (Tier 4a) is straightforward and high-impact. The coasting position sync (Tier 4b) is the harder part: vehicles retain their speed after exit and continue following path boundaries via `CalculateTransform()` with spline evaluation. This requires either periodic position broadcasts (simple but adds bandwidth) or deterministic path replay (fragile). A pragmatic approach is to implement 4a first, then add 4b with periodic position sync.
|
|
||||||
|
|
||||||
**Tier 2 (NPC customization) should be deprioritized or dropped.** NPCs are randomly spawned on randomized path boundaries with randomized walking modes and speeds (`g_pathWalkingModeSelector`, `SDL_rand()`, `SDL_randf()`). NPC positions are never saved -- only customization data persists. This means players never see the same NPCs in the same places, so syncing appearance changes produces near-zero perceptible benefit. Making NPC sync meaningful would require deterministic spawning and synchronized pathfinding -- a fundamentally different (and much larger) undertaking.
|
|
||||||
|
|
||||||
**Tier 3 (vehicle colors + environment) is low-effort and low-value** -- fine as incremental work whenever convenient.
|
|
||||||
|
|
||||||
## Key Files
|
|
||||||
|
|
||||||
- `extensions/src/multiplayer/server/relay.ts` - host tracking additions
|
|
||||||
- `extensions/include/extensions/multiplayer/protocol.h` - new message types
|
|
||||||
- `extensions/src/multiplayer/networkmanager.cpp` - world sync logic
|
|
||||||
- `extensions/include/extensions/multiplayer/networkmanager.h` - new fields/methods
|
|
||||||
- `LEGO1/lego/legoomni/src/entity/legoentity.cpp` - extension hook in Notify()
|
|
||||||
- `LEGO1/lego/legoomni/src/common/legoplantmanager.cpp` - existing Write/Read to reuse
|
|
||||||
- `LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp` - existing Write/Read to reuse
|
|
||||||
- `LEGO1/lego/legoomni/include/legoplants.h` - LegoPlantInfo struct definition
|
|
||||||
- `LEGO1/lego/legoomni/include/legobuildingmanager.h` - LegoBuildingInfo struct definition
|
|
||||||
- `LEGO1/lego/legoomni/include/isle.h` - Act1State with vehicle LegoNamedPlane fields
|
|
||||||
- `LEGO1/lego/legoomni/src/worlds/isle.cpp` - Act1State::Serialize(), RemoveActors(), PlaceActors()
|
|
||||||
- `LEGO1/lego/legoomni/src/actors/islepathactor.cpp` - Enter()/Exit() with SetVisibility toggle
|
|
||||||
- `LEGO1/lego/legoomni/src/paths/legopathactor.cpp` - CalculateTransform() autonomous coasting logic
|
|
||||||
- `LEGO1/lego/legoomni/src/paths/legoanimactor.cpp` - Animate() frame loop (m_worldSpeed check)
|
|
||||||
- `LEGO1/lego/legoomni/include/legonamedplane.h` - LegoNamedPlane struct (position/direction/up)
|
|
||||||
Loading…
Reference in New Issue
Block a user