mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Codechange: use std::chrono to track time in modal windows
Adding to _realtime_ticks in a random place is a bit of a hack, and by using modern C++, we can avoid this hack.
This commit is contained in:
parent
1f6fb8c290
commit
d437445c67
@ -1188,7 +1188,7 @@ struct GenWorldStatus {
|
|||||||
StringID cls;
|
StringID cls;
|
||||||
uint current;
|
uint current;
|
||||||
uint total;
|
uint total;
|
||||||
int timer;
|
std::chrono::steady_clock::time_point timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GenWorldStatus _gws;
|
static GenWorldStatus _gws;
|
||||||
@ -1294,7 +1294,7 @@ void PrepareGenerateWorldProgress()
|
|||||||
_gws.current = 0;
|
_gws.current = 0;
|
||||||
_gws.total = 0;
|
_gws.total = 0;
|
||||||
_gws.percent = 0;
|
_gws.percent = 0;
|
||||||
_gws.timer = 0; // Forces to paint the progress window immediately
|
_gws.timer = std::chrono::steady_clock::now() - std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT * 2); // Ensure we draw on first update
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1329,7 +1329,7 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Don't update the screen too often. So update it once in every once in a while... */
|
/* Don't update the screen too often. So update it once in every once in a while... */
|
||||||
if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < MODAL_PROGRESS_REDRAW_TIMEOUT) return;
|
if (!_network_dedicated && std::chrono::steady_clock::now() - _gws.timer < std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT)) return;
|
||||||
|
|
||||||
/* Percentage is about the number of completed tasks, so 'current - 1' */
|
/* Percentage is about the number of completed tasks, so 'current - 1' */
|
||||||
_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
|
_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
|
||||||
@ -1365,7 +1365,7 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
|
|||||||
_modal_progress_work_mutex.lock();
|
_modal_progress_work_mutex.lock();
|
||||||
_modal_progress_paint_mutex.unlock();
|
_modal_progress_paint_mutex.unlock();
|
||||||
|
|
||||||
_gws.timer = _realtime_tick;
|
_gws.timer = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1470,9 +1470,8 @@ void DrawDirtyBlocks()
|
|||||||
_modal_progress_paint_mutex.unlock();
|
_modal_progress_paint_mutex.unlock();
|
||||||
_modal_progress_work_mutex.unlock();
|
_modal_progress_work_mutex.unlock();
|
||||||
|
|
||||||
/* Wait a while and update _realtime_tick so we are given the rights */
|
/* Wait a while and hope the modal gives us a bit of time to draw the GUI. */
|
||||||
if (!IsFirstModalProgressLoop()) CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT);
|
if (!IsFirstModalProgressLoop()) CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT);
|
||||||
_realtime_tick += MODAL_PROGRESS_REDRAW_TIMEOUT;
|
|
||||||
|
|
||||||
/* Modal progress thread may need blitter access while we are waiting for it. */
|
/* Modal progress thread may need blitter access while we are waiting for it. */
|
||||||
VideoDriver::GetInstance()->ReleaseBlitterLock();
|
VideoDriver::GetInstance()->ReleaseBlitterLock();
|
||||||
|
Loading…
Reference in New Issue
Block a user