From b98787c2ad3e29a142b5f08239830c9233a24a12 Mon Sep 17 00:00:00 2001 From: Ali <47182802+UnknownOre@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:19:32 +0300 Subject: [PATCH] session/player.go: Avoid showing & unhiding entities when not necessary (#894) --- server/session/player.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server/session/player.go b/server/session/player.go index 82724fa3a..0980ce353 100644 --- a/server/session/player.go +++ b/server/session/player.go @@ -28,21 +28,33 @@ import ( // StopShowingEntity stops showing a world.Entity to the Session. It will be completely invisible until a call to // StartShowingEntity is made. func (s *Session) StopShowingEntity(e world.Entity) { - s.HideEntity(e) s.entityMutex.Lock() - s.hiddenEntities[e] = struct{}{} + _, ok := s.hiddenEntities[e] + if !ok { + s.hiddenEntities[e] = struct{}{} + } s.entityMutex.Unlock() + + if !ok { + s.HideEntity(e) + } } // StartShowingEntity starts showing a world.Entity to the Session that was previously hidden using StopShowingEntity. func (s *Session) StartShowingEntity(e world.Entity) { s.entityMutex.Lock() - delete(s.hiddenEntities, e) + _, ok := s.hiddenEntities[e] + if ok { + delete(s.hiddenEntities, e) + } s.entityMutex.Unlock() - s.ViewEntity(e) - s.ViewEntityState(e) - s.ViewEntityItems(e) - s.ViewEntityArmour(e) + + if ok { + s.ViewEntity(e) + s.ViewEntityState(e) + s.ViewEntityItems(e) + s.ViewEntityArmour(e) + } } // closeCurrentContainer closes the container the player might currently have open.