Skip to content

Commit

Permalink
start worker stuff (sad)
Browse files Browse the repository at this point in the history
  • Loading branch information
onlypuppy7 committed Oct 7, 2024
1 parent 35ed617 commit 492981c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 75 deletions.
3 changes: 3 additions & 0 deletions server-client/src/client-static/src/shellshock.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ minMaps = LEGACYSHELLMINMAPS;

LEGACYSHELLCONSTANTS

var interval = new IntervalManagerConstructor();
var timeout = new TimeoutManagerConstructor();

var NextRoundTimeout = 20;
var skybox;
var skyboxMaterial;
Expand Down
2 changes: 1 addition & 1 deletion server-game/run-game.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function startServer() {
console.log("roomFound", !!roomFound);

if (roomFound) {
roomFound.joinPlayer(msg, ws);
RoomManager.joinRoom(roomFound, msg, ws);
} else {
console.log(Comm.Close.gameNotFound);
ws.close(Comm.Close.gameNotFound);
Expand Down
6 changes: 3 additions & 3 deletions server-game/src/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//legacyshell: client
import ran from '#scrambled';
import Comm from '#comm';
import { ItemType, itemIdOffsets, FramesBetweenSyncs, stateBufferSize, timeout, maxChatWidth } from '#constants';
import { ItemType, itemIdOffsets, FramesBetweenSyncs, stateBufferSize, TimeoutManagerConstructor, maxChatWidth } from '#constants';
import { fixStringWidth } from '#stringWidth';
import Player from '#player';
import CatalogConstructor from '#catalog';
Expand All @@ -19,6 +19,7 @@ function setSS(newSS) {
class newClient {
constructor(room, info, ws) {
//
this.timeout = new TimeoutManagerConstructor();
this.clientReady = false;
this.room = room;
this.ws = ws;
Expand Down Expand Up @@ -123,7 +124,7 @@ class newClient {
case Comm.Code.pause:
this.player.resetDespawn();

timeout.set(() => {
this.timeout.set(() => {
this.player.removeFromPlay();
this.room.sendToOthers(this.packPaused(), this.id);
}, 3e3);
Expand Down Expand Up @@ -168,7 +169,6 @@ class newClient {

} catch (error) {
console.error('Error processing message:', error);
// ws.send(JSON.stringify({ error: 'Internal server error' }));
};
};

Expand Down
5 changes: 5 additions & 0 deletions server-game/src/roomManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ran from '#scrambled';
import RoomConstructor from '#rooms';
import Comm from '#comm';
import { Worker } from 'worker_threads';
//

const id_length = 3; //btw you cant just modify this without also adjusting the client's code. do you ever NEED to modify this? no. just have it static.
Expand Down Expand Up @@ -118,6 +119,10 @@ class newRoomManager {
return null; //doesnt exist
};
};

joinRoom(room, msg, ws) {
room.joinPlayer(msg, ws);
};
};

export default {
Expand Down
2 changes: 2 additions & 0 deletions server-game/src/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class newRoom {
};

disconnectClient(client) {


delete this.clients[client.id];
delete this.players[client.id];

Expand Down
66 changes: 23 additions & 43 deletions src/shell/collider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { isClient } from '#constants';

//(server-only-start)
var ss;
var map = null;
var mapMeshes = null;
var playerLimit = null;
var players = null;
var map;
var mapMeshes;
var playerLimit;
var players;
//(server-only-end)

class ColliderConstructor {
Expand Down Expand Up @@ -55,62 +55,50 @@ class ColliderConstructor {
this.v4 = new BABYLON.Vector3();
this.ray = new BABYLON.Ray(BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), 1);
this.matrix = new BABYLON.Matrix();

this.map = map;
this.mapMeshes = mapMeshes;
this.playerLimit = playerLimit;
this.players = players;
};

setSS(ssP, mapP, mapMeshesP, playerLimitP, playersP) {
ss = ssP
this.map = mapP;
this.mapMeshes = mapMeshesP;
this.playerLimit = playerLimitP;
this.players = playersP;
map = mapP;
mapMeshes = mapMeshesP;
playerLimit = playerLimitP;
players = playersP;
};

pointCollidesWithMap(point, ignoreSoft) {
var map_ = map || this.map;

if (isNaN(point.x) || isNaN(point.y) || isNaN(point.z)) return false;
var cx = Math.floor(point.x),
cy = Math.floor(point.y),
cz = Math.floor(point.z);
return !(cx < 0 || cx >= map_.width || cz < 0 || cz >= map_.depth || cy < 0 || cy >= map_.height) && this.meshCollidesWithCell(this.pointCollisionMesh, point, cx, cy, cz, ignoreSoft);
return !(cx < 0 || cx >= map.width || cz < 0 || cz >= map.depth || cy < 0 || cy >= map.height) && this.meshCollidesWithCell(this.pointCollisionMesh, point, cx, cy, cz, ignoreSoft);
}

playerCollidesWithMap(player) {
return this.meshCollidesWithMap(this.playerCollisionMesh, player);
}

meshCollidesWithMap(mesh, pos) {
var map_ = map || this.map;

var cellsChecked = {};
if (isNaN(pos.x) || isNaN(pos.y) || isNaN(pos.z)) return true;
for (var bbox = mesh.getBoundingInfo().boundingBox, i = 0; i < bbox.vectors.length; i++) {
var cx = Math.floor(pos.x + bbox.vectors[i].x),
cy = Math.floor(pos.y + bbox.vectors[i].y),
cz = Math.floor(pos.z + bbox.vectors[i].z);
if (cx < 0 || cx >= map_.width || cz < 0 || cz >= map_.depth || cy < 0) return true;
if (cx < 0 || cx >= map.width || cz < 0 || cz >= map.depth || cy < 0) return true;
var checkId = cx + 1e3 * cy + 1e6 * cz;
if (cy < map_.height && !cellsChecked[checkId]) {
if (cy < map.height && !cellsChecked[checkId]) {
var res = this.meshCollidesWithCell(mesh, pos, cx, cy, cz);
if (res) return res;
cellsChecked[checkId] = true;
};
};
}
}
return false;
};
}

meshCollidesWithCell(mesh, pos, cx, cy, cz, ignoreSoft) {
var map_ = map || this.map;
var mapMeshes_ = mapMeshes || this.mapMeshes;

var cell = map_.data[cx][cy][cz];
var cell = map.data[cx][cy][cz];
if (cell.idx) {
var mapMesh = mapMeshes_[cell.idx];
var mapMesh = mapMeshes[cell.idx];
if (ignoreSoft && mapMesh.softness) return false;
switch (mapMesh.colliderType) {
case "full":
Expand Down Expand Up @@ -144,11 +132,8 @@ class ColliderConstructor {
}

rayCollidesWithMap(origin, direction, callback) {
var map_ = map || this.map;
var mapMeshes_ = mapMeshes || this.mapMeshes;

if (isNaN(origin.x) || isNaN(origin.y) || isNaN(origin.z)) return false;
if (origin.x < 0 || origin.x >= map_.width || origin.z < 0 || origin.z >= map_.depth || origin.y < 0 || origin.y >= map_.height) return false;
if (origin.x < 0 || origin.x >= map.width || origin.z < 0 || origin.z >= map.depth || origin.y < 0 || origin.y >= map.height) return false;
var radius = direction.length(),
x = Math.floor(origin.x),
y = Math.floor(origin.y),
Expand All @@ -169,14 +154,14 @@ class ColliderConstructor {
if (0 === dx && 0 === dy && 0 === dz) return false;

for (radius /= Math.sqrt(dx * dx + dy * dy + dz * dz);
(0 < stepX ? x < map_.width : 0 <= x) && (0 < stepY ? y < map_.height : 0 <= y) && (0 < stepZ ? z < map_.depth : 0 <= z);) {
if (!(x < 0 || y < 0 || z < 0 || x >= map_.width || y >= map_.height || z >= map_.depth)) {
(0 < stepX ? x < map.width : 0 <= x) && (0 < stepY ? y < map.height : 0 <= y) && (0 < stepZ ? z < map.depth : 0 <= z);) {
if (!(x < 0 || y < 0 || z < 0 || x >= map.width || y >= map.height || z >= map.depth)) {
var res = callback(origin, direction, {
x: x,
y: y,
z: z
});
if (res && "verysoft" != mapMeshes_[res.cell.idx].softness) return res;
if (res && "verysoft" != mapMeshes[res.cell.idx].softness) return res;
}
if (tMaxX < tMaxY)
if (tMaxX < tMaxZ) {
Expand Down Expand Up @@ -205,10 +190,8 @@ class ColliderConstructor {
}

getCellForRay(voxel) {
var map_ = map || this.map;

try {
var cell = map_.data[voxel.x][voxel.y][voxel.z];
var cell = map.data[voxel.x][voxel.y][voxel.z];
} catch (e) {
console.log(voxel);
}
Expand Down Expand Up @@ -309,11 +292,8 @@ class ColliderConstructor {
}

rayCollidesWithPlayer(origin, direction, proj) {
var playerLimit_ = playerLimit || this.playerLimit;
var players_ = players || this.players;

for (var fromTeam = proj ? proj.player.team : null, fromId = proj ? proj.player.id : null, i = 0; i < playerLimit_; i++) {
var player = this.players_[i];
for (var fromTeam = proj ? proj.player.team : null, fromId = proj ? proj.player.id : null, i = 0; i < playerLimit; i++) {
var player = players[i];
if (player && player.playing && player.id != fromId && (0 == player.team || player.team != fromTeam)) {
this.ray.origin.copyFrom(origin);
this.ray.direction.copyFrom(direction);
Expand Down
57 changes: 31 additions & 26 deletions src/shell/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export const isServer = typeof (window) === 'undefined'; //clearer in code
/**
* do not change! this is basically how many updates per second. change this and you will change the speed of the game!
*/
const fps = 60;
export const fps = 60;

/**
* you can change this, it will affect the next variable (which is actually used)
*
* (fyi: never directly used)
*/
const syncsPerSecond = 10;
export const syncsPerSecond = 10;

/**
* how many statebuffers to pack at once. in theory, it will be less smoother the higher it is, but demands better latency.
Expand Down Expand Up @@ -325,34 +325,39 @@ export var Ease = {

const thingForTheThing = isClient ? window : null;

export var interval = {
intervals: {},
set: function (func, delay) {
export class IntervalManagerConstructor {
constructor () {
this.intervals = {};
};
set (func, delay) {
var newInterval = setInterval.apply(thingForTheThing, [func, delay].concat([].slice.call(arguments, 2)));
return interval.intervals[newInterval] = true, newInterval
},
clear: function (handle) {
return delete interval.intervals[handle], clearInterval(handle)
},
clearAll: function () {
for (var all = Object.keys(interval.intervals), len = all.length; 0 < len--;) clearInterval(all.shift());
interval.intervals = {}
}
return this.intervals[newInterval] = true, newInterval
};
clear (handle) {
return delete this.intervals[handle], clearInterval(handle)
};
clearAll () {
for (var all = Object.keys(this.intervals), len = all.length; 0 < len--;) clearInterval(all.shift());
this.intervals = {}
};
};

export var timeout = {
timeouts: {},
set: function (func, delay) {
export class TimeoutManagerConstructor {
constructor () {
this.timeouts = {};
};
set (func, delay) {
var newTimeout = setTimeout.apply(thingForTheThing, [func, delay].concat([].slice.call(arguments, 2)));
return timeout.timeouts[newTimeout] = true, newTimeout
},
clear: function (handle) {
return delete timeout.timeouts[handle], clearTimeout(handle)
},
clearAll: function () {
for (var all = Object.keys(timeout.timeouts), len = all.length; 0 < len--;) clearTimeout(all.shift());
timeout.timeouts = {}
}
return this.timeouts[newTimeout] = true, newTimeout
};
clear (handle) {
delete this.timeouts[handle];
return clearTimeout(handle)
};
clearAll () {
for (var all = Object.keys(this.timeouts), len = all.length; 0 < len--;) clearTimeout(all.shift());
this.timeouts = {}
};
};

export const getTimestamp = (noBrackets) => {
Expand Down
7 changes: 5 additions & 2 deletions src/shell/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class Player {
this.id == meId && this.triggerPulled && this.fire()
} else if (0 < this.shotsQueued) {
this.lastActivity = isClient ? now : Date.now();
this.fire(); //TODO! firing...
// this.fire(); //TODO! firing...
};
this.stateBuffer[this.stateIdx].x = this.x;
this.stateBuffer[this.stateIdx].y = this.y;
Expand Down Expand Up @@ -568,7 +568,10 @@ class Player {
this.rofCountdown *= .9;
this.shotsQueued--
};
this.client.room.sendToAll(this.weapon.fire());

var output = this.weapon.fire();
if (isServer && output) this.client.room.sendToAll(output);

this.weapon.ammo.rounds--;
this.recoilCountdown = this.weapon.subClass.recoil;
this.rofCountdown = this.weapon.subClass.rof;
Expand Down

0 comments on commit 492981c

Please sign in to comment.