From: Christian Heller Date: Wed, 13 Aug 2014 23:56:18 +0000 (+0200) Subject: Server: Minor field of view code simplifications. X-Git-Tag: tce~666 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/do_todos?a=commitdiff_plain;h=3cb6ed6453b22eba62f7c9186790813b0abebeb9;p=plomrogue Server: Minor field of view code simplifications. --- diff --git a/src/server/ai.c b/src/server/ai.c index 91a6c86..0fd43ad 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -5,7 +5,6 @@ #include /* uint8_t, uint16_t, uint32_t, UINT16_MAX */ #include /* free() */ #include "../common/try_malloc.h" /* try_malloc() */ -#include "field_of_view.h" /* HIDDEN */ #include "hardcoded_strings.h" /* s */ #include "thing_actions.h" /* get_thing_action_id_by_name() */ #include "things.h" /* struct Thing */ @@ -140,7 +139,7 @@ static char get_dir_to_nearest_enemy(struct Thing * t_origin) for (; t != NULL; t = t->next) { if ( !t->lifepoints || t == t_origin - || HIDDEN == t_origin->fov_map[t->pos.y*world.map.length+t->pos.x]) + || 'H' == t_origin->fov_map[t->pos.y * world.map.length + t->pos.x]) { continue; } diff --git a/src/server/field_of_view.c b/src/server/field_of_view.c index 6ccd16f..ae8aa9c 100644 --- a/src/server/field_of_view.c +++ b/src/server/field_of_view.c @@ -65,21 +65,12 @@ static uint8_t try_merging_angles(uint32_t left_angle, uint32_t right_angle, /* Test whether angle between "left_angle" and "right_angle", or at least * "middle_angle", is captured inside one of the shadow angles in "shadows". If - * so, set hex in "fov_map" indexed by "pos_in_map" to HIDDEN. If the whole - * angle and not just "middle_angle" is captured, return 1. Any other case: 0. + * so, set hex in "fov_map" indexed by "pos_in_map" to 'H'. If the whole angle + * and not just "middle_angle" is captured, return 1. Any other case: 0. */ static uint8_t shade_hex(uint32_t left_angle, uint32_t right_angle, uint32_t middle_angle, struct shadow_angle ** shadows, - uint16_t pos_in_map, uint8_t * fov_map); - -/* Test whether angle between "left_angle" and "right_angle", or at least - * "middle_angle", is captured inside one of the shadow angles in "shadows". If - * so, set hex in "fov_map" indexed by "pos_in_map" to HIDDEN. If the whole - * angle and not just "middle_angle" is captured, return 1. Any other case: 0. - */ -static uint8_t shade_hex(uint32_t left_angle, uint32_t right_angle, - uint32_t middle_angle, struct shadow_angle ** shadows, - uint16_t pos_in_map, uint8_t * fov_map); + uint16_t pos_in_map, char * fov_map); /* Free shadow angles list "angles". */ static void free_angles(struct shadow_angle * angles); @@ -89,7 +80,7 @@ static void free_angles(struct shadow_angle * angles); * the circle's rightmost point), for setting shaded hexes in "fov_map" and * potentially adding a new shadow to linked shadow angle list "shadows". */ -static void eval_position(uint16_t dist, uint16_t hex_i, uint8_t * fov_map, +static void eval_position(uint16_t dist, uint16_t hex_i, char * fov_map, struct yx_uint8 * test_pos, struct shadow_angle ** shadows); @@ -264,23 +255,23 @@ static uint8_t try_merging_angles(uint32_t left_angle, uint32_t right_angle, static uint8_t shade_hex(uint32_t left_angle, uint32_t right_angle, uint32_t middle_angle, struct shadow_angle ** shadows, - uint16_t pos_in_map, uint8_t * fov_map) + uint16_t pos_in_map, char * fov_map) { struct shadow_angle * shadow_i; - if (fov_map[pos_in_map] == VISIBLE) + if (fov_map[pos_in_map] == 'v') { for (shadow_i = *shadows; shadow_i; shadow_i = shadow_i->next) { if ( left_angle <= shadow_i->left_angle && right_angle >= shadow_i->right_angle) { - fov_map[pos_in_map] = HIDDEN; + fov_map[pos_in_map] = 'H'; return 1; } if ( middle_angle < shadow_i->left_angle && middle_angle > shadow_i->right_angle) { - fov_map[pos_in_map] = HIDDEN; + fov_map[pos_in_map] = 'H'; } } } @@ -331,7 +322,7 @@ static void free_angles(struct shadow_angle * angles) -static void eval_position(uint16_t dist, uint16_t hex_i, uint8_t * fov_map, +static void eval_position(uint16_t dist, uint16_t hex_i, char * fov_map, struct yx_uint8 * test_pos, struct shadow_angle ** shadows) { @@ -373,7 +364,7 @@ static void update_map_memory(struct Thing * t, uint32_t map_size) uint32_t i; for (i = 0; i < map_size; i++) { - if (' ' == t->mem_map[i] && t->fov_map[i] == VISIBLE) + if (' ' == t->mem_map[i] && t->fov_map[i] == 'v') { t->mem_map[i] = world.map.cells[i]; } @@ -386,7 +377,7 @@ extern void build_fov_map(struct Thing * t) { uint32_t map_size = world.map.length * world.map.length; t->fov_map = t->fov_map ? t->fov_map : try_malloc(map_size, __func__); - memset(t->fov_map, VISIBLE, map_size); + memset(t->fov_map, 'v', map_size); struct yx_uint8 test_pos = t->pos; struct shadow_angle * shadows = NULL; char * circle_dirs = "xswedc"; diff --git a/src/server/field_of_view.h b/src/server/field_of_view.h index aa8fe7c..503fba9 100644 --- a/src/server/field_of_view.h +++ b/src/server/field_of_view.h @@ -13,12 +13,6 @@ struct Thing; -/* States that cells in the field of view map may be in. */ -enum fov_cell_states { - HIDDEN = 0x00, - VISIBLE = 0x01 -}; - /* Build "t"'s field of view and update its map memory with the result. */ extern void build_fov_map(struct Thing * t); diff --git a/src/server/io.c b/src/server/io.c index b5a6871..947c146 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -17,7 +17,6 @@ #include "../common/rexit.h" /* exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ #include "cleanup.h" /* set_cleanup_flag() */ -#include "field_of_view.h" /* VISIBLE */ #include "hardcoded_strings.h" /* s */ #include "things.h" /* Thing, ThingType, ThingAction, get_thing_type(), * get_player() @@ -309,7 +308,7 @@ static char * build_visible_map(struct Thing * player) uint32_t pos_i; for (pos_i = 0; pos_i < map_size; pos_i++) { - if (player->fov_map[pos_i] == VISIBLE) + if (player->fov_map[pos_i] == 'v') { visible_map[pos_i] = world.map.cells[pos_i]; } @@ -322,8 +321,7 @@ static char * build_visible_map(struct Thing * player) { for (t = world.things; t != 0; t = t->next) { - if ( ( player->fov_map[t->pos.y * world.map.length +t->pos.x] - == VISIBLE) + if ( 'v'==player->fov_map[t->pos.y*world.map.length+t->pos.x] && ( (0 == i && 0 == t->lifepoints) || (1 == i && 0 < t->lifepoints))) { diff --git a/src/server/things.h b/src/server/things.h index 4b9291c..4c21c45 100644 --- a/src/server/things.h +++ b/src/server/things.h @@ -18,8 +18,8 @@ struct Thing uint8_t id; /* individual thing's unique identifier */ struct Thing * owns; /* chain of things owned / in inventory */ struct yx_uint8 pos; /* coordinate on map */ - uint8_t * fov_map; /* map of the thing's field of view */ - uint8_t * mem_map; /* map knowledge of thing by FOV and memory */ + char * fov_map; /* map of the thing's field of view */ + char * mem_map; /* map knowledge of thing by FOV and memory */ uint8_t type; /* ID of appropriate thing definition */ uint8_t lifepoints; /* 0: thing is inanimate; >0: hitpoints */ uint8_t command; /* thing's current action; 0 if none */