The local multiplayer saga, ep 2
Slowly but steadily, I'm working on it. For now, I'm keeping my work private, so I'm not bothered by people wanting to try an unfinished branch, reporting issues with it, etc.

We assume here that you're familiar with local multiplayer terms. If you're not: read this.

I introduced a crude synchronization mechanism where the host of a local multiplayer game can instruct clients to stay in sync. When a client connects, the host sends its USCOUNTER (the wifi system's microsecond counter) value to that client, which can then compare that to its own USCOUNTER value: the point a connection is established is considered the reference point, and the client will then wait for the host to allow it to run, so it doesn't get too far ahead or behind.

Thus, the host can enforce sync (and also wait for clients to have caught up) before sending a CMD frame to its clients, thus ensuring that everybody is at the same point at that time. It can then send its CMD frame and allow clients to run ahead for a given amount of time that covers the entire MP exchange process.

The results aren't perfect, but they are somewhat promising.

For example, Pictochat doesn't seem to get stuck trying to send messages. I have only tested with two instances for now, but they seem to stay in sync fine.

However, there is still data loss in the client->host direction, which I need to investigate further.

I suspect there might be issues with ack frames being received too late. I intend to just fake them, to simplify things and reduce the amount of data being transferred. I made a quick attempt at that yesterday, but so far it's not working as intended.

It may also be caused by lacking emulation of the error handling processes in hardware (like automatically resending the CMD frame if some clients failed to respond, for example). I will have to do some more reverse-engineering to determine how that works in detail.

Also, the performance is currently less than optimal. For now I'm focused on getting the communication stable, so I will take care of optimizing later, but I have some ideas for this. Namely, BSD sockets are probably suboptimal for fast IPC. It would likely be faster to use shared memory, or even run multiple emulated DS's inside the same melonDS instance, although the latter would require a large restructuration of the melonDS codebase.

All in all, I'm hopeful we can pull it off.

I'm also going on vacation next week, so I'll have more time to work on it (provided my brain lets me, of course).
Asphixy says:
Aug 5th 2022
Thank you for keeping us up to date
keisui says:
Aug 5th 2022
anything that becomes a saga always excites me , totally looking forward to how this saga ends
poudink says:
Aug 5th 2022
I hear performance often goes to shit when synchronisation is involved, so good luck with this.
mga-py says:
Aug 5th 2022
I am still quite active in the development of the emulator and I would like to contribute with my time although I am a developer I have never worked in cpp although learning that would not be too complicated but it is to understand many emulation concepts I see that it works practically at the processor level and that paradigm would be difficult for me to understand.
Could someone contribute by teaching me just this if possible in Spanish since my English is quite bad
I would not mind dedicating time to the development of melonDS, above all I would like to focus on the Wifi part since it is the one that I have been waiting for the most years and I think it is the emulator that is closest to achieving it.

my email
Alex says:
Aug 5th 2022
Just off-topic, it could be cool to be able to install MelonDS with Winget (refer to webpages like winstall DOT app).
Just a regular guy c says:
Aug 6th 2022
Is there multiplayer on android melonds just kindly asking
mrpokeboy8 says:
Aug 6th 2022
to Just a regular guy c : The Android port I know of is an unofficial port and lists it does not support Wi-Fi. It would rely on somebody to make Wi-Fi successfully interact with that MelonDS port, then do something like setting up Kaeru DNS for trying WFC, which took me some finagling on PC to do right in Pokemon Black/White 2.
kevincrans says:
Aug 6th 2022
I wish you a happy vacation! I just came back from mine.
Marcos L says:
Aug 7th 2022
You are awesome buddy, have a nice vacations, enjoy and don't work so hard xD
Maximo says:
Aug 9th 2022
Question since I have doubts since I was little? because some emulators cannot connect to more than two players in online multiplayer mode both in bluetooth and wifi as is the case with game boy, drastic, epsxe, etc etc etc. I'm not saying that it can't be done or that it can't be done much less if you do it yourself, but if you can clarify that doubt for me it would be of great help, thank you and success.
MPS64 says:
Aug 15th 2022
you got this, guys. good luck with the local play implementation :)
Post a comment