我需要向sdl-applications的几个实例之一发送一个退出信号。如果我这样做(sdl2:push-event:quit)或(sdl2:push-quit-event)它会转到任何/所有应用程序,我只需要它一个。
所以我尝试注册一个用整数作为数据的用户定义事件,但不能让它退出事件循环,如:quit does。这可能吗?
这是一个小测试程序,显示了我想要做的事情。执行(sdl2:push-event:quit)两次终止程序,但尝试使用:my-quit只打印数据值,但不退出循环。
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :bordeaux-threads)
(ql:quickload :sdl2))
(defparameter *display* 0)
(defun sdl1 ()
(sdl2:with-init (:video)
(sdl2:hide-cursor)
(sdl2:with-window (win
:x (sdl2:windowpos-centered *display*)
:y (sdl2:windowpos-centered *display*)
:flags '())
(sdl2:with-renderer (ren win)
(dotimes (n 2)
(sdl2:with-event-loop (:method :poll)
(:idle ()
(sdl2:set-render-draw-color ren (* n 50) (* n 50) (* n 50) 255)
(sdl2:render-clear ren)
(sdl2:render-present ren)
(sleep 2))
(:my-quit (:user-data data)
(pprint data)
t)
(:quit () t)))))))
(defun sdltest (d)
(setf *display* d)
(sdl2:register-user-event-type :my-quit)
(bt:make-thread (lambda () (sdl2:make-this-thread-main #'sdl1)))
(sleep 1)
(sdl2:push-user-event :my-quit 0))