0.2.74 • Published 5 months ago

pogp v0.2.74

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
5 months ago

Portable Open Game Protocol 0.0.19

Making games should feel like playing games.

Introducing the POG protocol

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.

Portable

  • 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

Open

  • 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

Game

  • 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

Goals

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.

Code Example (typescript/browser)

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)`;
})

Interactive Examples


Pong

https://pogprotocol.com

Project Status

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

Path to 1.0


  • Define state protocol

  • 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

Client Libraries


Game Logic Client Libraries

languagedev environmentinputsstatewasm support
c#unity@ns@nsn/a
c++unrealOPENOPENOPEN
rustbevyOPENOPENOPEN
c#browserOPENOPENOPEN
c++browserOPENOPENOPEN
rustbrowser@ns@ns@ns
typescriptbrowser@ns@ns@ns

Rendering Client Libraries

languageframeworkenvironmentstatus
c#unitypc/mac/mobile/consoleOPEN
c++unrealpc/mac/mobile/consoleOPEN
rustbevypc/macOPEN
swiftxcode/autolayoutiosOPEN
typescriptpixi.jsbrowser@ns

Contributors:

@ns - @neilsarkar

Reference


Inputs

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

Touch Input

Mouse Input

Keyboard Input

Gamepad 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.

JSON Schema | JSON Example

Binary Schema | Binary Example

Gamepad JSON Schema

type

id

vendorId

productId

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, ZR 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. left-face-top, right-shoulder-front

axes

  • An array of Axes states * hand string enum representing hand intended to be used with joystick: left | right | unknown value * an array of two signed longs representing the x and y position of the thumbstick

Gamepad JSON Example

{
	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

dataexampletypeindexlength (bytes)
type1byte (Input Type)01
buttons.length12uint1612
axes.length12uint1632
buttons[Button, Button]Button569 * buttons.length
axes[Axes, Axes]Axes5 + (69 * buttons.length)129 * axes.length

Gamepad Button Binary Schema

dataexampletypeindexlength (bytes)
position2byte (ButtonPosition)01
value100000uint3214
label"A"string564

Gamepad Axes Binary Schema

dataexampletypeindexlength (bytes)
hand1byte (Hand)01
x100000int64164
y100000int646564

Keyboard Input

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

{
       type: "keyboard",
       keys: [
               27,
               65
       ]
}
datatypebyte indexbit index
Nullbool00
ArrowDownbool01
ArrowLeftbool02
ArrowRightbool03
ArrowUpbool04
Backspacebool05
Tabbool06
CapsLockbool07
Enterbool10
ShiftLeftbool11
ShiftRightbool12
ControlLeftbool13
MetaLeftbool14
AltLeftbool15
Spacebool16
AltRightbool17
MetaRightbool20
...bool......
IntlRobool94

Touch Input (WIP)

{
	type: "touch",
	resolution: [0,0],
	fingers: [
		// there will always be at least one element
		{
			position: [0,0],
			pressure: 0
		}
	]
}

Mouse Input (WIP)

{
	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)

{
	type: "custom",
	id: 'my-flightstick',
	fields: [
		{
			id: 'whammybar',
			values: [420,69]
		},
		{
			id: 'something',
			values: [0]
		}
	]
}

State (WIP)

Game state represents the state of the game. This is going to be custom for each game.

int is short for int32

{
	// 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

dataexampletypeindexlength (bytes)
pog major version0int04
pog minor version1int44
* 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:

{
	// 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

valuenameexample (xbox one)
0null
1left-face-topdpad up
2left-face-rightdpad right
3left-face-bottomdpad down
4left-face-leftdpad left
5left-shoulder-frontLB
6left-shoulder-backLT
7left-thumbstickL3
8right-face-topY
9right-face-rightB
10right-face-bottomA
11right-face-leftX
12right-shoulder-frontRB
13right-shoulder-backRT
14right-thumbstickR3
15middleXbox Button
16middle-leftView Button
17middle-rightMenu Button

Input Type Enum

valuename
0null
1gamepad
2touch
3mouse
4keyboard
5custom

Hand Enum

valuename
0null
1left
2right

Key Enum

valuename
0Null
1ArrowDown
2ArrowLeft
3ArrowRight
4ArrowUp
5Backspace
6Tab
7CapsLock
8Enter
9ShiftLeft
10ShiftRight
11ControlLeft
12MetaLeft
13AltLeft
14Space
15AltRight
16MetaRight
17ContextMenu
18ControlRight
19Backquote
20Digit1
21Digit2
22Digit3
23Digit4
24Digit5
25Digit6
26Digit7
27Digit8
28Digit9
29Digit0
30Minus
31Equal
32IntlYen
33KeyQ
34KeyW
35KeyE
36KeyR
37KeyT
38KeyY
39KeyU
40KeyI
41KeyO
42KeyP
43BracketLeft
44BracketRight
45Backslash
46KeyA
47KeyS
48KeyD
49KeyF
50KeyG
51KeyH
52KeyJ
53KeyK
54KeyL
55Semicolon
56Quote
57IntlBackslash
58KeyZ
59KeyX
60KeyC
61KeyV
62KeyB
63KeyN
64KeyM
65Comma
66Period
67Slash
68IntlRo
0.2.74

5 months ago

0.2.73

5 months ago

0.2.72

5 months ago

0.2.63

5 months ago

0.2.62

5 months ago

0.2.61

6 months ago

0.2.60

6 months ago

0.2.69

5 months ago

0.2.68

5 months ago

0.2.67

5 months ago

0.2.66

5 months ago

0.2.65

5 months ago

0.0.111

6 months ago

0.2.64

5 months ago

0.0.110

6 months ago

0.2.52

6 months ago

0.2.51

6 months ago

0.2.50

6 months ago

0.2.59

6 months ago

0.2.58

6 months ago

0.2.57

6 months ago

0.2.56

6 months ago

0.2.55

6 months ago

0.2.54

6 months ago

0.2.53

6 months ago

0.2.41

6 months ago

0.2.49

6 months ago

0.2.48

6 months ago

0.2.47

6 months ago

0.2.46

6 months ago

0.2.45

6 months ago

0.2.44

6 months ago

0.2.43

6 months ago

0.2.42

6 months ago

0.0.105

6 months ago

0.0.104

6 months ago

0.2.71

5 months ago

0.0.103

6 months ago

0.2.70

5 months ago

0.0.109

6 months ago

0.0.108

6 months ago

0.0.107

6 months ago

0.2.36

6 months ago

0.0.102

6 months ago

0.2.34

6 months ago

0.0.101

6 months ago

0.2.33

6 months ago

0.0.17

1 year ago

0.0.18

12 months ago

0.0.19

12 months ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago