From 7f08a396e92c71a2baf9aca2fdba9ca60d6137c0 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 1 Sep 2019 15:14:46 +0200 Subject: [PATCH] Optimize bandwidth and memory usage of item stats networking --- qcsrc/common/items/inventory.qh | 8 ++++---- qcsrc/common/t_items.qh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index ed6c7355d2..017ada75c0 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -15,8 +15,8 @@ ENDCLASS(Inventory) REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY) -const int Inventory_groups_major = 16; -const int Inventory_groups_minor = 8; // ceil(Items_MAX / Inventory_groups_major) +const int Inventory_groups_minor = 8; // exactly 1 byte +const int Inventory_groups_major = 3; // ceil(Items_MAX / Inventory_groups_minor) #define G_MAJOR(id) (floor((id) / Inventory_groups_minor)) #define G_MINOR(id) ((id) % Inventory_groups_minor) @@ -28,7 +28,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) { make_pure(this); g_inventory = this; - const int majorBits = ReadShort(); + const int majorBits = ReadByte(); for (int i = 0; i < Inventory_groups_major; ++i) { if (!(majorBits & BIT(i))) { continue; @@ -72,7 +72,7 @@ void Inventory_Write(Inventory data) minorBitsArr[maj] = BITSET(minorBitsArr[maj], BIT(G_MINOR(it.m_id)), true); } }); - WriteShort(MSG_ENTITY, majorBits); + WriteByte(MSG_ENTITY, majorBits); for (int i = 0; i < Inventory_groups_major; ++i) { diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index a0321c2444..5c916866f8 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -1,6 +1,6 @@ #pragma once -const int AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel +const int AMMO_COUNT = 4; // amount of ammo types to show in the ammo panel // item networking const int ISF_LOCATION = BIT(1); -- 2.39.2