博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Networked Game High-level Structure
阅读量:2340 次
发布时间:2019-05-10

本文共 3234 字,大约阅读时间需要 10 分钟。

[Link]http://www.mindcontrol.org/~hplus/networked-game.html 

 

An often-asked question is how to structure a networked game at the high level: what do you do in the client and in the server, and what do you put into the packets you send?

The basic client loop for this kind of game consists of:

while(true) { read_messages_from_server(); update_objects(); render_scene(); read_user_input(); send_user_input_to_server(); }

Here is the basic loop for the server:

while(true) { service_client_connections(); update_objects(); queue_object_changes_to_clients(); }

Here's what the functions do:

service_client_connections():

Read messages from clients, forwarding them to the appropriate objects. Send as much of you can of each clients outgoing queue to each client (to manage bandwidth). Handle log-in and log-out.

update_objects():

Given the current state of the objects, step one step forward (typically, around 20-50 milliseconds per step), doing collision detection, force and velocity integration, setting off triggered scripting events, etc.

queue_object_changes_to_clients():

Figure out what objects changed the most compared to what the client knows about, and queue data for those objects to the clients. Also, send "new object" messages for any new objects that may have entered the world.

read_messages_from_server():

Read the server connection, and dispatch any messages you receive to the appropriate objects.

update_objects():

Same thing as on the server, except you probably don't want to run the scripts etc; just trust that the scripts will run server-side and send appropriate object state changes to the clients.

render_scene():

Traverse the scene from the point of view of the player camera, rendering stuff to the screen.

read_user_input():

Read keyboard/gamepad/whatever. Deal with OS events as necessary.

send_user_input_to_server():

Package up the data you read from the user, and forward it to the user object on the server.

With this basic implementation, the object you control won't start moving on the screen until the user keypress made it to the server and back. Often, that's quite good enough.

  • There are many different improvements you can make on this scheme:
  • Mask object position updates that put the objects in a different place from where they are currently on the client.
  • Apply user input to the user's object immediately when you send it. Figure out some way to account for corrections from the server that you will receive "in the past".
  • Forward extrapolate various attributes (position, orientation, etc) when you decide where to draw objects, so that objects are drawn in a predicted position where they might be "now" instead of where the server thought they were "back then."
  • Various compression, prioritization and interest management schemes.
  • Various control and state information encoding schemes.

I'd suggest you start with the scheme I describe above first, and then improve from there if necessary.

  <script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>

More pointers can be found in the on .

 

[Summary]展示了基本的High-level logic structure.

improvements: Client interpolation; compression, prioritization

转载地址:http://kdzvb.baihongyu.com/

你可能感兴趣的文章
X264的参考帧设置
查看>>
三种帧的说明
查看>>
感知视频编码
查看>>
深度学习 vs 机器学习 vs 模式识别
查看>>
Tone mapping进化论
查看>>
XAVC
查看>>
详解HDR的三个标准——HLG/HDR10/Dolby Vision
查看>>
流言终结者 1080P全高清都等于高画质?
查看>>
PSNR指标值
查看>>
灰度图像-图像增强 中值滤波
查看>>
两种HDR格式(HLG, HDR10)的理解
查看>>
视频主观质量对比工具(Visual comparision tool based on ffplay)
查看>>
HDMI 接口及CEC信号
查看>>
H.264专利介绍
查看>>
YUV格式小结
查看>>
log4j2.xml实用例子
查看>>
Dockerfile中的CMD和ENTRYPOINT有什么区别?
查看>>
jQuery提示和技巧
查看>>
是否可以在Python中将长行分成多行[重复]
查看>>
使用pip找不到TensorFlow
查看>>