diff --git a/code/game/src/entity_view.c b/code/game/src/entity_view.c index c957ecd..96e00c5 100644 --- a/code/game/src/entity_view.c +++ b/code/game/src/entity_view.c @@ -10,14 +10,14 @@ pkt_desc pkt_entity_view_desc[] = { { PKT_HALF(entity_view, x) }, { PKT_HALF(entity_view, y) }, - { PKT_SKIP_IF(entity_view, blocks_used, 1, 2) }, // NOTE(zaklaus): skip velocity for chunks + { PKT_KEEP_IF(entity_view, blocks_used, 0, 2) }, // NOTE(zaklaus): skip velocity for chunks { PKT_HALF(entity_view, vx) }, { PKT_HALF(entity_view, vy) }, { PKT_SKIP_IF(entity_view, blocks_used, 0, 1) }, // NOTE(zaklaus): skip blocks for anything else { PKT_ARRAY(entity_view, blocks) }, - { PKT_SKIP_IF(entity_view, blocks_used, 1, 2) }, // NOTE(zaklaus): skip hp for chunks + { PKT_KEEP_IF(entity_view, blocks_used, 0, 2) }, // NOTE(zaklaus): skip hp for chunks { PKT_HALF(entity_view, hp) }, { PKT_HALF(entity_view, max_hp) }, diff --git a/code/game/src/packet.c b/code/game/src/packet.c index cb0fae9..b530a8c 100644 --- a/code/game/src/packet.c +++ b/code/game/src/packet.c @@ -106,9 +106,10 @@ int32_t pkt_pack_struct(cw_pack_context *pc, pkt_desc *desc, void *raw_blob, uin for (pkt_desc *field = desc; field->type != CWP_NOT_AN_ITEM; ++field) { if (field->skip_count != 0) { uint8_t val = *(uint8_t*)(blob + field->offset); - if (val == field->skip_eq) { - cw_pack_unsigned(pc, field->skip_count); - field += field->skip_count; + if ((field->skip_count > 0 && val == field->skip_eq) || + (field->skip_count < 0 && val != field->skip_eq)) { + cw_pack_unsigned(pc, zpl_abs(field->skip_count)); + field += zpl_abs(field->skip_count); } else { cw_pack_unsigned(pc, 0); } diff --git a/code/game/src/packet_utils.h b/code/game/src/packet_utils.h index 43b9cd6..e522661 100644 --- a/code/game/src/packet_utils.h +++ b/code/game/src/packet_utils.h @@ -101,6 +101,10 @@ static inline int32_t pkt_world_write(pkt_messages id, size_t pkt_size, int8_t i #define PKT_SKIP_IF(t, a, e, n) .skip_count = n, .offset = PKT_OFFSETOF(t, a), .skip_eq = e, .name = #a #endif +#ifndef PKT_KEEP_IF +#define PKT_KEEP_IF(t, a, e, n) .skip_count = -(n), .offset = PKT_OFFSETOF(t, a), .skip_eq = e, .name = #a +#endif + #ifndef PKT_END #define PKT_END .type = CWP_NOT_AN_ITEM #endif @@ -115,7 +119,7 @@ typedef struct pkt_desc { size_t offset; size_t size; size_t it_size; - size_t skip_count; + int16_t skip_count; uint8_t skip_eq; } pkt_desc;