diff --git a/JavascriptServer/concepts/entity.js b/JavascriptServer/concepts/entity.js index f36bea2..9bcb201 100644 --- a/JavascriptServer/concepts/entity.js +++ b/JavascriptServer/concepts/entity.js @@ -2,6 +2,7 @@ import { EventEmitter } from "events"; import { CircleCollider, BoxCollider, PolygonCollider } from '#concepts/collider'; import { v4 as uuidv4 } from 'uuid'; +import { isDeepStrictEqual } from 'util'; // a thing class Entity extends EventEmitter { @@ -21,7 +22,7 @@ class Entity extends EventEmitter { angle = 0; prev_pos; - prev_serialized; // json of serialized entity + serialized; // save the last serialized version of this entity (to compare changes) base_size = { x: 64, y: 64 }; scale = { x: 1, y: 1 }; @@ -112,10 +113,10 @@ class Entity extends EventEmitter { this.emit('update'); // if something changed - send again (add to the room's bundle) - const serialized = JSON.stringify(this.serialize()); - if (serialized != this.prev_serialized || this.sendEveryTick) { - this.prev_serialized = serialized; - this.send(); // add to the bundle + const new_serialized = this.serialize(); + if (this.sendEveryTick || !isDeepStrictEqual(new_serialized, this.serialized)) { + this.serialized = new_serialized; + this.send(true); // add to the bundle } } @@ -187,10 +188,6 @@ class Entity extends EventEmitter { this.regenerateCollider(x, y); } - // if (this.size.x != this.prev_size.x || this.size.y != this.prev_size.y) { - // // change the collider scale by the same ratio as the entity scale - // this.collider.setScale(this.collider.scaleX * this.size.x / this.prev_size.x, this.collider.scaleY * this.size.y / this.prev_size.y); - // } this.collider.setAngle(this.angle); this.collider.setPosition(x, y); this.tree.updateBody(this.collider); @@ -278,8 +275,9 @@ class Entity extends EventEmitter { y: this.roundedPos(this.y), xs: this.xscale, ys: this.yscale, + a: this.angle, spd: this.spd, - p: this.props, + p: this.props, // uses a getter for props st: this.state }; } @@ -288,8 +286,14 @@ class Entity extends EventEmitter { return this.serialize(); } - send() { - const data = this.bundle(); + send(cached = false) { + let data; + + if (!cached) + data = this.bundle(); + else + data = this.serialized; + this.room.bundle.push(data); } @@ -299,11 +303,6 @@ class Entity extends EventEmitter { let w = this.width, h = this.height; return { - // left: x - w/2, - // top: y - h/2, - // right: x + w/2, - // bottom: y + h/2, - left: x, top: y, right: x + w, diff --git a/JavascriptServer/config.js b/JavascriptServer/config.js index 4f50041..66124e5 100644 --- a/JavascriptServer/config.js +++ b/JavascriptServer/config.js @@ -90,24 +90,24 @@ const common_config = { // some fundamental lobby settings lobby: { - max_players: 100, - add_into_play_on_full: true, - add_into_play_on_join: false, + max_players: 100, // used when creating a lobby with no map/game mode + add_into_play_on_full: true, // true - add all the players into play at the same time once the lobby is filled, + add_into_play_on_join: false, // true - add players one by one immediately as they join a lobby allow_join_by_id: false, close_on_leave: true // close the lobby if a player leaves }, room: { // .yy room loading - rooms_path: '../Client/rooms', + rooms_path: '../Client/rooms', // (overriden in prod config) warn_on_unknown_entity: false, - use_starting_room: true, - use_last_profile_room: false, - use_persistent_position: false, + use_starting_room: true, // join config.room.starting_room on start + use_last_profile_room: false, // join client.profile.state.room on start if logged in + use_persistent_position: false, // load the last x/y from the profile on room join and save them on room leave starting_room: 'Test Room', - rest_timeout: 5, + rest_timeout: 5, // (seconds) - prevents rooms from processing entities // when no players are present for a certain amount of time // set to -1 to disable this feature // (!!! setting to 0 might cause problems and unexpected behaviour !!!) @@ -116,42 +116,42 @@ const common_config = { }, party: { - max_members: 5, + max_members: 5, // max party size leader_only_mm: false // true - only party leader can start matchmaking }, matchmaking: { - mmr_starting: 1000, - mmr_min: 1, + mmr_starting: 1000, // the starting mmr given to new players + mmr_min: 1, // can't go below this - mmr_scale: 1000, + mmr_scale: 1000, // lower number = less effect opponent's mmr has on mmr change // (chess uses 400, meaning a player with 400 mmr more is on average 10x more likely to win) - mmr_max_gain: 50, - mmr_max_difference: 500, + mmr_max_gain: 50, // the maximum possible amount of mmr that a player can gain after a single game, winning against an equal opponent will give half of this + mmr_max_difference: 500, // can't ever register a ranked match with players' mmr difference more than this process_interval: 1 * 1000 // matchmaking: attempt to create new matches every X ms }, - tps: 20, + tps: 20, // tickrate // Disable some of the features that you don't need in your game // true = enabled, false = disabled - timestamps_enabled: true, - ws_enabled: true, - db_enabled: true, - shell_enabled: false, - rooms_enabled: true, - entities_enabled: true, - dt_enabled: true, - ssl_enabled: false, - logging_enabled: true, - validation_enabled: true, - middleware_enabled: true, - matchmaking_enabled: true, - - verbose_lag: false, - - necessary_login: false, + timestamps_enabled: true, // send timestamps with each packet (there is a client-side config as well) + ws_enabled: true, // websocket server? + db_enabled: true, // MongoDB support + shell_enabled: false, // toggles a console that allows code execution while running the game (better to change this in prod/dev configs rather than here) + rooms_enabled: true, // toggles lobbies being split into rooms (sub-lobbies with entities) + entities_enabled: true, // toggles loading/spawning entities + dt_enabled: true, // toggles delta time for entity physics + ssl_enabled: false, // SSL support. false by default (best set in the prod/dev configs) + logging_enabled: true, // whether or not to log trace()'d messages to server_log.txt + validation_enabled: true, // validate the incoming commands using ValidatorJS's validators + middleware_enabled: true, // middleware to execute before some packets are handled + matchmaking_enabled: true, // use the matchmaking system with queues and tickets + + verbose_lag: false, // logs warning messages to chat when a game tick is taking longer than expected + + necessary_login: false, // if true, won't allow a client to join any lobby before logging in ping_interval: 5 * 1000 }; @@ -161,7 +161,7 @@ const prod_config = { server: 'production' }, env_name: 'prod', - ip: '0.0.0.0', + ip: '0.0.0.0', // you need to replace this with your domain if using ssl for it to work port: parseInt(args.port) || 1337, ws_port: parseInt(args.ws_port) || 3000, @@ -174,7 +174,7 @@ const prod_config = { ssl_cert_path: '/etc/letsencrypt/live/example.com/cert.pem', ssl_key_path: '/etc/letsencrypt/live/example.com/privkey.pem', - db: args.db || 'mongodb://127.0.0.1:27017/warp-game', + db: args.db || 'mongodb://127.0.0.1:27017/warp-game', // by default it uses the same db name for dev/prod, but // you can add a postfix at the end of the name to separate them shell_enabled: false, verbose_lag: false, diff --git a/JavascriptServer/schemas/profile.js b/JavascriptServer/schemas/profile.js index c1a6a01..524f08c 100644 --- a/JavascriptServer/schemas/profile.js +++ b/JavascriptServer/schemas/profile.js @@ -12,7 +12,7 @@ const profileSchema = new Schema({ last_online: { type: Date, default: Date.now }, friends: [{ type: Schema.Types.ObjectId, ref: 'Profile' }], - mmr: { type: Number, required: false }, + mmr: { type: Number, required: false }, // matchmaking rating state: { diff --git a/JavascriptServer/util/load_room.js b/JavascriptServer/util/load_room.js index 377aa10..348761c 100644 --- a/JavascriptServer/util/load_room.js +++ b/JavascriptServer/util/load_room.js @@ -65,6 +65,7 @@ export default function LoadRoom(room_name) { y: inst.y, xs: inst.scaleX, ys: inst.scaleY, + a: inst.rotation, t: type, spd: { x: 0, y: 0 }, p: props, diff --git a/Release/GMClient.zip b/Release/GMClient.zip index 9c5fecf..6adb3a2 100644 Binary files a/Release/GMClient.zip and b/Release/GMClient.zip differ diff --git a/Release/JSServer.zip b/Release/JSServer.zip index 6f84a63..2c819a0 100644 Binary files a/Release/JSServer.zip and b/Release/JSServer.zip differ diff --git a/Release/TSServer.zip b/Release/TSServer.zip index 42768ec..ff46f29 100644 Binary files a/Release/TSServer.zip and b/Release/TSServer.zip differ diff --git a/Release/Warp.yymps b/Release/Warp.yymps index 9c5fecf..6adb3a2 100644 Binary files a/Release/Warp.yymps and b/Release/Warp.yymps differ diff --git a/Release/WebClient.zip b/Release/WebClient.zip index 0a3404d..89af152 100644 Binary files a/Release/WebClient.zip and b/Release/WebClient.zip differ diff --git a/TypescriptServer/src/util/load_room.ts b/TypescriptServer/src/util/load_room.ts index 800b842..48a2646 100644 --- a/TypescriptServer/src/util/load_room.ts +++ b/TypescriptServer/src/util/load_room.ts @@ -72,6 +72,7 @@ export default function LoadRoom(room_name:string):LoadedRoom { y: inst.y, xs: inst.scaleX, ys: inst.scaleY, + a: inst.rotation, t: type, spd: {x: 0, y: 0}, p: props,