Clean up ChatThrottle (Not currently used?)

main
jeffi 10 months ago
parent 49b1a92252
commit 2ee8f47827
  1. 69
      DiesalComm-1.0/ChatThrottleLib.lua

@ -25,36 +25,32 @@
local CTL_VERSION = 23 local CTL_VERSION = 23
local _G = _G if ChatThrottleLib then
if ChatThrottleLib.version >= CTL_VERSION then
if _G.ChatThrottleLib then
if _G.ChatThrottleLib.version >= CTL_VERSION then
-- There's already a newer (or same) version loaded. Buh-bye. -- There's already a newer (or same) version loaded. Buh-bye.
return return
elseif not _G.ChatThrottleLib.securelyHooked then elseif not ChatThrottleLib.securelyHooked then
print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!") print("ChatThrottleLib: Warning: There's an ANCIENT ChatThrottleLib.lua (pre-wow 2.0, <v16) in an addon somewhere. Get the addon updated or copy in a newer ChatThrottleLib.lua (>=v16) in it!")
-- ATTEMPT to unhook; this'll behave badly if someone else has hooked... -- ATTEMPT to unhook; this'll behave badly if someone else has hooked...
-- ... and if someone has securehooked, they can kiss that goodbye too... >.< -- ... and if someone has securehooked, they can kiss that goodbye too... >.<
_G.SendChatMessage = _G.ChatThrottleLib.ORIG_SendChatMessage SendChatMessage = ChatThrottleLib.ORIG_SendChatMessage
if _G.ChatThrottleLib.ORIG_SendAddonMessage then if ChatThrottleLib.ORIG_SendAddonMessage then
_G.SendAddonMessage = _G.ChatThrottleLib.ORIG_SendAddonMessage SendAddonMessage = ChatThrottleLib.ORIG_SendAddonMessage
end end
end end
_G.ChatThrottleLib.ORIG_SendChatMessage = nil ChatThrottleLib.ORIG_SendChatMessage = nil
_G.ChatThrottleLib.ORIG_SendAddonMessage = nil ChatThrottleLib.ORIG_SendAddonMessage = nil
end end
if not _G.ChatThrottleLib then if not ChatThrottleLib then
_G.ChatThrottleLib = {} ChatThrottleLib = {}
end end
ChatThrottleLib = _G.ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh) ChatThrottleLib = ChatThrottleLib -- in case some addon does "local ChatThrottleLib" above us and we're copypasted (AceComm-2, sigh)
local ChatThrottleLib = _G.ChatThrottleLib local ChatThrottleLib = ChatThrottleLib
ChatThrottleLib.version = CTL_VERSION ChatThrottleLib.version = CTL_VERSION
------------------ TWEAKABLES ----------------- ------------------ TWEAKABLES -----------------
ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800. ChatThrottleLib.MAX_CPS = 800 -- 2000 seems to be safe if NOTHING ELSE is happening. let's call it 800.
@ -64,7 +60,6 @@ ChatThrottleLib.BURST = 4000 -- WoW's server buffer seems to be about 32KB. 8
ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value ChatThrottleLib.MIN_FPS = 20 -- Reduce output CPS to half (and don't burst) if FPS drops below this value
local setmetatable = setmetatable local setmetatable = setmetatable
local table_remove = table.remove local table_remove = table.remove
local tostring = tostring local tostring = tostring
@ -78,7 +73,6 @@ local strlower = string.lower
local unpack, type, pairs, wipe = unpack, type, pairs, wipe local unpack, type, pairs, wipe = unpack, type, pairs, wipe
local UnitInRaid, UnitInParty = UnitInRaid, UnitInParty local UnitInRaid, UnitInParty = UnitInRaid, UnitInParty
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Double-linked ring implementation -- Double-linked ring implementation
@ -115,8 +109,6 @@ function Ring:Remove(obj)
end end
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Recycling bin for pipes -- Recycling bin for pipes
-- A pipe is a plain integer-indexed queue of messages -- A pipe is a plain integer-indexed queue of messages
@ -139,9 +131,6 @@ local function NewPipe()
return {} return {}
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Recycling bin for messages -- Recycling bin for messages
@ -163,14 +152,11 @@ local function NewMsg()
return {} return {}
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- ChatThrottleLib:Init -- ChatThrottleLib:Init
-- Initialize queues, set up frame for OnUpdate, etc -- Initialize queues, set up frame for OnUpdate, etc
function ChatThrottleLib:Init() function ChatThrottleLib:Init()
-- Set up queues -- Set up queues
if not self.Prio then if not self.Prio then
self.Prio = {} self.Prio = {}
@ -191,7 +177,6 @@ function ChatThrottleLib:Init()
self.nTotalSent = 0 -- v5 self.nTotalSent = 0 -- v5
end end
-- Set up a frame to get OnUpdate events -- Set up a frame to get OnUpdate events
if not self.Frame then if not self.Frame then
self.Frame = CreateFrame("Frame") self.Frame = CreateFrame("Frame")
@ -220,7 +205,6 @@ function ChatThrottleLib:Init()
self.nBypass = 0 self.nBypass = 0
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage -- ChatThrottleLib.Hook_SendChatMessage / .Hook_SendAddonMessage
@ -240,21 +224,19 @@ function ChatThrottleLib.Hook_SendAddonMessage(prefix, text, chattype, destinati
return return
end end
local self = ChatThrottleLib local self = ChatThrottleLib
local size = tostring(text or ""):len() + tostring(prefix or ""):len(); local size = tostring(text or ""):len() + tostring(prefix or ""):len()
size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD size = size + tostring(destination or ""):len() + self.MSG_OVERHEAD
self.avail = self.avail - size self.avail = self.avail - size
self.nBypass = self.nBypass + size -- just a statistic self.nBypass = self.nBypass + size -- just a statistic
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- ChatThrottleLib:UpdateAvail -- ChatThrottleLib:UpdateAvail
-- Update self.avail with how much bandwidth is currently available -- Update self.avail with how much bandwidth is currently available
function ChatThrottleLib:UpdateAvail() function ChatThrottleLib:UpdateAvail()
local now = GetTime() local now = GetTime()
local MAX_CPS = self.MAX_CPS; local MAX_CPS = self.MAX_CPS
local newavail = MAX_CPS * (now - self.LastAvailUpdate) local newavail = MAX_CPS * (now - self.LastAvailUpdate)
local avail = self.avail local avail = self.avail
@ -278,7 +260,6 @@ function ChatThrottleLib:UpdateAvail()
return avail return avail
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Despooling logic -- Despooling logic
-- Reminder: -- Reminder:
@ -321,7 +302,6 @@ function ChatThrottleLib:Despool(Prio)
end end
end end
function ChatThrottleLib.OnEvent(this, event) function ChatThrottleLib.OnEvent(this, event)
-- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too. -- v11: We know that the rate limiter is touchy after login. Assume that it's touchy after zoning, too.
local self = ChatThrottleLib local self = ChatThrottleLib
@ -331,7 +311,6 @@ function ChatThrottleLib.OnEvent(this,event)
end end
end end
function ChatThrottleLib.OnUpdate(this, delay) function ChatThrottleLib.OnUpdate(this, delay)
local self = ChatThrottleLib local self = ChatThrottleLib
@ -380,12 +359,8 @@ function ChatThrottleLib.OnUpdate(this,delay)
end end
end end
end end
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Spooling logic -- Spooling logic
@ -410,7 +385,7 @@ function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, languag
error('Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]]', 2) error('Usage: ChatThrottleLib:SendChatMessage("{BULK||NORMAL||ALERT}", "prefix", "text"[, "chattype"[, "language"[, "destination"]]]', 2)
end end
if callbackFn and type(callbackFn) ~= "function" then if callbackFn and type(callbackFn) ~= "function" then
error('ChatThrottleLib:ChatMessage(): callbackFn: expected function, got '..type(callbackFn), 2) error("ChatThrottleLib:ChatMessage(): callbackFn: expected function, got " .. type(callbackFn), 2)
end end
local nSize = text:len() local nSize = text:len()
@ -450,16 +425,15 @@ function ChatThrottleLib:SendChatMessage(prio, prefix, text, chattype, languag
self:Enqueue(prio, queueName or (prefix .. (chattype or "SAY") .. (destination or "")), msg) self:Enqueue(prio, queueName or (prefix .. (chattype or "SAY") .. (destination or "")), msg)
end end
function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target, queueName, callbackFn, callbackArg) function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target, queueName, callbackFn, callbackArg)
if not self or not prio or not prefix or not text or not chattype or not self.Prio[prio] then if not self or not prio or not prefix or not text or not chattype or not self.Prio[prio] then
error('Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"])', 2) error('Usage: ChatThrottleLib:SendAddonMessage("{BULK||NORMAL||ALERT}", "prefix", "text", "chattype"[, "target"])', 2)
end end
if callbackFn and type(callbackFn) ~= "function" then if callbackFn and type(callbackFn) ~= "function" then
error('ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got '..type(callbackFn), 2) error("ChatThrottleLib:SendAddonMessage(): callbackFn: expected function, got " .. type(callbackFn), 2)
end end
local nSize = text:len(); local nSize = text:len()
if RegisterAddonMessagePrefix then if RegisterAddonMessagePrefix then
if nSize > 255 then if nSize > 255 then
@ -472,7 +446,7 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
end end
end end
nSize = nSize + self.MSG_OVERHEAD; nSize = nSize + self.MSG_OVERHEAD
-- Check if there's room in the global available bandwidth gauge to send directly -- Check if there's room in the global available bandwidth gauge to send directly
if not self.bQueueing and nSize < self:UpdateAvail() then if not self.bQueueing and nSize < self:UpdateAvail() then
@ -495,7 +469,7 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
msg[2] = text msg[2] = text
msg[3] = chattype msg[3] = chattype
msg[4] = target msg[4] = target
msg.n = (target~=nil) and 4 or 3; msg.n = (target ~= nil) and 4 or 3
msg.nSize = nSize msg.nSize = nSize
msg.callbackFn = callbackFn msg.callbackFn = callbackFn
msg.callbackArg = callbackArg msg.callbackArg = callbackArg
@ -503,9 +477,6 @@ function ChatThrottleLib:SendAddonMessage(prio, prefix, text, chattype, target,
self:Enqueue(prio, queueName or (prefix .. chattype .. (target or "")), msg) self:Enqueue(prio, queueName or (prefix .. chattype .. (target or "")), msg)
end end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- Get the ball rolling! -- Get the ball rolling!
@ -520,5 +491,3 @@ if(WOWB_VER) then
ChatThrottleLib.Frame:RegisterEvent("CHAT_MSG_SAY") ChatThrottleLib.Frame:RegisterEvent("CHAT_MSG_SAY")
end end
]] ]]

Loading…
Cancel
Save