From: terencehill Date: Sun, 1 Sep 2019 08:41:06 +0000 (+0200) Subject: Fix item stats networking by refactoring algorithm that sends item stats X-Git-Tag: xonotic-v0.8.5~1333 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=128f95f1eebf94df206c7fd2210c70f5fb0e24de;p=xonotic%2Fxonotic-data.pk3dir.git Fix item stats networking by refactoring algorithm that sends item stats --- diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 75abe46cc..ed6c7355d 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -50,6 +50,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) #endif #ifdef SVQC +int minorBitsArr[Inventory_groups_major]; void Inventory_Write(Inventory data) { if (!data) { @@ -58,45 +59,37 @@ void Inventory_Write(Inventory data) } TC(Inventory, data); + for (int i = 0; i < Inventory_groups_major; ++i) + minorBitsArr[i] = 0; + int majorBits = 0; FOREACH(Items, true, { .int fld = inv_items[it.m_id]; const bool changed = data.inventory.(fld) != data.(fld); if (changed) { - majorBits = BITSET(majorBits, BIT(G_MAJOR(it.m_id)), true); + int maj = G_MAJOR(it.m_id); + majorBits = BITSET(majorBits, BIT(maj), true); + minorBitsArr[maj] = BITSET(minorBitsArr[maj], BIT(G_MINOR(it.m_id)), true); } }); WriteShort(MSG_ENTITY, majorBits); - int minorBits = 0; - int lastMaj = 0; - int maj = 0; - FOREACH(Items, majorBits & BIT(maj = G_MAJOR(it.m_id)), { - .int fld = inv_items[it.m_id]; - const bool changed = data.inventory.(fld) != (data.inventory.(fld) = data.(fld)); - if (changed) { - if (maj != lastMaj) { - lastMaj = maj; -#define X() MACRO_BEGIN \ - if (minorBits) { \ - WriteByte(MSG_ENTITY, minorBits); \ - for (int j = 0; j < Inventory_groups_minor; ++j) { \ - if (!(minorBits & BIT(j))) { \ - continue; \ - } \ - const entity it = Items_from(Inventory_groups_minor * maj + j); \ - WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); \ - } \ - } \ -MACRO_END - X(); - minorBits = 0; - } - minorBits = BITSET(minorBits, BIT(G_MINOR(it.m_id)), true); - } - }); - X(); -#undef X + for (int i = 0; i < Inventory_groups_major; ++i) + { + if (!(majorBits & BIT(i))) + continue; + + const int minorBits = minorBitsArr[i]; + WriteByte(MSG_ENTITY, minorBits); + for (int j = 0; j < Inventory_groups_minor; ++j) + { + if (!(minorBits & BIT(j))) + continue; + + const entity it = Items_from(Inventory_groups_minor * i + j); + WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); + } + } } #endif