-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Emulated local Wi-Fi multiplayer support #242
base: dev
Are you sure you want to change the base?
Conversation
Thanks for contributing! I'll review and test this and get back to you as soon as I can. |
72efaba
to
1d5cb99
Compare
I seem to have made a bit of a mess when trying to rebase this to the dev branch. I Will try to fix it. |
1d5cb99
to
2d2c7fc
Compare
Would close issue #225 |
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.
Thanks for your contribution, and for your patience. Broadly speaking this looks okay, but there are some changes I'd like you to make. Some of the proposed changes will reduce the number of copies made of packets, which may help performance.
I also suggest adding Tracy markers at the start of important functions, then running a RelWithDebInfo
build through Tracy.
Once you make these changes I'll take another review pass and test it. Keep up the good work!
Added the tracepoints, will run with Tracy and analyze the result later. |
Ran it with Tracy, it appears that most of the time spent in the multiplayer code is spent waiting blocking for a packet. Sending a packet and receiving one are super quick by comparison. |
I've been trying to get Tracy to connect to my Android phone, but no luck so far. Any ideas? |
After testing more, it seems timeout has little impact on performance. However, too low of a timeout will cause frequent crashes. The value of 25 ms is good. |
I'll test this today and get back to you with thoughts. I'll also compare this to the upstream implementation, see if there's something we can do about the blocking. |
src/libretro/net/mp.cpp
Outdated
// Necessary because arithmetic on void* is forbidden | ||
const char *indexableBuf = (const char *)buf; | ||
const char *data = indexableBuf + HeaderSize; | ||
retro_assert(len > HeaderSize); |
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.
Looks like this assertion doesn't hold up; I just triggered it in Mario Kart DS. I created the in-game lobby from one of my devices, but as soon as the second device connected this retro_assert
went off.
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.
Try changing it to len >= HeaderSize
. If it works, then zero sized packets are possible.
Interestingly, I was not able to reproduce this.
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.
Managed to reproduce it, but switching to len >= HeaderSize
fixes it.
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.
What game did you test it with? I used Mario Kart DS.
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.
Me too. .nds file format, MD5 hash: 8cbf438d5a7c0d9acbe56a9b627ca6c5
The game indeed crashes if the condition is len > HeaderSize
but switching to len >= HeaderSize
fixed it for me.
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.
I initially tested it with Pokémon HeartGold as well.
I had a chance to reproduce the lag in the core you described. Notably, standalone melonDS does not have this issue. Before we can merge this PR, we need to diagnose the lag and see how much of it actually comes from the core. I'll take some traces and get back to you. |
When you took your trace, what build settings did you use? I built the core (but not RetroArch itself) with optimizations and the lag wasn't as pronounced. I'm still looking over the trace for specifics. |
The traces I took were taken in a RelWithDebInfo build. |
I wonder if upstream melonDS does the same thing? I'll look into it. |
The lag is far less pronounced when building the core in Let me see what happens when using a wireless connection. |
Not too bad over wireless. It looks like on frames where |
This patch adds support for emulated local (Wi-Fi) multiplayer using libretro's netpacket API, which allows a core to send and receive arbitrary data packets across the network. In RetroArch, this can be done by using the same interface used for netplay.
Unfortunately, due to the DS's tight latency requirements for local networks, it only works for good LAN connections on a few games. I managed to play Pokémon HeartGold between my phone (connected to a WiFi AP very close by) and my PC (wired), for example. On an emulated connection, the same game worked with 8ms ping and 3% packet loss, but it could get rather laggy at times.
Thanks to @JesseTG for helping me with this.