diff options
| author | Crystalwarrior <Varsash@Gmail.com> | 2021-03-21 05:12:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-20 21:12:44 -0500 |
| commit | 510c0f4b17f24eb534d22654a41e9157c89a8211 (patch) | |
| tree | 079a0e3f799ed55ac80370b289b0ba9496eeb7c0 | |
| parent | e3ba27c47e4846e1a93057d83464ecff027da7be (diff) | |
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>
| -rw-r--r-- | include/aoclocklabel.h | 2 | ||||
| -rw-r--r-- | include/courtroom.h | 1 | ||||
| -rw-r--r-- | include/demoserver.h | 2 | ||||
| -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 |
8 files changed, 42 insertions, 5 deletions
diff --git a/include/aoclocklabel.h b/include/aoclocklabel.h index 472ce68c..830fb527 100644 --- a/include/aoclocklabel.h +++ b/include/aoclocklabel.h @@ -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; diff --git a/include/courtroom.h b/include/courtroom.h index 9766c7bf..21191e58 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -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 diff --git a/include/demoserver.h b/include/demoserver.h index e4eeef50..3dc645be 100644 --- a/include/demoserver.h +++ b/include/demoserver.h @@ -48,7 +48,7 @@ public slots: void start_server(); signals: - + void skip_timers(qint64 msecs); }; #endif // DEMOSERVER_H 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) |
