The POG Protocol for game development defines a portable game loop and language-neutral binary representations of Inputs and State.
npm install pogpMaking games should feel like playing games.
The POG Protocol defines language-neutral binary representations of Inputs and State.
This allows us to create a portable game loop that can be run in browser or any major game engine.
* browser - use wasm to prototype and playtest with hot reloading
* standalone / mobile / console - use ffi to bring your game loop into any game engine
* online multiplayer - run your game loop on any web server or exchange pogp binary input peer to peer
* input representations are based on web standards
* state representations use open standards (WIP)
* games that adopt the protocol can benefit from shared solutions for common functionality
* immersion during the development process is sacrosanct. making games feels like playing games.
* the POG protocol is designed to be zero-copy, zero-alloc per frame
* you can continue to use and benefit from all the great game making tools and rendering you use today for mobile, browser, standalone and console targets
The goal of the POG protocol is to help create better games for players, to make game development more accessible, and to reduce crunch.
The goal is for anyone familiar with basic software development to create a game using the protocol today, using the languages and tools they're already familiar with.
Web and app developers benefit from industry-wide adoption of open technology like the HTTP protocol and Linux.
Game developers have typically suffered from a more closed source mindset, with many shared solutions for crucial low-level problems locked behind paywalls or other privileged access.
I love games, and I believe that by embracing open standards and shared solutions across languages and game engines, there can be a better world for developers and players of games.
``ts
import { GameLoop, MarshalInput, KeyboardSnapshot } from 'pogp';
const keyboard = new KeyboardSnapshot();
const heroElement = document.body.appendChild('div') as HTMLElement;
let state = {
hero: { x: 0, y: 0 }
};
new GameLoop((frame, now, inputs) => {
// read inputs from binary buffer
keyboard.addInput(MarshalInput.decodeKeyboard(inputs));
// run update loop
if (keyboard.isKeyDown(Key.KeyD)) {
state.hero.x += 10;
} else if (keyboard.isKeyDown(Key.KeyA)) {
state.hero.x -= 10;
}
// render to screen
heroElement.style.transform = translateX(${state.hero.x}px);`
})
Pong
https://pogprotocol.com
The Pog Protocol is in a pre-alpha state. The protocol itself is still being defined, and client libraries currently only exist for rust.
We are looking for domain experts to contribute to libraries for each major game engine and runtime environment.
If you are interested in contributing or adding an environment to the list, please open a github issue or drop me a line on discord nu11#1111 or neil at nullent.com
* Define rendering protocol
* Flesh out existing libraries
* rust
* typescript
* unity c#
* Add client libraries
* c++
* modern c#
* Add online multiplayer demo
* in browser
* in a game engine
* Add engine demos beyond unity
* unreal engine
* godot
* bevy
language | dev environment | inputs | state | wasm support
-|-|-|-|-
c# | unity | @ns | @ns | n/ac++ | unreal | OPEN | OPEN | OPENrust | bevy | OPEN | OPEN | OPENc# | browser | OPEN | OPEN | OPENc++ | browser | OPEN | OPEN | OPENrust | browser | @ns | @ns | @nstypescript | browser | @ns | @ns | @ns
__Rendering Client Libraries__
language | framework | environment | status
-|-|-|-
c# | unity | pc/mac/mobile/console | OPENc++ | unreal | pc/mac/mobile/console | OPENrust | bevy | pc/mac | OPENswift | xcode/autolayout | ios | OPENtypescript | pixi.js | browser | @ns
Contributors:
@ns - @neilsarkar
Inputs contain the state of the input at the current frame.
Whenever possible, representations are based on open standards.
Gamepad (a.k.a. Controller) Input
Gamepad input represents what's commonly called a "Controller".
We extend the open standard https://developer.mozilla.org/en-US/docs/Web/API/Gamepad with a standard for generic positional identifiers.
Binary Schema | Binary Example
#### Gamepad JSON Schema
type
* This will be an Input Type set to gamepad
id
* The Gamepad.id of the gamepad
vendorId
* The vendor id of the gamepad.
productId
* The product id of the gamepad.
vendorName
* A human readable name for the vendor, e.g. Nintendo, Microsoft, Sony etc
productName
* A human readable name for the product, e.g. Left joy-con, Xbox Series S, Dualshock 5
buttons
* An array of Button states
label*
* the text printed on the button, e.g. Triangle, A, ZRleft-face-top
value*
* int representing the percentage depressed with four digits of precision
touched*
* boolean representing whether button is touched
position*
* string enum representing button position , e.g. , right-shoulder-front
axes
* An array of Axes statesleft
hand*
* string enum representing hand intended to be used with joystick: | right | unknownx
value*
* an array of two signed longs representing the and y position of the thumbstick
#### Gamepad JSON Example
`js
{
type: 'Gamepad',
id: 'Stadia Controller rev. A (STANDARD GAMEPAD Vendor: 18d1 Product: 9400)'
vendorName: "Google",
productName: "Stadia",
buttons: [
{
label: 'A',
position: 'right-face-bottom',
value: 100000 // 100%
},
{
label: 'B',
position: 'right-face-right',
value: 500600 // 50.06%
},
{
label: 'X',
position: 'right-face-left',
touched: true,
value: 0
},
{
label: 'Y',
position: 'right-face-top',
value: 0
},
{
label: 'L1',
position: 'left-shoulder-front',
value: 0
},
{
label: 'L2',
position: 'left-shoulder-back',
value: 0
},
// ...
],
axes: [
{
hand: 'left',
value: [
0n, // x-axis idle
2147483647n // y-axis max up
]
},
{
hand: 'right',
value: [
-2147483647, // x-axis full left
-2147483647 // y-axis full down
]
}
],
}
`
#### Gamepad Binary Schema
data | example | type | index | length (bytes)
|-|-|-|-|-|
type | 1 | byte (Input Type)| 0 | 1buttons.length | 12 | uint16 | 1 | 2axes.length | 12 | uint16 | 3 | 2buttons | [Button, Button] | Button | 5 | 69 * buttons.lengthaxes | [Axes, Axes] | Axes | 5 + (69 buttons.length)| 129 axes.length
#### Gamepad Button Binary Schema
data | example | type | index | length (bytes)
|-|-|-|-|-|
position | 2 | byte ([ButtonPosition]()) | 0 | 1value | 100000 | uint32 | 1 | 4label | "A" | string | 5 | 64
#### Gamepad Axes Binary Schema
data | example | type | index | length (bytes)
|-|-|-|-|-|
hand | 1 | byte (Hand) | 0 | 1x | 100000 | int64 | 1 | 64y | 100000 | int64 | 65 | 64
Keyboard keys are represented using the w3 standard, supporting standard 101, Korean, Brazilian and Japanese keyboards.
https://www.toptal.com/developers/keycode
https://www.w3.org/TR/uievents-code/#keyboard-mac
`js`
{
type: "keyboard",
keys: [
27,
65
]
}
data | type | byte index | bit index
-|-|-|-
Null | bool | 0 | 0ArrowDown | bool | 0 | 1ArrowLeft | bool | 0 | 2ArrowRight | bool | 0 | 3ArrowUp | bool | 0 | 4Backspace | bool | 0 | 5Tab | bool | 0 | 6CapsLock | bool | 0 | 7Enter | bool | 1 | 0ShiftLeft | bool | 1 | 1ShiftRight | bool | 1 | 2ControlLeft | bool | 1 | 3MetaLeft | bool | 1 | 4AltLeft | bool | 1 | 5Space | bool | 1 | 6AltRight | bool | 1 | 7MetaRight | bool | 2 | 0bool
... | | ... | ...IntlRo | bool | 9 | 4
`js`
{
type: "touch",
resolution: [0,0],
fingers: [
// there will always be at least one element
{
position: [0,0],
pressure: 0
}
]
}
`js`
{
type: "mouse",
resolution: [1920, 1080],
position: [100, 100],
buttons: [
{
id: 'left',
down: true
},
{
id :'right',
down: false
},
],
wheels: [
{
id: 'scroll',
delta: [0,20,0]
}
]
}
Custom (WIP)
`js`
{
type: "custom",
id: 'my-flightstick',
fields: [
{
id: 'whammybar',
values: [420,69]
},
{
id: 'something',
values: [0]
}
]
}
Game state represents the state of the game. This is going to be custom for each game.
int is short for int32
`js
{
// this is the pog protocol major version
pog: 0,
// this is the pog protocol minor version
pogMinorVersion: 1
// these are the members of the state.
fields: {
// primitives
timeLeft: 'int',
// objects defined below
player: 'player',
level: 'level',
// arrays of primitives or objects
enemy: ['enemy'],
// dictionaries of primitives or objects
levelClearTimes: {
int: 'int'
},
levelsById: {
int: 'level'
}
},
// these are objects defined by the game
objects: [
player: {
position: 'vector2',
score: 'int',
jump: 'bool',
myIntList: ['int'],
}
enemy: {
position: 'vector2',
health: 'int',
},
level: {
id: 'int',
tiles: ['tile']
},
tile: {
position: 'vector2',
type: 'int'
}
],
}
`
The json state will exist in both the logic and the renderer, so object structures are not shared, only the values
data | example | type | index | length (bytes)
|-|-|-|-|-|
pog major version | 0 | int | 0 | 4pog minor version | 1 | int | 4 | 4
`
* fields are done alphabetically
* vectors and fixed length structs are inline
* arrays, lists and dictionaries are represented as an integer of their total length
* array, list and dictionary reading happens after reading the primitives in the state
* strings are utf32 encoded
`
tic tac toe example:
`json`
{
// 0 is not taken, 1 is X 2 is O
board: [
0, 0, 0,
0, 2, 0
1, 0, 0
]
}
`
// fields
uint 9 // length of array
// arrays, lists and dictionaries
ubyte 0 // top left
ubyte 0 // top middle
ubyte 0 // top right
ubyte 0 // middle left
ubyte 2 // middle middle
ubyte 1 // bottom left
ubyte 0 // bottom middle
ubyte 0 // bottom right
`
pong example:
``
{
isGameOver: false,
player1: {
position: [0, 100],
score: 1
}
player2: {
position: [100,-100],
score: 0
},
ball: {
position: [50, 50]
}
}
Client libraries:
`
(json schema) => file of native object
(binary data, json schema) => native object
(native object, json schema) => binary data
`
e.g. csharp
`
public static string StateFile(string json, string path) {
// outputs a .cs file to path that has the structure of the json file
}
`
#### Button Position Enum
value | name | example (xbox one)
-|-|-
0 | nullleft-face-top
1 | | dpad upleft-face-right
2 | | dpad rightleft-face-bottom
3 | | dpad downleft-face-left
4 | | dpad leftleft-shoulder-front
5 | | LBleft-shoulder-back
6 | | LTleft-thumbstick
7 | | L3right-face-top
8 | | Yright-face-right
9 | | Bright-face-bottom
10 | | Aright-face-left
11 | | Xright-shoulder-front
12 | | RBright-shoulder-back
13 | | RTright-thumbstick
14 | | R3middle
15 | | Xbox Buttonmiddle-left
16 | | View Buttonmiddle-right
17 | | Menu Button
#### Input Type Enum
| value | name |
|-|-|
0 | nullgamepad
1 | touch
2 | mouse
3 | keyboard
4 | custom
5 |
#### Hand Enum
value | name
-|-
0 | nullleft
1 | right
2 |
#### Key Enum
value | name
-|-
0 | NullArrowDown
1 | ArrowLeft
2 | ArrowRight
3 | ArrowUp
4 | Backspace
5 | Tab
6 | CapsLock
7 | Enter
8 | ShiftLeft
9 | ShiftRight
10 | ControlLeft
11 | MetaLeft
12 | AltLeft
13 | Space
14 | AltRight
15 | MetaRight
16 | ContextMenu
17 | ControlRight
18 | Backquote
19 | Digit1
20 | Digit2
21 | Digit3
22 | Digit4
23 | Digit5
24 | Digit6
25 | Digit7
26 | Digit8
27 | Digit9
28 | Digit0
29 | Minus
30 | Equal
31 | IntlYen
32 | KeyQ
33 | KeyW
34 | KeyE
35 | KeyR
36 | KeyT
37 | KeyY
38 | KeyU
39 | KeyI
40 | KeyO
41 | KeyP
42 | BracketLeft
43 | BracketRight
44 | Backslash
45 | KeyA
46 | KeyS
47 | KeyD
48 | KeyF
49 | KeyG
50 | KeyH
51 | KeyJ
52 | KeyK
53 | KeyL
54 | Semicolon
55 | Quote
56 | IntlBackslash
57 | KeyZ
58 | KeyX
59 | KeyC
60 | KeyV
61 | KeyB
62 | KeyN
63 | KeyM
64 | Comma
65 | Period
66 | Slash
67 | IntlRo`
68 |