]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize bandwidth and memory usage of item stats networking
authorterencehill <piuntn@gmail.com>
Sun, 1 Sep 2019 13:14:46 +0000 (15:14 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 1 Sep 2019 13:14:46 +0000 (15:14 +0200)
qcsrc/common/items/inventory.qh
qcsrc/common/t_items.qh

index ed6c7355d2232b5c561b47be4efd08ed7fe442b3..017ada75c0288df84ce093b80dffefa8316a810c 100644 (file)
@@ -15,8 +15,8 @@ ENDCLASS(Inventory)
 
 REGISTER_NET_LINKED(ENT_CLIENT_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)
 
 #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;
 {
     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;
     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);
         }
     });
                        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)
        {
 
        for (int i = 0; i < Inventory_groups_major; ++i)
        {
index a0321c2444961234305f7689ef5d32b8d0008685..5c916866f8691f840d34f43ccdf39a51a7d5f95c 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
 #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);
 
 // item networking
 const int ISF_LOCATION                         = BIT(1);