? diff ? civscore.log ? short_worklists1.diff ? data/misc/chiefs_front.spec ? data/misc/shields_front.spec Index: common/capstr.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v retrieving revision 1.89 diff -u -r1.89 capstr.c --- common/capstr.c 2001/10/12 12:22:18 1.89 +++ common/capstr.c 2001/10/25 10:46:43 @@ -71,7 +71,8 @@ */ #define CAPABILITY "+1.11.6 conn_info pop_cost turn attributes new_bonus_tech"\ -" fund_added processing_packets angrycitizen tile_trade init_techs" +" fund_added processing_packets angrycitizen tile_trade init_techs"\ +" short_worklists" /* "+1.11.6" is protocol for 1.11.6 beta release. @@ -103,6 +104,8 @@ "init_techs" allows global and nation specific initial techs to be specified in rulesets. + + "short_worklists" sends short worklists to reduce bandwidth used. */ void init_our_capability(void) Index: common/packets.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v retrieving revision 1.166 diff -u -r1.166 packets.c --- common/packets.c 2001/10/18 16:45:32 1.166 +++ common/packets.c 2001/10/25 10:46:45 @@ -1330,20 +1330,30 @@ use separate packets, to avoid this problem (and would also reduce amount sent). --dwp **************************************************************************/ -static unsigned char *put_worklist(unsigned char *buffer, - const struct worklist *pwl, - int real_wl) +static unsigned char *put_worklist(struct connection *pc, + unsigned char *buffer, + const struct worklist *pwl, int real_wl) { - int i; + int i, length, short_wls = + has_capability("short_worklists", pc->capability); buffer = put_uint8(buffer, pwl->is_valid); - if (real_wl) - buffer = put_string(buffer, pwl->name); - else - buffer = put_string(buffer, "\0"); - for (i = 0; i < MAX_LEN_WORKLIST; i++) { - buffer = put_uint8(buffer, pwl->wlefs[i]); - buffer = put_uint8(buffer, pwl->wlids[i]); + + if ((short_wls && pwl->is_valid) || !short_wls) { + if (real_wl) + buffer = put_string(buffer, pwl->name); + else + buffer = put_string(buffer, "\0"); + if (short_wls) { + length = worklist_length(pwl); + buffer = put_uint8(buffer, length); + } else { + length = MAX_LEN_WORKLIST; + } + for (i = 0; i < length; i++) { + buffer = put_uint8(buffer, pwl->wlefs[i]); + buffer = put_uint8(buffer, pwl->wlids[i]); + } } return buffer; @@ -1352,15 +1362,32 @@ /************************************************************************** ... **************************************************************************/ -static void iget_worklist(struct pack_iter *piter, struct worklist *pwl) +static void iget_worklist(struct connection *pc, struct pack_iter *piter, + struct worklist *pwl) { - int i; + int i, length, short_wls = + has_capability("short_worklists", pc->capability); iget_uint8(piter, &pwl->is_valid); - iget_string(piter, pwl->name, MAX_LEN_NAME); - for (i = 0; i < MAX_LEN_WORKLIST; i++) { - iget_uint8(piter, (int*)&pwl->wlefs[i]); - iget_uint8(piter, &pwl->wlids[i]); + + if ((short_wls && pwl->is_valid) || !short_wls) { + iget_string(piter, pwl->name, MAX_LEN_NAME); + + if (short_wls) { + iget_uint8(piter, &length); + + if (length < MAX_LEN_WORKLIST) { + pwl->wlefs[length] = WEF_END; + pwl->wlids[length] = 0; + } + } else { + length = MAX_LEN_WORKLIST; + } + + for (i = 0; i < length; i++) { + iget_uint8(piter, (int *) &pwl->wlefs[i]); + iget_uint8(piter, &pwl->wlids[i]); + } } } @@ -1627,8 +1654,8 @@ cptr=put_uint8(cptr, packet->science); cptr=put_uint8(cptr, packet->government); cptr=put_uint8(cptr, packet->tech); - cptr=put_worklist(cptr, &packet->worklist, - req_type == PACKET_PLAYER_WORKLIST); + cptr = put_worklist(pc, cptr, &packet->worklist, + req_type == PACKET_PLAYER_WORKLIST); cptr=put_uint8(cptr, packet->wl_idx); if (pc && has_capability("attributes", pc->capability)) { @@ -1657,7 +1684,7 @@ iget_uint8(&iter, &preq->science); iget_uint8(&iter, &preq->government); iget_uint8(&iter, &preq->tech); - iget_worklist(&iter, &preq->worklist); + iget_worklist(pc, &iter, &preq->worklist); iget_uint8(&iter, &preq->wl_idx); if (pc && has_capability("attributes", pc->capability)) iget_uint8(&iter, &preq->attribute_block); @@ -1686,7 +1713,7 @@ cptr=put_uint8(cptr, packet->worker_y); cptr=put_uint8(cptr, packet->specialist_from); cptr=put_uint8(cptr, packet->specialist_to); - cptr=put_worklist(cptr, &packet->worklist, 1); + cptr = put_worklist(pc, cptr, &packet->worklist, 1); cptr=put_string(cptr, packet->name); put_uint16(buffer, cptr-buffer); @@ -1713,7 +1740,7 @@ iget_uint8(&iter, &preq->worker_y); iget_uint8(&iter, &preq->specialist_from); iget_uint8(&iter, &preq->specialist_to); - iget_worklist(&iter, &preq->worklist); + iget_worklist(pc, &iter, &preq->worklist); iget_string(&iter, preq->name, sizeof(preq->name)); pack_iter_end(&iter, pc); @@ -1771,7 +1798,7 @@ cptr=put_uint8(cptr, pinfo->is_barbarian); for (i = 0; i < MAX_NUM_WORKLISTS; i++) { - cptr = put_worklist(cptr, &pinfo->worklists[i], 1); + cptr = put_worklist(pc, cptr, &pinfo->worklists[i], 1); } cptr=put_uint32(cptr, pinfo->gives_shared_vision); @@ -1833,7 +1860,7 @@ iget_uint8(&iter, &pinfo->is_barbarian); for (i = 0; i < MAX_NUM_WORKLISTS; i++) { - iget_worklist(&iter, &pinfo->worklists[i]); + iget_worklist(pc, &iter, &pinfo->worklists[i]); } /* Unfortunately the second argument to iget_uint32 is int, not uint: */ @@ -2281,7 +2308,7 @@ cptr=put_uint16(cptr, req->disbanded_shields); cptr=put_uint16(cptr, req->caravan_shields); - cptr=put_worklist(cptr, &req->worklist, 1); + cptr = put_worklist(pc, cptr, &req->worklist, 1); data=req->is_building_unit?1:0; data|=req->did_buy?2:0; @@ -2374,7 +2401,7 @@ iget_uint16(&iter, &packet->disbanded_shields); iget_uint16(&iter, &packet->caravan_shields); - iget_worklist(&iter, &packet->worklist); + iget_worklist(pc, &iter, &packet->worklist); iget_uint8(&iter, &data); packet->is_building_unit = data&1; Index: common/worklist.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/worklist.c,v retrieving revision 1.5 diff -u -r1.5 worklist.c --- common/worklist.c 2000/08/31 13:32:46 1.5 +++ common/worklist.c 2001/10/25 10:46:45 @@ -61,7 +61,7 @@ /**************************************************************** ... ****************************************************************/ -int worklist_length(struct worklist *pwl) +int worklist_length(const struct worklist *pwl) { int len = 0; @@ -75,7 +75,7 @@ /**************************************************************** ... ****************************************************************/ -int worklist_is_empty(struct worklist *pwl) +int worklist_is_empty(const struct worklist *pwl) { return pwl == NULL || pwl->wlefs[0] == WEF_END; } @@ -85,7 +85,7 @@ if the worklist is non-empty. Return 1 iff id and is_unit are valid. ****************************************************************/ -int worklist_peek(struct worklist *pwl, int *id, int *is_unit) +int worklist_peek(const struct worklist *pwl, int *id, int *is_unit) { if (worklist_is_empty(pwl)) return 0; @@ -97,7 +97,8 @@ Fill in the id and is_unit values for the ith element in the worklist. If the worklist has fewer than i elements, return 0. ****************************************************************/ -int worklist_peek_ith(struct worklist *pwl, int *id, int *is_unit, int idx) +int worklist_peek_ith(const struct worklist *pwl, int *id, int *is_unit, + int idx) { int i; @@ -127,7 +128,7 @@ /**************************************************************** ... ****************************************************************/ -void copy_worklist(struct worklist *dst, struct worklist *src) +void copy_worklist(struct worklist *dst, const struct worklist *src) { memcpy(dst, src, sizeof(struct worklist)); } Index: common/worklist.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/worklist.h,v retrieving revision 1.3 diff -u -r1.3 worklist.h --- common/worklist.h 2000/08/31 13:32:46 1.3 +++ common/worklist.h 2001/10/25 10:46:45 @@ -39,13 +39,14 @@ void init_worklist(struct worklist *pwl); void destroy_worklist(struct worklist *pwl); -int worklist_length(struct worklist *pwl); -int worklist_is_empty(struct worklist *pwl); -int worklist_peek(struct worklist *pwl, int *id, int *is_unit); -int worklist_peek_ith(struct worklist *pwl, int *id, int *is_unit, int idx); +int worklist_length(const struct worklist *pwl); +int worklist_is_empty(const struct worklist *pwl); +int worklist_peek(const struct worklist *pwl, int *id, int *is_unit); +int worklist_peek_ith(const struct worklist *pwl, int *id, int *is_unit, + int idx); void worklist_advance(struct worklist *pwl); -void copy_worklist(struct worklist *dst, struct worklist *src); +void copy_worklist(struct worklist *dst, const struct worklist *src); void worklist_remove(struct worklist *pwl, int idx); #endif /* FC__WORKLIST_H */