Skip to content

Commit

Permalink
use notepack.io instead of msgpack-lite. bump 0.7.7-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Nov 5, 2017
1 parent c89baf1 commit adab3f0
Show file tree
Hide file tree
Showing 8 changed files with 799 additions and 4,859 deletions.
5,561 changes: 717 additions & 4,844 deletions dist/colyseus.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
})

room.onLeave.add(function() {
room.connection.reconnectEnabled = false;
console.log("LEFT ROOM", arguments);
});

Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colyseus.js",
"version": "0.7.6",
"version": "0.7.7-alpha.1",
"description": "Multiplayer Game Client for the Browser",
"keywords": [
"multiplayer",
Expand All @@ -20,7 +20,7 @@
"build": "tsc && npm run build-dist",
"watch": "tsc -w",
"prepublish": "npm run build",
"test": "npm run build && mocha test/",
"test": "mocha test/*.ts --require ts-node/register",
"postinstall": "npm run -s donate",
"donate": "echo \"\u001b[35m\u001b[1mLove Colyseus? Support its development by becoming a backer:\u001b[22m\u001b[39m\n > \u001b[34mhttps://www.patreon.com/endel\u001b[39m\""
},
Expand All @@ -32,18 +32,22 @@
"@gamestdio/websocket": "^0.2.2",
"delta-listener": "^2.1.0",
"fossil-delta": "^1.0.0",
"msgpack-lite": "^0.1.20",
"notepack.io": "^2.1.2",
"signals.js": "^1.0.0"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/fast-json-patch": "^1.0.4",
"@types/fossil-delta": "^1.0.0",
"@types/mocha": "^2.2.44",
"@types/msgpack-lite": "^0.1.1",
"msgpack-lite": "^0.1.20",
"benchmark": "^2.1.4",
"chai": "^3.5.0",
"mocha": "^3.1.0",
"nodemon": "^1.7.1",
"ts-loader": "^2.3.7",
"ts-node": "^3.3.0",
"typescript": "^2.5.3",
"uglify-js": "^2.6.1",
"watchify": "^3.6.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as msgpack from "msgpack-lite";
import * as msgpack from "notepack.io";
import { Signal } from "signals.js";

import { Protocol } from "./Protocol";
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WebSocketClient from "@gamestdio/websocket";
import * as msgpack from "msgpack-lite";
import * as msgpack from "notepack.io";

export class Connection extends WebSocketClient {

Expand Down
6 changes: 3 additions & 3 deletions src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Signal } from "signals.js";
import Clock = require("@gamestdio/clock");

import { DeltaContainer } from "delta-listener";
import * as msgpack from "msgpack-lite";
import * as msgpack from "notepack.io";
import * as fossilDelta from "fossil-delta";

import { Protocol } from "./Protocol";
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Room<T=any> extends DeltaContainer<T & any> {

setState ( state: T, remoteCurrentTime?: number, remoteElapsedTime?: number ): void {
this.set(state);
this._previousState = msgpack.encode( state )
this._previousState = new Uint8Array( msgpack.encode(state) );

// set remote clock properties
if (remoteCurrentTime && remoteElapsedTime) {
Expand Down Expand Up @@ -104,7 +104,7 @@ export class Room<T=any> extends DeltaContainer<T & any> {
this.clock.tick();

// apply patch
this._previousState = (<any>fossilDelta).apply( this._previousState, binaryPatch, { verifyChecksum: false } );
this._previousState = new Uint8Array( fossilDelta.apply( this._previousState, binaryPatch, { verifyChecksum: false } ) );

// trigger state callbacks
this.set( msgpack.decode( this._previousState ) );
Expand Down
63 changes: 63 additions & 0 deletions test/benchmark/patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as Benchmark from "benchmark";
import * as notepack from "notepack.io";
import * as msgpackLite from "msgpack-lite";
import * as fossilDelta from "fossil-delta";

let data1 = {
one: 1,
two: "two",
list: [1,2,3,4,5,6,7,8,9],
map: {
"1982739173": { x: 0, y: 100 },
"1982739174": { x: 10, y: 200 },
"1982739175": { x: 20, y: 300 },
"1982739176": { x: 30, y: 400 },
"1982739177": { x: 40, y: 500 },
"1982739178": { x: 50, y: 600 },
"1982739179": { x: 60, y: 700 },
"1982739180": { x: 70, y: 800 },
"1982739181": { x: 80, y: 900 },
"1982739182": { x: 90, y: 1000 },
"1982739183": { x: 100, y: 1100 },
}
}

let data2 = {
two: "two 2",
list: [1,2,3,4,5,6,7,8,9],
map: {
"1982739173": { x: 0, y: 100 },
"1982739174": { x: 10, y: 200 },
"1982739175": { x: 20, y: 300 },
"1982739176": { x: 30, y: 400 },
"1982739177": { x: 50, y: 500 },
"1982739179": { x: 60, y: 700 },
"1982739180": { x: 70, y: 800 },
"1982739181": { x: 80, y: 900 },
"1982739182": { x: 90, y: 1000 },
"1982739183": { x: 100, y: 1100 },
"1982739184": { x: 110, y: 1200 },
}
}

let notepackDelta = fossilDelta.create(notepack.encode(data1), notepack.encode(data2));
let msgpackLiteDelta = fossilDelta.create(msgpackLite.encode(data1), msgpackLite.encode(data2));

let data1Encoded = msgpackLite.encode(data1)
let packed1 = notepack.encode(data1);

let suite = new Benchmark.Suite();
suite.add("notepack", () => {
notepack.decode(data1Encoded);;
new Uint8Array(fossilDelta.apply(packed1, notepackDelta));
});

suite.add("msgpack-lite", () => {
msgpackLite.decode(data1Encoded);
fossilDelta.apply(packed1, msgpackLiteDelta);
});

suite.on('cycle', (e) => console.log(String(e.target)));

console.log("Start...");
suite.run();
13 changes: 7 additions & 6 deletions test/room_test.js → test/room_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const assert = require('chai').assert;
const Room = require('../lib/Room').Room;
import { assert } from "chai";
import { Room } from "../src/Room";

const fossilDelta = require('fossil-delta');
const msgpack = require('msgpack-lite');
import * as fossilDelta from "fossil-delta";
import * as msgpack from "notepack.io";

describe("Room", function() {
let room = null;
let room: Room = null;

beforeEach(function() {
room = new Room("chat");
Expand Down Expand Up @@ -35,7 +35,8 @@ describe("Room", function() {
room.setState(state, 0, 0);

// get previous state encoded
let previousState = msgpack.encode(state);
let previousState = new Uint8Array(msgpack.encode(state));

// change state and encode it
let nextState = msgpack.encode({
players: {
Expand Down

0 comments on commit adab3f0

Please sign in to comment.