refactor: Model Preview use time delta instead of frame/tick rate (#2881)
Closes #2880
This commit is contained in:
parent
6212171fc8
commit
0fb17b668e
@ -131,6 +131,8 @@ namespace big
|
|||||||
|
|
||||||
g_fiber_pool->queue_job([this] {
|
g_fiber_pool->queue_job([this] {
|
||||||
m_loop_running = true;
|
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()))
|
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);
|
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)
|
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 = 0;
|
|
||||||
}
|
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();
|
script::get_current()->yield();
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,6 @@ namespace big
|
|||||||
{
|
{
|
||||||
class model_preview_service
|
class model_preview_service
|
||||||
{
|
{
|
||||||
std::condition_variable m_cond;
|
|
||||||
std::mutex m_mutex;
|
|
||||||
|
|
||||||
Entity m_current_ent = 0;
|
Entity m_current_ent = 0;
|
||||||
|
|
||||||
Hash m_veh_model_hash = 0;
|
Hash m_veh_model_hash = 0;
|
||||||
@ -24,6 +21,8 @@ namespace big
|
|||||||
|
|
||||||
std::string m_current_persisted_vehicle_name;
|
std::string m_current_persisted_vehicle_name;
|
||||||
|
|
||||||
|
std::chrono::time_point<std::chrono::steady_clock> start_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
model_preview_service();
|
model_preview_service();
|
||||||
~model_preview_service();
|
~model_preview_service();
|
||||||
@ -36,7 +35,10 @@ namespace big
|
|||||||
void show_vehicle_persisted(std::string vehicle_name);
|
void show_vehicle_persisted(std::string vehicle_name);
|
||||||
void show_vehicle(Vehicle veh);
|
void show_vehicle(Vehicle veh);
|
||||||
|
|
||||||
|
private:
|
||||||
void preview_loop();
|
void preview_loop();
|
||||||
|
|
||||||
|
public:
|
||||||
void stop_preview();
|
void stop_preview();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user