Advertisement
feos

scripting dolphin

Nov 26th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | None | 0 0
  1. <phire> I've actually been looking into scripting
  2. <Warepire> I have considered some approaches to a "bring your own scripting language" approach, but haven't had time to draft it.
  3. <phire> yeah, I'm halfway through drafting mine
  4. <Warepire> My idea was to extend the memory watcher interface into a control socket.
  5. <phire> so RPC?
  6. <Warepire> And then provide example bindings for a language, e.g. python.
  7. <Warepire> Pretty much
  8. <Warepire> But, that's as far as my idea is defined, not a single line of code exists yet
  9. <phire> jroweboy has a prototype of such an idea: https://github.com/jroweboy/emurpc/
  10. <feos> does that allows to use an interactive scripting console?
  11. <Warepire> In my idea you'd use the one that comes with the scripting language.
  12. <phire> you can have whatever you want at the other side of the socket
  13. <Warepire> Yeah ^
  14. <phire> or, if you really want an intergrated console into dolphin, you can make a two way connection back
  15. <phire> so, my idea is a bit more OTT
  16. <phire> for context, scripting preformance is an issue for me. Because I want the scripting interface to be powerfull enough to do shader replacement or geometery replacement.
  17. <feos> how fast would this approach be? when people get scripting support in emulators, they go nuts with it and uncover bottlenecks
  18. <feos> heh, you've read my mind
  19. <phire> So, I want a plugin api, where plugins are loaded via DLLs
  20. <phire> and the scripting api would be a subset of the c ABI
  21. <phire> So, if you really need preformance. you write a plugin in c.
  22. <phire> But... The most common type of plugin would be scripting host plugins
  23. <delroth> maybe we can even allow registering plugins for mmio ranges or IOS devices! then you can write your own implementation of GX or WiimoteEmu or DiscIO in a plugin!
  24. <delroth> /me hides
  25. <phire> you would have one for javascript, one for python, one for lua
  26. <phire> delroth, I'll add it to the list
  27. <feos> https://pastebin.com/wRPpesBj
  28. <phire> And users would be albe to use whatever scripting interface they want
  29. <feos> to emphasize the most important lines from there,
  30. <feos> <Masterjun> adelikat_: https://twitter.com/Masterjun3/status/1191520618841362432
  31. <feos> <Masterjun> that twitter link is Lua, fully emulating a 65816 cpu, at 250 fps
  32. <booto> haha, also include on the list the ability to trigger scripting stuff on breakpoints :P
  33. <phire> booto: yeah
  34. <delroth> there's basically 3 main use cases: TAS, modding, and general automation
  35. <delroth> figuring an API that works well for all 3 is tricky
  36. <delroth> for automation a control socket API is enough, but likely not for the other two
  37. <feos> well of course writing pluginc in C makes them unbeatable in terms of speed
  38. <delroth> might barely work for TAS
  39. <feos> if you can register callbacks on some variety of internal events, tas would be fine
  40. <delroth> for modding an extra constraint is you probably want some level of safety, e.g. not allowing people to trivially write malware through such a plug-in API
  41. <phire> ugh... that's the hard one
  42. <delroth> because otherwise you're basically screwed if you also want to provide a distribution platform
  43. <phire> in my design, the scripting host dlls would be allowed to state they are sandboxed (or provide a sandboxed mode). But c dlls could never be sandboxed
  44. <delroth> something something WASM also
  45. <delroth> might be a solution
  46. <delroth> not completely sure to what problem though
  47. <phire> sandboxing, maybe
  48. <phire> I mean, if you have a v8 plugin, it comes with WASM and you can use it to execute compiled code
  49. <delroth> I think scripting hosts could be somehow built and distributed by us
  50. <delroth> just separately built to avoid bulking the regular downloads
  51. <phire> yeah, potentially downloaded an installed automatically
  52. <feos> so with this approach, a plugin for lua scripting would accept lua code, turn it into C API calls (or sockets) and send to dolphin?
  53. <phire> yes
  54. <feos> would they be strictly limited to just C, or any language that can work with C API?
  55. <phire> pretty much any language has support for calling c APIs
  56. <phire> and almost every compiled language supports being compiled to a .dll that can be loaded and comunicated with via a C API
  57. <feos> good
  58. <feos> so what about registering callbacks in this scenario?
  59. <phire> so sligthly more controversial in my design. It's entirely callback based
  60. <feos> I mean I can have a lua function registered and called every frame?
  61. <phire> there is no main loop
  62. <phire> if your script wants to do anything useful, there is an init() callback that gets called on boot, and it has to register callbacks for any events it's interested in
  63. <feos> alright
  64. <phire> it might register for once a frame, at any point during the frame (based on timing)
  65. <phire> or it might register for when a certan emulated function is called
  66. <feos> so the internal scripting api should provide enough places you'd want to hook into
  67. <phire> or for a render compele interrupt
  68. <phire> yeah, like I said, I'm designing this with modding in mind
  69. <feos> nice
  70. <phire> because I see modding as the most demanding workload
  71. <feos> this approach is properly mature compared to "support lua"
  72. <feos> we're considering taking it in bizhawk
  73. <feos> it already has api for compiled plugins
  74. <phire> oh, I should check that out
  75. <feos> well plugins are meant to be c#
  76. <feos> that allows exposing entire classes
  77. <Bh44L> you can still do that in lua with metatables, so not really an argument :D
  78. <feos> except that'd be "just lua"
  79. <feos> while plugin api allows anything
  80. <phire> ah, so limiting to a single language (of c#)
  81. <phire> the downside of my planned approach, is the raw c api might look a bit janky.
  82. <phire> because it needs to support everything
  83. <feos> c# makes it harder for plugins to talk to *anything*, so the original intent was just having plugins as ends
  84. <feos> when porting mame to bizhawk, I took an interesting approach. I implemented basic c api to send lua code, and then mame's internal luaengine interprets it and reacts, sending stuff back through c api
  85. <phire> delroth: the other thing I was thinking about is making the scripting host dlls portable to any emulator (or other program) supporting the same base ABI
  86. <feos> so I only need a string sender, and a few type returners
  87. <phire> so if I can convince citra and other emualtors to support the same base ABI, then a scripting plugin for any given language only need to be written once
  88. <feos> that's actually crazy!
  89. <phire> the ABI would include a discovery endpoint, so the scripting plugin can ask whatever emulator it's plugged into "What types and methods do you support"
  90. <phire> then it can automatically export them to it's scripting enviroment
  91. <phire> Also means, dolphin wouldn't have to rebuild it's scripting host plugins every single time a new API is added or modified
  92. <feos> what about emulators exposing unique things? plugins would have to be different even for the same master language
  93. <phire> yes, but that's a given
  94. <phire> it might be possible to write plugins that work in multiple emulators, also taking advantage of the discovery endpoint
  95. <feos> right
  96. <phire> I don't really want to force a "this is what your emulator API must look like"
  97. <phire> maybe, I'll try to define a few base things, like "this is the memory reading endpoint that should be flexable enough for anything"
  98. <feos> for sane memory reading you need to report regions to the user, then it can be made really handy
  99. <phire> I guess allow that as part of the discovery api
  100. <phire> this project has a few parts.
  101. <feos> in hawk, since we emulate a ton of systems, we have getregions() iirc, that just prints them, same for getregisters()
  102. <feos> and then you work with the region you want
  103. <phire> 1. A c++ library for registering hooks, types and method exports, exporting them over c
  104. <phire> 2. The actual plugin lifecycle
  105. <phire> 3. The ABI, what types are we supporting
  106. <phire> 4. The discovery API for comunicating those types to plugins
  107. <phire> 5. The 3 base scripting plugins: Javascript, Python, Lua (Luajit?)
  108. <phire> 6. The actual API for dolphin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement