From ecf5988584059d99975bc580d9094fc24c9880aa Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Mon, 14 Nov 2022 19:50:23 -0800 Subject: [PATCH] PropData: Breakmodels now spawn fully client-side! This will remove a lot of network overhead. --- src/client/event.qc | 3 ++ src/shared/NSRenderableEntity.qc | 4 ++ src/shared/events.h | 1 + src/shared/propdata.h | 6 +++ src/shared/propdata.qc | 68 +++++++++++++++++++++++++++----- 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/client/event.qc b/src/client/event.qc index 9be4d774..b8ff24bb 100644 --- a/src/client/event.qc +++ b/src/client/event.qc @@ -135,6 +135,9 @@ Event_Parse(float type) pSeat->m_flShakeFreq = readfloat(); pSeat->m_flShakeTime = pSeat->m_flShakeDuration; break; + case EV_BREAKMODEL: + BreakModel_Receive(); + break; default: error("event not recognized. abort immediately.\n"); } diff --git a/src/shared/NSRenderableEntity.qc b/src/shared/NSRenderableEntity.qc index 5ba4eb2a..bbd9e508 100644 --- a/src/shared/NSRenderableEntity.qc +++ b/src/shared/NSRenderableEntity.qc @@ -548,6 +548,10 @@ void NSRenderableEntity::SetBody(int newBody) { m_iBody = newBody; + +#ifdef CLIENT + setcustomskin(this, "", sprintf("geomset 0 %i\ngeomset 1 %i\n", m_iBody, m_iBody)); +#endif } void diff --git a/src/shared/events.h b/src/shared/events.h index 1adb854c..1ab702f1 100644 --- a/src/shared/events.h +++ b/src/shared/events.h @@ -51,5 +51,6 @@ enum EV_CLEARDECALS, EV_SURFIMPACT, EV_DECALGROUP, + EV_BREAKMODEL, EV_SEPARATOR }; diff --git a/src/shared/propdata.h b/src/shared/propdata.h index f9366969..71eb07df 100644 --- a/src/shared/propdata.h +++ b/src/shared/propdata.h @@ -128,7 +128,13 @@ breakmodel_t *g_breakmodel; int g_breakmodel_count; var hashtable g_hashbreakmodel; + +#ifdef CLIENT +void BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int count, int index); +void BreakModel_Receive(void); +#else void BreakModel_Spawn(vector pos, vector dir, vector spread, float speed, int count, string type); +#endif /* necessary API functions */ //void BreakModel_Init(void); diff --git a/src/shared/propdata.qc b/src/shared/propdata.qc index 60ddc09c..1a164c8d 100644 --- a/src/shared/propdata.qc +++ b/src/shared/propdata.qc @@ -485,17 +485,10 @@ PropData_Finish(void) } /* BreakModel related helper API */ +#ifdef CLIENT void -BreakModel_Spawn(vector smins, vector smaxs, vector dir, float speed, int count, string type) +BreakModel_SpawnID(vector smins, vector smaxs, vector dir, float speed, int count, int index) { - int index; - index = (int)hash_get(g_hashbreakmodel, type, -1); - - if (index < 0) { - crossprint(sprintf("^1BreakModel_Spawn: type %s is not defined\n", type)); - return; - } - float x = tokenize(g_breakmodel[index].data); int modelcount = x / 2; @@ -591,4 +584,59 @@ BreakModel_Spawn(vector smins, vector smaxs, vector dir, float speed, int count, /* re-calculate the tokenization */ x = tokenize(g_breakmodel[index].data); } -} \ No newline at end of file +} + +void +BreakModel_Receive(void) +{ + vector smins, smaxs, dir; + float speed; + int count; + int index; + + index = readbyte(); + smins[0] = readcoord(); + smins[1] = readcoord(); + smins[2] = readcoord(); + + smaxs[0] = readcoord(); + smaxs[1] = readcoord(); + smaxs[2] = readcoord(); + + dir[0] = readcoord(); + dir[1] = readcoord(); + dir[2] = readcoord(); + + speed = readfloat(); + count = readbyte(); + + BreakModel_SpawnID(smins, smaxs, dir, speed, count, index); +} + +#else +void +BreakModel_Spawn(vector smins, vector smaxs, vector dir, float speed, int count, string type) +{ + int index; + index = (int)hash_get(g_hashbreakmodel, type, -1); + + if (index == -1) + return; + + WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); + WriteByte(MSG_MULTICAST, EV_BREAKMODEL); + WriteByte(MSG_MULTICAST, index); + WriteCoord(MSG_MULTICAST, smins[0]); + WriteCoord(MSG_MULTICAST, smins[1]); + WriteCoord(MSG_MULTICAST, smins[2]); + WriteCoord(MSG_MULTICAST, smaxs[0]); + WriteCoord(MSG_MULTICAST, smaxs[1]); + WriteCoord(MSG_MULTICAST, smaxs[2]); + WriteCoord(MSG_MULTICAST, dir[0]); + WriteCoord(MSG_MULTICAST, dir[1]); + WriteCoord(MSG_MULTICAST, dir[2]); + WriteFloat(MSG_MULTICAST, speed); + WriteByte(MSG_MULTICAST, count); + multicast((smins - smaxs), MULTICAST_PVS); +} +#endif \ No newline at end of file