added bw calcs
unfortunately there is an issue with how these are calculated, and they don't decrease as things quiet down. Well, the bad numbers are their for your consumption, and should Just Work TM when appropriate changes in bitbucket.org/smcquay/bandwith land. And they will. But I'm tired now.
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/smcquay/bandwidth"
|
||||
)
|
||||
|
||||
const maxPlayer = 128
|
||||
@@ -84,6 +86,7 @@ type game struct {
|
||||
tick_duration int
|
||||
stats GameStats
|
||||
mode GameMode
|
||||
bw *bandwidth.Bandwidth
|
||||
}
|
||||
|
||||
type GameMode interface {
|
||||
@@ -92,7 +95,16 @@ type GameMode interface {
|
||||
gameOver(gg *game) (bool, *GameOver)
|
||||
}
|
||||
|
||||
func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, mode string) *game {
|
||||
func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, mode string) (*game, error) {
|
||||
bw, err := bandwidth.NewBandwidth(
|
||||
[]int{1, 10, 60},
|
||||
time.Duration(500)*time.Millisecond,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("seriously, what the fuck")
|
||||
return nil, err
|
||||
}
|
||||
go bw.Run()
|
||||
g := &game{
|
||||
id: id,
|
||||
register: make(chan *player, maxPlayer),
|
||||
@@ -115,6 +127,7 @@ func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, m
|
||||
tick_duration: tick,
|
||||
players_remaining: 2,
|
||||
stats: GameStats{PlayerStats: make(map[string]*PlayerStats)},
|
||||
bw: bw,
|
||||
}
|
||||
|
||||
if mode == "melee" {
|
||||
@@ -125,7 +138,7 @@ func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, m
|
||||
|
||||
g.mode.setup(g)
|
||||
|
||||
return g
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (g *game) tick(payload *Boardstate) {
|
||||
@@ -286,6 +299,7 @@ func (g *game) run() {
|
||||
select {
|
||||
case <-g.kill:
|
||||
log.Printf("game %s: received kill signal, dying gracefully", g.id)
|
||||
close(g.bw.Quit)
|
||||
games.Lock()
|
||||
for player := range g.players {
|
||||
close(player.send)
|
||||
|
||||
Reference in New Issue
Block a user