使用 javaNIO 发送游戏/模拟状态有哪些可能的方法?

发布于 2024-10-27 07:30:28 字数 315 浏览 6 评论 0原文

我经常听到这句话在网络游戏/模拟领域“发送游戏状态或模拟状态”,我的问题源于此,我真的需要知道如何? 。

我正在研究实时网络物理模拟,我的问题只是: *模拟状态如何从服务器传输到客户端*? (最少的模拟状态是模拟物体的坐标X,Y=))

可能的场景:以简单的球模拟为例,服务器正在移动多个球,并且应该将每个球的坐标发送给客户端以绘制和更新模拟,每个球应该根据从服务器接收到的坐标移动。

谢谢,

jibbylala

P.S:请不要提及任何基于字符串的解决方案,我正在寻找可适用于不同物理模拟的通用机制。

i heard this phrase quite often to "send the game state or simulation state " in network game/simulation realm and my question is stem from that and i really need to know how? .

I m working on real time network physics simulation, my question is only that :
*How simulation state can be transfer from server to client*? (the least simulation state are the coordinates X,Y of simulated bodies=))

Possible scenario: taking the example of simple ball simulation, the server is moving the multiple balls and should send coordinates of each ball to client for drawing and updating simulation, and each ball should move according to its received coordinates from the sever.

thanks,

jibbylala

P.S: please don't mention any string based solution i am looking for generic mechanism which can be applicable on different Physics simulation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久隐师 2024-11-03 07:30:29

在快节奏的动作游戏中,动态对象的状态在结构中不断发送。我所说的状态通常是位置和旋转。根据模型的架构,服务器可以不断推送状态,或者在状态发生变化时发送状态变化。更多时候是第一个。当一段时间内没有收到状态时,就会出现游戏滞后。状态还可以具有速度、加速度等参数,这实际上取决于游戏以及您想要如何处理游戏事件。假设我们正在编写简单的 2D 游戏,水面上有飞船,那么状态可以是 java 中的一个简单类,例如:

class ShipState{ 
      public float x; 
      public float y; 
      public float angle;
}

游戏中的网络代码负责传输这些结构。游戏通常有自己的基于 TCP/IP 和 UDP 的协议来处理所有事情,因为在真实游戏中,有很多不同类型的信息双向传递,而不仅仅是物理状态。如果你认真对待你的项目,你应该真正研究一下网络库。我强烈怀疑有什么真正好的东西,因为 JAVA 在这个领域并不是很流行。单个 Google 请求调出了这个 Kryo 库,它看起来相当不错。您还可以查看 netty,这是一个非常可靠的通用网络库。如果我要用 Java 编写游戏网络代码,我只会去挖掘用 C/C++ 编写的开源游戏网络库,例如 Enet 来获取一些想法。

追根溯源,关于服务器上的球模拟,就像服务器发送球坐标和客户端接收这些坐标一样简单。如果您不确定它是如何完成的,您可能需要查看 这些教程。以及其他一般 Java 网络教程。祝你好运!

In fast paced action games, the state of dynamic objects is sent constantly in structures. By state I mean it is usually position and rotation. Depending on model's architecture, it can be server constantly pushing the states, or sending the change in state when it occurs. More often the first one. When the state is not received in some period of time the game lag occurs. The state can also have parameters such as velocity, acceleration, etc. really depends on game and on how you want to handle game events. Lets say we are writing simple 2D game with flying ships on surface then the state could be a simple class in java like:

class ShipState{ 
      public float x; 
      public float y; 
      public float angle;
}

The netcode in game takes care of transporting these structures. Games usually have their own protocol built on top of TCP/IP and UDP to handle everything, since there is lot of different type of information going both ways in real games, not just physical state. If you are serious about your project, you should really look into networking libraries. I strongly doubt there is anything really good, since JAVA is not very popular on this frontier. Single google request brought up this Kryo library which seems pretty good. You could also probably look into netty, which is a very solid general purpose networking library. If I was to write a netcode for game in Java I would just go and dig up open source game networking libraries written in C/C++, such as Enet to get some ideas.

Getting to the bottom of your question, regarding the ball simulation on server, it is as simple as server sending ball coordinates and clients receiving those. If you are not sure how it is done, you probably want to look at these tutorials. And other general Java networking tutorials. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文