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:
sm
2014-03-03 22:56:26 -08:00
parent ecc70606a9
commit 6fd4138740
5 changed files with 73 additions and 15 deletions
+16 -2
View File
@@ -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)