From c443d40d2fe3cba1d14ac7955ad21f8ebd6eb6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen?= Date: Sun, 28 Dec 2025 22:15:13 +0100 Subject: [PATCH] async send of messages to avoid fps drop --- .../Modules/ChannelSync.lua | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua b/TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua index 0b22006..cb1ccc9 100644 --- a/TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua +++ b/TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua @@ -13,14 +13,18 @@ local ChannelSync = TSM:NewModule("ChannelSync", "AceEvent-3.0") local CHANNEL_NAME = "TSM_AuctionDB" local COMM_PREFIX = "TSMADB1" -local CHUNK_SIZE = 200 +local CHUNK_SIZE = 220 local BUNDLE_TIMEOUT = 45 +local SEND_INTERVAL = 0.08 +local MAX_TOTAL_CHUNKS = 800 local private = { channelId = nil, channelName = nil, lastBroadcastHash = nil, incoming = {}, + sendQueue = {}, + isSending = false, } local strbyte = string.byte @@ -84,7 +88,7 @@ end local function EncodePayload(payload) if not CanEncode() then return end local serialized = libS:Serialize(payload) - local compressed = libD:CompressDeflate(serialized, { level = 7 }) + local compressed = libD:CompressDeflate(serialized, { level = 9 }) if not compressed then return end return libD:EncodeForPrint(compressed) end @@ -125,11 +129,15 @@ function ChannelSync:BroadcastScanData(scanType) if hash == private.lastBroadcastHash then return end private.lastBroadcastHash = hash local total = ceil(#encoded / CHUNK_SIZE) - if total > 65535 then return end - for i = 1, total do - local chunk = strsub(encoded, (i - 1) * CHUNK_SIZE + 1, i * CHUNK_SIZE) - local msg = COMM_PREFIX .. string.format("%08x%04x%04x", tonumber(hash), i, total) .. chunk - SendChatMessage(msg, "CHANNEL", nil, private.channelId) + if total > MAX_TOTAL_CHUNKS then + TSM:Print("AuctionDB channel sync payload too large; skipping broadcast.") + return + end + + tinsert(private.sendQueue, {hash = hash, encoded = encoded, total = total}) + if not private.isSending then + private.isSending = true + TSMAPI.Threading:Start(ChannelSync.SendQueueThread, 0.3) end end @@ -205,3 +213,17 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName if not payload then return end MergeIncomingData(payload) end + +function ChannelSync:SendQueueThread() + while #private.sendQueue > 0 do + local job = private.sendQueue[1] + for i = 1, job.total do + local chunk = strsub(job.encoded, (i - 1) * CHUNK_SIZE + 1, i * CHUNK_SIZE) + local msg = COMM_PREFIX .. string.format("%08x%04x%04x", job.hash, i, job.total) .. chunk + SendChatMessage(msg, "CHANNEL", nil, private.channelId) + self:Sleep(SEND_INTERVAL) + end + tremove(private.sendQueue, 1) + end + private.isSending = false +end