Skip to content

Commit

Permalink
Add NETPLAY docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aduros committed May 20, 2022
1 parent c678ada commit c22c2b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions site/docs/guides/multiplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,26 @@ There are currently some caveats to keep in mind:
- State saving/loading and cart reset is currently disabled during netplay.
- Netplay is new and there may be bugs, please [report
issues](https://github.com/aduros/wasm4/issues/new)!

### The `NETPLAY` memory register

WASM-4 exposes the state of netplay to the cart via the [`NETPLAY`](/docs/reference/memory#netplay)
memory register.

Reading this register is not required to implement netplay, but it can be used to implement advanced
features such as non-shared screen multiplayer:

```c
// If netplay is active
if (*NETPLAY & 0b100) {
int playerIdx = *NETPLAY & 0b011;
// Render the game from playerIdx's perspective
// ...
}
```

This is a powerful feature enabling games with hidden information, like card games, strategy games,
and first person shooters. However, caution must be taken by developers to not introduce
desynchronization. In other words, the netplay player index should only be used to adjust how a
frame is rendered, and not affect game logic. Each connected player must run the same game logic for
all players in order to prevent desyncs.
12 changes: 11 additions & 1 deletion site/docs/reference/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ WASM-4 uses a fixed memory layout of 64 KB.
| `$001c` | 2 | [MOUSE_Y](#mouse_y) |
| `$001e` | 1 | [MOUSE_BUTTONS](#mouse_buttons) |
| `$001f` | 1 | [SYSTEM_FLAGS](#system_flags) |
| `$0020` | 128 | Reserved for future use |
| `$0020` | 1 | [NETPLAY](#netplay) |
| `$0021` | 127 | Reserved for future use |
| `$00a0` | 6400 | [FRAMEBUFFER](#framebuffer) |
| `$19a0` | 58976 | Available program memory |

Expand Down Expand Up @@ -91,6 +92,15 @@ Byte containing flags that modify WASM-4's operation. By default all flags are o
| 0 | `SYSTEM_PRESERVE_FRAMEBUFFER` | Prevent clearing the framebuffer between frames. |
| 1 | `SYSTEM_HIDE_GAMEPAD_OVERLAY` | Hide the gamepad UI overlay on mobile. |

### NETPLAY

Byte containing netplay multiplayer state.

| Bits | Description |
| --- | --- |
| 0 - 1 | Local player index (0 to 3). |
| 2 | Set if netplay is currently active. |

### FRAMEBUFFER

Array of 160x160 pixels, with each pixel packed into 2 bits (colors 0 to 3).
Expand Down

0 comments on commit c22c2b1

Please sign in to comment.