Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Showing/hiding entities unconditionally #894

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions server/session/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading