Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions internal/gameServer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ func (g *GameServer) ManageBuffer() {
g.GameDataMutex.Lock() // BufferHealth can be modified by processUDP in a different thread
for i := range 4 {
if g.GameData.CountLag[i] == 0 {
playerBufferHealth, err := g.bufferHealthAverage(i)
var err error
g.GameData.BufferHealthAverage[i], err = g.bufferHealthAverage(i)
if err == nil {
activePlayers = true
}
if playerBufferHealth > bufferHealth {
bufferHealth = playerBufferHealth
if g.GameData.BufferHealthAverage[i] > bufferHealth {
bufferHealth = g.GameData.BufferHealthAverage[i]
}
}
g.GameData.BufferHealth[i].Purge()
Expand Down Expand Up @@ -156,7 +157,7 @@ func (g *GameServer) ManagePlayers() {
_, ok := g.Registrations[i]
if ok {
if g.GameData.PlayerAlive[i] {
g.Logger.Info("player status", "player", i, "regID", g.Registrations[i].RegID, "bufferSize", g.GameData.BufferSize, "countLag", g.GameData.CountLag[i], "address", g.GameData.PlayerAddresses[i])
g.Logger.Info("player status", "player", i, "regID", g.Registrations[i].RegID, "bufferHealthAverage", g.GameData.BufferHealthAverage[i], "bufferSize", g.GameData.BufferSize, "countLag", g.GameData.CountLag[i], "address", g.GameData.PlayerAddresses[i])
playersActive = true
} else {
g.Logger.Info("player disconnected UDP", "player", i, "regID", g.Registrations[i].RegID, "address", g.GameData.PlayerAddresses[i])
Expand Down
28 changes: 14 additions & 14 deletions internal/gameServer/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ type InputData struct {
}

type GameData struct {
SyncValues *lru.Cache[uint32, []byte]
PlayerAddresses [4]*net.UDPAddr
BufferSize uint32
BufferHealth [4]*lru.Cache[uint32, byte]
Inputs [4]*lru.Cache[uint32, InputData]
PendingInput [4]InputData
CountLag [4]uint32
sendBuffer []byte
recvBuffer []byte
PlayerAlive [4]bool
LeadCount uint32
Status byte
SyncValues *lru.Cache[uint32, []byte]
PlayerAddresses [4]*net.UDPAddr
BufferSize uint32
BufferHealth [4]*lru.Cache[uint32, byte]
BufferHealthAverage [4]float32
Inputs [4]*lru.Cache[uint32, InputData]
PendingInput [4]InputData
CountLag [4]uint32
sendBuffer []byte
recvBuffer []byte
PlayerAlive [4]bool
LeadCount uint32
Status byte
}

const (
Expand All @@ -46,7 +47,6 @@ const (
DisconnectTimeoutS = 30
NoRegID = 255
InputDataMax int = 60 * 60 // One minute of input data
BufferHealthMax = 10
CS4 = 32
)

Expand Down Expand Up @@ -213,7 +213,7 @@ func (g *GameServer) createUDPServer() error {
g.GameData.BufferSize = 3
for i := range 4 {
g.GameData.Inputs[i], _ = lru.New[uint32, InputData](InputDataMax)
g.GameData.BufferHealth[i], _ = lru.New[uint32, byte](BufferHealthMax)
g.GameData.BufferHealth[i], _ = lru.New[uint32, byte](InputDataMax)
}
g.GameData.SyncValues, _ = lru.New[uint32, []byte](100) // Store up to 100 sync values
g.GameData.sendBuffer = make([]byte, 508)
Expand Down