From: Christian Heller Date: Fri, 1 Aug 2014 00:34:33 +0000 (+0200) Subject: Server: Reduce malloc() calls in FOV generation. X-Git-Tag: tce~681 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=bfcf7850e4f5aa11ae5a33d78e153075032ff76d;p=plomrogue Server: Reduce malloc() calls in FOV generation. --- diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c index f34885d..440c84c 100644 --- a/src/server/field_of_view.c +++ b/src/server/field_of_view.c @@ -327,12 +327,12 @@ static void eval_position(uint16_t dist, uint16_t hex_i, uint8_t * fov_map, -extern void build_fov_map(struct Thing * eye) +extern void build_fov_map(struct Thing * t) { uint32_t map_size = world.map.length * world.map.length; - uint8_t * fov_map = try_malloc(map_size, __func__); - memset(fov_map, VISIBLE, map_size); - struct yx_uint8 test_pos = eye->pos; + t->fov_map = t->fov_map ? t->fov_map : try_malloc(map_size, __func__); + memset(t->fov_map, VISIBLE, map_size); + struct yx_uint8 test_pos = t->pos; struct shadow_angle * shadows = NULL; char * circle_dirs = "xswedc"; uint16_t dist; @@ -350,7 +350,7 @@ extern void build_fov_map(struct Thing * eye) { if (mv_yx_in_dir_legal(dir, &test_pos)) { - eval_position(dist, hex_i, fov_map, &test_pos, &shadows); + eval_position(dist, hex_i, t->fov_map, &test_pos, &shadows); circle_on_map = 1; } dir = circle_dirs[i_dir]; @@ -363,6 +363,4 @@ extern void build_fov_map(struct Thing * eye) } mv_yx_in_dir_wrap(0, NULL, 1); free_angles(shadows); - free(eye->fov_map); - eye->fov_map = fov_map; } diff --git a/src/server/field_of_view.h b/src/server/field_of_view.h index 555ae63..6920594 100644 --- a/src/server/field_of_view.h +++ b/src/server/field_of_view.h @@ -19,8 +19,8 @@ enum fov_cell_states { VISIBLE = 0x01 }; -/* Build "eye"'s field of view. */ -extern void build_fov_map(struct Thing * eye); +/* Build "t"'s field of view. */ +extern void build_fov_map(struct Thing * t);