Ruby合宿のゲームをブラウザへ

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
ItoJum PRO
December 04, 2026

 Ruby合宿のゲームをブラウザへ

RubyWorld Conference 2026で発表した資料になります

ItoJum PRO

December 04, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

42 slides
  1. Ruby合宿のDXRubyゲームを ブラウザへ PicoRuby.wasmでゲーム実⾏環境を作り直す Bringing a Ruby Camp game to the

    browser: rebuilding its runtime with PicoRuby.wasm SmartHR プロダクトエンジニア Jumpei Ito (@itojum1230) 2026/12/04 © SmartHR, Inc.
  2. whoami いとじゅん(@itojum1230) SmartHR, class of 2026 / VRChat.rb organizer /

    Born in Shimane, raised in Tottori • 株式会社SmartHR ◦ 26新卒 • 島根⽣まれ • ⿃取育ち • VRChat.rb オーガナイザー 写真撮影‧SNS共有 歓迎🙌 Photos and posts welcome
  3. VRChat.rb 宣伝 VRChatでやってる地域.rb らしきもの HMD, Windows PC, スマホ があれば参加できちゃう Promo:

    a local Ruby meetup, held inside VRChat. Join with an HMD, a Windows PC, or a phone. 3
  4. Ruby合宿ありけり There was once a Ruby Camp 島根県の取り組み 「Ruby合宿 2024春」

    Ruby Camp 2024 Spring, a Shimane Prefecture program はじめてRubyに触れ、チームのリー ダーとして5⼈でゲームを開発した My first Ruby: I led a team of five and built a game 引用: Ruby合宿 公式サイト, 「Ruby合宿2024春 報告」 https://www.rubycamp.jp/reports/2024-03-09-2024-spring/ 5
  5. 作ったゲームはこちら Here is the game we made RubyCamp2024春 チーム5 Ruby

    Camp 2024 Spring, Team 5 Ms.T イラスト・曲 Mr.I リーダー・ロジック (←これが私) Mr.U グラフィック Mr.T グラフィック Ms.S ロジック https://github.com/RubyCamp/rc2024sp_team5 6
  6. DXRubyで作られてる Built with DXRuby: a library for using DirectX from

    Ruby • RubyからDirectXを利⽤するためのライブラリ ◦ https://github.com/mirichi/dxruby • Ruby合宿2024春でこちらを利⽤して開発した require 'dxruby' Window.loop do # 1フレーム分の処理 end 7
  7. RubyKaigi 2026 引用: HASUMI Hitoshi, Funicular: A Browser App Framework

    Powered by PicoRuby.WASM, https://slide.rabbit-shocker.org/authors/hasumikin/RubyKaigi2026/ 10
  8. ブラウザでRubyが動く なら、あのゲームも動 くのでは? If Ruby runs in the browser, maybe

    that game can run there too? <script type="text/ruby"> puts "Hello, Ruby!" </script> 11
  9. PicoDX:PicoRuby.wasmのDXRubyライク な描画ライブラリ PicoDX: a DXRuby-like graphics library for PicoRuby.wasm DXRubyと同じAPIを⽬指す

    Aiming for the same API as DXRuby Window / Image / Sprite / Input / player = Image.load('player.png') x=0 Font / Sound / RenderTarget Canvas 2Dで描画 Window.loop do x += Input.x * 4 Window.draw(x, 200, player) end Draws with Canvas 2D npmで公開 Published on npm 13
  10. 課題1: Window.loopを再現したい Problem 1: Reproducing Window#loop メインループを回してくれるメソッド ゲームの基礎になる The method

    that runs the main loop, the foundation of a game Window.loop do Window.draw_box_fill(0, 0, 50, 50, C_WHITE) end 17
  11. Rubyが処理を占有すると描画されない If Ruby holds the thread, nothing gets drawn 現状

    描画 Ruby Now Drawing 理想 Ruby 描画 Ruby 描画 Ruby 描画 Ideal 18
  12. .awaitを使って⽌めて描画させる Pause with .await, and let the browser draw def

    loop(&block) while !@closed JS.global.__picodx_nextFrame().await # 次の描画までSTOP _tick # ブロックを1回呼ぶ end end CRubyには処理を途中で止める仕組み(Fiber)があるが、 PicoRuby.wasmには無いので、.awaitする CRuby can pause with Fiber, but PicoRuby.wasm has no Fiber, so we use .await 19
  13. 課題2: require が使えない Problem 2: require does not work 合宿のゲームは、以下のようにファイルに分

    かれている The camp game is split across files, like this require "./page/gameplay.rb" require "./page/home.rb" require "./class/player.rb" 21
  14. 仮想FSが空なので LoadError The virtual FS is empty, so: LoadError require

    は仮想FSしか読まない サーバーから取ってきてはくれない require only reads the virtual FS. It does not fetch from the server. require "./class/player.rb" # => LoadError 22
  15. 事前にfetchして仮想FSへ書き込むと... What if we fetch and write to the virtual

    FS first… # player.rb PLAYER_IMAGE = Image.load("player.png") # 内部で.awaitしてる class Player # 以下は実行されない end require先のファイルで.awaitするとエラーなしで 途中で終わる If a required file calls .await, it silently stops halfway 23
  16. 当初の解決策 First solution Prismでrequireを⾒つけてきて、1ファイルに 結合してみた Find each require with Prism,

    and combine everything into one file $ npx picodx bundle main.rb これでもいけるがせっかくなので... That works, but since we are here… To Be Continued… 24
  17. 事前にfetchして仮想FSへ書き込むと... What if we fetch and write to the virtual

    FS first… # player.rb PLAYER_IMAGE = Image.load("player.png") # 内部で.awaitしてる class Player # 以下は実行されない これが解決すれば、 ファイル結合はしなくても良い end If this gets solved, no need to combine files require先のファイルで.awaitするとエラーなしで 途中で終わる If a required file calls .await, it silently stops halfway 25
  18. 途中で終わる原因 Why it stops halfway # sub.rb(require 先) puts "sub:

    first" ここで終了 promise.await puts "sub: second" 1. 2. 3. 4. require先のコードで.awaitする stateが:SUSPENDEDになる requireはそれを終了と⾒なす(Ctrl+Zと同じ扱い) 残りの⾏を打ち切って戻る .await in required file → :SUSPENDED → require treats it as done (like Ctrl+Z) → rest is skipped 26
  19. PicoRubyへIssue🚀 Filed an Issue to PicoRuby 原因がWasmに収まらず、影 響範囲が広そうだったの で、⼀旦Issueで🍵 The

    cause went beyond the Wasm side and seemed to have a wide impact, so I filed an Issue first 27
  20. PicoRubyへIssue🚀 Filed an Issue to PicoRuby 原因がWasmに収まらず、影 響範囲が広そうだったの で、⼀旦Issueで🍵 The

    cause went beyond the Wasm side and seemed to have a wide impact, so I filed an Issue first 次の⽇に⽻⾓さんが修正を ⼊れてくださった早い Hasumi-san fixed it the very next day. So fast! 28
  21. しかし、ダメ! But, no! cannot load such file -- ./main.rb (LoadError)

    LoadError…なんでなの LoadError… but why? 30
  22. 思い出すシリーズ Flashback series 課題2のコード Rubyistの皆さんなら違和感を覚えるはず なんか拡張⼦があるなァ Hmm, there’s a file

    extension… require "./page/gameplay.rb" require "./page/home.rb" require "./class/player.rb" The code from Problem 2 — Rubyists, something here should feel off 32
  23. PicoRubyのrequireは拡張⼦を許容していな かったので、PR🚀 慣習的に拡張⼦描かな いからね PicoRuby’s require didn’t accept file extensions,

    so I sent a PR 次の⽇にマージされた 早い We don’t usually write the extension, after all Merged the next day. So fast! 33
  24. その後:ファイル結合を消した After that: no more combining files 結合するのをやめ、importmap-picoruby で 読む

    PicoDX 3.0.0 drops picodx bundle; importmap-picoruby (my library) fetches the required files require "./page/gameplay.rb" # そのまま # → 実行時に importmap-picorubyでサーバーから取ってくる PicoRuby.wasm の head 版で動作。正式版は次のリリースから Works on the PicoRuby.wasm head build; the next stable release will include it 35
  25. 互換できなくて差分が出たところ Where the code had to change Showing 9 changed

    files with 112 additions and 47 deletions ファイル 追加 compat.rb・set.rb +43 Set・Kernel#randを補うため entry.rb・ranking.rb +7 ランキング機能を外す: net/http が使えない block_grid.rb +56 当たり判定を絞る gameplay.rb +5 bgm.rb ほか player.rb・main.rb +1 削除 変更内容:できなかったこと −3 同上(判定する相手を近くのブロックに) −42 BGMを消す −2 require を直す・require 'dxruby' を消す compat.rb and set.rb add Kernel#rand and Set / entry.rb and ranking.rb remove rankings (no net/http) / block_grid.rb and gameplay.rb narrow collision checks / bgm.rb and related lines remove the BGM / player.rb and main.rb fix requires 37
  26. ブラウザゲームを書き慣れたRubyで書こう Write browser games in the Ruby you already know

    PicoRuby.wasm の本体は約2MB(gzip 0.91MB) script タグ数⾏でブラウザで動く PicoRuby.wasm itself is about 2 MB, and runs with a few script tags 制約 CRubyとの標準モジュールの違い C拡張ほど速くはない Limits: standard modules differ from CRuby, and it is not as fast as C extensions 39
  27. 謝辞 Acknowledgments Ruby合宿でRubyを触った学⽣は Rubyエンジニアになれました A student who first tried Ruby

    at Ruby Camp in Shimane became a Ruby engineer. • 島根県 • Ruby合宿の運営企業 • Ruby合宿2024春 チーム5 メンバー Shimane Prefecture / The companies that ran Ruby Camp / Ruby Camp 2024 Spring, Team 5 40

More Decks by ItoJum

Other Decks in Programming