func (g *Game) RenderLocalSetup(region g2.Region) { g.Setup.local.RLock() defer g.Setup.local.RUnlock() dict := base.GetDictionary("luxisr") size := 60.0 y := 100.0 dict.RenderString("Engines:", size, y, 0, size, gui.Left) for i, id := range g.Setup.EngineIds { y += size if id == g.local.Engine.Id() { gui.SetFontColor(0.7, 0.7, 1, 1) } else { gui.SetFontColor(0.7, 0.7, 0.7, 1) } dataStr := fmt.Sprintf("Engine %d, Side %d, %s", id, g.Setup.Players[id].Side, g.Champs[g.Setup.Players[id].ChampIndex].Name) dict.RenderString(dataStr, size, y, 0, size, gui.Left) if g.IsManaging() && i == g.Setup.local.Index { dict.RenderString(">", 50, y, 0, size, gui.Right) } } y += size gui.SetFontColor(0.7, 0.7, 0.7, 1) if g.IsManaging() { dict.RenderString("Start!", size, y, 0, size, gui.Left) if g.Setup.local.Index == len(g.Setup.EngineIds) { dict.RenderString(">", 50, y, 0, size, gui.Right) } } }
func (g *Game) RenderLocalSetup(region g2.Region, local *LocalData) { dict := base.GetDictionary("luxisr") size := 60.0 y := 100.0 dict.RenderString("Engines:", size, y, 0, size, gui.Left) for i, id := range g.Setup.EngineIds { y += size if id == local.engine.Id() { gui.SetFontColor(0.7, 0.7, 1, 1) } else { gui.SetFontColor(0.7, 0.7, 0.7, 1) } dataStr := fmt.Sprintf("Engine %d, Side %d, %s", id, g.Setup.Sides[id].Side, g.Champs[g.Setup.Sides[id].Champ].Name) dict.RenderString(dataStr, size, y, 0, size, gui.Left) if local.engine.Id() == 1 && i == local.setup.index { dict.RenderString(">", 50, y, 0, size, gui.Right) } } y += size gui.SetFontColor(0.7, 0.7, 0.7, 1) if local.engine.Id() == 1 { dict.RenderString("Start!", size, y, 0, size, gui.Left) if local.setup.index == len(g.Setup.EngineIds) { dict.RenderString(">", 50, y, 0, size, gui.Right) } } ids := local.engine.Ids() if len(ids) > 0 { // This is the host engine - so update the list of ids in case it's changed local.engine.ApplyEvent(SetupSetEngineIds{ids}) } }
func (b *Button) Draw(region Region, style StyleStack) { b.Last = region selected, ok := style.Get("selected").(bool) var xOffset float64 var renderName string if b.Hover || (ok && selected) { gui.SetFontColor(0, 0, 0, 1) renderName = ">" + b.Name xOffset = 0.0 } else { gui.SetFontColor(0, 0, 0, 0.7) renderName = b.Name xOffset = base.GetDictionary("luxisr").StringWidth(">", float64(b.Size)) } base.GetDictionary("luxisr").RenderString(renderName, xOffset+float64(region.X), float64(region.Y), 0, float64(b.Size), gui.Left) }
func (g *Game) renderLocalMoba(region g2.Region, local *LocalData) { g.renderLocalHelper(region, local, &local.moba.currentPlayer.camera, local.moba.currentPlayer.side) if g.Ents[local.moba.currentPlayer.gid] == nil { var id int64 fmt.Sscanf(string(local.moba.currentPlayer.gid), "Engine:%d", &id) seconds := float64(g.Engines[id].CountdownFrames) / 60.0 dict := base.GetDictionary("luxisr") gui.SetFontColor(0.7, 0.7, 1, 1) dict.RenderString(fmt.Sprintf("%2.3f", seconds), 300, 300, 0, 100, gui.Left) } }
func (c *Console) Draw(x, y, dx, dy int) { if !gin.In().GetKeyFlat(gin.EitherShift, gin.DeviceTypeAny, gin.DeviceIndexAny).IsDown() { return } c.tail.GetLines(c.lines) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4d(0.2, 0, 0.3, 0.8) gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.QUADS) { glx := gl.Int(x) gly := gl.Int(y) glx2 := gl.Int(x + dx) gly2 := gl.Int(y + dy) gl.Vertex2i(glx, gly) gl.Vertex2i(glx, gly2) gl.Vertex2i(glx2, gly2) gl.Vertex2i(glx2, gly) } gl.End() gui.SetFontColor(1, 1, 1, 1) startY := float64(y + dy - len(c.lines)*lineHeight) for i, line := range c.lines { switch { case strings.HasPrefix(line, "LOG"): gui.SetFontColor(1, 1, 1, 1) case strings.HasPrefix(line, "WARN"): gui.SetFontColor(1, 1, 0, 1) case strings.HasPrefix(line, "ERROR"): gui.SetFontColor(1, 0, 0, 1) default: gui.SetFontColor(1, 1, 1, 0.7) } c.dict.RenderString(line, float64(x), startY+float64(i*lineHeight), 0, lineHeight, gui.Left) } }
func (c *Console) Draw(region Region, stlye StyleStack) { if !c.visible { return } gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4d(0.2, 0, 0.3, 0.8) gl.Disable(gl.TEXTURE_2D) gl.Begin(gl.QUADS) { x := gl.Int(region.X) y := gl.Int(region.Y) x2 := gl.Int(region.X + region.Dx) y2 := gl.Int(region.Y + region.Dy) gl.Vertex2i(x, y) gl.Vertex2i(x, y2) gl.Vertex2i(x2, y2) gl.Vertex2i(x2, y) } gl.End() gui.SetFontColor(1, 1, 1, 1) startY := float64(region.Y + region.Dy - len(c.lines)*lineHeight) for i, line := range c.lines { switch { case strings.HasPrefix(line, "LOG"): gui.SetFontColor(1, 1, 1, 1) case strings.HasPrefix(line, "WARN"): gui.SetFontColor(1, 1, 0, 1) case strings.HasPrefix(line, "ERROR"): gui.SetFontColor(1, 0, 0, 1) default: gui.SetFontColor(1, 1, 1, 0.7) } c.dict.RenderString(line, float64(region.X), startY+float64(i*lineHeight), 0, lineHeight, gui.Left) } }
func getPlayers(console *base.Console) []gin.DeviceId { var ct controllerTracker gin.In().RegisterEventListener(&ct) defer gin.In().UnregisterEventListener(&ct) ticker := time.Tick(time.Millisecond * 17) start := time.Time{} readyDuration := time.Second * 2 for start.IsZero() || time.Now().Sub(start) < readyDuration { <-ticker sys.Think() if ct.Ready() && start.IsZero() { start = time.Now() } if !ct.Ready() { start = time.Time{} } render.Queue(func() { defer console.Draw(0, 0, wdx, wdy) gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num players: %d", len(ct.ids)), float64(wdx)/2, 300, 0, 100, gui.Center) base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num ready: %d", ct.NumReady()), float64(wdx)/2, 400, 0, 100, gui.Center) if !start.IsZero() { base.GetDictionary("crackin").RenderString(fmt.Sprintf("Starting in %2.2f", (readyDuration-time.Now().Sub(start)).Seconds()), float64(wdx)/2, 500, 0, 100, gui.Center) } }) render.Queue(func() { sys.SwapBuffers() }) render.Purge() } var devices []gin.DeviceId for id := range ct.ids { devices = append(devices, id) } return devices }
func mainLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) { client.MakeRequest(game.Join{Rebels: make([]*game.RebelPlayer, 2)}) ticker := time.Tick(time.Millisecond * 17) render.Queue(func() { gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) }) for { <-ticker if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 { return } sys.Think() render.Queue(func() { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() base.GetDictionary("crackin").RenderString("Waiting on some nubs", float64(wdx)/2, 300, 0, 100, gui.Center) }) client.RLock() g := client.Game().(*game.Game) mode := g.Mode client.RUnlock() if mode == game.ModeWaiting { } else if mode == game.ModeProgram { programLoop(client, controllers, console) } else if mode == game.ModeRun { } render.Queue(func() { sys.SwapBuffers() }) render.Purge() } }
// For invaders or moba, does a lot of basic stuff common to both func (g *Game) renderLocalHelper(region g2.Region, local *LocalData, camera *cameraInfo, side int) { camera.doInvadersFocusRegion(g, side) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) level := g.Levels[GidInvadersStart] zoom := camera.current.dims.X / float64(region.Dims.Dx) level.ManaSource.Draw(local, zoom, float64(level.Room.Dx), float64(level.Room.Dy)) gl.Color4d(1, 1, 1, 1) var expandedPoly linear.Poly for _, poly := range g.Levels[GidInvadersStart].Room.Walls { // Don't draw counter-clockwise polys, specifically this means don't draw // the boundary of the level. if poly.IsCounterClockwise() { continue } // KLUDGE: This will expand the polygon slightly so that it actually shows // up when the los shadows are drawn over it. Eventually there should be // separate los polys, colision polys, and draw polys so that this isn't // necessary. gl.Begin(gl.TRIANGLE_FAN) expandPoly(poly, &expandedPoly) for _, v := range expandedPoly { gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y)) } gl.End() } gui.SetFontColor(0, 255, 0, 255) for side, pos := range g.Levels[GidInvadersStart].Room.Starts { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), pos.X, pos.Y, 0, 100, gui.Center) } gl.Color4d(1, 1, 1, 1) for _, ent := range g.temp.AllEnts { ent.Draw(g, side) } gl.Disable(gl.TEXTURE_2D) if local.mode != LocalModeMoba { panic("Need to implement drawing players from standard mode data") } for i := range local.moba.players { p := &local.moba.players[i] if p.abs.activeAbility != nil { p.abs.activeAbility.Draw(p.gid, g, side) } } for _, proc := range g.Processes { proc.Draw(Gid(""), g, side) } gl.Color4ub(0, 0, 255, 200) g.renderLosMask(local) }
func programLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) { ticker := time.Tick(time.Millisecond * 17) var selections cardSelections selections.cols = 7 selections.players = make([]cardSelection, len(controllers)) client.RLock() g := client.Game().(*game.Game) for _, card := range g.Cards { selections.cards = append(selections.cards, card) selections.used = append(selections.used, -1) } client.RUnlock() for { <-ticker if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 { return } for i, device := range controllers { up := gin.In().GetKeyFlat(gin.ControllerHatSwitchUp, device.Type, device.Index).FramePressCount() down := gin.In().GetKeyFlat(gin.ControllerHatSwitchDown, device.Type, device.Index).FramePressCount() left := gin.In().GetKeyFlat(gin.ControllerHatSwitchLeft, device.Type, device.Index).FramePressCount() right := gin.In().GetKeyFlat(gin.ControllerHatSwitchRight, device.Type, device.Index).FramePressCount() selections.HandleMove(i, right-left, down-up) drop := gin.In().GetKeyFlat(gin.ControllerButton0+1, device.Type, device.Index).FramePressCount() > 0 choose := gin.In().GetKeyFlat(gin.ControllerButton0+2, device.Type, device.Index).FramePressCount() > 0 if choose { selections.HandleChoose(i) } if drop { selections.HandleDrop(i) } } sys.Think() render.Queue(func() { defer console.Draw(0, 0, wdx, wdy) gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() client.RLock() g := client.Game().(*game.Game) renderBoard(g, 10, 10, 400, 400) client.RUnlock() renderCards(selections.cards, 64, 400, 400, selections.cols, &selections) for i, player := range selections.players { setColorForIndex(i) renderCardReticle(false, 64, player.sx, player.sy, 400, 400) renderCards(player.cards, 64, 400, 300-100*i, selections.cols, nil) } }) render.Queue(func() { sys.SwapBuffers() }) render.Purge() } }
func (g *Game) renderBases() { gui.SetFontColor(0, 255, 0, 255) for side, data := range g.Level.Room.SideData { base.GetDictionary("luxisr").RenderString(fmt.Sprintf("S%d", side), data.Base.X, data.Base.Y, 0, 100, gui.Center) } }