polish batching
This commit is contained in:
parent
c3b6d652b4
commit
82dc081c35
22
gfx/gfx.go
22
gfx/gfx.go
|
@ -65,8 +65,8 @@ func loadPicture(path string) (pixel.Picture, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteBank) RenderState {
|
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteBank) RenderState {
|
||||||
batch := pixel.NewBatch(new(pixel.TrianglesData), nil)
|
bgBatch := pixel.NewBatch(new(pixel.TrianglesData), nil)
|
||||||
renderBackground(w, batch)
|
renderBackground(w, bgBatch)
|
||||||
|
|
||||||
colors := teamColors(sNew.Teams)
|
colors := teamColors(sNew.Teams)
|
||||||
ctx := context{
|
ctx := context{
|
||||||
|
@ -75,8 +75,12 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteB
|
||||||
tween: float64(rs.Frame) / float64(rs.Frames),
|
tween: float64(rs.Frame) / float64(rs.Frames),
|
||||||
w: w,
|
w: w,
|
||||||
}
|
}
|
||||||
renderRacers(ctx, colors, sb.racer)
|
rBatch := pixel.NewBatch(new(pixel.TrianglesData), sb.racer)
|
||||||
renderObstacles(sNew, w, sb.obstacle)
|
renderRacers(ctx, rBatch, colors, sb.racer)
|
||||||
|
rBatch.Draw(w)
|
||||||
|
oBatch := pixel.NewBatch(new(pixel.TrianglesData), sb.obstacle)
|
||||||
|
renderObstacles(sNew, w, oBatch, sb.obstacle)
|
||||||
|
oBatch.Draw(w)
|
||||||
|
|
||||||
rs.Frame++
|
rs.Frame++
|
||||||
if rs.Frame > rs.Frames {
|
if rs.Frame > rs.Frames {
|
||||||
|
@ -114,8 +118,7 @@ func renderBackground(w *pixelgl.Window, batch *pixel.Batch) {
|
||||||
batch.Draw(w)
|
batch.Draw(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderRacers(ctx context, colors map[*game.Team]pixel.RGBA, pic pixel.Picture) {
|
func renderRacers(ctx context, batch *pixel.Batch, colors map[*game.Team]pixel.RGBA, pic pixel.Picture) {
|
||||||
batch := pixel.NewBatch(new(pixel.TrianglesData), pic)
|
|
||||||
for i, t := range ctx.sNew.Teams {
|
for i, t := range ctx.sNew.Teams {
|
||||||
c := colors[&ctx.sNew.Teams[i]]
|
c := colors[&ctx.sNew.Teams[i]]
|
||||||
for j, racer := range t.Racers {
|
for j, racer := range t.Racers {
|
||||||
|
@ -134,7 +137,6 @@ func renderRacers(ctx context, colors map[*game.Team]pixel.RGBA, pic pixel.Pictu
|
||||||
|
|
||||||
renderBaton(pos, batch)
|
renderBaton(pos, batch)
|
||||||
}
|
}
|
||||||
batch.Draw(ctx.w)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderRacer(ctx context, batch *pixel.Batch, oldRacer, racer game.Racer, active bool, c pixel.RGBA, pic pixel.Picture) {
|
func renderRacer(ctx context, batch *pixel.Batch, oldRacer, racer game.Racer, active bool, c pixel.RGBA, pic pixel.Picture) {
|
||||||
|
@ -218,7 +220,7 @@ func lanePos(pos, lane int, width float64, bounds pixel.Rect) pixel.Vec {
|
||||||
bounds.Min.Y+float64(lane+1)*vOffset)
|
bounds.Min.Y+float64(lane+1)*vOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderObstacles(s game.State, w *pixelgl.Window, pic pixel.Picture) {
|
func renderObstacles(s game.State, w *pixelgl.Window, batch *pixel.Batch, pic pixel.Picture) {
|
||||||
b := w.Bounds()
|
b := w.Bounds()
|
||||||
im := imdraw.New(nil)
|
im := imdraw.New(nil)
|
||||||
|
|
||||||
|
@ -231,10 +233,10 @@ func renderObstacles(s game.State, w *pixelgl.Window, pic pixel.Picture) {
|
||||||
|
|
||||||
im.Clear()
|
im.Clear()
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
sprite := pixel.NewSprite(pic, pic.Bounds())
|
||||||
sprite.Draw(w, pixel.IM.Moved(pos))
|
sprite.Draw(batch, pixel.IM.Moved(pos))
|
||||||
//im.Circle(float64(racerWidth), 0)
|
//im.Circle(float64(racerWidth), 0)
|
||||||
|
|
||||||
im.Draw(w)
|
im.Draw(batch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue