From fc953da8c079178c5533ce34111c805c028394f7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 25 Sep 2023 00:22:23 +0300 Subject: [PATCH 49/49] Avoid tripled map_get_player_tile() calls on shared vision changes Both give_shared_vision() and remove_shared_vision() were constructing v_radius_t by calling map_get_own_seen() for each of the three vision layers, and thus causing three identical map_get_player_tile() calls. See osdn #48211 Signed-off-by: Marko Lindqvist --- server/maphand.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/server/maphand.c b/server/maphand.c index 4eb77b6900..70c2ae4223 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -1115,6 +1115,19 @@ void map_change_seen(struct player *pplayer, } } +/**********************************************************************//** + Get own seen count from player tile. Doesn't count shared vision. + + @param plrtile Player tile to check own seen count from + @param vlayer Vision layer which we want the count for + @return Own seen count +**************************************************************************/ +static inline int player_tile_own_seen(const struct player_tile *plrtile, + enum vision_layer vlayer) +{ + return plrtile->own_seen[vlayer]; +} + /**********************************************************************//** Returns the own seen count of a tile for a player. It doesn't count the shared vision. @@ -1125,7 +1138,7 @@ static inline int map_get_own_seen(const struct player *pplayer, const struct tile *ptile, enum vision_layer vlayer) { - return map_get_player_tile(ptile, pplayer)->own_seen[vlayer]; + return player_tile_own_seen(map_get_player_tile(ptile, pplayer), vlayer); } /**********************************************************************//** @@ -1644,10 +1657,11 @@ void give_shared_vision(struct player *pfrom, struct player *pto) log_debug("really giving shared vision from %s to %s", player_name(pplayer), player_name(pplayer2)); whole_map_iterate(&(wld.map), ptile) { + const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer); const v_radius_t change = - V_RADIUS(map_get_own_seen(pplayer, ptile, V_MAIN), - map_get_own_seen(pplayer, ptile, V_INVIS), - map_get_own_seen(pplayer, ptile, V_SUBSURFACE)); + V_RADIUS(player_tile_own_seen(plrtile, V_MAIN), + player_tile_own_seen(plrtile, V_INVIS), + player_tile_own_seen(plrtile, V_SUBSURFACE)); if (0 < change[V_MAIN] || 0 < change[V_INVIS]) { map_change_seen(pplayer2, ptile, change, @@ -1702,10 +1716,11 @@ void remove_shared_vision(struct player *pfrom, struct player *pto) log_debug("really removing shared vision from %s to %s", player_name(pplayer), player_name(pplayer2)); whole_map_iterate(&(wld.map), ptile) { + const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer); const v_radius_t change = - V_RADIUS(-map_get_own_seen(pplayer, ptile, V_MAIN), - -map_get_own_seen(pplayer, ptile, V_INVIS), - -map_get_own_seen(pplayer, ptile, V_SUBSURFACE)); + V_RADIUS(-player_tile_own_seen(plrtile, V_MAIN), + -player_tile_own_seen(plrtile, V_INVIS), + -player_tile_own_seen(plrtile, V_SUBSURFACE)); if (0 > change[V_MAIN] || 0 > change[V_INVIS]) { map_change_seen(pplayer2, ptile, change, FALSE); -- 2.40.1