运行无阻塞
我是扭曲和编程的新手,我正在制作多人游戏,我需要客户端做的是将玩家的位置发送到服务器并检索对手的位置,但是当我运行反应堆时陷入检查事件的循环中,我想要它做的是获取并发送数据,然后继续运行游戏循环。
I'm new to twisted and programming, I'm making a multiplayer game, and what i need the client to do is send the location of the player to the server and retrieve the location of the opponent, but when I run the reactor it gets stuck in the loop checking for events, what I want it to do is get and send data and then continue to run the game loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想做的事情与 Game 所做的事情几乎相同。重要的是,您不想“运行反应堆......然后继续运行游戏循环”。您希望反应器和游戏循环同时运行。特别是,看看这个 go 方法,其中设置了 100Hz 渲染循环和 25Hz 输入处理循环,并且此 start 方法,其中设置模型模拟循环。
这些循环都可以运行,因为它们使用reactor的调度API,并且由于它们在reactor运行时运行,因此也可以同时处理网络事件。
It sounds like you want to do just about the same thing as is done by Game. Importantly, you don't want to "run the reactor ... and then continue to run the game loop". You want the reactor and the game loop running in tandem. In particular, take a look at this go method, where a 100Hz rendering loop and a 25Hz input handling loop are set up, and this start method where a model simulation loop is set up.
These loops can all run because they use the reactor's scheduling APIs, and since they run while the reactor is running, network events can be handled at the same time as well.