From 728b7f990fde6a91bfb128934ad883705ba5116a Mon Sep 17 00:00:00 2001 From: GreenComfyTea Date: Wed, 16 Aug 2023 10:30:59 +0300 Subject: [PATCH] Move timers initializations into time.lua --- reframework/autorun/MHR_Overlay.lua | 1 + .../autorun/MHR_Overlay/Buffs/buffs.lua | 2 +- .../MHR_Overlay/Damage_Meter/players.lua | 2 -- .../MHR_Overlay/Game_Handler/quest_status.lua | 2 -- .../MHR_Overlay/Game_Handler/screen.lua | 1 - .../MHR_Overlay/Game_Handler/singletons.lua | 1 - .../autorun/MHR_Overlay/Game_Handler/time.lua | 23 ++++++++++++++++--- .../autorun/MHR_Overlay/Misc/player_info.lua | 1 - 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/reframework/autorun/MHR_Overlay.lua b/reframework/autorun/MHR_Overlay.lua index 3a6f3b2..20ef5cd 100644 --- a/reframework/autorun/MHR_Overlay.lua +++ b/reframework/autorun/MHR_Overlay.lua @@ -532,4 +532,5 @@ if imgui.begin_table == nil then re.msg(language.current_language.customization_menu.reframework_outdated); end +time.init_global_timers(); time.new_timer(update_UI, 0.5); \ No newline at end of file diff --git a/reframework/autorun/MHR_Overlay/Buffs/buffs.lua b/reframework/autorun/MHR_Overlay/Buffs/buffs.lua index 32b47ce..7dea2e7 100644 --- a/reframework/autorun/MHR_Overlay/Buffs/buffs.lua +++ b/reframework/autorun/MHR_Overlay/Buffs/buffs.lua @@ -231,7 +231,7 @@ function this.init_dependencies() end function this.init_module() - time.new_timer(this.update, 1/60); + end return this; \ No newline at end of file diff --git a/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua b/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua index 2302f7a..4926637 100644 --- a/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua +++ b/reframework/autorun/MHR_Overlay/Damage_Meter/players.lua @@ -664,8 +664,6 @@ end function this.init_module() this.init(); - time.new_timer(this.update_display_list, 0.5); - time.new_timer(this.update_myself_position, 1); end return this; diff --git a/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua b/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua index 33e7f0f..78c279b 100644 --- a/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua +++ b/reframework/autorun/MHR_Overlay/Game_Handler/quest_status.lua @@ -405,8 +405,6 @@ end function this.init_module() this.init(); - time.new_timer(this.update_is_online, 1); - sdk.hook(on_changed_game_status_method, function(args) this.on_changed_game_status(sdk.to_int64(args[3])); end, function(retval) return retval; end); diff --git a/reframework/autorun/MHR_Overlay/Game_Handler/screen.lua b/reframework/autorun/MHR_Overlay/Game_Handler/screen.lua index b6fd20e..ae3fb87 100644 --- a/reframework/autorun/MHR_Overlay/Game_Handler/screen.lua +++ b/reframework/autorun/MHR_Overlay/Game_Handler/screen.lua @@ -143,7 +143,6 @@ function this.init_dependencies() end function this.init_module() - time.new_timer(this.update_window_size, 1); end return this; diff --git a/reframework/autorun/MHR_Overlay/Game_Handler/singletons.lua b/reframework/autorun/MHR_Overlay/Game_Handler/singletons.lua index 1acfbf7..ba56536 100644 --- a/reframework/autorun/MHR_Overlay/Game_Handler/singletons.lua +++ b/reframework/autorun/MHR_Overlay/Game_Handler/singletons.lua @@ -191,7 +191,6 @@ end function this.init_module() this.init(); - time.new_timer(this.init, 1); end return this; diff --git a/reframework/autorun/MHR_Overlay/Game_Handler/time.lua b/reframework/autorun/MHR_Overlay/Game_Handler/time.lua index f92a9ac..b27478e 100644 --- a/reframework/autorun/MHR_Overlay/Game_Handler/time.lua +++ b/reframework/autorun/MHR_Overlay/Game_Handler/time.lua @@ -9,6 +9,9 @@ local config; local small_monster; local utils; local error_handler; +local screen; +local buffs; +local player_info; local sdk = sdk; local tostring = tostring; @@ -60,23 +63,34 @@ function this.new_timer(callback, cooldown_seconds, start_offset_seconds) if callback == nil or cooldown_seconds == nil then return; end + local timer = {}; timer.callback = callback; timer.cooldown = cooldown_seconds; timer.last_trigger_time = os.clock() + start_offset_seconds; - table.insert(this.list, timer); + this.list[callback] = timer; end +function this.init_global_timers() + this.new_timer(singletons.init, 1); + this.new_timer(screen.update_window_size, 1); + this.new_timer(quest_status.update_is_online, 1); + this.new_timer(players.update_display_list, 0.5); + this.new_timer(players.update_myself_position, 1); + this.new_timer(buffs.update, 1/60); + this.new_timer(player_info.update, 0.5); +end + function this.update_timers() this.update_script_time(); - for _, timer in ipairs(this.list) do + for callback, timer in pairs(this.list) do if this.total_elapsed_script_seconds - timer.last_trigger_time > timer.cooldown then timer.last_trigger_time = this.total_elapsed_script_seconds; - timer.callback(); + callback(); end end end @@ -122,6 +136,9 @@ function this.init_dependencies() non_players = require("MHR_Overlay.Damage_Meter.non_players"); utils = require("MHR_Overlay.Misc.utils"); error_handler = require("MHR_Overlay.Misc.error_handler"); + screen = require("MHR_Overlay.Game_Handler.screen"); + buffs = require("MHR_Overlay.Buffs.buffs"); + player_info = require("MHR_Overlay.Misc.player_info"); end function this.init_module() diff --git a/reframework/autorun/MHR_Overlay/Misc/player_info.lua b/reframework/autorun/MHR_Overlay/Misc/player_info.lua index 386f6fe..34cd99c 100644 --- a/reframework/autorun/MHR_Overlay/Misc/player_info.lua +++ b/reframework/autorun/MHR_Overlay/Misc/player_info.lua @@ -245,7 +245,6 @@ function this.init_dependencies() end function this.init_module() - time.new_timer(this.update, 0.5); end return this;