我正在为一个相当复杂的视频游戏做一些概念验证工作,我想使用HOpenGL库在Haskell中编写.我开始编写一个实现基于客户端 - 服务器事件的通信的模块.当我尝试将其连接到一个简单的程序以在屏幕上绘制点击时,我的问题出现了.
事件库使用TChans列表作为优先级队列进行通信.它返回一个"out"队列和一个对应于服务器绑定和客户端绑定消息的"in"队列.发送和接收事件使用forkIO在单独的线程中完成.在没有OpenGL部分的情况下测试事件库表明它成功通信.这是我用来测试它的代码:
-- Client connects to server at localhost with 3 priorities in the priority queue
do { (outQueue, inQueue) <- client Nothing 3
-- send 'Click' events until terminated, the server responds with the coords negated
; mapM_ (\x -> atomically $ writeThing outQueue (lookupPriority x) x)
(repeat (Click (fromIntegral 2) (fromIntegral 4)))
}
Run Code Online (Sandbox Code Playgroud)
这会产生预期的输出,即大量的发送和接收事件.我认为问题不在于事件处理库.
代码的OpenGL部分检查传入队列中displayCallback中的新事件,然后调用事件的关联处理程序.我可以得到一个事件(Init事件,它只是清除屏幕)被displayCallback捕获,但之后没有任何事情被捕获.这是相关的代码:
atomically $ PQ.writeThing inqueue (Events.lookupPriority Events.Init) Events.Init
GLUT.mainLoop
render pqueue =
do event <- atomically $
do e <- PQ.getThing pqueue …Run Code Online (Sandbox Code Playgroud)