refactor: Model Preview use time delta instead of frame/tick rate (#2881)

Closes #2880
This commit is contained in:
gir489 2024-03-27 09:10:14 -04:00 committed by GitHub
parent a9ccde5ac1
commit 659cffa6f7
2 changed files with 12 additions and 7 deletions

View File

@ -131,6 +131,8 @@ namespace big
g_fiber_pool->queue_job([this] {
m_loop_running = true;
m_heading = 0;
start_time = std::chrono::steady_clock::now();
while (g_running && m_running && g_gui->is_open() && (m_ped_model_hash || m_veh_model_hash || !m_current_persisted_vehicle_name.empty()))
{
@ -204,10 +206,11 @@ namespace big
ENTITY::SET_ENTITY_COORDS(m_current_ent, location.x, location.y, location.z, 0, 0, 0, 0);
}
if (m_heading += 0.11111f; m_heading > 359)
{
m_heading = 0;
}
auto now = std::chrono::steady_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time).count() / 1000.0; // Convert to seconds
m_heading = (elapsed_time / 10.0) * 360.0; // Rotate 360 degrees every 10 seconds
m_heading = fmod(m_heading, 360.0); // Ensure rotation is always between 0 and 360
script::get_current()->yield();
}

View File

@ -5,9 +5,6 @@ namespace big
{
class model_preview_service
{
std::condition_variable m_cond;
std::mutex m_mutex;
Entity m_current_ent = 0;
Hash m_veh_model_hash = 0;
@ -24,6 +21,8 @@ namespace big
std::string m_current_persisted_vehicle_name;
std::chrono::time_point<std::chrono::steady_clock> start_time;
public:
model_preview_service();
~model_preview_service();
@ -36,7 +35,10 @@ namespace big
void show_vehicle_persisted(std::string vehicle_name);
void show_vehicle(Vehicle veh);
private:
void preview_loop();
public:
void stop_preview();
};