This commit is contained in:
Evert Prants 2022-04-12 18:24:05 +03:00
parent e33924329c
commit 42a4358df1
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
11 changed files with 35 additions and 32 deletions

View File

@ -6,12 +6,12 @@ import { IcyNetUser } from '../common/types/user';
import { ThirdPersonCamera } from './object/camera'; import { ThirdPersonCamera } from './object/camera';
import { Chat } from './object/chat'; import { Chat } from './object/chat';
import { Joystick } from './object/joystick'; import { Joystick } from './object/joystick';
import { CubeMap } from './object/other/cubemap'; import { PonyModelLoader } from './object/resource/pony-loader';
import { PonyEyes } from './object/other/eyes'; import { PonyEyes } from './object/model/eyes';
import { CubeMap } from './object/resource/cubemap';
import { VideoPlayer } from './object/other/video-player'; import { VideoPlayer } from './object/other/video-player';
import { Player } from './object/player'; import { Player } from './object/player';
import { PlayerEntity } from './object/player-entity'; import { PlayerEntity } from './object/player-entity';
import { PonyModel } from './object/pony-loader';
import { ClientWorld } from './object/world/ClientWorld'; import { ClientWorld } from './object/world/ClientWorld';
import { ClientWorldLoader } from './object/world/ClientWorldLoader'; import { ClientWorldLoader } from './object/world/ClientWorldLoader';
import { ClientWorldManifest } from './object/world/ClientWorldManifest'; import { ClientWorldManifest } from './object/world/ClientWorldManifest';
@ -40,7 +40,7 @@ export class Game {
const cube = await CubeMap.load('/assets/skybox/default'); const cube = await CubeMap.load('/assets/skybox/default');
await PonyModel.getInstance().loadPonyModel(); await PonyModelLoader.getInstance().loadPonyModel();
await PonyEyes.getInstance().initialize(); await PonyEyes.getInstance().initialize();
await this.world.initialize(); await this.world.initialize();

View File

@ -1,5 +1,5 @@
import { Color, ShaderMaterial, UniformsLib, UniformsUtils } from 'three'; import { Color, ShaderMaterial, UniformsLib, UniformsUtils } from 'three';
import { BaseTexture } from './texture'; import { BaseTexture } from '../resource/texture';
export const vertex = /* glsl */ ` export const vertex = /* glsl */ `
varying vec3 vViewPosition; varying vec3 vViewPosition;

View File

@ -1,7 +1,5 @@
import * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils'; import * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils';
import { CharacterPacket, FullStatePacket } from '../../common/types/packet';
import { NameTag } from './nametag';
import { CanvasUtils } from './canvas-utils';
import { import {
Mesh, Mesh,
MeshStandardMaterial, MeshStandardMaterial,
@ -12,9 +10,12 @@ import {
Vector3, Vector3,
ShaderMaterial, ShaderMaterial,
} from 'three'; } from 'three';
import { ClientWorld } from './world/ClientWorld'; import { FullStatePacket, CharacterPacket } from '../../../common/types/packet';
import { PonyEyes } from './other/eyes'; import { CanvasUtils } from '../canvas-utils';
import { PonyModel } from './pony-loader'; import { NameTag } from '../nametag';
import { PonyModelLoader } from '../resource/pony-loader';
import { ClientWorld } from '../world/ClientWorld';
import { PonyEyes } from './eyes';
const nameTagBuilder = new CanvasUtils({ const nameTagBuilder = new CanvasUtils({
fill: false, fill: false,
@ -39,7 +40,7 @@ export class PonyEntity {
public heightSource?: ClientWorld; public heightSource?: ClientWorld;
initialize() { initialize() {
const loader = PonyModel.getInstance(); const loader = PonyModelLoader.getInstance();
this.model = (SkeletonUtils as any).clone(loader.ponyModel); this.model = (SkeletonUtils as any).clone(loader.ponyModel);
this.material = ( this.material = (
(this.model.children[0].children[1] as Mesh) (this.model.children[0].children[1] as Mesh)

View File

@ -1,5 +1,5 @@
import { IcyNetUser } from '../../common/types/user'; import { IcyNetUser } from '../../common/types/user';
import { PonyEntity } from './pony'; import { PonyEntity } from './model/pony';
import { import {
FullStatePacket, FullStatePacket,
PositionUpdatePacket, PositionUpdatePacket,

View File

@ -1,6 +1,6 @@
import { IcyNetUser } from '../../common/types/user'; import { IcyNetUser } from '../../common/types/user';
import { Socket } from 'socket.io-client'; import { Socket } from 'socket.io-client';
import { PonyEntity } from './pony'; import { PonyEntity } from './model/pony';
import { Scene, Vector2, Vector3 } from 'three'; import { Scene, Vector2, Vector3 } from 'three';
export class Player extends PonyEntity { export class Player extends PonyEntity {

View File

@ -9,9 +9,9 @@ const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('/examples/js/libs/draco/'); dracoLoader.setDecoderPath('/examples/js/libs/draco/');
loader.setDRACOLoader(dracoLoader); loader.setDRACOLoader(dracoLoader);
let instance: PonyModel; let instance: PonyModelLoader;
export class PonyModel { export class PonyModelLoader {
public ponyModel!: THREE.Group; public ponyModel!: THREE.Group;
public animations!: THREE.AnimationClip[]; public animations!: THREE.AnimationClip[];
@ -49,9 +49,9 @@ export class PonyModel {
}); });
} }
public static getInstance(): PonyModel { public static getInstance(): PonyModelLoader {
if (!instance) { if (!instance) {
instance = new PonyModel(); instance = new PonyModelLoader();
} }
return instance; return instance;
} }

View File

@ -3,10 +3,8 @@ import {
Float32BufferAttribute, Float32BufferAttribute,
Material, Material,
Mesh, Mesh,
MeshLambertMaterial,
Vector3, Vector3,
} from 'three'; } from 'three';
import { to2D } from '../../../common/convert';
import { WorldChunk } from '../../../common/world/WorldChunk'; import { WorldChunk } from '../../../common/world/WorldChunk';
export class ClientWorldMesher { export class ClientWorldMesher {

View File

@ -1,15 +1,12 @@
import { Server, Socket } from 'socket.io'; import { Server, Socket } from 'socket.io';
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { IcyNetUser } from '../../common/types/user'; import { IcyNetUser } from '../common/types/user';
import { import { CharacterPacket, PositionUpdatePacket } from '../common/types/packet';
CharacterPacket,
PositionUpdatePacket,
} from '../../common/types/packet';
const PLACEHOLDER_USER = (socket: Socket): IcyNetUser => { const PLACEHOLDER_USER = (socket: Socket): IcyNetUser => {
const randomName = `player-${socket.id.substring(0, 8)}`; const randomName = `player-${socket.id.substring(0, 8)}`;
return { return {
id: Math.random() * 1000 + 1000, id: Math.floor(Math.random() * 1000 + 1000),
username: randomName, username: randomName,
display_name: randomName, display_name: randomName,
uuid: socket.id, uuid: socket.id,
@ -44,6 +41,14 @@ export class Game {
: (session?.passport?.user as IcyNetUser); : (session?.passport?.user as IcyNetUser);
const publicUserInfo = user ? this.mapPlayer(user) : null; const publicUserInfo = user ? this.mapPlayer(user) : null;
if (
user &&
this._connections.find((entry) => entry.data.user.id === user.id)
) {
socket.emit('error.duplicate');
return;
}
this._connections.push(socket); this._connections.push(socket);
socket.emit('me', publicUserInfo); socket.emit('me', publicUserInfo);
@ -77,9 +82,9 @@ export class Game {
...packet, ...packet,
}; };
if (!this._changedPlayers.includes(socket.data.user.id)) { // if (!this._changedPlayers.includes(socket.data.user.id)) {
this._changedPlayers.push(socket.data.user.id); // this._changedPlayers.push(socket.data.user.id);
} // }
}); });
socket.on('character', (info: CharacterPacket) => { socket.on('character', (info: CharacterPacket) => {
@ -113,8 +118,7 @@ export class Game {
const playerInfo: PositionUpdatePacket[] = []; const playerInfo: PositionUpdatePacket[] = [];
this._connections this._connections
.filter( .filter(
(conn) => (conn) => conn.data.user, // && this._changedPlayers.includes(conn.data.user.id),
conn.data.user && this._changedPlayers.includes(conn.data.user.id),
) )
.forEach((conn) => .forEach((conn) =>
playerInfo.push({ playerInfo.push({

View File

@ -11,7 +11,7 @@ import { Server } from 'socket.io';
import { IcyNetUser } from '../common/types/user'; import { IcyNetUser } from '../common/types/user';
import { config } from './config'; import { config } from './config';
import { Game } from './object/game'; import { Game } from './game';
const RedisStore = connectRedis(session); const RedisStore = connectRedis(session);
const redisClient = config.redis?.enabled ? redis.createClient() : undefined; const redisClient = config.redis?.enabled ? redis.createClient() : undefined;