我正在通過UDP實現聯網小行星。我打算限制客戶端發送的用戶輸入消息爲變化。因此,只有在箭頭鍵或空格鍵上存在鍵或鍵時才發送消息。這將大大減少從客戶端發送的數據包數量。在網絡遊戲中通過UDP發送鍵盤輸入
但是,現在我已經重讀了Gaffers關於網絡物理的文章和他關於使UDP消息可靠的更復雜的一個我正在反思。他指出:
The key to making this input stream tolerant of packet loss and out of order delivery is the inclusion of a floating point time in seconds value with every input rpc sent. The server keeps track of the current time on the server and ignores any input received with a time value less than the current time. This effectively drops any input that is received out of order. Lost packets are ignored.
所以,如果一個數據包丟失是不關心。現在我正在想,指示keydown向前推進船的重要數據包可能會被丟失,並且永遠不會怨恨,從而打破遊戲。
我,因此我說得對客戶端,而不是被迫派遣更多的定期(高達每物理學更新,每秒50次)轉儲實際鍵盤的狀態而不是國家改變以配合這容忍丟包的方案?還是有更高尚的方式?
這是網絡多人遊戲中最困難的事情之一。沒有適用於每場比賽的通用解決方案。許多動作遊戲使用近似和預測這些東西。之前我已經編制了一款多人跳板/打磚塊/乒乓球克隆,而且很難流利地做到這一點。像素動作遊戲通常在定位方面要求相當高的準確性,但也要求定時。 – 2012-04-05 07:29:12
遊戲將在我的家庭網絡CAT 5E或大學校園播放。我的滯後性會很低。目前使用C++進行測試的時間<3 ms。 – ScrollerBlaster 2012-04-05 07:47:39