-
Notifications
You must be signed in to change notification settings - Fork 87
[Utility] Support online multi-player mode #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
我讲讲我的理解看有没有问题:
这个实现在当前框架中非常简单直接!Thanks for your great work! 当然,这种实现的主要缺点是对延迟和丢包率要求极高,延迟或丢包会导致input queue不同步,不同客户端渲染不一致。不过在局域网内跑都没问题,之后我们再慢慢整。 |
src/battle_game/app/app.h
Outdated
Mode mode_{kOffline}, chosen_mode_{kOffline}; | ||
bool render_{true}; | ||
bool input_data_synced_; | ||
std::queue<std::vector<MessageInputData>> input_data_queue_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的input_data_queue_
因为会被两个线程同时访问,需要加std::mutex
。类似的还有input_data_
。不过write_messages_
应该不用,因为只有io_context
进行单线程访问。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来问题还有在另一个线程中调用app_->Start()
与app_->Stop()
之类的:sob:我有空多改改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在应该改好了。
In my implementation, the transmitted information is the users' input data, and all the computations are distributed to the clients.
You can start a server in the app window, or use
where the default port is 8088.
Currently I've only tested the situation where one player is connected to localhost and the server is run in the command line only. Because it was for the first time that I wrote asynchronous program using multithread, I think it must contains many bugs (, so you are welcomed to rewrite the server/client parts). It seems that the servers and clients sometimes crash.
Something we can do later:
glm::vec2
to bytes is directly usingmemcpy
);