X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fitems%2Finventory.qh;h=cc17571ecc91bee3d94f401d7fec2a12457a29aa;hb=873f1b3ef177d3b290982be4adb3707482b8c6fc;hp=017ada75c0288df84ce093b80dffefa8316a810c;hpb=126564db487c07249d4205e829d3cfe6df16635b;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 017ada75c..cc17571ec 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -6,17 +6,17 @@ CLASS(Inventory, Object) /** Stores counts of items, the id being the index */ ATTRIBARRAY(Inventory, inv_items, int, Items_MAX); - /** Previous state */ - ATTRIB(Inventory, inventory, Inventory); ENDCLASS(Inventory) /** Player inventory */ .Inventory inventory; +/** Player inventory storage (holds previous state) */ +.Inventory inventory_store; REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY) -const int Inventory_groups_minor = 8; // exactly 1 byte -const int Inventory_groups_major = 3; // ceil(Items_MAX / Inventory_groups_minor) +const int Inventory_groups_major = 16; +const int Inventory_groups_minor = 8; // ceil(Items_MAX / Inventory_groups_major) #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 = ReadByte(); + const int majorBits = ReadShort(); for (int i = 0; i < Inventory_groups_major; ++i) { if (!(majorBits & BIT(i))) { continue; @@ -51,7 +51,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) #ifdef SVQC int minorBitsArr[Inventory_groups_major]; -void Inventory_Write(Inventory data) +void Inventory_Write(Inventory data, Inventory store) { if (!data) { WriteShort(MSG_ENTITY, 0); @@ -65,14 +65,15 @@ void Inventory_Write(Inventory data) int majorBits = 0; FOREACH(Items, true, { .int fld = inv_items[it.m_id]; - const bool changed = data.inventory.(fld) != data.(fld); + const bool changed = store.(fld) != data.(fld); + store.(fld) = data.(fld); if (changed) { 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); } }); - WriteByte(MSG_ENTITY, majorBits); + WriteShort(MSG_ENTITY, majorBits); for (int i = 0; i < Inventory_groups_major; ++i) { @@ -102,7 +103,7 @@ bool Inventory_Send(Inventory this, Client to, int sf) TC(Inventory, this); WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY); TC(PlayerState, this.owner); - Inventory_Write(this); + Inventory_Write(this, to.inventory_store); return true; } @@ -114,11 +115,13 @@ bool Inventory_customize(entity this, entity client) void Inventory_new(PlayerState this) { - Inventory inv = NEW(Inventory), bak = NEW(Inventory); - inv.inventory = bak; + Inventory inv = NEW(Inventory); setcefc(inv, Inventory_customize); Net_LinkEntity((inv.owner = this).inventory = inv, false, 0, Inventory_Send); } -void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); } +void Inventory_delete(entity e) { delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } + +void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; } +void InventoryStorage_detach(entity e) { delete(e.inventory_store); } #endif