Esempio n. 1
0
func (a *app) Run() {
	// If updates start
	const maxMultipleUpdates = 6

	lastTime := time.Now().UnixNano()

	for len(a.states) > 0 {
		currentTime := time.Now().UnixNano()
		if currentTime-lastTime < a.nanosecondsPerFrame {
			// Avoid busy waiting and take short naps if ahead of schedule.
			// XXX: Is this a good thing?
			time.Sleep(10e6)
			continue
		}

		// If things get slow, tell Update multiple frames have elapsed.
		nUpdates := (currentTime - lastTime) / a.nanosecondsPerFrame

		if nUpdates < 1 {
			nUpdates = 1
		}

		if nUpdates > maxMultipleUpdates {
			nUpdates = maxMultipleUpdates
		}

		a.TopState().Draw()
		gfx.BlitX2(sdl.Frame(), sdl.Video())
		sdl.Flip()

		a.TopState().Update(nUpdates * a.nanosecondsPerFrame)
		lastTime += nUpdates * a.nanosecondsPerFrame
	}
	sdl.Stop()
}
Esempio n. 2
0
func BenchmarkTruecolorBlit(b *testing.B) {
	b.StopTimer()
	sdl.Run(320, 240)
	defer sdl.Stop()
	surf := unpaletted()
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		for y := 0; y < 30; y++ {
			for x := 0; x < 40; x++ {
				surf.Blit(surf.Bounds(), x*8, y*8, sdl.Frame())
			}
		}
		sdl.Flip()
	}
	b.StopTimer()
}