Add timer packets to demo playback (#494)
When the demo skips by some number of seconds, the timer will also skip forward by that duration. Co-authored-by: in1tiate <32779090+in1tiate@users.noreply.github.com> Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
This commit is contained in:
parent
e3ba27c47e
commit
510c0f4b17
@ -17,6 +17,8 @@ public:
|
||||
void set(qint64 msecs, bool update_text = false);
|
||||
void pause();
|
||||
void stop();
|
||||
void skip(qint64 msecs);
|
||||
bool active();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
|
@ -307,6 +307,7 @@ public:
|
||||
void pause_clock(int id);
|
||||
void stop_clock(int id);
|
||||
void set_clock_visibility(int id, bool visible);
|
||||
void skip_clocks(qint64 msecs);
|
||||
|
||||
qint64 pong();
|
||||
// Truncates text so it fits within theme-specified boundaries and sets the tooltip to the full string
|
||||
|
@ -48,7 +48,7 @@ public slots:
|
||||
void start_server();
|
||||
|
||||
signals:
|
||||
|
||||
void skip_timers(qint64 msecs);
|
||||
};
|
||||
|
||||
#endif // DEMOSERVER_H
|
||||
|
@ -48,7 +48,7 @@ void AOApplication::construct_lobby()
|
||||
|
||||
if (demo_server)
|
||||
demo_server->deleteLater();
|
||||
demo_server = new DemoServer();
|
||||
demo_server = new DemoServer(this);
|
||||
|
||||
w_lobby->show();
|
||||
}
|
||||
@ -79,6 +79,14 @@ void AOApplication::construct_courtroom()
|
||||
int x = (geometry.width() - w_courtroom->width()) / 2;
|
||||
int y = (geometry.height() - w_courtroom->height()) / 2;
|
||||
w_courtroom->move(x, y);
|
||||
|
||||
if (demo_server != nullptr) {
|
||||
QObject::connect(demo_server, &DemoServer::skip_timers,
|
||||
w_courtroom, &Courtroom::skip_clocks);
|
||||
}
|
||||
else {
|
||||
qDebug() << "W: demo server did not exist during courtroom construction";
|
||||
}
|
||||
}
|
||||
|
||||
void AOApplication::destruct_courtroom()
|
||||
|
@ -43,6 +43,17 @@ void AOClockLabel::stop()
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
void AOClockLabel::skip(qint64 msecs)
|
||||
{
|
||||
qint64 ms_left = QDateTime::currentDateTime().msecsTo(target_time);
|
||||
this->set(ms_left - msecs, true);
|
||||
}
|
||||
|
||||
bool AOClockLabel::active()
|
||||
{
|
||||
return timer.isActive();
|
||||
}
|
||||
|
||||
void AOClockLabel::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() == timer.timerId()) {
|
||||
|
@ -5446,7 +5446,7 @@ void Courtroom::start_clock(int id, qint64 msecs)
|
||||
{
|
||||
if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
|
||||
{
|
||||
ui_clock[id]->start(static_cast<int>(msecs));
|
||||
ui_clock[id]->start(msecs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5454,7 +5454,18 @@ void Courtroom::set_clock(int id, qint64 msecs)
|
||||
{
|
||||
if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
|
||||
{
|
||||
ui_clock[id]->set(static_cast<int>(msecs), true);
|
||||
ui_clock[id]->set(msecs, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Used by demo playback to adjust for max_wait skips
|
||||
void Courtroom::skip_clocks(qint64 msecs)
|
||||
{
|
||||
// Loop through all the timers
|
||||
for (int i = 0; i < max_clocks; i++) {
|
||||
// Only skip time on active clocks
|
||||
if (ui_clock[i]->active())
|
||||
ui_clock[i]->skip(msecs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,8 +259,11 @@ void DemoServer::playback()
|
||||
AOPacket wait_packet = AOPacket(current_packet);
|
||||
|
||||
int duration = wait_packet.get_contents().at(0).toInt();
|
||||
if (max_wait != -1 && duration + elapsed_time > max_wait)
|
||||
if (max_wait != -1 && duration + elapsed_time > max_wait) {
|
||||
duration = qMax(0, max_wait - elapsed_time);
|
||||
// Skip the difference on the timers
|
||||
emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
|
||||
}
|
||||
elapsed_time += duration;
|
||||
timer->start(duration);
|
||||
}
|
||||
|
@ -660,6 +660,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
|
||||
w_courtroom->set_clock_visibility(id, true);
|
||||
else if (type == 3)
|
||||
w_courtroom->set_clock_visibility(id, false);
|
||||
append_to_demofile(p_packet->to_string(true));
|
||||
}
|
||||
else if (header == "CHECK") {
|
||||
if (!courtroom_constructed)
|
||||
|
Loading…
Reference in New Issue
Block a user