Skip to content

Commit

Permalink
Use current position when finding player spectators
Browse files Browse the repository at this point in the history
  • Loading branch information
mbpolan committed Oct 29, 2023
1 parent f322443 commit eb704de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ func (g *Game) handleGameUpdate() error {
}

// find players within visual distance of this player
others := g.mapManager.FindSpectators(pe, regionGlobal)
others := g.mapManager.FindSpectators(pe)
updatedTracking := map[int]*playerEntity{}

for _, other := range others {
Expand Down
18 changes: 15 additions & 3 deletions internal/game/map_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,21 @@ func (m *MapManager) RemovePlayer(pe *playerEntity, regionGlobal model.Vector3D)
}
}

// FindSpectators returns a slice of playerEntity instances that are within viewable distance of the given player.
func (m *MapManager) FindSpectators(pe *playerEntity, regionGlobal model.Vector3D) []*playerEntity {
return m.regions[regionGlobal].FindSpectators(pe)
// FindSpectators returns a map of player IDs to playerEntity instances that are within viewable distance of the given
// player.
func (m *MapManager) FindSpectators(pe *playerEntity) map[int]*playerEntity {
spectators := map[int]*playerEntity{}

regions := m.findOverlappingRegions(pe.player.GlobalPos)
for _, origin := range regions {
region := m.regions[origin]

for _, pe := range region.FindSpectators(pe) {
spectators[pe.player.ID] = pe
}
}

return spectators
}

// AddGroundItem adds a ground Item to the top of a tile with an optional timeout (in seconds) when that Item should
Expand Down

0 comments on commit eb704de

Please sign in to comment.