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
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
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
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
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
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
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
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
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
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