Skip to content

Commit 36c3b58

Browse files
committed
Improve weapon collision and fix packet pack
- Pixel round the weapon and player positions when checking overlap. - Fix player-weapon collision box boundaries. - Pack the sync request packet so it's the correct size.
1 parent f8c582d commit 36c3b58

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/null/Math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ inline bool BoxBoxIntersect(const Vector2f& first_min, const Vector2f& first_max
199199

200200
inline bool BoxBoxOverlap(const Vector2f& first_min, const Vector2f& first_max, const Vector2f& second_min,
201201
const Vector2f& second_max) {
202-
return (first_max.x > second_min.x && first_min.x < second_max.x && first_max.y > second_min.y &&
202+
return (first_max.x >= second_min.x && first_min.x < second_max.x && first_max.y >= second_min.y &&
203203
first_min.y < second_max.y);
204204
}
205205

src/null/WeaponManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ WeaponSimulateResult WeaponManager::Simulate(Weapon& weapon) {
287287

288288
float radius = connection.settings.ShipSettings[player->ship].GetRadius();
289289
Vector2f player_r(radius, radius);
290-
Vector2f& pos = player->position;
290+
Vector2f pos = player->position.PixelRounded();
291291

292292
float weapon_radius = 18.0f;
293293

@@ -303,8 +303,8 @@ WeaponSimulateResult WeaponManager::Simulate(Weapon& weapon) {
303303

304304
weapon_radius = (weapon_radius - 14.0f) / 16.0f;
305305

306-
Vector2f min_w(weapon.position.x - weapon_radius, weapon.position.y - weapon_radius);
307-
Vector2f max_w(weapon.position.x + weapon_radius, weapon.position.y + weapon_radius);
306+
Vector2f min_w = weapon.position.PixelRounded() - Vector2f(weapon_radius, weapon_radius);
307+
Vector2f max_w = weapon.position.PixelRounded() + Vector2f(weapon_radius, weapon_radius);
308308

309309
if (BoxBoxOverlap(pos - player_r, pos + player_r, min_w, max_w)) {
310310
bool hit = true;
@@ -324,8 +324,8 @@ WeaponSimulateResult WeaponManager::Simulate(Weapon& weapon) {
324324

325325
weapon_radius = 4.0f / 16.0f;
326326

327-
min_w = Vector2f(weapon.position.x - weapon_radius, weapon.position.y - weapon_radius);
328-
max_w = Vector2f(weapon.position.x + weapon_radius, weapon.position.y + weapon_radius);
327+
min_w = weapon.position.PixelRounded() - Vector2f(weapon_radius, weapon_radius);
328+
max_w = weapon.position.PixelRounded() + Vector2f(weapon_radius, weapon_radius);
329329

330330
// Fully trigger the bomb if it hits the player's normal radius check
331331
hit = BoxBoxOverlap(pos - player_r, pos + player_r, min_w, max_w);

src/null/net/Connection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ void Connection::ProcessPacket(u8* pkt, size_t size) {
288288
case ProtocolCore::SyncTimeRequest: {
289289
u32 timestamp = buffer.ReadU32();
290290

291+
#pragma pack(push, 1)
291292
struct {
292293
u8 core;
293294
u8 type;
294295
u32 received_timestamp;
295296
u32 local_timestamp;
296297
} sync_response = {0x00, 0x06, timestamp, GetCurrentTick()};
298+
#pragma pack(pop)
297299

298300
packet_sequencer.SendReliableMessage(*this, (u8*)&sync_response, sizeof(sync_response));
299301

@@ -1021,10 +1023,12 @@ size_t Connection::Send(u8* data, size_t size) {
10211023
}
10221024

10231025
void Connection::SendDisconnect() {
1026+
#pragma pack(push, 1)
10241027
struct {
10251028
u8 core;
10261029
u8 type;
10271030
} disconnect = {0x00, 0x07};
1031+
#pragma pack(pop)
10281032

10291033
Send((u8*)&disconnect, sizeof(u16));
10301034
}
@@ -1065,10 +1069,12 @@ void Connection::SendSpectateRequest(u16 pid) {
10651069
}
10661070

10671071
void Connection::SendShipRequest(u8 ship) {
1072+
#pragma pack(push, 1)
10681073
struct {
10691074
u8 type;
10701075
u8 ship;
10711076
} request = {0x18, ship};
1077+
#pragma pack(pop)
10721078

10731079
packet_sequencer.SendReliableMessage(*this, (u8*)&request, sizeof(request));
10741080
}

0 commit comments

Comments
 (0)