fix action player wait actions to properly delay playback finish
Wait actions now extend the minimum finish time based on their timestamp + duration, ensuring timers and other async operations have time to complete before playback ends and screenshot is taken. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@ void ActionPlayer::Start() {
|
|||||||
|
|
||||||
m_start_time = std::chrono::steady_clock::now();
|
m_start_time = std::chrono::steady_clock::now();
|
||||||
m_paused_duration_ms = 0;
|
m_paused_duration_ms = 0;
|
||||||
|
m_min_finish_time_ms = 0;
|
||||||
m_current_index = 0;
|
m_current_index = 0;
|
||||||
m_playing = true;
|
m_playing = true;
|
||||||
m_paused = false;
|
m_paused = false;
|
||||||
@@ -74,17 +75,21 @@ float ActionPlayer::GetProgress() const {
|
|||||||
|
|
||||||
void ActionPlayer::Update() {
|
void ActionPlayer::Update() {
|
||||||
if (!m_playing || m_paused || m_finished) return;
|
if (!m_playing || m_paused || m_finished) return;
|
||||||
if (m_current_index >= m_sequence.actions.size()) {
|
|
||||||
m_finished = true;
|
|
||||||
m_playing = false;
|
|
||||||
std::cout << "ActionPlayer: Finished playback" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
int64_t elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start_time).count();
|
int64_t elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start_time).count();
|
||||||
elapsed_ms -= m_paused_duration_ms;
|
elapsed_ms -= m_paused_duration_ms;
|
||||||
|
|
||||||
|
// Check if all actions done AND minimum finish time reached
|
||||||
|
if (m_current_index >= m_sequence.actions.size()) {
|
||||||
|
if (elapsed_ms >= m_min_finish_time_ms) {
|
||||||
|
m_finished = true;
|
||||||
|
m_playing = false;
|
||||||
|
std::cout << "ActionPlayer: Finished playback" << std::endl;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Execute all actions whose timestamp has passed
|
// Execute all actions whose timestamp has passed
|
||||||
while (m_current_index < m_sequence.actions.size()) {
|
while (m_current_index < m_sequence.actions.size()) {
|
||||||
const auto& action = m_sequence.actions[m_current_index];
|
const auto& action = m_sequence.actions[m_current_index];
|
||||||
@@ -118,7 +123,11 @@ void ActionPlayer::ExecuteAction(const Action& action) {
|
|||||||
SimulateButton(arg.button);
|
SimulateButton(arg.button);
|
||||||
} else if constexpr (std::is_same_v<T, WaitAction>) {
|
} else if constexpr (std::is_same_v<T, WaitAction>) {
|
||||||
std::cout << "ActionPlayer: Wait " << arg.duration_ms << "ms" << std::endl;
|
std::cout << "ActionPlayer: Wait " << arg.duration_ms << "ms" << std::endl;
|
||||||
// Wait is implicit - timing handled by timestamp
|
// Extend the minimum finish time to allow the wait duration to elapse
|
||||||
|
int64_t wait_end_time = arg.timestamp_ms + arg.duration_ms;
|
||||||
|
if (wait_end_time > this->m_min_finish_time_ms) {
|
||||||
|
this->m_min_finish_time_ms = wait_end_time;
|
||||||
|
}
|
||||||
} else if constexpr (std::is_same_v<T, KeyAction>) {
|
} else if constexpr (std::is_same_v<T, KeyAction>) {
|
||||||
std::cout << "ActionPlayer: Key " << arg.key_code << " " << (arg.pressed ? "down" : "up") << std::endl;
|
std::cout << "ActionPlayer: Key " << arg.key_code << " " << (arg.pressed ? "down" : "up") << std::endl;
|
||||||
if (arg.pressed) {
|
if (arg.pressed) {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ private:
|
|||||||
std::chrono::steady_clock::time_point m_start_time;
|
std::chrono::steady_clock::time_point m_start_time;
|
||||||
std::chrono::steady_clock::time_point m_pause_time;
|
std::chrono::steady_clock::time_point m_pause_time;
|
||||||
int64_t m_paused_duration_ms = 0;
|
int64_t m_paused_duration_ms = 0;
|
||||||
|
int64_t m_min_finish_time_ms = 0; // Extended by wait actions
|
||||||
|
|
||||||
ScreenshotCallback m_screenshot_cb;
|
ScreenshotCallback m_screenshot_cb;
|
||||||
NavigateCallback m_navigate_cb;
|
NavigateCallback m_navigate_cb;
|
||||||
|
|||||||
Reference in New Issue
Block a user