Esempio n. 1
0
func main() {
	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		panic(sdl.GetError())
	}

	defer sdl.Quit()

	screen := sdl.SetVideoMode(400, 300, 32, 0)
	if screen == nil {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("Template", "")

	ticker := time.NewTicker(1e9 / 2 /*2 Hz*/)

loop:
	for {
		select {
		case <-ticker.C:
			// Note: For better efficiency, use UpdateRects instead of Flip
			screen.FillRect(nil /*color*/, rand.Uint32())
			//screen.Blit(&sdl.Rect{x,y, 0, 0}, image, nil)
			screen.Flip()

		case event := <-sdl.Events:
			fmt.Printf("%#v\n", event)

			switch event.(type) {
			case sdl.QuitEvent:
				break loop
			}
		}
	}
}
Esempio n. 2
0
func main() {
	verbose := flag.Bool("verbose", false, "verbose mode")
	debug := flag.Bool("debug", false, "debug mode")
	fullScreen := flag.Bool("fullscreen", false, "go fullscreen")
	cpuProfile := flag.String("cpuprofile", "", "write cpu profile to file")
	help := flag.Bool("help", false, "Show usage")
	flag.Usage = usage
	flag.Parse()

	if *help {
		usage()
		return
	}

	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	application.Verbose = *verbose
	application.Debug = *debug

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		log.Fatal(sdl.GetError())
	}

	screen := sms.NewSDL2xScreen(*fullScreen)
	sdlLoop := sms.NewSDLLoop(screen)
	emulatorLoop := newEmulatorLoop(sdlLoop)
	if emulatorLoop == nil {
		usage()
		return
	}
	cpuProfiling := *cpuProfile != ""
	commandLoop := newCommandLoop(emulatorLoop, sdlLoop, cpuProfiling)
	inputLoop := sms.NewInputLoop(emulatorLoop.sms)

	application.Register("Emulator loop", emulatorLoop)
	application.Register("Command loop", commandLoop)
	application.Register("SDL render loop", sdlLoop)
	application.Register("SDL input loop", inputLoop)

	exitCh := make(chan bool)
	application.Run(exitCh)
	<-exitCh
	sdl.Quit()
}
Esempio n. 3
0
// TODO: Sprite are not free (sdl)
func (this *RenderManager) Quit() {
	// image.Free()
	sdl.Quit()
}
Esempio n. 4
0
func (v *Video) Close() {
	sdl.Quit()
}
Esempio n. 5
0
func Main() {
	var init_waitGroup *sync.WaitGroup
	init_waitGroup = env.WaitName("init WaitGroup").(*sync.WaitGroup)
	init_waitGroup.Add(1)

	var app *spectrum.Application
	app = env.Wait(reflect.TypeOf(app)).(*spectrum.Application)

	var speccy *spectrum.Spectrum48k
	speccy = env.Wait(reflect.TypeOf(speccy)).(*spectrum.Spectrum48k)

	if !*enableSDL {
		return
	}

	uiSettings = &InitialSettings{
		scale2x:            Scale2x,
		fullscreen:         Fullscreen,
		showPaintedRegions: ShowPaintedRegions,
		audio:              Audio,
		audioFreq:          AudioFreq,
		hqAudio:            HQAudio,
	}

	composer = NewSDLSurfaceComposer(app)
	composer.ShowPaintedRegions(*ShowPaintedRegions)

	// SDL subsystems init
	if err := initSDLSubSystems(app); err != nil {
		app.PrintfMsg("%s", err)
		app.RequestExit()
		return
	}

	// Setup the display
	r = NewSDLRenderer(app, speccy, *Scale2x, *Fullscreen, *Audio, *HQAudio, *AudioFreq)
	setUI(r)
	initCLI()

	// Setup the audio
	if *Audio {
		audio, err := NewSDLAudio(app, *AudioFreq, *HQAudio)
		if err == nil {
			speccy.CommandChannel <- spectrum.Cmd_AddAudioReceiver{audio}
		} else {
			app.PrintfMsg("%s", err)
		}
	}

	// Start the SDL event loop
	go sdlEventLoop(app, speccy, *verboseInput)

	init_waitGroup.Done()

	hint := "Hint: Press F10 to invoke the built-in console.\n"
	hint += "      Input an empty line in the console to display available commands.\n"
	fmt.Print(hint)

	// Wait for all event loops to terminate, and then call 'sdl.Quit()'
	shutdown.Wait()
	if r.app.Verbose {
		r.app.PrintfMsg("SDL: sdl.Quit()")
	}
	sdl.Quit()
}
Esempio n. 6
0
func BenchmarkRender(b *testing.B) {
	b.StopTimer()

	initSDL()

	app := spectrum.NewApplication()

	sdlScreen := &SDLScreen{
		screenChannel:   make(chan *spectrum.DisplayData),
		screenSurface:   &SDLSurface{newSurface()},
		unscaledDisplay: newUnscaledDisplay(),
		updatedRectsCh:  make(chan []sdl.Rect),
		app:             app,
	}

	rom, err := spectrum.ReadROM("testdata/48.rom")
	if err != nil {
		panic(err)
	}

	speccy := spectrum.NewSpectrum48k(app, *rom)
	speccy.CommandChannel <- spectrum.Cmd_AddDisplay{sdlScreen}

	snapshot, err := formats.ReadProgram("testdata/fire.z80")
	if err != nil {
		panic(err)
	}

	errChan := make(chan error)
	speccy.CommandChannel <- spectrum.Cmd_LoadSnapshot{"<fire>", snapshot.(formats.Snapshot), errChan}
	err = <-errChan
	if err != nil {
		panic(err)
	}

	// Capture a number of frames sent from 'speccy' to the rendering backends
	const numFrames = 1000
	var frames [numFrames]*spectrum.DisplayData
	{
		go func() {
			for i := 0; i < numFrames; i++ {
				speccy.CommandChannel <- spectrum.Cmd_RenderFrame{nil}
			}
		}()

		for i := 0; i < numFrames; i++ {
			frames[i] = <-sdlScreen.screenChannel
		}
	}

	// The actual benchmark
	{
		b.StartTimer()

		go func() {
			for {
				<-sdlScreen.updatedRectsCh
				sdlScreen.screenSurface.surface.Flip()
			}
		}()

		for i := 0; i < b.N; i++ {
			sdlScreen.render(frames[i%numFrames])
		}

		b.StopTimer()
	}

	app.RequestExit()
	<-app.HasTerminated

	sdl.Quit()
}