func main() { defer profile.Start(&profile.Config{CPUProfile: true, ProfilePath: "/tmp/"}).Stop() // nCPU := runtime.NumCPU() nCPU := 2 runtime.GOMAXPROCS(nCPU) log.Printf("running on %d CPUs", nCPU) server := network.NewServer("8081") server.Start() world = NewWorld(entityManager, server) go world.worldTick() go world.networkTick() // wait for signal signalChan := make(chan os.Signal, 1) cleanupDone := make(chan bool) signal.Notify(signalChan, os.Interrupt) go func() { for _ = range signalChan { log.Printf("Received an interrupt, stopping services...\n") server.Stop() cleanupDone <- true } }() <-cleanupDone }
func TestAddSprite(t *testing.T) { list := NewEntityManager() spriteID := list.NewEntity(0, 0, ENT_ENT1) s := network.NewServer("8080") w := NewWorld(list, s) list.Update(w, 0.016) if spriteID != 1 { t.Errorf("Could not get sprite id") } }
// ~ 294222ns // ~ 135567ns // ~ 105126ns // ~ 137163ns func BenchmarkSpriteUpdate(b *testing.B) { b.StopTimer() list := NewEntityManager() rand.Seed(1) for i := 0; i < 100; i++ { list.NewEntity(rand.Float64()*1000, rand.Float64()*1000, ENT_ENT1) } s := network.NewServer("8080") w := NewWorld(list, s) b.StartTimer() for n := 0; n < b.N; n++ { list.Update(w, 0.0016) } }
func TestUpdate(t *testing.T) { e := NewEntityManager() s := network.NewServer("8080") w := NewWorld(e, s) e.Update(w, 0.016) }