Created
February 2, 2023 14:08
-
-
Save jnwhiteh/74f0f10430753ae968afad47c4bb0ac1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[--------------------------------------------------------------------------------- | |
GCTweaker by Cladhaire <[email protected]> | |
A small addon designed to perform more aggressive garbage collection in | |
higher FPS situations. This will not magically fix any memory issues, | |
but will help a garbage collection cycle to complete quicker | |
----------------------------------------------------------------------------------]] | |
-- Initialize default saved variables | |
GCTweakerDB = { | |
fps = 30, | |
enabled = true, | |
debug = false, | |
} | |
local frame = CreateFrame("Frame", "GCTweakerFrame") | |
frame:RegisterEvent("ADDON_LOADED") | |
frame:RegisterEvent("PLAYER_REGEN_ENABLED") | |
frame:RegisterEvent("PLAYER_REGEN_DISABLED") | |
local incombat = false | |
local delta_min | |
local function OnUpdate(self, delta) | |
if not incombat and delta < delta_min then | |
local cycle = collectgarbage("step") | |
if cycle and GCTweakerDB.debug then | |
ChatFrame1:AddMessage("GCTweaker just finished a GC cycle.") | |
end | |
end | |
end | |
frame:SetScript("OnUpdate", OnUpdate) | |
frame:Hide() | |
local function EnableDisable() | |
if GCTweakerDB.enabled then | |
frame:Show() | |
else | |
frame:Hide() | |
end | |
end | |
-- Respond to ADDON_LOADED | |
local function OnEvent(self, event, ...) | |
if event == "ADDON_LOADED" then | |
-- Calculate the correct delta | |
delta_min = 1 / GCTweakerDB.fps | |
EnableDisable() | |
self:UnregisterEvent("ADDON_LOADED") | |
elseif event == "PLAYER_REGEN_ENABLED" then | |
incombat = false | |
elseif event == "PLAYER_REGEN_DISABLED" then | |
incombat = true | |
end | |
end | |
frame:SetScript("OnEvent", OnEvent) | |
local function SlashHandler(msg) | |
local msg = msg:lower() | |
if not msg:match("%S") or msg:match("^help$")then | |
ChatFrame1:AddMessage("---GCTweak usage---") | |
ChatFrame1:AddMessage("/|cFF33FF99gctweak|r toggle |cFF33FF99- Toggles GCTweaker|r on |cFF33FF99or|r off") | |
ChatFrame1:AddMessage("/|cFF33FF99gctweak|r <num> |cFF33FF99- Enables aggressive GC above|r <num> |cFF33FF99fps|r") | |
ChatFrame1:AddMessage("/|cFF33FF99gctweak|r debug |cFF33FF99- Toggles GCTweaker debug messages|r") | |
-- Print current status | |
local statusfmt = "|cFF33FF99GCTweaker is |r%s|cFF33FF99 at |r%d|cFF33FF99 fps with debug messages |r%s" | |
local status = statusfmt:format(GCTweakerDB.enabled and "enabled" or "disabled", GCTweakerDB.fps, GCTweakerDB.debug and "on" or "off") | |
ChatFrame1:AddMessage(status) | |
return | |
elseif msg:match("^toggle$") then | |
GCTweakerDB.enabled = not GCTweakerDB.enabled | |
EnableDisable() | |
if GCTweakerDB.enabled then | |
ChatFrame1:AddMessage("|cFF33FF99GCTweaker has been |renabled|cFF33FF99.|r") | |
else | |
ChatFrame1:AddMessage("|cFF33FF99GCTweaker has been |rdisabled|cFF33FF99.|r") | |
end | |
elseif msg:match("^debug$") then | |
GCTweakerDB.debug = not GCTweakerDB.debug | |
if GCTweakerDB.debug then | |
ChatFrame1:AddMessage("|cFF33FF99GCTweaker debug messages|r enabled|cFF33FF99.|r") | |
else | |
ChatFrame1:AddMessage("|cFF33FF99GCTweaker debug messages|r disabled|cFF33FF99.|r") | |
end | |
else | |
local newfps = tonumber(msg:match("(%d+)")) | |
if newfps then | |
ChatFrame1:AddMessage("|cFF33FF99GCTweaker fps setting set to |r" .. newfps) | |
GCTweakerDB.fps = newfps | |
delta_min = 1 / GCTweakerDB.fps | |
end | |
end | |
end | |
SLASH_GCTWEAK1 = "/gctweak" | |
SLASH_GCTWEAK2 = "/gctweaker" | |
SLASH_GCTWEAK3 = "/gct" | |
SlashCmdList["GCTWEAK"] = SlashHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment