From: Christian Heller Date: Wed, 30 Jul 2014 04:38:31 +0000 (+0200) Subject: Server: Refactor writing of field of view to Thing struct. X-Git-Tag: tce~683 X-Git-Url: https://plomlompom.com/repos/ledger?a=commitdiff_plain;h=fa0c416ccad4c4278813909ca1b799cd0600840c;p=plomrogue Server: Refactor writing of field of view to Thing struct. --- diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c index 1a9acd5..f34885d 100644 --- a/src/server/field_of_view.c +++ b/src/server/field_of_view.c @@ -327,7 +327,7 @@ static void eval_position(uint16_t dist, uint16_t hex_i, uint8_t * fov_map, -extern uint8_t * build_fov_map(struct Thing * eye) +extern void build_fov_map(struct Thing * eye) { uint32_t map_size = world.map.length * world.map.length; uint8_t * fov_map = try_malloc(map_size, __func__); @@ -363,5 +363,6 @@ extern uint8_t * build_fov_map(struct Thing * eye) } mv_yx_in_dir_wrap(0, NULL, 1); free_angles(shadows); - return fov_map; + 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 85a414f..555ae63 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 }; -/* Return field of view map of the world as seen from the position of "eye". */ -extern uint8_t * build_fov_map(struct Thing * eye); +/* Build "eye"'s field of view. */ +extern void build_fov_map(struct Thing * eye); diff --git a/src/server/god_commands.c b/src/server/god_commands.c index b0aa86a..6eec572 100644 --- a/src/server/god_commands.c +++ b/src/server/god_commands.c @@ -239,10 +239,9 @@ static uint8_t parse_position(char* tok0, char * tok1, struct Thing * t) { t->pos.x = length; } - free(t->fov_map); if (world.exists && t->lifepoints) { - t->fov_map = build_fov_map(t); + build_fov_map(t); } } return 1; @@ -302,7 +301,7 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1) t = add_thing(id, world.thing_types->id, 0, 0); if (world.exists && t->lifepoints) { - t->fov_map = build_fov_map(t); + build_fov_map(t); } } } @@ -371,11 +370,7 @@ static uint8_t parse_world_active(char * tok0, char * tok1) { if (ti->lifepoints) { - if (ti->fov_map) - { - free(ti->fov_map); - } - ti->fov_map = build_fov_map(ti); + build_fov_map(ti); } } world.exists = 1; diff --git a/src/server/init.c b/src/server/init.c index 01950bc..42ec699 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -215,7 +215,10 @@ extern uint8_t remake_world() struct Thing * t; for (t = world.things; NULL != t; t = t->next) { - t->fov_map = t->lifepoints ? build_fov_map(t) : NULL; + if (t->lifepoints) + { + build_fov_map(t); + } } world.turn = 1; world.do_update = 1; diff --git a/src/server/thing_actions.c b/src/server/thing_actions.c index bcf9e45..8d6a802 100644 --- a/src/server/thing_actions.c +++ b/src/server/thing_actions.c @@ -266,8 +266,7 @@ extern void actor_move(struct Thing * t) if (passable) { set_thing_position(t, target); - free(t->fov_map); - t->fov_map = build_fov_map(t); + build_fov_map(t); } if (t == get_player()) {