tjwei / xnes

javascript SNES emulator
Other
215 stars 62 forks source link

Use JS-based joypad inputs? #12

Open 8enmann opened 7 years ago

8enmann commented 7 years ago

I'd like to modify this project two ways and then incorporate into https://github.com/8enmann/webtendo

  1. Allow JS to fire key events. Modify sdlinput.cpp and the build config to expose S9XReportButton or an abstraction of it to JS. Then call it from JS with the appropriate args. Where's the documentation for how to construct an ID to pass into S9XReportButton, assuming no mapping has been made? If a mapping has been made I assume it's as simple as using (mod << 16 | ksym | type == keydown) as you do in sdlinput.cpp.

  2. Support 2 controllers. I saw in sdlinput.cpp that you call with command "Joypad1 X" as the s9xcommand_t. Perhaps it's as simple as passing in "Joypad2 X" instead? What if I don't use a mapping, or do I have to?

Let me know if I'm on the right track. Thanks!

tjwei commented 7 years ago

this document might help http://src.gnu-darwin.org/ports/emulators/snes9x/work/snes9x-1.51-src/doc/porting.html IIRC, IDs are platform dependent. It is a mapping of SDL key into an uint32 so that snes9x can handle. So event.key.keysym.mod << 16 | event.key.keysym.sym is the ID. https://wiki.libsdl.org/SDL_Keycode

Use S9xMapButton to map buttons.

8enmann commented 7 years ago

Thanks for the quick response! Hope to try it out next week.

jasmith79 commented 7 years ago

@8enmann Note that I've implemented this in a branch on my copy, I'm just not quite ready to make a PR yet. https://github.com/jasmith79/xnes/tree/ux

It was annoyingly complicated. I did it by changing the signature of the key init function and exposing it to js, then hand-mapped all of the js key event codes to the SDL ones. The non-ASCII SDL codes I got via printfing the SDLK_* constants.

They're persisted to localStorage.

8enmann commented 7 years ago

Ooh cool. I moved on from this project but if I get a chance I'll come back and give it a shot!

kaikuehne commented 6 years ago

Hi, during the fall of 2017 I wrote my master's thesis which was about implementing a web platform where users can play snes games together in a multiplayer mode. For the emulation part, it is heavily based on xnes. The multiplayer part is based on webrtc, where I basically transfer a videostream from the host to the other players and the inputs back to the host (just like https://github.com/olahol/melody-jsnes). I also added basic support for controlling the games via your smartphone, like it's done in https://github.com/8enmann/webtendo.

The code is not super polished, because I had to get it done. I think it may be a good basis to hack away on it further though. The repo is here: https://github.com/kaikuehne/smes And if you care about the thesis itself: http://github.com/kaikuehne/master-thesis (german only, sorry).

So, I basically built upon work from you guys and improved several aspects of it and added a multiplayer mode (which would benefit from some kind of lag compensation, but that's another story). Thanks! Maybe try it out and tell me what you think! :-)

8enmann commented 6 years ago

Wow awesome!! Will take a look

On Sun, Jan 14, 2018, 8:13 AM Kai Kuehne notifications@github.com wrote:

Hi, during the fall of 2017 I wrote my master's thesis which was about implementing a multiplayer platform for snes games. For the emulation part, it is heavily based on xnes. The multiplayer part is based on webrtc, where I basically transfer a videostream from the host to the other players and the inputs back to the host (just like https://github.com/olahol/melody-jsnes). I also added basic support for controlling the games via your smartphone, like it's done in https://github.com/8enmann/webtendo.

The code is not super polished, because I had to get it done. I think it may be a good basis to hack away on it further though. The repo is here: https://github.com/kaikuehne/smes And if you care about the thesis itself: http://github.com/kaikuehne/master-thesis https://github.com/kaikuehne/master-thesis (german only, sorry).

So, I basically built upon work from you guys and improved several aspects of it and added a multiplayer mode (which would benefit from some kind of lag compensation, but that's another story). Thanks! Maybe try it out and tell me what you think! :-)

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/tjwei/xnes/issues/12#issuecomment-357522424, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-UsBgmBaLfE1tVUFKzp1Broa6Qcrueks5tKiengaJpZM4LdmUZ .