From a7ae460446a5dd5612deb68a130dffc0947962d1 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Tue, 8 Sep 2026 14:48:05 -0500 Subject: [PATCH] Use ChunkyPNG for converting ICO bmp to png as gosu doesn't like doing it on the background thread, fixed Worker#service payload sometimes returning multiple events causing the json parser to have a bad time- also can support payloads larger than a megabyte now. --- Gemfile | 3 +- Gemfile.lock | 101 +++++++++++++++++++------------------- lib/ico.rb | 3 +- lib/worker.rb | 42 ++++++++++------ w3d_hub_linux_launcher.rb | 1 + 5 files changed, 83 insertions(+), 67 deletions(-) diff --git a/Gemfile b/Gemfile index b72db0e..6f1e72e 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem "json" # "game" library gem gem "cyberarm_engine" -gem "sdl2-bindings" +gem "sdl3-bindings" # networking libs gem "async" @@ -19,3 +19,4 @@ gem "async-websocket" gem "digest-crc" gem "ircparser" gem "rubyzip" +gem "chunky_png" diff --git a/Gemfile.lock b/Gemfile.lock index d60f270..059e6f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,20 @@ GEM remote: https://gem.coop/ specs: - async (2.39.0) + async (2.45.1) console (~> 1.29) fiber-annotation - io-event (~> 1.11) - metrics (~> 0.12) - traces (~> 0.18) - async-http (0.95.1) - async (>= 2.10.2) - async-pool (~> 0.11) - io-endpoint (~> 0.14) - io-stream (~> 0.6) - metrics (~> 0.12) - protocol-http (~> 0.62) - protocol-http1 (~> 0.39) - protocol-http2 (~> 0.26) + io-event (~> 1.21) + async-http (0.103.0) + async (>= 2.35.1) + async-pool (~> 0.12) + io-endpoint (~> 0.18) + io-stream (~> 0.14) + protocol-http (~> 0.66) + protocol-http1 (~> 0.41) + protocol-http2 (~> 0.28) protocol-url (~> 0.2) - traces (~> 0.10) - async-pool (0.11.2) + async-pool (0.12.0) async (>= 2.0) async-websocket (0.30.1) async-http (~> 0.76) @@ -26,7 +22,8 @@ GEM protocol-rack (~> 0.7) protocol-websocket (~> 0.17) base64 (0.3.0) - console (1.36.0) + chunky_png (1.4.0) + console (1.37.0) fiber-annotation fiber-local (~> 1.1) json @@ -40,34 +37,35 @@ GEM fiber-storage fiber-storage (1.0.1) gosu (1.4.6) - io-endpoint (0.17.2) - io-event (1.16.2) - io-stream (0.13.1) + io-endpoint (0.18.0) + openssl (>= 3.3.0) + io-event (1.21.1) + io-stream (0.14.0) + openssl (>= 3.3) ircparser (1.0.0) - json (2.19.9) + json (3.0.1) logger (1.7.0) - metrics (0.15.0) + openssl (4.0.2) protocol-hpack (1.5.1) - protocol-http (0.62.2) - protocol-http1 (0.39.0) - protocol-http (~> 0.62) - protocol-http2 (0.26.0) + protocol-http (0.71.0) + protocol-http1 (0.41.0) + protocol-http (~> 0.68) + protocol-http2 (0.28.0) protocol-hpack (~> 1.4) protocol-http (~> 0.62) protocol-rack (0.22.1) io-stream (>= 0.10) protocol-http (~> 0.58) rack (>= 1.0) - protocol-url (0.4.0) - protocol-websocket (0.21.1) + protocol-url (0.19.0) + protocol-websocket (0.21.2) protocol-http (~> 0.2) - rack (3.2.6) + rack (3.2.7) rake (13.4.2) rexml (3.4.4) - rubyzip (3.4.0) - sdl2-bindings (0.2.3) - ffi (~> 1.15) - traces (0.18.2) + rubyzip (3.6.0) + sdl3-bindings (1.0.4) + ffi (~> 1.16) PLATFORMS x86_64-linux @@ -77,6 +75,7 @@ DEPENDENCIES async-http async-websocket base64 + chunky_png cyberarm_engine digest-crc ircparser @@ -84,15 +83,16 @@ DEPENDENCIES logger rexml rubyzip - sdl2-bindings + sdl3-bindings CHECKSUMS - async (2.39.0) sha256=df18730073f2bbb45788077dfa20cb365ecc1b9453969f44de6796b5191a00aa - async-http (0.95.1) sha256=0c3dd458c204c06d5c4b20b01bbec4794a1203db627fb2ce536e1799ec14786c - async-pool (0.11.2) sha256=0a43a17b02b04d9c451b7d12fafa9a50e55dc6dd00d4369aca00433f16a7e3ed + async (2.45.1) sha256=95849f7432eca535146c69f3078dab3c7228d0075ed71f48733f3e585dd7c267 + async-http (0.103.0) sha256=137e3d5d419f7d72d5fa33cf04f30232e79c57b690025a650b8f9e48ece8bc41 + async-pool (0.12.0) sha256=5580493dc024bd704dab2ed0bf1307100722e49cbb825c7965f8501194f58506 async-websocket (0.30.1) sha256=54bb8a8f184e4aa64434c7a78ecc55850a67a3d1dcd02e3ae787376e2c673936 base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b - console (1.36.0) sha256=45599ea906cf80a73d8941f03abf873fe66a6a954e0bac5bc1c01e2cdc406f07 + chunky_png (1.4.0) sha256=89d5b31b55c0cf4da3cf89a2b4ebc3178d8abe8cbaf116a1dba95668502fdcfe + console (1.37.0) sha256=8093b286c2595a063849c098594fee5155ecc7967d36f3aa8cbe7569c8f3efd7 cyberarm_engine (0.25.1) sha256=6f851a2ed0a32bdd25fc619172b546a8e26eefeb13a62c509f226337170d0efe digest-crc (0.7.0) sha256=64adc23a26a241044cbe6732477ca1b3c281d79e2240bcff275a37a5a0d78c07 ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d @@ -100,26 +100,25 @@ CHECKSUMS fiber-local (1.1.0) sha256=c885f94f210fb9b05737de65d511136ea602e00c5105953748aa0f8793489f06 fiber-storage (1.0.1) sha256=f48e5b6d8b0be96dac486332b55cee82240057065dc761c1ea692b2e719240e1 gosu (1.4.6) sha256=80c7fa48cf61f4960ef067fdd1c000d98b4adc8e11faeaa486543d00908a5c15 - io-endpoint (0.17.2) sha256=3feaf766c116b35839c11fac68b6aaadc47887bb488902a57bf8e1d288fb3338 - io-event (1.16.2) sha256=9f9cb0a96ea5c3850a672606c65f27bc96d7621399ef6196acbfe2be0cd1279c - io-stream (0.13.1) sha256=570d7c4dfb0fbd767480b4a222048a2be6d9b78febc1ec68258d0e0a4cde20de + io-endpoint (0.18.0) sha256=720d186bcd584e8ba490bfc91dab332cc3c5ffee848b5b03894555cb275151aa + io-event (1.21.1) sha256=b3088f89ad67edf9be9fc2f48a5fae0790e92862487551eeb337b49098eb99e6 + io-stream (0.14.0) sha256=07d9b13ea2066ccbbc761fff8d69ad5a31e47561d31e02cc271f3ed9c1a8f1cd ircparser (1.0.0) sha256=0d4598f691172e2ad078207c50ba62c0d3428ae841836b0a682e6cd01d62878d - json (2.19.9) sha256=9b9025b7cdddafa38d316eca0b2358488e42d417045c1b90d216a9fefe46b79a + json (3.0.1) sha256=c80f74a3570c3a310cd41c526904e7ef8363abdece4432f31fe97d812bc4a39e logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203 - metrics (0.15.0) sha256=61ded5bac95118e995b1bc9ed4a5f19bc9814928a312a85b200abbdac9039072 + openssl (4.0.2) sha256=1037ad2868ae58df9ad917891c0c0f9815a1172f6846d4bcdd508e4c2ee747c2 protocol-hpack (1.5.1) sha256=6feca238b8078da1cd295677d6f306c6001af92d75fe0643d33e6956cbc3ad91 - protocol-http (0.62.2) sha256=e1c1f2f56029c1af8c4e2b8a67d0d096c76620f3afd8d99d1dcd2f6b8ffa773b - protocol-http1 (0.39.0) sha256=e49b3f4cda6f5d94c76a323d2b7f6977cba3ebd082d2da437039594da77ad8eb - protocol-http2 (0.26.0) sha256=bac89cd78082b241ccd0cf7246f5160e4bb0c9c975fb4bf7deef5f88cc317486 + protocol-http (0.71.0) sha256=38577bf3df0bf0c3f7ee7e21b43fcb4bd7624e36f697dbe9c3eea344f14bd9ba + protocol-http1 (0.41.0) sha256=9863874a1228948a896c3e7ea16d13a680c8f3ed50706007c78b7033018b0ea3 + protocol-http2 (0.28.0) sha256=b7c6195dcfa80ec2484670e9fd8fc21024cc654a391aa0792433aff1188c1691 protocol-rack (0.22.1) sha256=1185d245927ef9849a603700d6991ca353bc89724fbf98efa4a4333ed62a9fc3 - protocol-url (0.4.0) sha256=64d4c03b6b51ad815ac6fdaf77a1d91e5baf9220d26becb846c5459dacdea9e1 - protocol-websocket (0.21.1) sha256=34325e4325697f0956877e67784bcc838cfd51ebbf4f8e9e5201be292041ee61 - rack (3.2.6) sha256=5ed78e1f73b2e25679bec7d45ee2d4483cc4146eb1be0264fc4d94cb5ef212c2 + protocol-url (0.19.0) sha256=3f6b9f6aa742a259a0b3610fbbd9685dcd9506adf6734f428ff96259faabfb21 + protocol-websocket (0.21.2) sha256=cbe35be8e045597b221874fba5928d7cd2483884126e3e36faece4741dc88eb7 + rack (3.2.7) sha256=93e13e1c24f93556671d85d2d79fa228c3485815c50d7e2f265b5330c6528fb7 rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701 rexml (3.4.4) sha256=19e0a2c3425dfbf2d4fc1189747bdb2f849b6c5e74180401b15734bc97b5d142 - rubyzip (3.4.0) sha256=6de39bc9eba302b635a476d16c9e16b0872ad24517c2f98f2b3a7ea23caff57b - sdl2-bindings (0.2.3) sha256=878c0755a4bea1aed0fa85c01596effd1c2b7d1878141ceec5bef808038bd309 - traces (0.18.2) sha256=80f1649cb4daace1d7174b81f3b3b7427af0b93047759ba349960cb8f315e214 + rubyzip (3.6.0) sha256=268994d44d62282d1cfd99bf10eae48d7267199158ad7ea3e1fee2da9458b695 + sdl3-bindings (1.0.4) sha256=326f497c30e6a5cab402e6178403b30c9df4a11a4e109e08c5da6e920c7bb55b BUNDLED WITH 4.0.8 diff --git a/lib/ico.rb b/lib/ico.rb index 492ccde..c7a7121 100644 --- a/lib/ico.rb +++ b/lib/ico.rb @@ -122,7 +122,8 @@ module W3DHubLauncher end end - Gosu::Image.from_blob(image.width, image.height, blob) + # Gosu::Image.from_blob(image.width, image.height, blob) + ChunkyPNG::Canvas.from_rgba_stream(image.width, image.height, blob) end def image_data(image) diff --git a/lib/worker.rb b/lib/worker.rb index 39a5403..90bf5f9 100644 --- a/lib/worker.rb +++ b/lib/worker.rb @@ -4,6 +4,7 @@ module W3DHubLauncher ["user-agent", W3DHubLauncher::USER_AGENT] ].freeze DEFAULT_NETWORK_TIMEOUT = 30 + RESPONSE_SEPARATOR = "\04".freeze Response = Data.define(:status, :request_id, :result) @@ -13,6 +14,7 @@ module W3DHubLauncher def connect puts :connect + @buffer = StringIO.new @socket = UNIXSocket.new(IPC_PATH) end @@ -55,7 +57,9 @@ module W3DHubLauncher response = send(query.type, query) # pp [:server_to_client, response] payload = { status: response.status, request_id: response.request_id, data: response.result.data, error: response.result.error }.to_json - socket.puts(payload) + socket.write(payload) + socket.write(RESPONSE_SEPARATOR) + socket.flush end end end @@ -133,22 +137,32 @@ module W3DHubLauncher def service data = @socket.read_nonblock(1_048_576) # 1 MB - # pp [:CLIENT, data] - json = JSON.parse(data) - request = W3DHubLauncher::Worker::Request.requests.find { |r| r.request_id == json["request_id"] } + @buffer << data - # pp [json, request] - return unless request + @buffer.rewind + payloads = @buffer.readlines(RESPONSE_SEPARATOR, chomp: true) + @buffer.reopen(@buffer.string[@buffer.pos..@buffer.length]) + @buffer.pos = @buffer.length - CyberarmEngine::Window.instance&.add_to_queue(proc { - request.handle_event( - json["status"], - CyberarmEngine::Result.new(data: json["data"], error: json["error"]) - ) - }) + payloads.each do |payload| + # pp [:CLIENT, data] + json = JSON.parse(payload) + request = W3DHubLauncher::Worker::Request.requests.find { |r| r.request_id == json["request_id"] } - rescue JSON::ParserError => e - puts "This should never happen!?!?!" + # pp [json, request] + return unless request + + CyberarmEngine::Window.instance&.add_to_queue(proc { + request.handle_event( + json["status"], + CyberarmEngine::Result.new(data: json["data"], error: json["error"]) + ) + }) + + rescue JSON::ParserError => e + puts "This should never happen!?!?!" + pp data, payload + end rescue Errno::EWOULDBLOCK end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index bbbc5e7..b99e2aa 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -18,6 +18,7 @@ require "async/websocket" require "digest/crc" require "ircparser" require "zip" +require "chunky_png" require_relative "lib/version" require_relative "lib/constants"