📜 ⬆️ ⬇️

Network game in NES (Dendy) implemented on Flash P2P

image

More than a year and a half has passed since the launch of nesbox.com , all this time the idea to make a game for two over the Internet has not left me. If you are interested in how we came to the working version, welcome under cat.

I'll start with how our emulator works. For a comfortable game, it should work out ~ 50-60 frames per second. For each frame we transmit the state of both joysticks, in the form of 2 bytes, in which the set bit is responsible for one of the joystick buttons, and the output is a full screen buffer 256x240, and a sound range of 44100/60 ~ = 735 samples.

image
')
As you can see, the interface is the simplest, but in order to make it all work on the network, we need to send the joystick state of the first player to the second player, get its joystick state, and then start generating a screen frame with sound. And this should happen 50-60 times per second.

The first prototype was a scheme with a primitive C ++ server that received data about the joysticks via the Flash Sockets and sent them to both clients. The prototype was quite working, but users who were near the nesbox.com server could play on the network (ping ~ 60ms). Were thought to post it in open source, so that people themselves collected it and launched it on their servers in the immediate vicinity. But here Adobe releases RTMFP protocol and Cirrus technology, which solves all our problems, and now we can connect both emulators via P2P , and the problem with ping disappears. At least, people within the same city can comfortably play together.

image

Start working with Flash P2P is elementary, the whole process has already been described in Habré: Adobe Flash Player and the transfer of streaming data without server involvement , we will not repeat. The general meaning is that we connect to the Cirrus server, get a 256-bit id, send them to each other. Everything, now you can send data peer-to-peer, which is implemented in our emulator.

To test this technology and play together on the Internet, I suggest choosing one of the 16,000 roms on nesbox.com and running emulation. Not all Roma workers, so choose the green with the tag verified .

image

Choose two players via internet .

image

Copy the resulting URL into the clipboard and send it to the second player. If everything is in order with the configurations of your networks, the game will start in a few seconds, if not, you can test the connection here http://cc.rtmfp.net .

My dream came true (and not only mine, a lot of people asked for it), now you can play dandy on the network with your friend in a browser!

Below are some links to popular games for two players. All your questions and suggestions will answer in the comments.

Battle city
image


Battletoads & Double Dragon - The Ultimate Team
image


Contra
image


Chip 'n Dale Rescue Rangers
image

Source: https://habr.com/ru/post/133827/


All Articles