Author Topic: Net Play module  (Read 11270 times)

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Net Play module
« on: June 07, 2013, 01:56:25 PM »
Something I've been talking about for a while is a separate commercial app that provides a communications interface with services that Mupen64Plus AE (and potentially other emulators) can leverage for Net Play.  I've been tinkering around with this off and on for the past few weeks, and actually ran some rough tests using Diddy Kong Racing yesterday with my wife (she on her Droid Razr and me on the OUYA).  The current system I have is built into Mupen64Plus AE's Java code, so not I'm not posting it for testing yet until I get it separated out into its own app (otherwise I would have to release the source under the GPL).

Currently there are still some glitches I need to work out.  The math for slowing down the faster device is not working properly, so the devices quickly go out of sync and you are no longer really playing the same game.

Anyway, thought I would start a thread to document my progress.  I was going to start a thread in the "Paul's Projects" board, but figured this is closely enough related to Mupen64Plus AE that it should probably go here.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Net Play module
« Reply #1 on: June 07, 2013, 02:04:24 PM »
Very cool!  With netplay, are you simply mirroring each user's inputs over to the opposite device, or is there more to it than that?  (And by 'simply' I mean conceptually, not technically ;D  That alone sounds hard enough)
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Net Play module
« Reply #2 on: June 07, 2013, 02:46:50 PM »
Both input and frame-rate are mirrored.  Basically the way the system works is first it sets up a network connection with the players devices connected as clients on my server (will eventually incorporate a switch to P2P).  One device is the initiator (the one who created the game session).

Both devices start the core and immediately pause after the first call to flip buffers, storing the frame number and timestamp for when the pause completed.  They then do a "hand shake" of sorts, where basically the initiating device says, "I'm ready!", and the other device (when ready) responds with "I'm resuming in 10 seconds from timestamp X at frame number X".  The initiating device uses this information to calculate when to resume.  They then enter an asynchronous communication loop with each other, where both devices send repeated messages with the following information:

1) N64 digital button states (queue of states if more than one change between messages)
2) N64 analog state (or queue of states if message time exceeds a minimum time delay between snapshots)
3) Video frame number (counted as a 1-up integer) with a timestamp when that frame occurred

Upon receiving the message, each device applies the queue of button and analog states (need an option for touchscreen controls for picking player number), then compares the video frame number and timestamp with their own numbers to determine if they are running faster or slower than the other device.  If faster, emulation speed is decreased (minimum 0%).  If slower, emulation speed is increased (maximum 100%).  In theory, this causes a fast device to slow down when playing with a slow device (not really working correctly yet though).
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Net Play module
« Reply #3 on: June 07, 2013, 02:55:08 PM »
Very cool...
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Vincentmrl

  • Cyan Team
  • long
  • *
  • Posts: 121
    • View Profile
Re: Net Play module
« Reply #4 on: June 07, 2013, 07:27:17 PM »
Great Paul! Can't wait for this. Will it work on mobile data too?
Device: Lg Optimus One
CPU: 600 Mhz ARMv6 (Overclocked to 748Mhz ondemand governor)
GPU: Qualcomm Adreno 200
RAM: 512 MB
Resolution: 320 x 480
Rom: Unofficial Cyanogenmod 9

Offline beansta

  • byte
  • *
  • Posts: 29
    • View Profile
Re: Net Play module
« Reply #5 on: June 08, 2013, 12:16:00 PM »
The problem with P2P is that it tends to be very unstable (however it supports a wide range of parameters). Im speaking from my experience with using 2 different types of protocols for netplay. P2P and AQZ. The latter is much more specific, requires that all players are using the same plugins/settings/(possibly device too) for stable netplay emulation. The advantage is very good FPS and lack of lag. Me and my friend are able to play MK64 from either side of england with a lag counter of 1 providing a smooth experience.
Devices:
Samsung Galaxy S3 LTE international
rXtreme v14.1 ROM and Perceus v36.2 kernel
1.7ghz Quadcore CPU and 533mhz GPU
1.77 GB useable RAM

Samsung Galaxy Tab 2 10.1 Wifi
Zap Blaster v2.2 ROM and Next v1.41 kernel
1.35ghz Dualcore CPU and 384mhz GPU
1006MB useable RAM


Offline harrbri

  • bit
  • Posts: 7
    • View Profile
Re: Net Play module
« Reply #6 on: July 08, 2013, 06:18:39 PM »
wouldnt it  be easier to have a host device "host" the game, and one that is simply obtaining a video feed and sending button data, so its like btcontroller + video feed

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Net Play module
« Reply #7 on: July 08, 2013, 09:23:45 PM »
The difficulty would be in obtaining the video to send.  Last I checked there isn't an API for this (granted it has been a while since I looked into that route).
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline x3ro

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Net Play module
« Reply #8 on: July 09, 2013, 03:08:27 AM »
Wouldn't the "video send" approach be very performance intensive? While most graphic chipsets support h.264 encoding/decoding, I assume that it still uses up a lot of resources, especially if you have to do it in real time. Also, sending that video stream over the internet would require lot of upload bandwith from the hosting party (2Mbit/s for Level 2 h.264, which is only 352x288).

Another question: Wouldn't it be feasible to nonetheless release the net-play module as open source? I can only speak for myself, but I'd really like to see how you accomplish this, and I doubt that you'll loose many (if any) sales, because people who'd buy it out of the store are hardly those who'd download the ADK and compile it themselves, or so I imagine.

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Net Play module
« Reply #9 on: July 09, 2013, 06:08:15 AM »
You're right, most people wouldn't compile from source.  But other developers would compile the source, re-brand the software, and sell it for a little less, thus undercutting Paul's sales.  It already happens with Mupen64Plus AE -- all the N64 emulators in Google Play are just clones with added bloat and ads.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline x3ro

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Net Play module
« Reply #10 on: July 09, 2013, 07:20:56 AM »
Ah, I see. I didn't think of that, to be honest. Pretty sad, actually...

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Net Play module
« Reply #11 on: July 09, 2013, 08:29:09 AM »
My plan is to release the source once Mupen64Plus core officially has netplay, and an Android-specific solution is no longer relevant.  Netplay is in the official roadmap for Mupen64Plus, but not very high on the core team's priority list at this time.  I definitely agree it would be useful to have the source code out there, and I'm sure folks will come along to vastly improve on it.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Net Play module
« Reply #12 on: July 09, 2013, 08:35:37 AM »
Ah, I see. I didn't think of that, to be honest. Pretty sad, actually...

To be fair, all the copy-cats came it pretty handy when I was in the market for a job (specifically their use of 3rd-party advertisement systems to boost their install numbers and ratings).  Being able to show that branches of an app I wrote were installed on millions of phones was one of the focal points on my resume, and easy for any potential employer to Google up and verify as accurate.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted