mirror of
https://github.com/GreenComfyTea/MHR-Overlay.git
synced 2026-01-24 04:18:11 -08:00
Clean up.
This commit is contained in:
@@ -22,38 +22,6 @@ local stamina_param_type_def = sdk.find_type_definition("snow.enemy.EnemyStamina
|
|||||||
local stamina_sub_method = stamina_param_type_def:get_method("sub");
|
local stamina_sub_method = stamina_param_type_def:get_method("sub");
|
||||||
local stamina_update_method = stamina_param_type_def:get_method("updateParam");
|
local stamina_update_method = stamina_param_type_def:get_method("updateParam");
|
||||||
|
|
||||||
local tick_count = 0;
|
|
||||||
local last_update_tick = 0;
|
|
||||||
local recorded_monsters = {};
|
|
||||||
local updated_monsters = {};
|
|
||||||
local known_big_monsters = {};
|
|
||||||
local num_known_monsters = 0;
|
|
||||||
local num_updated_monsters = 0;
|
|
||||||
|
|
||||||
local updates_this_tick = 0;
|
|
||||||
|
|
||||||
-- run every tick to keep track of msonsters
|
|
||||||
-- whenever we've updated enough monsters to surpass how many we've seen,
|
|
||||||
-- we reset and start over
|
|
||||||
-- this allows us to only update N monsters per tick to save on performance
|
|
||||||
-- the reason for this is that the hooks on all the monsters' update functions
|
|
||||||
-- causes a HUGE performance hit (adds ~3+ ms to UpdateBehavior and frame time)
|
|
||||||
re.on_pre_application_entry("UpdateBehavior", function()
|
|
||||||
tick_count = tick_count + 1;
|
|
||||||
updates_this_tick = 0;
|
|
||||||
|
|
||||||
if num_known_monsters ~= 0 and num_updated_monsters >= num_known_monsters or tick_count >= num_known_monsters * 2 then
|
|
||||||
recorded_monsters = {};
|
|
||||||
updated_monsters = {};
|
|
||||||
known_big_monsters = {};
|
|
||||||
last_update_tick = 0;
|
|
||||||
tick_count = 0;
|
|
||||||
num_known_monsters = 0;
|
|
||||||
num_updated_monsters = 0;
|
|
||||||
updates_this_tick = 0;
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
--snow.enemy.EnemyDamageStockParam
|
--snow.enemy.EnemyDamageStockParam
|
||||||
function monster_hook.update_health(enemy_damage_stock_param)
|
function monster_hook.update_health(enemy_damage_stock_param)
|
||||||
local enemy = enemy_damage_stock_param:call("get_RefEnemy");
|
local enemy = enemy_damage_stock_param:call("get_RefEnemy");
|
||||||
@@ -118,81 +86,30 @@ function monster_hook.update_rage_timer(anger_param, enemy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function monster_hook.update_monster(enemy)
|
function monster_hook.update_monster(enemy)
|
||||||
|
local is_large = is_boss_enemy_method:call(enemy);
|
||||||
if enemy == nil then
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
if not recorded_monsters[enemy] then
|
|
||||||
num_known_monsters = num_known_monsters + 1;
|
|
||||||
recorded_monsters[enemy] = true;
|
|
||||||
end
|
|
||||||
|
|
||||||
-- saves on a method call.
|
|
||||||
if not known_big_monsters[enemy] then
|
|
||||||
known_big_monsters[enemy] = is_boss_enemy_method:call(enemy);
|
|
||||||
end
|
|
||||||
|
|
||||||
local is_large = known_big_monsters[enemy];
|
|
||||||
|
|
||||||
if is_large == nil then
|
if is_large == nil then
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_large then
|
if is_large then
|
||||||
monster_hook.update_large_monster(enemy);
|
local cached_config = config.current_config.large_monster_UI;
|
||||||
|
local monster = large_monster.get_monster(enemy);
|
||||||
|
|
||||||
|
if not cached_config.dynamic.enabled then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
large_monster.update_position(enemy, monster);
|
||||||
else
|
else
|
||||||
monster_hook.update_small_monster(enemy);
|
if not config.current_config.small_monster_UI.enabled then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
local monster = small_monster.get_monster(enemy);
|
||||||
|
small_monster.update_position(enemy, monster);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function monster_hook.update_large_monster(enemy)
|
|
||||||
local cached_config = config.current_config.large_monster_UI;
|
|
||||||
|
|
||||||
local monster = large_monster.get_monster(enemy);
|
|
||||||
|
|
||||||
if not cached_config.dynamic.enabled then
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
-- this is the VERY LEAST thing we should do all the time
|
|
||||||
-- so the position doesn't lag all over the place
|
|
||||||
-- due to how infrequently we update the monster(s).
|
|
||||||
large_monster.update_position(enemy, monster);
|
|
||||||
end
|
|
||||||
|
|
||||||
function monster_hook.update_small_monster(enemy)
|
|
||||||
if not config.current_config.small_monster_UI.enabled then
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
local monster = small_monster.get_monster(enemy);
|
|
||||||
|
|
||||||
-- this is the VERY LEAST thing we should do all the time
|
|
||||||
-- so the position doesn't lag all over the place
|
|
||||||
-- due to how infrequently we update the monster(s).
|
|
||||||
small_monster.update_position(enemy, monster);
|
|
||||||
|
|
||||||
if updated_monsters[enemy] then
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
-- is it old tick?
|
|
||||||
-- is update limit reached?
|
|
||||||
if tick_count == last_update_tick and updates_this_tick >= config.current_config.global_settings.performance.max_monster_updates_per_tick then
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
-- actually update the enemy now. we don't do this very often
|
|
||||||
-- due to how much CPU time it takes to update each monster.
|
|
||||||
updates_this_tick = updates_this_tick + 1;
|
|
||||||
last_update_tick = tick_count;
|
|
||||||
num_updated_monsters = num_updated_monsters + 1;
|
|
||||||
updated_monsters[enemy] = true;
|
|
||||||
|
|
||||||
--small_monster.update(enemy, monster);
|
|
||||||
end
|
|
||||||
|
|
||||||
function monster_hook.init_module()
|
function monster_hook.init_module()
|
||||||
small_monster = require("MHR_Overlay.Monsters.small_monster");
|
small_monster = require("MHR_Overlay.Monsters.small_monster");
|
||||||
large_monster = require("MHR_Overlay.Monsters.large_monster");
|
large_monster = require("MHR_Overlay.Monsters.large_monster");
|
||||||
|
|||||||
Reference in New Issue
Block a user