aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCrystalwarrior <Varsash@Gmail.com>2021-03-21 05:12:44 +0300
committerGitHub <noreply@github.com>2021-03-20 21:12:44 -0500
commit510c0f4b17f24eb534d22654a41e9157c89a8211 (patch)
tree079a0e3f799ed55ac80370b289b0ba9496eeb7c0 /src
parente3ba27c47e4846e1a93057d83464ecff027da7be (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>
Diffstat (limited to 'src')
-rw-r--r--src/aoapplication.cpp10
-rw-r--r--src/aoclocklabel.cpp11
-rw-r--r--src/courtroom.cpp15
-rw-r--r--src/demoserver.cpp5
-rw-r--r--src/packet_distribution.cpp1
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)