refactor: net
This commit is contained in:
parent
0eaa32f0d7
commit
79d358b3ee
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "@avocado/client",
|
||||
"version": "1.0.1",
|
||||
"main": "index.js",
|
||||
"author": "cha0s",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"socket.io-client": "2.2.0"
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
"@avocado/resource": "1.x",
|
||||
"@avocado/physics": "1.x",
|
||||
"@avocado/timing": "1.x",
|
||||
"debug": "^3.1.0",
|
||||
"debug": "3.1.0",
|
||||
"immutable": "4.0.0-rc.12",
|
||||
"lodash.mapvalues": "4.6.0",
|
||||
"lodash.merge": "4.6.1",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"@avocado/mixins": "1.x",
|
||||
"@avocado/resource": "1.x",
|
||||
"@pixi/filter-advanced-bloom": "2.7.0",
|
||||
"debug": "^3.1.0",
|
||||
"debug": "3.1.0",
|
||||
"immutable": "4.0.0-rc.12",
|
||||
"pixi.js": "4.8.6",
|
||||
"three": "0.103.0",
|
||||
|
|
92
packages/graphics/three/scene.js
Normal file
92
packages/graphics/three/scene.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
const PIXI = 'undefined' !== typeof window ? require('pixi.js') : undefined;
|
||||
|
||||
import * as THREE from 'three';
|
||||
|
||||
import {compose} from '@avocado/core';
|
||||
import {Property} from '@avocado/mixins';
|
||||
|
||||
import {hasGraphics} from '../has-graphics';
|
||||
import {Image} from '../image';
|
||||
import {Renderable} from '../renderable';
|
||||
import {Sprite} from '../sprite';
|
||||
|
||||
const decorate = compose(
|
||||
Property('camera'),
|
||||
)
|
||||
|
||||
export class ThreeScene extends Renderable {
|
||||
|
||||
constructor(size) {
|
||||
super();
|
||||
// Default camera. Orthographic projection starting at "true" 0, 0.
|
||||
const camera = new THREE.OrthographicCamera(
|
||||
size[0] / -2,
|
||||
size[0] / 2,
|
||||
size[1] / 2,
|
||||
size[1] / -2,
|
||||
0,
|
||||
200,
|
||||
);
|
||||
camera.position.z = 100;
|
||||
camera.updateProjectionMatrix();
|
||||
this.camera = camera;
|
||||
// THREE stuff.
|
||||
this.scene = new THREE.Scene();
|
||||
this.renderer = new THREE.WebGLRenderer({
|
||||
alpha: true,
|
||||
});
|
||||
this.renderer.setSize(size[0], size[1]);
|
||||
// THREE/PIXI bridge.
|
||||
this.image = Image.fromHtmlCanvas(this.renderer.domElement);
|
||||
this.sprite = new Sprite(this.image);
|
||||
this.sprite.anchor = [0, 0];
|
||||
// First tick math is all weird...
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
}
|
||||
|
||||
add(...args) {
|
||||
this.scene.add(...args);
|
||||
}
|
||||
|
||||
get internal() {
|
||||
return this.sprite.internal;
|
||||
}
|
||||
|
||||
render() {
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
this.image.updateBaseTexture();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// // THREE scene.
|
||||
// import {ThreeScene} from '@avocado/graphics/three/scene';
|
||||
// const threeScene = new ThreeScene(visibleSize);
|
||||
// const geometry = new THREE.BoxGeometry(8, 8, 8);
|
||||
// const material = new THREE.MeshNormalMaterial();
|
||||
// const mesh = new THREE.Mesh(geometry, material);
|
||||
// threeScene.add(mesh);
|
||||
// stage.addChild(threeScene);
|
||||
|
||||
|
||||
// selfEntity.on('positionChanged', () => {
|
||||
// mesh.position.x = selfEntity.x;
|
||||
// mesh.position.y = -(selfEntity.y - 32);
|
||||
// });
|
||||
// camera.on('realPositionChanged', () => {
|
||||
// const realPosition = camera.realPosition;
|
||||
// threeScene.camera.position.x = realPosition[0];
|
||||
// threeScene.camera.position.y = -realPosition[1];
|
||||
// threeScene.camera.updateProjectionMatrix();
|
||||
// const realOffset = camera.realOffset;
|
||||
// threeScene.sprite.x = realOffset[0];
|
||||
// threeScene.sprite.y = realOffset[1];
|
||||
// });
|
||||
|
||||
|
||||
// mesh.rotation.x += .1
|
||||
// mesh.rotation.y += .1
|
||||
|
||||
|
||||
// // THREE render.
|
||||
// threeScene.render();
|
|
@ -1,6 +1,6 @@
|
|||
import * as I from 'immutable';
|
||||
|
||||
import {Packet} from '@avocado/packet';
|
||||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class InputPacket extends Packet {
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ import io from 'socket.io-client';
|
|||
|
||||
import {compose} from '@avocado/core';
|
||||
import {EventEmitter} from '@avocado/mixins';
|
||||
import {SocketIoParser, allPackets, idFromPacket} from '@avocado/packet';
|
||||
|
||||
import {SocketIoParser, allPackets, idFromPacket} from '../packet';
|
||||
|
||||
const debug = D('@avocado:client:socket');
|
||||
|
||||
|
@ -11,7 +12,7 @@ const decorate = compose(
|
|||
EventEmitter,
|
||||
);
|
||||
|
||||
class SocketClient extends decorate(class {}) {
|
||||
export class SocketClient extends decorate(class {}) {
|
||||
|
||||
constructor(address, options = {}) {
|
||||
super();
|
||||
|
@ -94,7 +95,3 @@ class SocketClient extends decorate(class {}) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
export function create(address) {
|
||||
return new SocketClient(address);
|
||||
}
|
8
packages/net/index.js
Normal file
8
packages/net/index.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
export {
|
||||
allPackets,
|
||||
idFromPacket,
|
||||
Packet,
|
||||
packetFromId,
|
||||
registerPacket,
|
||||
SocketIoParser,
|
||||
} from './packet';
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@avocado/packet",
|
||||
"name": "@avocado/net",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"author": "cha0s",
|
||||
|
@ -7,6 +7,9 @@
|
|||
"dependencies": {
|
||||
"@avocado/core": "1.x",
|
||||
"@avocado/mixins": "1.x",
|
||||
"schemapack": "1.4.2"
|
||||
"debug": "3.1.0",
|
||||
"schemapack": "1.4.2",
|
||||
"socket.io": "2.2.0",
|
||||
"socket.io-client": "2.2.0"
|
||||
}
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
const SocketServer = require('socket.io');
|
||||
import SocketIoServer from 'socket.io';
|
||||
|
||||
import {compose} from '@avocado/core';
|
||||
import {EventEmitter} from '@avocado/mixins';
|
||||
import {SocketIoParser, allPackets, idFromPacket} from '@avocado/packet';
|
||||
|
||||
import {SocketIoParser, allPackets, idFromPacket} from '../packet';
|
||||
|
||||
const decorateServer = compose(
|
||||
EventEmitter,
|
||||
);
|
||||
|
||||
export class Server extends decorateServer(class {}) {
|
||||
export class SocketServer extends decorateServer(class {}) {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -25,7 +26,7 @@ export class Server extends decorateServer(class {}) {
|
|||
}
|
||||
|
||||
open(httpServer) {
|
||||
this.io = new SocketServer(httpServer, {
|
||||
this.io = new SocketIoServer(httpServer, {
|
||||
parser: SocketIoParser,
|
||||
path: '/avocado',
|
||||
perMessageDeflate: false,
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "@avocado/server",
|
||||
"version": "1.0.2",
|
||||
"main": "index.js",
|
||||
"author": "cha0s",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"socket.io": "2.2.0"
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import {Packet} from '@avocado/packet';
|
||||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class StateKeysPacket extends Packet {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Packet} from '@avocado/packet';
|
||||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class StatePacket extends Packet {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user