Index: common/mem.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/mem.c,v retrieving revision 1.8 diff -u -u -r1.8 mem.c --- common/mem.c 2002/12/11 10:39:42 1.8 +++ common/mem.c 2003/03/13 16:45:07 @@ -27,9 +27,15 @@ #include "fcintl.h" #include "log.h" #include "shared.h" /* TRUE, FALSE */ +#include "timing.h" #include "mem.h" +struct timer *mem_timer = NULL; + +#define START if(!mem_timer) mem_timer=new_timer(TIMER_CPU,TIMER_ACTIVE); start_timer(mem_timer); +#define END stop_timer(mem_timer); + /********************************************************************** Do whatever we should do when malloc fails. At the moment this just prints a log message and calls exit(EXIT_FAILURE) @@ -55,7 +61,9 @@ called_as, (unsigned long)size, line, file); return NULL; } + START; ptr = malloc(size); + END; if(!ptr) { handle_alloc_failure(size, called_as, line, file); } @@ -80,7 +88,9 @@ free(ptr); return NULL; } + START; new_ptr = realloc(ptr, size); + END; if(!new_ptr) { handle_alloc_failure(size, called_as, line, file); } @@ -102,9 +112,11 @@ { size_t size = nelem*elsize; /* potential overflow */ void *ptr; - + ptr = fc_real_malloc(size, called_as, line, file); + START; memset(ptr, 0, size); + END; return ptr; } @@ -117,6 +129,9 @@ { char *dest = (char *)fc_real_malloc(strlen(str)+1, called_as, line, file); /* no need to check whether dest is non-NULL! */ + + START; strcpy(dest, str); + END; return dest; } Index: common/timing.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/timing.c,v retrieving revision 1.10 diff -u -u -r1.10 timing.c --- common/timing.c 2002/02/14 15:17:20 1.10 +++ common/timing.c 2003/03/13 16:45:07 @@ -180,7 +180,7 @@ enum timer_use use) { if (!t) { - t = (struct timer *)fc_malloc(sizeof(struct timer)); + t = (struct timer *)malloc(sizeof(struct timer)); } t->type = type; t->use = use; Index: server/gotohand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v retrieving revision 1.169 diff -u -u -r1.169 gotohand.c --- server/gotohand.c 2003/03/07 05:08:42 1.169 +++ server/gotohand.c 2003/03/13 16:45:10 @@ -26,12 +26,17 @@ #include "map.h" #include "mem.h" #include "rand.h" +#include "timing.h" #include "airgoto.h" #include "maphand.h" #include "settlers.h" +#include "stdinhand.h" #include "unithand.h" #include "unittools.h" +#include "path_finding.h" +#include "pf_tools.h" +#include "srv_main.h" #include "aitools.h" @@ -355,6 +360,76 @@ orig_x, orig_y); } +#if 0 +static bool is_safe(int x, int y) +{ + return map_get_terrain(x, y) != T_OCEAN || is_coastline(x, y); +} + +static int my_get_ECOT(int x, int y, enum known_type known, void *user_data) +{ + return 0;//(x*100 + 10000*y); +} + +static int my_get_COP(int BMC, int EC, int turns, int moves_left, + void *user_data) +{ + if (BMC == -1) { + return EC + + (((turns + 1) * (int) user_data - moves_left) * 45) / + (int) user_data; + } else { + return BMC * 123 + EC; + } +} +#endif + +static enum tile_behavior my_get_TB(int x, int y, enum known_type known, + struct pf_parameter *param) +{ + if (known == TILE_UNKNOWN) { + return TB_IGNORE; + } + + return TB_NORMAL; +} + +static void stimulate_pf(struct unit *punit) +{ + struct pf_parameter parameter; + struct pf_map *pf_map; + + pft_fill_default_parameter(¶meter); + pft_fill_unit_parameter(¶meter, punit); + + parameter.omniscience = TRUE; + parameter.zoc_used = FALSE; + parameter.get_TB = my_get_TB; + + freelog(LOG_DEBUG, "stimulate_pf: create map for %s at (%d,%d)", + unit_name(punit->type), punit->x, punit->y); + + pf_map = pf_create_map(¶meter); + + while (pf_next(pf_map)) { + /* + struct pf_path path; + int x = pf_next_get_x(pf_map); + int y = pf_next_get_y(pf_map); + + pf_next_get_path(pf_map, &path); + + if (is_safe(punit->x, punit->y) && path.positions_used == 1 + && !is_safe(x, y)) { + freelog(LOG_NORMAL, "position returned (%d,%d) is unsafe", x, y); + pf_print_path(&path); + assert(0); + } + */ + } + pf_destroy_map(pf_map); +} + /************************************************************************** This is a wrapper for really_generate_warmap that checks if the warmap we want is allready in existence. Also calls correctly depending on whether @@ -362,11 +437,60 @@ FIXME: Why is the movetype not used initialized on the warmap? Leaving it for now. **************************************************************************/ +extern struct timer *mem_timer; void generate_warmap(struct city *pcity, struct unit *punit) { freelog(LOG_DEBUG, "Generating warmap, pcity = %s, punit = %s", (pcity ? pcity->name : "NULL"), (punit ? unit_type(punit)->name : "NULL")); + + if (TRUE) { + double pf = 0, gotohand = 0; + double pf_mem = 0, goto_mem = 0; + int i; + const int N = 10; + struct timer *timer = new_timer(TIMER_CPU,TIMER_ACTIVE); + + for (i = 0; i < N; i++) { + clear_timer_start(timer); + clear_timer(mem_timer); + + players_iterate(pplayer) { + unit_list_iterate(pplayer->units, punit) { + if (is_ground_unit(punit)) { + really_generate_warmap(pcity, punit, LAND_MOVING); + } + } unit_list_iterate_end; + } players_iterate_end; + + + gotohand += read_timer_seconds(timer); + goto_mem += read_timer_seconds(mem_timer); + + clear_timer_start(timer); + players_iterate(pplayer) { + unit_list_iterate(pplayer->units, punit) { + if (is_ground_unit(punit)) { + stimulate_pf(punit); + } + } unit_list_iterate_end; + } players_iterate_end; + + pf += read_timer_seconds(timer); + pf_mem += read_timer_seconds(mem_timer); + } + + freelog(LOG_NORMAL, "all: gotohand=%fs path_finding=%fs factor=%f", + gotohand, pf, pf / gotohand); + freelog(LOG_NORMAL, "mem: gotohand=%fs path_finding=%fs factor=%f", + goto_mem, pf_mem, pf_mem / goto_mem); + + if (1) { + server_quit(); + exit(EXIT_SUCCESS); + assert(0); + } + } if (punit) { /*