The local multiplayer saga, ep 7
At this point, we should have this published on Netflix or something :P

In the previous post, we saw that we had lag in some games because the client was sometimes not replying, so I had to deal with that issue.

I introduced the new local-multiplayer data exchange/sync mechanism in ep 2, and since then it has seen several iterations as I made it simpler and more efficient.

For one, I used special-purpose microsecond counters for this instead of relying on USCOUNT. The first issue there was with that was that USCOUNT can be disabled or modified at any time by software, which isn't ideal if we're going to rely on it for sync purposes. Second benefit is that now, when a client connects, I can just sync up its counter to the host's, and not have to deal with any offset between the two. So, all in all, it's more reliable this way, and a lot easier to deal with.

Next change was that I got rid of the specific 'sync point' messages and simply attached timestamps to packets. This reduces the amount of data being exchanged, and let me simplify the sync mechanism too. Now, when receiving a packet from the host, clients know when to actually start emulating reception of that packet, and how long they can keep running on their own before having to wait for another packet from the host. This way, clients can't run too far ahead of the host, and we also ensure the host doesn't run too far ahead by dropping any replies that are too old. All in all, this system is more efficient.

Lately, I also reworked how replies are dealt with, to make things more efficient and reliable, and to deal with the issue at hand in this post. Replies go through a separate FIFO, and instead of being broadcast to everybody, they're only received by the host, which mirrors the way local-multiplayer communication works in real life.

To deal with the problem of clients sometimes not being ready to reply, I simply made clients send a blank if they receive a CMD frame they can't reply to. The blank is a frame with no data, that the host ignores -- it's just there so that there is something to receive, so that we don't hit the timeout.

A problem with this system is that it won't function well if there are two or more concurrent local-multiplayer games running on the same computer, but I don't think that's a use case we need to worry about.

Anyway, this isn't perfect yet, but the results are encouraging. Tetris DS and Mario Kart DS connect with no hitch now, so that issue is dealt with. However, I'm noticing some regressions. For example, NSMB minigames won't connect: I immediately get a comm error screen on the client. I looked into it quickly, and found out that the client is doing weird things (like occasionally setting RXBUF_RDCSR to 0x05FE, which doesn't look right), but I need to look deeper into it. It's possible that the issue was always here but was less apparent due to the different way of doing things. I have also seen some occasional slowdown in NSMB and Mario Kart, so that may be related.

Oh well, we'll get there. It's getting close at this point.
Zyute says:
Aug 25th 2022
Sounds like multiplayer wont be a issue for long. Arisotura I have to say you are one of the most dedicated and hard working developers I've seen. Thanks for the time and effort you put into MelonDS.😎
LinuxDuck says:
Aug 25th 2022
I know this isn't related to the post at hand, but is the melonds flatpak on flathub official? Love this emu and got a new laptop recently and put fedora on it, so..
ArcticHusky says:
Aug 25th 2022
Your posts excite me so much, like, everyday I come here to check if there’s something new lol, kinda makes me want to learn how emulation works just for fun

Can’t believe I’ll be able to play some Inazuma Eleven multiplayer on an emulator soonish! :D
Jay says:
Aug 25th 2022
Can't wait for the next lil bit of information.
MarioFan587 says:
Aug 26th 2022
I been following this saga since the beginning, it sounds like you're doing well! I hope it all works great in the end, this can't be easy to replicate.
Rayyan says:
Aug 26th 2022
LinuxDuck: yes it is
Post a comment
Name:
DO NOT TOUCH