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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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