[Enhancement]: Stability Improvements to Black Hole Feature (#3132)
This commit is contained in:
parent
059f831c52
commit
00f5c34e2a
@ -11,27 +11,41 @@ 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
|
||||||
{
|
{
|
||||||
if (entity::take_control_of(entity, 0))
|
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_coord = ENTITY::GET_ENTITY_COORDS(entity, false);
|
auto entity = entity_list[i];
|
||||||
ENTITY::APPLY_FORCE_TO_ENTITY(entity,
|
|
||||||
1,
|
if (entity::take_control_of(entity, 0))
|
||||||
((g.world.blackhole.pos.x - entity_coord.x) * 9.f),
|
{
|
||||||
((g.world.blackhole.pos.y - entity_coord.y) * 9.f),
|
auto entity_coord = ENTITY::GET_ENTITY_COORDS(entity, false);
|
||||||
((g.world.blackhole.pos.z - entity_coord.z) * 9.f),
|
ENTITY::APPLY_FORCE_TO_ENTITY(entity,
|
||||||
0.f,
|
1,
|
||||||
0.f,
|
((g.world.blackhole.pos.x - entity_coord.x) * 9.f),
|
||||||
0.f,
|
((g.world.blackhole.pos.y - entity_coord.y) * 9.f),
|
||||||
0,
|
((g.world.blackhole.pos.z - entity_coord.z) * 9.f),
|
||||||
false,
|
0.f,
|
||||||
true,
|
0.f,
|
||||||
true,
|
0.f,
|
||||||
0,
|
0,
|
||||||
0);
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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);
|
||||||
}
|
}
|
Reference in New Issue
Block a user