[Freeciv-Dev] (PR#3781) Micro size of structs optimizations
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#3781) Micro size of structs optimizations |
From: |
"Rafa³ Bursig" <bursig@xxxxxxxxx> |
Date: |
Mon, 24 Mar 2003 09:18:57 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
Hi
As I know "bool" type is unisgnet char then we can sort all this type (
and others ) variable than gcc can pack it in one 32 bit field. This
problem touch all types < int (32bits) and by sorting we can reduce
size of some game structs. This is rather micro optimizations but can
be done without cost.
Attached patch almost don't change structs only sort variables. I
change some types city.h to show that we can reduce size of game
structs even more ( sizeof(struct city) : before 2128, after 2028 )
Rafal
----------------------------------------------------------------------
Kochasz pilke nozna? Zagraj i wygraj! >>> http://link.interia.pl/f16fa
diff -u -r freeciv/common/city.h fc2/common/city.h
--- freeciv/common/city.h Wed Feb 5 17:41:34 2003
+++ fc2/common/city.h Mon Mar 24 17:17:02 2003
@@ -167,25 +167,32 @@
};
struct ai_city {
+ bool diplomat_threat; /* enemy diplomat or spy is near the city */
+ bool has_diplomat; /* this city has diplomat or spy defender */
+ /* Used by _other_ cities temporarily while assigning diplomat targets */
+ bool already_considered_for_diplomat;
+
int workremain;
-
/* building desirabilities - easiest to handle them here -- Syela */
int building_want[B_LAST]; /* not sure these will always be < 256 */
int danger; /* danger to be compared to assess_defense */
- bool diplomat_threat; /* enemy diplomat or spy is near the city */
- bool has_diplomat; /* this city has diplomat or spy defender */
int urgency; /* how close the danger is; if zero,
- bodyguards can leave */
+ bodyguards can leave */
int grave_danger; /* danger, should show positive feedback */
int wallvalue; /* how much it helps for defenders to be
ground units */
int trade_want; /* saves a zillion calculations */
- struct ai_choice choice; /* to spend gold in the right place only */
int downtown; /* distance from neighbours, for locating
wonders wisely */
int distance_to_wonder_city; /* wondercity will set this for us,
avoiding paradox */
+ /* so we can contemplate with warmap fresh and decide later */
+ int settler_want, founder_want; /* for builder (F_SETTLERS) and founder
(F_CITIES) */
+ int invasion; /* who's coming to kill us, for attack co-ordination */
+ int attack, bcost; /* This is also for invasion - total power and value of
+ * all units coming to kill us. */
+
/* Used for caching when settlers evalueate which tile to improve,
and when we place workers. */
signed short int detox[5][5];
@@ -196,39 +203,47 @@
signed short int railroad[5][5];
signed short int transform[5][5];
signed short int tile_value[5][5];
-
- /* so we can contemplate with warmap fresh and decide later */
- int settler_want, founder_want; /* for builder (F_SETTLERS) and founder
(F_CITIES) */
- int invasion; /* who's coming to kill us, for attack co-ordination */
- int attack, bcost; /* This is also for invasion - total power and value of
- * all units coming to kill us. */
-
- /* Used by _other_ cities temporarily while assigning diplomat targets */
- bool already_considered_for_diplomat;
+
+ struct ai_choice choice; /* to spend gold in the right place only */
};
struct city {
- int id;
- int owner;
- int x, y;
- char name[MAX_LEN_NAME];
-
- /* the people */
- int size;
-
+ bool is_building_unit; /* boolean unit/improvement */
+ /* TRUE iff there units in the town. Only set at the client. */
+ bool occupied;
+ /* turn states */
+ bool did_buy;
+ bool did_sell, is_updated;
+ bool changed_from_is_unit; /* If changed this turn, what changed from
(unit?) */
+ bool was_happy;
+ bool airlift;
+ /* server variable. indicates if the city map is synced with the client. */
+ bool synced;
+
/* How the citizens feel:
ppl_*[0] is distribution before any of the modifiers below.
ppl_*[1] is distribution after luxury.
ppl_*[2] is distribution after after building effects.
ppl_*[3] is distribution after units enfored martial order.
ppl_*[4] is distribution after wonders. (final result.) */
- int ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
-
+ signed char ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
/* Specialists */
- int ppl_elvis, ppl_scientist, ppl_taxman;
+ signed char ppl_elvis, ppl_scientist, ppl_taxman;
- /* trade routes */
- int trade[NUM_TRADEROUTES], trade_value[NUM_TRADEROUTES];
+ /* the people */
+ signed char size;
+
+ /* trade routes value */
+ signed char trade_value[NUM_TRADEROUTES];
+
+ char name[MAX_LEN_NAME];
+
+ int id;
+ int owner;
+ int x, y;
+
+ /* trade routes : cities */
+ int trade[NUM_TRADEROUTES];
/* the productions */
int food_prod, food_surplus;
@@ -236,58 +251,38 @@
int shield_prod, shield_surplus, shield_waste;
int trade_prod, corruption, tile_trade;
int shield_bonus, tax_bonus, science_bonus; /* more CPU savings! */
-
/* the totals */
int luxury_total, tax_total, science_total;
-
/* the physics */
int food_stock;
int shield_stock;
int pollution;
/* city can't be incited if INCITE_IMPOSSIBLE_COST */
int incite_revolt_cost;
-
- bool is_building_unit; /* boolean unit/improvement */
int currently_building;
-
- Impr_Status improvements[B_LAST];
-
- struct worklist worklist;
-
- enum city_tile_type city_map[CITY_MAP_SIZE][CITY_MAP_SIZE];
-
- struct unit_list units_supported;
-
- /* TRUE iff there units in the town. Only set at the client. */
- bool occupied;
-
- int steal; /* diplomats steal once; for spies, gets harder */
+ int steal; /* diplomats steal once; for spies, gets harder
*/
/* turn states */
- bool did_buy;
- bool did_sell, is_updated;
- int turn_last_built; /* The last year in which something was built */
- int changed_from_id; /* If changed this turn, what changed from (id) */
- bool changed_from_is_unit; /* If changed this turn, what changed from
(unit?) */
- int disbanded_shields; /* If you disband unit in a city. Count them */
- int caravan_shields; /* If caravan has helped city to build wonder. */
- int before_change_shields; /* If changed this turn, shields before penalty
*/
- int anarchy; /* anarchy rounds count */
- int rapture; /* rapture rounds count */
- bool was_happy;
- bool airlift;
+ int turn_last_built; /* The last year in which something was built */
+ int changed_from_id; /* If changed this turn, what changed from (id)
*/
+ int disbanded_shields; /* If you disband unit in a city. Count
them */
+ int caravan_shields; /* If caravan has helped city to build wonder.
*/
+ int before_change_shields; /* If changed this turn, shields before penalty
*/
+ int anarchy; /* anarchy rounds count */
+ int rapture; /* rapture rounds count */
int original; /* original owner */
int city_options; /* bitfield; positions as enum city_options */
-
- /* server variable. indicates if the city map is synced with the client. */
- bool synced;
-
int turn_founded; /* In which turn was the city founded? */
+ Impr_Status improvements[B_LAST];
+ enum city_tile_type city_map[CITY_MAP_SIZE][CITY_MAP_SIZE];
+
/* info for dipl/spy investigation -- used only in client */
struct unit_list info_units_supported;
struct unit_list info_units_present;
struct ai_city ai;
+ struct worklist worklist;
+ struct unit_list units_supported;
};
/* city drawing styles */
@@ -299,6 +294,8 @@
char name_orig[MAX_LEN_NAME]; /* untranslated */
char graphic[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
+ char citizens_graphic[MAX_LEN_NAME];
+ char citizens_graphic_alt[MAX_LEN_NAME];
int techreq; /* tech required to use a style */
int replaced_by; /* index to replacing style */
/* client side-only: */
diff -u -r freeciv/common/connection.h fc2/common/connection.h
--- freeciv/common/connection.h Thu Mar 6 00:59:06 2003
+++ fc2/common/connection.h Mon Mar 24 16:03:04 2003
@@ -88,11 +88,15 @@
bool established; /* have negotiated initial packets */
bool first_packet; /* check byte order on first packet */
bool byte_swap; /* connection uses non-network byte order */
- struct player *player; /* NULL for connections not yet associated
- with a specific player */
+ bool delayed_disconnect;
+ /* Something has occurred that means the connection should be closed, but
+ * the closing has been postponed. */
bool observer; /* connection is "observer", not controller;
may be observing specific player, or all
(implementation incomplete) */
+
+ struct player *player; /* NULL for connections not yet associated
+ with a specific player */
struct socket_packet_buffer *buffer;
struct socket_packet_buffer *send_buffer;
time_t last_write;
@@ -115,9 +119,6 @@
/* These are used when recieving goto routes; they are sent split, and in
* the time where the route is partially received it is stored here. */
- bool delayed_disconnect;
- /* Something has occurred that means the connection should be closed, but
- * the closing has been postponed. */
void (*notify_of_writable_data) (struct connection * pc,
bool data_available_and_socket_full);
diff -u -r freeciv/common/game.h fc2/common/game.h
--- freeciv/common/game.h Thu Feb 13 16:48:21 2003
+++ fc2/common/game.h Mon Mar 24 16:00:46 2003
@@ -54,6 +54,18 @@
struct civ_game {
bool is_new_game; /* 1 for games never started */
+ bool angrycitizen;
+ bool scorelog;
+ bool savepalace;
+ bool natural_city_names;
+ bool spacerace;
+ bool turnblock;
+ bool fixedlength;
+ bool auto_ai_toggle;
+ bool fogofwar;
+ bool fogofwar_old; /* as the fog_of_war bit get changed by setting
+ the server we need to remember the old setting */
+
int version;
char id[MAX_ID_LEN]; /* server only */
int civstyle;
@@ -92,7 +104,6 @@
int nbarbarians;
int occupychance;
int unhappysize;
- bool angrycitizen;
char *startmessage;
int conn_id; /* client-only: id client known to server as */
int player_idx;
@@ -125,20 +136,11 @@
int killcitizen;
int techpenalty;
int razechance;
- bool scorelog;
+
int randseed;
int aqueduct_size;
int sewer_size;
int add_to_size_limit;
- bool savepalace;
- bool natural_city_names;
- bool spacerace;
- bool turnblock;
- bool fixedlength;
- bool auto_ai_toggle;
- bool fogofwar;
- bool fogofwar_old; /* as the fog_of_war bit get changed by setting
- the server we need to remember the old setting */
int num_unit_types;
int num_impr_types;
diff -u -r freeciv/common/map.h fc2/common/map.h
--- freeciv/common/map.h Thu Mar 13 12:53:07 2003
+++ fc2/common/map.h Mon Mar 24 15:56:37 2003
@@ -48,10 +48,10 @@
};
struct tile {
- enum tile_terrain_type terrain;
- enum tile_special_type special;
- struct city *city;
- struct unit_list units;
+ signed char move_cost[8]; /* don't know if this helps! */
+
+ unsigned short continent;
+
unsigned int known; /* A bitvector on the server side, an
enum known_type on the client side.
Player_no is index */
@@ -59,9 +59,13 @@
as TILE_KNOWN_NODRAW. A bitvector like known.
Not used on the client side. */
int assigned; /* these can save a lot of CPU usage -- Syela */
- struct city *worked; /* city working tile, or NULL if none */
- unsigned short continent;
- signed char move_cost[8]; /* don't know if this helps! */
+
+ enum tile_terrain_type terrain;
+ enum tile_special_type special;
+
+ struct city *city;
+ struct city *worked; /* city working tile, or NULL if none */
+ struct unit_list units;
};
@@ -155,10 +159,17 @@
};
struct civ_map {
+ bool fixed_start_positions;
+ bool have_specials;
+ bool have_huts;
+ bool have_rivers_overlay; /* only applies if !have_specials */
+ bool is_earth;
+ bool tinyisles;
+ bool separatepoles;
+
int xsize, ysize;
int seed;
int riches;
- bool is_earth;
int huts;
int landpercent;
int grasssize;
@@ -168,13 +179,7 @@
int riverlength;
int forestsize;
int generator;
- bool tinyisles;
- bool separatepoles;
int num_start_positions;
- bool fixed_start_positions;
- bool have_specials;
- bool have_huts;
- bool have_rivers_overlay; /* only applies if !have_specials */
int num_continents;
struct tile *tiles;
struct map_position start_positions[MAX_NUM_NATIONS];
diff -u -r freeciv/common/player.h fc2/common/player.h
--- freeciv/common/player.h Thu Mar 6 00:59:06 2003
+++ fc2/common/player.h Mon Mar 24 15:50:51 2003
@@ -164,42 +164,45 @@
***************************************************************************/
struct player {
- int player_no;
+ bool is_male;
+ bool turn_done;
+ bool is_alive;
+ bool got_tech;
+ bool capital; /* used to give player capital in first city. */
+ bool is_connected; /* observers don't count */
+
char name[MAX_LEN_NAME];
char username[MAX_LEN_NAME];
- bool is_male;
+
+ int player_no;
int government;
Nation_Type_id nation;
Team_Type_id team;
- bool turn_done;
int nturns_idle;
- bool is_alive;
- bool got_tech;
int revolution;
- bool capital; /* used to give player capital in first city. */
int embassy;
int reputation;
- struct player_diplstate diplstates[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
int city_style;
+ int future_tech;
+ unsigned int gives_shared_vision; /* bitvector those that give you shared
vision */
+ unsigned int really_gives_vision; /* takes into account that p3 may see what
p1 has via p2 */
+ Impr_Status improvements[B_LAST]; /* improvements with equiv_range==Player */
+ Impr_Status *island_improv; /* improvements with equiv_range==Island,
dimensioned to
+ [map.num_continents][game.num_impr_types] */
+
+ struct player_tile *private_map;
+ struct connection *current_conn; /* non-null while handling packet */
struct unit_list units;
struct city_list cities;
struct player_score score;
struct player_economic economic;
struct player_research research;
struct player_spaceship spaceship;
- int future_tech;
struct player_ai ai;
- bool is_connected; /* observers don't count */
- struct connection *current_conn; /* non-null while handling packet */
struct conn_list connections; /* will replace conn */
struct worklist worklists[MAX_NUM_WORKLISTS];
- struct player_tile *private_map;
- unsigned int gives_shared_vision; /* bitvector those that give you shared
vision */
- unsigned int really_gives_vision; /* takes into account that p3 may see what
p1 has via p2 */
- Impr_Status improvements[B_LAST]; /* improvements with equiv_range==Player */
- Impr_Status *island_improv; /* improvements with equiv_range==Island,
dimensioned to
- [map.num_continents][game.num_impr_types] */
+ struct player_diplstate diplstates[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
struct {
int length;
void *data;
diff -u -r freeciv/common/unit.h fc2/common/unit.h
--- freeciv/common/unit.h Thu Mar 13 12:53:07 2003
+++ fc2/common/unit.h Mon Mar 24 09:43:17 2003
@@ -108,7 +108,6 @@
int id;
int owner;
int x, y;
- bool veteran;
int homecity;
int moves_left;
int hp;
@@ -116,22 +115,23 @@
int upkeep;
int upkeep_food;
int upkeep_gold;
- bool foul;
int fuel;
int bribe_cost;
- struct unit_ai ai;
- enum unit_activity activity;
int goto_dest_x, goto_dest_y;
int activity_count;
- enum tile_special_type activity_target;
- enum unit_focus_status focus_status;
int ord_map, ord_city;
/* ord_map and ord_city are the order index of this unit in tile.units
and city.units_supported; they are only used for save/reload */
+ int transported_by;
+ enum unit_activity activity;
+ enum tile_special_type activity_target;
+ enum unit_focus_status focus_status;
bool moved;
bool paradropped;
bool connecting;
- int transported_by;
+ bool foul;
+ bool veteran;
+ struct unit_ai ai;
struct goto_route *pgr;
};
- [Freeciv-Dev] (PR#3781) Micro size of structs optimizations,
Rafa³ Bursig <=
|
|