Example #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
}
Example #2
0
File: al.go Project: beoran/algo
// Waits for the next event from the event queue
func (self *EventQueue) WaitForEvent() (event *Event) {
	event = &Event{}
	C.al_wait_for_event(self.handle, event.toC())
	return event
}
Example #3
0
func (e *EventQueue) WaitForEvent() *Event {
	ev := new(Event)
	C.al_wait_for_event((*C.ALLEGRO_EVENT_QUEUE)(unsafe.Pointer(e)), (*C.ALLEGRO_EVENT)(unsafe.Pointer(ev)))
	return ev
}