diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/aoapplication.cpp | 10 | ||||
| -rw-r--r-- | src/aoclocklabel.cpp | 11 | ||||
| -rw-r--r-- | src/courtroom.cpp | 15 | ||||
| -rw-r--r-- | src/demoserver.cpp | 5 | ||||
| -rw-r--r-- | src/packet_distribution.cpp | 1 |
5 files changed, 38 insertions, 4 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index 00845385..00175e56 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -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() diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp index 67a82fe5..ce62f320 100644 --- a/src/aoclocklabel.cpp +++ b/src/aoclocklabel.cpp @@ -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()) { diff --git a/src/courtroom.cpp b/src/courtroom.cpp index d68038c1..fe5f74d1 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -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); } } diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 75664659..88dfdb4b 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -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); } diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 7ec685a6..95b8fa06 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -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) |
