本文介绍了本地主机上的2人游戏,客户端和服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 大家。 我正在写一个应该支持网络模式的2人游戏。我现在在一台PC上测试它是因为我没有2.我直接使用套接字,并且 客户端和服务器都进行计算,这是唯一的数据转移是 用户鼠标/ kbd输入。 它同步工作,但不知何故,当我在客户端窗口玩时, 客户端和服务器都有17 fps,而在服务器上玩时,b / b 窗口,服务器有44 fps而客户端有5 fps,并且由于强制 同步,它们都运行非常慢(我想知道怎么来服务器 说它有44fps?)。 有谁知道这怎么可能?并不是说用户会通过localhost测试2个游戏内容,但是我需要正常工作 。 - - 最诚挚的问候, Michael Rybak mailto:ac ****** @ ukr.net 解决方案 我建议不要花时间分析,调试,优化 home -brewed"使用套接字实现,但切换到Twisted或Pyro 或类似的东西,为自己省去了很多麻烦。 这可能会让事情变得神奇可接受的水平。 -Peter DLB> ;定义正常工作......听起来他们正在工作 DLB>正确/编码/并受OS优先级方案的影响。我 DLB>说编码因为,正如我在第一段中所提到的那样,听起来好像是b $ b DLB>就像你让你的服务器做双重任务 - 无论是作为客户还是作为 DLB>第二个客户端的服务器。服务器不应该有任何客户端 DLB>类型接口(启动和关闭或调试覆盖除外) DLB>命令)。所有基于帧的渲染都应该在客户端中。我还 DLB>怀疑,有两个客户和一台服务器,你会看到相同的行为 DLB> - 非输入 - 客户端将以较低的优先级运行,因此 DLB>实现较低的帧速率。 DLB>这听起来像你的服务器正在做类似的事情: DLB>循环 DLB>如果socket有数据那么 DLB>读取插座 DLB>计算新州 DLB>发送回复 DLB>结束如果 DLB>讨厌的计算 DLB>结束循环 DLB>这个逻辑将吸收尽可能多的CPU时间,因为操作系统将给出 DLB>程序...如果客户端看起来像 DLB>循环 DLB>将数据发送到服务器 DLB>阅读回复(阻止) DLB>讨厌的计算 DLB>结束循环 DLB>那么它不仅要争夺CPU时间,它什么也不做,而 DLB>等待服务器处理IF块内的部分。 DLB>但是如果你输入类似os.sleep(0.025) DLB>会发生什么?循环内?假设循环需要0.025秒来处理,总数 DLB>到达0.05秒(20fps)并释放CPU用于其他过程 DLB>计算。 DLB> - DLB> > ================================================== ============< DLB> > wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG< DLB> > wu******@dm.net | Bestiaria支持人员< DLB> > ================================================== ============< DLB> >主页:< http://www.dm.net/~wulfraed/> < DLB> >溢出页面:< http://wlfraed.home.netcom.com/> < - 最诚挚的问候, Michael Rybak mailto:ac ****** @ ukr.net hi, everyone.I''m writing a 2-players game that should support network mode. I''m nowtesting it on 1 PC since I don''t have 2. I directly use sockets, andboth client and server do computations, the only data transfered isuser mouse/kbd input.It works synchronously, but somehow, when I play in client window,both client and server have 17 fps, while when playing in serverwindow, server has 44 fps while client has 5, and due to forcedsynchronization, they both run very slowly (I wonder how come serversays it has 44fps?).Does anybody have an idea how can this be? Not that users will test 2game intances communicating via localhost, but I need to make it workproperly.--Best Regards,Michael Rybak mailto:ac******@ukr.net 解决方案I''d suggest not spending time profiling, debugging, optimizing a"home-brewed" implementation using sockets but switch to Twisted or Pyroor something like that and save yourself a lot of headaches.Chances are this will magically speed things up to acceptable levels, too.-PeterDLB> Define "work properly"... It sounds like they are workingDLB> properly /as coded/ and are being affected by OS priority schemes. IDLB> say "as coded" since, as I mentioned in the first paragraph, it soundsDLB> like you have your server doing double duty -- both as a client and asDLB> the server for the second client. The server should not have ANY clientDLB> type interface (other than start-up and shut-down or debug overrideDLB> commands). All frame-based rendering should be in the clients. I alsoDLB> suspect that, with two clients and a server, you''d see the same behaviorDLB> -- the "non-input" client will be running at a lower priority, therebyDLB> achieving a lower frame-rate.DLB> It also sounds like your server is doing something like:DLB> loopDLB> if socket has data thenDLB> read socketDLB> compute new stateDLB> send replyDLB> end ifDLB> do nasty computationDLB> end loopDLB> This logic will suck up as much CPU time as the OS will give theDLB> program... While if the client looks likeDLB> loopDLB> send data to serverDLB> read reply (blocking)DLB> do nasty computationDLB> end loopDLB> then it not only has to compete for CPU time, it does nothing whileDLB> waiting for the server to handle the section inside the IF block.DLB> But what would happen if you put something like os.sleep(0.025)DLB> inside the loops? Assuming the loop takes 0.025sec to process, the totalDLB> comes to 0.05 seconds (20fps) AND releases the CPU for the other processDLB> to compute.DLB> --DLB> > ================================================== ============ <DLB> > wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <DLB> > wu******@dm.net | Bestiaria Support Staff <DLB> > ================================================== ============ <DLB> > Home Page: <http://www.dm.net/~wulfraed/> <DLB> > Overflow Page: <http://wlfraed.home.netcom.com/> <--Best Regards,Michael Rybak mailto:ac******@ukr.net 这篇关于本地主机上的2人游戏,客户端和服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-09 02:45