Exemplo n.º 1
0
func GetEvents(sources []*EventSource) chan interface{} {
	ch := make(chan interface{}, 10)

	sourcesStopped := make(chan bool)
	for _, evSrc := range sources {
		go func() {
			<-evSrc.stopped
			sourcesStopped <- true
		}()
	}

	go func() {
		var queue *C.ALLEGRO_EVENT_QUEUE
		queue = C.al_create_event_queue()
		defer C.al_destroy_event_queue(queue)

		for _, src := range sources {
			ptr := (*C.ALLEGRO_EVENT_SOURCE)(src.src)
			C.al_register_event_source(queue, ptr)
		}

		stopped := false
		for !stopped {
			var gotEv sync.Mutex
			var al_event C.ALLEGRO_EVENT
			gotEv.Lock()
			go func() {
				C.al_wait_for_event(queue, &al_event)
				gotEv.Unlock()
			}()
			go func() {
				<-sourcesStopped
				stopped = true
				gotEv.Unlock()
			}()
			gotEv.Lock()

			ev := toEv(al_event)
			if ev != nil {
				ch <- ev
			}
		}
	}()
	return ch
}
Exemplo n.º 2
0
Arquivo: al.go Projeto: beoran/algo
// Create an event queue.
func CreateEventQueue() *EventQueue {
	return wrapEventQueue(C.al_create_event_queue())
}
Exemplo n.º 3
0
func CreateEventQueue() *EventQueue {
	return (*EventQueue)(unsafe.Pointer(C.al_create_event_queue()))
}