switch geohash technique to 15-bit precision integer

This commit is contained in:
Reese Norris
2024-04-09 15:18:18 -07:00
parent ed3eee721f
commit 59b02eade5
3 changed files with 7 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ type FSDClient struct {
NetworkRating int
SimulatorType int
RealName string
CurrentGeohash string
CurrentGeohash uint64
SendFastEnabled bool
Kill chan string // Signal to disconnect this client
@@ -367,7 +367,7 @@ func HandleConnection(conn *net.TCPConn) {
NetworkRating: int(claimedRating),
SimulatorType: addPilotPDU.SimulatorType,
RealName: addPilotPDU.RealName,
CurrentGeohash: "",
CurrentGeohash: 0,
SendFastEnabled: false,
Kill: make(chan string, 1),
Mailbox: make(chan string, 16),

View File

@@ -114,7 +114,7 @@ func configurePostOffice() {
PO = &PostOffice{
clientRegistry: make(map[string]*FSDClient),
supervisorRegistry: make(map[string]*FSDClient),
geohashRegistry: make(map[string][]*FSDClient),
geohashRegistry: make(map[uint64][]*FSDClient),
}
}

View File

@@ -11,7 +11,7 @@ import (
type PostOffice struct {
clientRegistry map[string]*FSDClient
supervisorRegistry map[string]*FSDClient
geohashRegistry map[string][]*FSDClient
geohashRegistry map[uint64][]*FSDClient
lock sync.RWMutex
}
@@ -141,7 +141,7 @@ func (p *PostOffice) SendMail(messages []Mail) {
}
}
case MailTypeBroadcastRanged:
neighbors := geohash.Neighbors(msg.Source.CurrentGeohash)
neighbors := geohash.NeighborsInt(msg.Source.CurrentGeohash)
searchHashes := append(neighbors, msg.Source.CurrentGeohash)
for _, hash := range searchHashes {
clients, ok := p.geohashRegistry[hash]
@@ -186,7 +186,7 @@ func (p *PostOffice) SendMail(messages []Mail) {
}
}
func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash string) {
func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash uint64) {
clientList, ok := p.geohashRegistry[client.CurrentGeohash]
if !ok {
return
@@ -217,7 +217,7 @@ func (p *PostOffice) removeClientFromGeohashRegistry(client *FSDClient, hash str
// SetLocation updates the internal geohash tracking state for a client, if necessary
func (p *PostOffice) SetLocation(client *FSDClient, lat, lng float64) {
// Check if the geohash has changed since we last updated
hash := geohash.EncodeWithPrecision(lat, lng, 3)
hash := geohash.EncodeIntWithPrecision(lat, lng, 15)
if hash == client.CurrentGeohash {
return
}