使用 MVC 模式避免多人游戏和重播中出现同步问题的提示
只是想知道人们有什么技巧可以避免多人游戏中的游戏同步问题以及使用模型视图控制器模式中的模型记录游戏逻辑的重播问题,
到目前为止,我意识到在外部任何地方提供对模型的非常量访问并不是一个好主意其中,但除此之外,我有点卡住了,仍然有一些同步问题,
谢谢
just wondering what tips people have for avoiding game synchronisation issues in multiplayer games and replays recorded off of game logic using the model in a model view controller pattern
so far im aware that its not a good idea to give non const access to the model anywhere outside of it, but apart from that im a little stuck and still have a number of sync issues
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了实现分布式同步,您需要指定一个主模型,最好是在单独的游戏服务器上。 控制事件到达那里,获得时间戳,计算发生的所有事情的交互,并发送带有时间戳的更新事件。 只需存储和重播更新事件即可完成重播。
由于模型在单独的服务器上运行,您甚至无法向视图授予对它的常量(同步)访问权限。 通用 MVC 并不是真正正确的方法,它更多的是:
两个流绝对是异步的,并且可能是 UDP,因此有损。
避免多线程,如果有的话,它应该完全本地化在上述组件之一内(例如选择器内的线程池,模型中每个区域一个线程)。
对于很多游戏,出于性能原因,您需要破坏该模型并让控制器直接更新本地模型的某些部分(例如,您可以在拔掉互联网连接的情况下在 Wow 中四处走动)。 这肯定会导致同步问题,但对于 ping 时间 > 的网络上的实时游戏来说可能无法避免。 人的反应时间。
To achieve distributed synchronisation, you need a designated single master model, ideally on a separate game server. Control events go to that, get timestamped, the interactions of everything going on gets calculated, and timestamped update events get sent out. Replays can be done just by storing and replaying the update events.
As the model is running on a separate server, you can't even give the view const (synchronous) access to it. General purpose MVC isn't really the right approach, it is more:
Where the two streams are definitely asynchronous and probably UDP, so lossy.
Avoid multithreading, if you have any it should be entirely localised within one of the above components (for example thread pooling within the selector, one thread per zone in the model).
For a lot of games, for performance reasons you will need to break that model and have the controller update some parts of the local model directly (e.g the way you can walk around in Wow with your internet connection unplugged). This will definitely lead to sync problems, but probably can't be avoided for a realtime game on a network with ping time > human reaction time.
你所说的同步是指多线程同步吗? 如果是这种情况我会使用互斥锁。 如果您的意思是通信同步,您能解释一下正在发生的事情吗?
By synchronization do you mean multithread synchronization? If it is the case I would use a mutex. If you meant communications synchronization can you explain a bit more what is happening?