Commit 23869751 authored by TimePath's avatar TimePath

Merge branch 'TimePath/inventory_tweaks'

parents cf1512be 201e1dac
Pipeline #5542499 failed with stages
in 10 minutes and 12 seconds
......@@ -4,7 +4,7 @@
#include "item.qh"
REGISTRY(Items, BITS(5))
REGISTRY(Items, BITS(7))
#define Items_from(i) _Items_from(i, NULL)
REGISTER_REGISTRY(Items)
#define REGISTER_ITEM(id, class) REGISTER(Items, ITEM, id, m_id, NEW(class))
......
......@@ -15,17 +15,33 @@ 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)
#define G_MAJOR(id) (floor((id) / Inventory_groups_minor))
#define G_MINOR(id) ((id) % Inventory_groups_minor)
#ifdef CSQC
NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
{
make_pure(this);
const int bits = ReadInt24_t();
FOREACH(Items, bits & BIT(it.m_id), {
.int fld = inv_items[it.m_id];
int prev = this.(fld);
int next = this.(fld) = ReadByte();
LOG_TRACEF("%s: %.0f -> %.0f", it.m_name, prev, next);
});
const int majorBits = ReadShort();
for (int i = 0; i < Inventory_groups_major; ++i) {
if (!(majorBits & BIT(i))) {
continue;
}
const int minorBits = ReadByte();
for (int j = 0; j < Inventory_groups_minor; ++j) {
if (!(minorBits & BIT(j))) {
continue;
}
const GameItem it = Items_from(Inventory_groups_minor * i + j);
.int fld = inv_items[it.m_id];
int prev = this.(fld);
int next = this.(fld) = ReadByte();
LOG_TRACEF("%s: %.0f -> %.0f", it.m_name, prev, next);
}
}
return true;
}
#endif
......@@ -34,22 +50,56 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
void Inventory_Write(Inventory data)
{
if (!data) {
WriteInt24_t(MSG_ENTITY, 0);
WriteShort(MSG_ENTITY, 0);
return;
}
TC(Inventory, data);
int bits = 0;
int majorBits = 0;
FOREACH(Items, true, {
.int fld = inv_items[it.m_id];
bits = BITSET(bits, BIT(it.m_id), data.inventory.(fld) != (data.inventory.(fld) = data.(fld)));
const bool changed = data.inventory.(fld) != data.(fld);
if (changed) {
majorBits = BITSET(majorBits, BIT(G_MAJOR(it.m_id)), true);
}
});
WriteInt24_t(MSG_ENTITY, bits);
FOREACH(Items, bits & BIT(it.m_id), {
WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
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 GameItem 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
}
#endif
#undef G_MAJOR
#undef G_MINOR
#ifdef SVQC
bool Inventory_Send(Inventory this, Client to, int sf)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment