Skip to content

Commit

Permalink
the collider is bad
Browse files Browse the repository at this point in the history
  • Loading branch information
onlypuppy7 committed Oct 7, 2024
1 parent 48ae7e7 commit 35ed617
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion server-client/src/client-static/src/shellshock.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ function openCustomizerFromMainMenu() {

LEGACYSHELLCOLLIDER

let Collider;
var Collider;

// [LS] ######## Actor Constructors ---------------------------------
// _ ___ _____ ___ ___ ___
Expand Down
45 changes: 30 additions & 15 deletions src/shell/collider.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,46 @@ class ColliderConstructor {
};

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 >= this.map.width || cz < 0 || cz >= this.map.depth || cy < 0 || cy >= this.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 >= this.map.width || cz < 0 || cz >= this.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 < this.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 cell = this.map.data[cx][cy][cz];
var map_ = map || this.map;
var mapMeshes_ = mapMeshes || this.mapMeshes;

var cell = map_.data[cx][cy][cz];
if (cell.idx) {
var mapMesh = this.mapMeshes[cell.idx];
var mapMesh = mapMeshes_[cell.idx];
if (ignoreSoft && mapMesh.softness) return false;
switch (mapMesh.colliderType) {
case "full":
Expand Down Expand Up @@ -137,8 +144,11 @@ 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 >= this.map.width || origin.z < 0 || origin.z >= this.map.depth || origin.y < 0 || origin.y >= this.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 @@ -159,14 +169,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 < this.map.width : 0 <= x) && (0 < stepY ? y < this.map.height : 0 <= y) && (0 < stepZ ? z < this.map.depth : 0 <= z);) {
if (!(x < 0 || y < 0 || z < 0 || x >= this.map.width || y >= this.map.height || z >= this.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" != this.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 @@ -195,8 +205,10 @@ class ColliderConstructor {
}

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

try {
var cell = this.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 @@ -297,8 +309,11 @@ class ColliderConstructor {
}

rayCollidesWithPlayer(origin, direction, proj) {
for (var fromTeam = proj ? proj.player.team : null, fromId = proj ? proj.player.id : null, i = 0; i < this.playerLimit; i++) {
var player = this.players[i];
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];
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
6 changes: 4 additions & 2 deletions src/shell/guns.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gun.prototype.collectAmmo = function () {
Gun.prototype.fire = function () {
if (this.actor) this.actor.fire();
else { //if server, actually make the bullet and fire that shit

var rotMat = BABYLON.Matrix.RotationYawPitchRoll(this.player.yaw, this.player.pitch, 0);
var forwardMat = BABYLON.Matrix.Translation(0, 0, this.subClass.range);
var dirMat = forwardMat.multiply(rotMat, forwardMat);
Expand Down Expand Up @@ -57,8 +58,9 @@ Gun.prototype.fire = function () {
output.packFloat(dir.y);
output.packFloat(dir.z);
output.packInt8(Math.seed);
sendToAll(output.buffer);
this.fireMunitions(pos, dir);

return output;
this.fireMunitions(pos, dir); //todo
};
};
Gun.prototype.equip = function () {
Expand Down
35 changes: 20 additions & 15 deletions src/shell/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const wsSend = function (output, CommCode) {
console.log("wtf?", CommCode); //case that shouldnt exist
};

let Collider;
let mapMeshes;
let map;
let Collider = null;
let mapMeshes = null;
let map = null;

let meId = -100;
//(server-only-end)

Expand All @@ -19,9 +20,13 @@ class Player {
constructor (data, scene, client) {
if (client) {
this.client = client;
Collider = this.client.room.Collider;
mapMeshes = this.client.room.mapMeshes;
map = this.client.room.map;
this.Collider = this.client.room.Collider;
this.mapMeshes = this.client.room.mapMeshes;
this.map = this.client.room.map;
} else {
this.Collider = Collider;
this.mapMeshes = mapMeshes;
this.map = map;
};

this.id = data.id;
Expand Down Expand Up @@ -210,11 +215,11 @@ class Player {
var cy = Math.floor(this.y + 1e-4);
var cz = Math.floor(this.climbingCell.z);

if (0 == this.climbingCell.ry || this.climbingCell.ry, cy >= map.height) {
if (0 == this.climbingCell.ry || this.climbingCell.ry, cy >= this.map.height) {
this.climbing = false;
} else {
var cell = map.data[cx][cy][cz];
if (!(cell.idx && mapMeshes[cell.idx].colliderType === "ladder" && cell.ry === this.climbingCell.ry)) {
var cell = this.map.data[cx][cy][cz];
if (!(cell.idx && this.mapMeshes[cell.idx].colliderType === "ladder" && cell.ry === this.climbingCell.ry)) {
this.y = Math.round(this.y);
this.climbing = false;
};
Expand Down Expand Up @@ -314,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 @@ -563,7 +568,7 @@ class Player {
this.rofCountdown *= .9;
this.shotsQueued--
};
this.weapon.fire();
this.client.room.sendToAll(this.weapon.fire());
this.weapon.ammo.rounds--;
this.recoilCountdown = this.weapon.subClass.recoil;
this.rofCountdown = this.weapon.subClass.rof;
Expand Down Expand Up @@ -795,7 +800,7 @@ class Player {
return this.hp <= 0;
};
lookForLadder (collide) {
if (collide && collide.cell && this.controlKeys & CONTROL.up && "ladder" == mapMeshes[collide.cell.idx].colliderType) {
if (collide && collide.cell && this.controlKeys & CONTROL.up && "ladder" == this.mapMeshes[collide.cell.idx].colliderType) {
var diff = Math.abs(Math.radDifference(this.yaw, collide.cell.ry));
if (!(.75 < diff && diff < 2.391)) {
if (1 == collide.cell.ry || 3 == collide.cell.ry) {
Expand All @@ -811,16 +816,16 @@ class Player {
};
};
getOccupiedCell () {
if (this.x < 0 || this.y < 0 || this.z < 0 || this.x >= map.width || this.y >= map.height || this.z > map.depth) return {};
if (this.x < 0 || this.y < 0 || this.z < 0 || this.x >= this.map.width || this.y >= this.map.height || this.z > this.map.depth) return {};

var cx = Math.floor(this.x);
var cy = Math.floor(this.y + 1e-4);
var cz = Math.floor(this.z);

return map.data[cx][cy][cz]
return this.map.data[cx][cy][cz]
};
collidesWithMap () {
return Collider.playerCollidesWithMap(this);
return this.Collider.playerCollidesWithMap(this);
};
};

Expand Down

0 comments on commit 35ed617

Please sign in to comment.