From 02991e71c4dbf05ea3fccf85da8c4c41cd34b022 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 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/server/maphand.c b/server/maphand.c index 4eb77b6900..26e0f8b67c 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -83,9 +83,6 @@ static void map_change_own_seen(struct player *pplayer, static inline int map_get_seen(const struct player *pplayer, const struct tile *ptile, enum vision_layer vlayer); -static inline int map_get_own_seen(const struct player *pplayer, - const struct tile *ptile, - enum vision_layer vlayer); static inline bool map_is_also_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer); @@ -1116,16 +1113,16 @@ void map_change_seen(struct player *pplayer, } /**********************************************************************//** - Returns the own seen count of a tile for a player. It doesn't count the - shared vision. + Get own seen count from player tile. Doesn't count shared vision. - See also map_get_seen(). + @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 map_get_own_seen(const struct player *pplayer, - const struct tile *ptile, - enum vision_layer vlayer) +static inline int player_tile_own_seen(const struct player_tile *plrtile, + enum vision_layer vlayer) { - return map_get_player_tile(ptile, pplayer)->own_seen[vlayer]; + return plrtile->own_seen[vlayer]; } /**********************************************************************//** @@ -1644,10 +1641,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 +1700,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