store client coords as a single atomic unit

This commit is contained in:
Reese Norris
2025-05-25 11:57:06 -07:00
parent 2f423ed824
commit c0155e78d4
3 changed files with 17 additions and 8 deletions

View File

@@ -16,7 +16,8 @@ type Client struct {
cancelCtx func()
sendChan chan string
lat, lon, visRange atomic.Float64
coords atomic.Value
visRange atomic.Float64
closestVelocityClientDistance float64 // The closest Velocity-compatible client in meters
flightPlan atomic.String
@@ -37,6 +38,7 @@ type Client struct {
}
type LatLon struct {
lat, lon float64
}
func newClient(ctx context.Context, conn net.Conn, scanner *bufio.Scanner, loginData loginData) (client *Client) {
@@ -125,5 +127,10 @@ func (s *Server) eventLoop(client *Client) {
}
func (c *Client) latLon() [2]float64 {
return [2]float64{c.lat.Load(), c.lon.Load()}
latLon := c.coords.Load().(LatLon)
return [2]float64{latLon.lat, latLon.lon}
}
func (c *Client) setLatLon(lat, lon float64) {
c.coords.Store(LatLon{lat: lat, lon: lon})
}