本文整理匯總了Golang中github.com/remogatto/gospeccy/src/spectrum.Application.NewEventLoop方法的典型用法代碼示例。如果您正苦於以下問題:Golang Application.NewEventLoop方法的具體用法?Golang Application.NewEventLoop怎麽用?Golang Application.NewEventLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/remogatto/gospeccy/src/spectrum.Application
的用法示例。
在下文中一共展示了Application.NewEventLoop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewSDLScreen2x
func NewSDLScreen2x(app *spectrum.Application) *SDLScreen2x {
SDL_screen := &SDLScreen2x{
screenChannel: make(chan *spectrum.DisplayData),
screenSurface: NewSDLSurface2x(app),
unscaledDisplay: newUnscaledDisplay(),
updatedRectsCh: make(chan []sdl.Rect),
app: app,
}
go screenRenderLoop(app.NewEventLoop(), SDL_screen.screenChannel, SDL_screen)
return SDL_screen
}
示例2: commandLoop
// The composer's command loop.
// This function runs in a separate goroutine.
func (composer *SDLSurfaceComposer) commandLoop(app *spectrum.Application) {
evtLoop := app.NewEventLoop()
shutdown.Add(1)
for {
select {
case <-evtLoop.Pause:
evtLoop.Pause <- 0
case <-evtLoop.Terminate:
// Terminate this goroutine
if app.Verbose {
app.PrintfMsg("surface compositing loop: exit")
}
evtLoop.Terminate <- 0
shutdown.Done()
return
case untyped_cmd := <-composer.commandChannel:
switch cmd := untyped_cmd.(type) {
case cmd_add:
composer.add(app, cmd.surface, cmd.x, cmd.y, cmd.updatedRectsCh)
case cmd_remove:
composer.remove(cmd.surface, cmd.done)
case cmd_removeAll:
composer.removeAll(cmd.done)
case cmd_setPosition:
composer.setPosition(cmd.surface, cmd.x, cmd.y)
case cmd_replaceOutputSurface:
composer.output_orNil = cmd.surface_orNil
cmd.done <- 0
case cmd_showPaintedRegions:
composer.showPaintedRegions = cmd.enable
composer.repaintTheWholeOutputSurface()
case cmd_update:
composer.performCompositing(cmd.surface.x, cmd.surface.y, cmd.rects)
}
}
}
}
示例3: NewSDLAudio
// Opens SDL audio.
// If 'playbackFrequency' is 0, the frequency will be equivalent to PLAYBACK_FREQUENCY.
func NewSDLAudio(app *spectrum.Application, playbackFrequency uint, hqAudio bool) (*SDLAudio, error) {
if playbackFrequency == 0 {
playbackFrequency = PLAYBACK_FREQUENCY
}
if playbackFrequency < MIN_PLAYBACK_FREQUENCY {
return nil, errors.New(fmt.Sprintf("playback frequency of %d Hz is too low", playbackFrequency))
}
// Open SDL audio
var spec sdl_audio.AudioSpec
{
spec.Freq = int(playbackFrequency)
spec.Format = sdl_audio.AUDIO_S16SYS
spec.Channels = 1
spec.Samples = uint16(2048 * float32(playbackFrequency) / PLAYBACK_FREQUENCY)
if sdl_audio.OpenAudio(&spec, &spec) != 0 {
return nil, errors.New(sdl.GetError())
}
if app.Verbose {
app.PrintfMsg("%#v", spec)
}
}
audio := &SDLAudio{
data: make(chan *spectrum.AudioData),
playback: make(chan *spectrum.AudioData, 2*BUFSIZE_IDEAL), // Use a buffered Go channel
playbackLoopFinished: make(chan byte),
forwarderLoopFinished: nil,
sdlAudioUnpaused: false,
bufSize: 0,
freq: uint(spec.Freq),
virtualFreq: uint(spec.Freq),
hqAudio: hqAudio,
}
go forwarderLoop(app.NewEventLoop(), audio)
go playbackLoop(app, audio)
return audio, nil
}
示例4: add
func (composer *SDLSurfaceComposer) add(app *spectrum.Application, surface *sdl.Surface, x, y int, updatedRectsCh <-chan []sdl.Rect) {
newInput := &input_surface_t{
surface: surface,
updatedRectsCh: updatedRectsCh,
forwarderLoop: app.NewEventLoop(),
x: x,
y: y,
}
composer.inputs = append(composer.inputs, newInput)
updateRect := sdl.Rect{
X: int16(0),
Y: int16(0),
W: uint16(newInput.surface.W),
H: uint16(newInput.surface.H),
}
composer.performCompositing(x, y, []sdl.Rect{updateRect})
go composer.forwarderLoop(newInput)
}
示例5: sdlEventLoop
// A Go routine for processing SDL events.
func sdlEventLoop(app *spectrum.Application, speccy *spectrum.Spectrum48k, verboseInput bool) {
evtLoop := app.NewEventLoop()
consoleIsVisible := false
shutdown.Add(1)
for {
select {
case <-evtLoop.Pause:
evtLoop.Pause <- 0
case <-evtLoop.Terminate:
// Terminate this Go routine
if app.Verbose {
app.PrintfMsg("SDL event loop: exit")
}
evtLoop.Terminate <- 0
shutdown.Done()
return
case event := <-sdl.Events:
switch e := event.(type) {
case sdl.QuitEvent:
if app.Verbose {
app.PrintfMsg("SDL quit -> request[exit the application]")
}
app.RequestExit()
case sdl.JoyAxisEvent:
if verboseInput {
app.PrintfMsg("[Joystick] Axis: %d, Value: %d", e.Axis, e.Value)
}
if e.Axis == 0 {
if e.Value > 0 {
speccy.Joystick.KempstonDown(spectrum.KEMPSTON_RIGHT)
} else if e.Value < 0 {
speccy.Joystick.KempstonDown(spectrum.KEMPSTON_LEFT)
} else {
speccy.Joystick.KempstonUp(spectrum.KEMPSTON_RIGHT)
speccy.Joystick.KempstonUp(spectrum.KEMPSTON_LEFT)
}
} else if e.Axis == 1 {
if e.Value > 0 {
speccy.Joystick.KempstonDown(spectrum.KEMPSTON_UP)
} else if e.Value < 0 {
speccy.Joystick.KempstonDown(spectrum.KEMPSTON_DOWN)
} else {
speccy.Joystick.KempstonUp(spectrum.KEMPSTON_UP)
speccy.Joystick.KempstonUp(spectrum.KEMPSTON_DOWN)
}
}
case sdl.JoyButtonEvent:
if verboseInput {
app.PrintfMsg("[Joystick] Button: %d, State: %d", e.Button, e.State)
}
if e.Button == 0 {
if e.State > 0 {
speccy.Joystick.KempstonDown(spectrum.KEMPSTON_FIRE)
} else {
speccy.Joystick.KempstonUp(spectrum.KEMPSTON_FIRE)
}
}
case sdl.KeyboardEvent:
keyName := sdl.GetKeyName(sdl.Key(e.Keysym.Sym))
if verboseInput {
app.PrintfMsg("\n")
app.PrintfMsg("%v: %v", e.Keysym.Sym, keyName)
app.PrintfMsg("Type: %02x Which: %02x State: %02x\n", e.Type, e.Which, e.State)
app.PrintfMsg("Scancode: %02x Sym: %08x Mod: %04x Unicode: %04x\n", e.Keysym.Scancode, e.Keysym.Sym, e.Keysym.Mod, e.Keysym.Unicode)
}
if (keyName == "escape") && (e.Type == sdl.KEYDOWN) {
if app.Verbose {
app.PrintfMsg("escape key -> request[exit the application]")
}
app.RequestExit()
} else if (keyName == "f10") && (e.Type == sdl.KEYDOWN) {
//if app.Verbose {
// app.PrintfMsg("f10 key -> toggle console")
//}
if !r.toggling {
r.toggling = true
if r.cliSurface_orNil == nil {
done := make(chan bool)
r.cliSurfaceCh <- cmd_newCliSurface{newCLISurface(r.scale2x, r.fullscreen), done}
<-done
}
anim := clingon.NewSliderAnimation(0.500, 1.0)
var targetState int
if consoleIsVisible {
targetState = HIDE
} else {
//.........這裏部分代碼省略.........