Fixed high memory usage issue

This commit is contained in:
OTCv8
2020-01-14 01:09:33 +01:00
parent 26c347d2bc
commit 11ad766308
16 changed files with 111 additions and 37 deletions

View File

@@ -1,3 +1,23 @@
BotTabBar < MoveableTabBar
tab-spacing: 1
margin-left: 1
margin-right: 1
movable: false
height: 20
$on:
visible: true
margin-top: 2
$!on:
visible: false
margin-top: -20
BotTabBarButton < MoveableTabBarButton
padding: 3
text-horizontal-auto-resize: true
MiniWindow
id: botWindow
!text: tr('Bot')
@@ -88,24 +108,12 @@ MiniWindow
margin-left: 2
margin-right: 2
MoveableTabBar
BotTabBar
id: botTabs
anchors.top: prev.bottom
anchors.left: parent.left
anchors.right: parent.right
tab-spacing: 1
margin-left: 1
margin-right: 1
height: 20
movable: false
$on:
visible: true
margin-top: 2
$!on:
visible: false
margin-top: -20
margin-right: -20
Panel
id: botPanel

View File

@@ -67,6 +67,12 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
context.table = table
context.string = string
context.tonumber = tonumber
context.type = type
context.pcall = pcall
context.load = function(str) return load(str, nil, nil, context) end
context.loadstring = context.load
context.assert = assert
context.gcinfo = gcinfo
context.tr = tr
context.json = json
context.regexMatch = regexMatch
@@ -84,9 +90,16 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
context.g_window = g_window
context.g_mouse = g_mouse
context.Item = Item
context.Creature = Creature
context.ThingType = ThingType
context.Effect = Effect
context.Missile = Missile
context.Player = Player
context.Monster = Monster
context.StaticText = StaticText
context.Config = Config
context.HTTP = HTTP
context.OutputMessage = OutputMessage
context.modules = modules
-- log functions
@@ -123,7 +136,7 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
context.time = g_clock.millis()
for i, macro in ipairs(context._macros) do
if macro.lastExecution + macro.timeout <= context.now and (macro.name == nil or macro.name:len() < 1 or macro.enabled) then
if macro.lastExecution + macro.timeout <= context.now and macro.enabled then
local status, result = pcall(function()
if macro.callback(macro) then
macro.lastExecution = context.now

View File

@@ -0,0 +1,8 @@
North = 0
East = 1
South = 2
West = 3
NorthEast = 4
SouthEast = 5
SouthWest = 6
NorthWest = 7

View File

@@ -10,8 +10,6 @@ context.addIcon = function(id, options, callback)
text: string
x: float (0.0 - 1.0)
y: float (0.0 - 1.0)
width: number
height: number
hotkey: string
switchable: true / false [default: true]
movable: true / false [default: true]
@@ -63,6 +61,9 @@ context.addIcon = function(id, options, callback)
widget.status:hide()
widget.status:setOn(true)
else
if config.enabled ~= true then
config.enabled = false
end
widget.status:setOn(config.enabled)
end

View File

@@ -95,6 +95,8 @@ context.macro = function(timeout, name, hotkey, callback, parent)
if context.storage._macros[name] == true then
macro.setOn()
end
else
macro.enabled = true -- unnamed macros are enabled by default
end
local desc = "lua"

View File

@@ -16,16 +16,17 @@ context.NPC.isTrading = function()
end
context.NPC.hasTrade = context.NPC.isTrading
context.NPC.hasTradeWindow = context.NPC.isTrading
context.NPC.isTradeOpen = context.NPC.isTrading
context.NPC.getSellItems = function()
if not context.NPC.isTrading() then return {} end
local items = {}
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.SELL]) do
table.insert(items, {
item = item.ptr,
id = item.ptr:getId(),
name = item.name,
count = item.ptr:getCount(),
name = item.name,
subType = item.ptr:getSubType(),
weight = item.weight / 100,
price = item.price
@@ -36,11 +37,13 @@ end
context.NPC.getBuyItems = function()
if not context.NPC.isTrading() then return {} end
local items = {}
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.BUY]) do
table.insert(items, {
item = item.ptr,
id = item.ptr:getId(),
name = item.name,
count = item.ptr:getCount(),
name = item.name,
subType = item.ptr:getSubType(),
weight = item.weight / 100,
price = item.price
@@ -67,7 +70,15 @@ end
context.NPC.sell = function(item, count, ignoreEquipped)
if type(item) == 'number' then
for i, entry in ipairs(context.NPC.getSellItems()) do
if entry.id == item then
item = entry.item
break
end
end
if type(item) == 'number' then
item = Item.create(item)
end
end
if count == 0 then
count = 1
@@ -83,7 +94,15 @@ end
context.NPC.buy = function(item, count, ignoreCapacity, withBackpack)
if type(item) == 'number' then
for i, entry in ipairs(context.NPC.getBuyItems()) do
if entry.id == item then
item = entry.item
break
end
end
if type(item) == 'number' then
item = Item.create(item)
end
end
if count == nil or count <= 0 then
count = 1

View File

@@ -10,9 +10,24 @@ context.setupUI = function(otml, parent)
end
context.addTab = function(name)
local tab = context.tabs:getTab(name)
if tab then -- return existing tab
return tab.tabPanel.content
end
context.tabs:setOn(true)
return context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content
local newTab = context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content
print(#(context.tabs.tabs))
if #(context.tabs.tabs) > 5 then
for k,tab in pairs(context.tabs.tabs) do
tab:setPadding(3)
tab:setFont('cipsoftFont')
end
end
return newTab
end
context.getTab = context.addTab
context.addSwitch = function(id, text, onClickCallback, parent)
if not parent then