[Freeciv-Dev] (PR#8584) remove dio_[put|get]_city_map
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8584 >
This patch removes dio_put_citY_map and dio_get_city_map, along with the
hard-coding of the city map indices in dataio.c. This code is too much
of a hack to live. It's not extensible or debuggable.
No doubt this increases the size of network packets (or maybe not...the
array size is actually smaller). I suspect that under delta this is a
non-issue. Obviously optimization of this code is possible, but it
needs to be done in an extensible way. Would it be possible for the
packet generator to have a uint2/uint4 type? This could be
automatically unpacked from a byte value in the generated code, and
would work fine with arrays.
jason
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.164
diff -u -r1.164 capstr.c
--- common/capstr.c 14 Apr 2004 11:19:44 -0000 1.164
+++ common/capstr.c 24 Apr 2004 23:01:38 -0000
@@ -77,7 +77,7 @@
#define CAPABILITY "+1.14.delta +last_turns_shield_surplus veteran +orders " \
"+starter +union +iso_maps +orders2client " \
"+change_production +tilespec1 +no_earth +trans " \
- "+want_hack invasions killstack bombard"
+ "+want_hack invasions killstack bombard +city_map"
/* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
*
@@ -114,6 +114,8 @@
* "killstack" means ruleset option to ignore unit killstack effect
*
* "bombard" means units support the bombard ability.
+ *
+ * "city_map" means the city_map is sent as an array instead of a bitfield.
*/
void init_our_capability(void)
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.10
diff -u -r1.10 dataio.c
--- common/dataio.c 14 Feb 2004 02:21:25 -0000 1.10
+++ common/dataio.c 24 Apr 2004 23:01:38 -0000
@@ -53,10 +53,6 @@
#include "dataio.h"
-static const int city_map_index[20] = {
- 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23
-};
-
/**************************************************************************
...
**************************************************************************/
@@ -403,22 +399,6 @@
/**************************************************************************
...
**************************************************************************/
-void dio_put_city_map(struct data_out *dout, const char *value)
-{
- int i;
-
- for (i = 0; i < 20; i += 5) {
- dio_put_uint8(dout, (value[city_map_index[i]] - '0') * 81 +
- (value[city_map_index[i + 1]] - '0') * 27 +
- (value[city_map_index[i + 2]] - '0') * 9 +
- (value[city_map_index[i + 3]] - '0') * 3 +
- (value[city_map_index[i + 4]] - '0') * 1);
- }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
void dio_get_uint8(struct data_in *din, int *dest)
{
if (enough_data(din, 1)) {
@@ -625,55 +605,6 @@
if (din->too_short) {
din->bad_bit_string = TRUE;
- }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size)
-{
- int i;
-
- if (dest) {
- assert(max_dest_size >= 26);
- dest[0] = '2';
- dest[4] = '2';
- dest[12] = '1';
- dest[20] = '2';
- dest[24] = '2';
- dest[25] = '\0';
- }
-
- if (!enough_data(din, 4)) {
- if (dest) {
- for (i = 0; i < 20;) {
- int j;
-
- for (j = 0; j < 5; j++) {
- dest[city_map_index[i++]] = '0';
- }
- }
- }
- return;
- }
-
- for (i = 0; i < 20;) {
- int j;
-
- dio_get_uint8(din, &j);
-
- if (dest) {
- dest[city_map_index[i++]] = '0' + j / 81;
- j %= 81;
- dest[city_map_index[i++]] = '0' + j / 27;
- j %= 27;
- dest[city_map_index[i++]] = '0' + j / 9;
- j %= 9;
- dest[city_map_index[i++]] = '0' + j / 3;
- j %= 3;
- dest[city_map_index[i++]] = '0' + j;
- }
}
}
Index: common/dataio.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.h,v
retrieving revision 1.5
diff -u -r1.5 dataio.h
--- common/dataio.h 10 Apr 2004 03:47:49 -0000 1.5
+++ common/dataio.h 24 Apr 2004 23:01:38 -0000
@@ -68,7 +68,6 @@
void dio_get_string(struct data_in *din, char *dest, size_t max_dest_size);
void dio_get_bit_string(struct data_in *din, char *dest,
size_t max_dest_size);
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size);
void dio_get_tech_list(struct data_in *din, int *dest);
void dio_get_worklist(struct data_in *din, struct worklist *pwl);
void dio_get_diplstate(struct data_in *din, struct player_diplstate *pds);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.21
diff -u -r1.21 packets.def
--- common/packets.def 24 Apr 2004 17:32:47 -0000 1.21
+++ common/packets.def 24 Apr 2004 23:01:38 -0000
@@ -151,7 +151,6 @@
type MEMORY = memory(unsigned char)
type STRING = string(char)
type BIT_STRING = bit_string(char)
-type CITY_MAP = city_map(char)
type WORKLIST = worklist(struct worklist)
type TECH_LIST = tech_list(int)
type EFFECT = effect(struct impr_effect)
@@ -169,6 +168,7 @@
type RIVER_MOVE = uint8(enum special_river_move)
type REPORT_TYPE = uint8(enum report_type)
type AUTH_TYPE = uint8(enum authentication_type)
+type CITY_MAP = uint8(enum city_tile_type)
type IMPR_RANGE = uint8(enum impr_range)
type DIRECTION = uint8(enum direction8)
type ORDERS = uint8(enum unit_orders)
@@ -408,7 +408,7 @@
WORKLIST worklist;
BIT_STRING improvements[B_LAST+1];
- CITY_MAP city_map[CITY_MAP_SIZE*CITY_MAP_SIZE+1];
+ CITY_MAP city_map[CITY_MAP_SIZE * CITY_MAP_SIZE];
BOOL did_buy, did_sell, was_happy, airlift, diplomat_investigate;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8584) remove dio_[put|get]_city_map,
Jason Short <=
|
|