[Enhancement]: Stability Improvements to Black Hole Feature (#3132)

This commit is contained in:
R.K 2024-05-16 09:47:25 -07:00 committed by GitHub
parent 059f831c52
commit 00f5c34e2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,10 +11,23 @@ namespace big
{ {
using looped_command::looped_command; using looped_command::looped_command;
std::vector<Entity> entity_list;
std::chrono::steady_clock::time_point last_call_time;
virtual void on_tick() override virtual void on_tick() override
{ {
for (auto entity : entity::get_entities(g.world.blackhole.include_vehicles, g.world.blackhole.include_peds)) auto current_time = std::chrono::steady_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - last_call_time).count();
if (elapsed_time >= 1000) // Reduce black hole gather spam so it pulses only every second
{ {
entity_list = entity::get_entities(g.world.blackhole.include_vehicles, g.world.blackhole.include_peds);
last_call_time = current_time;
for (int i = 0; i < 30 && i < entity_list.size(); i++) // Only yeet up to 30 entities every second to prevent crashes
{
auto entity = entity_list[i];
if (entity::take_control_of(entity, 0)) if (entity::take_control_of(entity, 0))
{ {
auto entity_coord = ENTITY::GET_ENTITY_COORDS(entity, false); auto entity_coord = ENTITY::GET_ENTITY_COORDS(entity, false);
@ -34,6 +47,7 @@ namespace big
0); 0);
} }
} }
}
//draw blackhole //draw blackhole
GRAPHICS::DRAW_MARKER(28, GRAPHICS::DRAW_MARKER(28,
@ -64,6 +78,8 @@ namespace big
}; };
blackhole g_blackhole("blackhole", "GUI_TAB_BLACKHOLE", "BACKEND_LOOPED_WORLD_BLACKHOLE_DESC", g.world.blackhole.enable); blackhole g_blackhole("blackhole", "GUI_TAB_BLACKHOLE", "BACKEND_LOOPED_WORLD_BLACKHOLE_DESC", g.world.blackhole.enable);
bool_command g_blackhole_peds("blackholeincpeds", "PEDS", "BACKEND_LOOPED_WORLD_BLACKHOLE_PEDS_DESC", g.world.blackhole.include_peds); bool_command
bool_command g_blackhole_vehicles("blackholeincvehs", "VEHICLES", "BACKEND_LOOPED_WORLD_BLACKHOLE_VEHS_DESC", g.world.blackhole.include_vehicles); g_blackhole_peds("blackholeincpeds", "PEDS", "BACKEND_LOOPED_WORLD_BLACKHOLE_PEDS_DESC", g.world.blackhole.include_peds);
bool_command g_blackhole_vehicles("blackholeincvehs", "VEHICLES", "BACKEND_LOOPED_WORLD_BLACKHOLE_VEHS_DESC",
g.world.blackhole.include_vehicles);
} }