Fix demoserver max_wait skips happening even when they're not supposed to (#680)
* Fix demoserver max_wait logic being absolutely bonkers, causing random skips that make no sense actually comment this piece of code * Add /debug command to demos which allows you to see the remaining time for each packet, allowing you to visualize wait packets. Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
df1c8ccd83
commit
aa2a29f091
@ -31,6 +31,7 @@ private:
|
|||||||
QTcpSocket* client_sock = nullptr;
|
QTcpSocket* client_sock = nullptr;
|
||||||
bool client_connected = false;
|
bool client_connected = false;
|
||||||
bool partial_packet = false;
|
bool partial_packet = false;
|
||||||
|
bool debug_mode = false;
|
||||||
QString temp_packet = "";
|
QString temp_packet = "";
|
||||||
QQueue<QString> demo_data;
|
QQueue<QString> demo_data;
|
||||||
QString sc_packet;
|
QString sc_packet;
|
||||||
|
@ -233,9 +233,39 @@ void DemoServer::handle_packet(AOPacket packet)
|
|||||||
QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%";
|
QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%";
|
||||||
client_sock->write(packet.toUtf8());
|
client_sock->write(packet.toUtf8());
|
||||||
}
|
}
|
||||||
|
else if (contents[1].startsWith("/debug"))
|
||||||
|
{
|
||||||
|
QStringList args = contents[1].split(" ");
|
||||||
|
if (args.size() > 1)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
int toggle = args.at(1).toInt(&ok);
|
||||||
|
if (ok && (toggle == 0 || toggle == 1)) {
|
||||||
|
debug_mode = toggle == 1;
|
||||||
|
QString packet = "CT#DEMO#" + tr("Setting debug mode to %1").arg(static_cast<int>(debug_mode)) + "#1#%";
|
||||||
|
client_sock->write(packet.toUtf8());
|
||||||
|
// Debug mode disabled?
|
||||||
|
if (!debug_mode) {
|
||||||
|
// Reset the timer
|
||||||
|
client_sock->write("TI#4#1#0#%");
|
||||||
|
client_sock->write("TI#4#3#0#%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString packet = "CT#DEMO#" + tr("Valid values are 1 or 0!") + "#1#%";
|
||||||
|
client_sock->write(packet.toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString packet = "CT#DEMO#" + tr("Set debug mode using /debug 1 to enable, and /debug 0 to disable, which will use the fifth timer (TI#4) to show the remaining time until next demo line.") + "#1#%";
|
||||||
|
client_sock->write(packet.toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (contents[1].startsWith("/help"))
|
else if (contents[1].startsWith("/help"))
|
||||||
{
|
{
|
||||||
QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%";
|
QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, debug, help") + "#1#%";
|
||||||
client_sock->write(packet.toUtf8());
|
client_sock->write(packet.toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,8 +351,8 @@ void DemoServer::reset_state()
|
|||||||
client_sock->write("LE##%");
|
client_sock->write("LE##%");
|
||||||
|
|
||||||
// Reset timers
|
// Reset timers
|
||||||
client_sock->write("TI#0#3#0#%");
|
|
||||||
client_sock->write("TI#0#1#0#%");
|
client_sock->write("TI#0#1#0#%");
|
||||||
|
client_sock->write("TI#0#3#0#%");
|
||||||
client_sock->write("TI#1#1#0#%");
|
client_sock->write("TI#1#1#0#%");
|
||||||
client_sock->write("TI#1#3#0#%");
|
client_sock->write("TI#1#3#0#%");
|
||||||
client_sock->write("TI#2#1#0#%");
|
client_sock->write("TI#2#1#0#%");
|
||||||
@ -359,19 +389,25 @@ void DemoServer::playback()
|
|||||||
AOPacket wait_packet = AOPacket(current_packet);
|
AOPacket wait_packet = AOPacket(current_packet);
|
||||||
|
|
||||||
int duration = wait_packet.get_contents().at(0).toInt();
|
int duration = wait_packet.get_contents().at(0).toInt();
|
||||||
if (max_wait != -1) {
|
// Max wait reached
|
||||||
if (duration + elapsed_time > max_wait) {
|
if (max_wait != -1 && duration + elapsed_time > max_wait) {
|
||||||
duration = qMax(0, max_wait - elapsed_time);
|
duration = qMax(0, max_wait - elapsed_time);
|
||||||
// Skip the difference on the timers
|
qDebug() << "Max_wait of " << max_wait << " reached. Forcing duration to " << duration << "ms";
|
||||||
emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
|
// Skip the difference on the timers
|
||||||
}
|
emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
|
||||||
else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) {
|
}
|
||||||
duration = qMax(0, timer->interval() - elapsed_time);
|
// Manual user skip, such as with >
|
||||||
emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
|
else if (timer->remainingTime() > 0) {
|
||||||
}
|
qDebug() << "Timer of interval " << timer->interval() << " is being skipped. Forcing to skip " << timer->remainingTime() << "ms on TI# clocks";
|
||||||
|
emit skip_timers(timer->remainingTime());
|
||||||
}
|
}
|
||||||
elapsed_time += duration;
|
elapsed_time += duration;
|
||||||
timer->start(duration);
|
timer->start(duration);
|
||||||
|
if (debug_mode) {
|
||||||
|
client_sock->write("TI#4#2#%");
|
||||||
|
QString debug_timer = "TI#4#0#" + QString::number(duration) + "#%";
|
||||||
|
client_sock->write(debug_timer.toUtf8());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QString end_packet = "CT#DEMO#" + tr("Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.") + "#1#%";
|
QString end_packet = "CT#DEMO#" + tr("Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.") + "#1#%";
|
||||||
|
Loading…
Reference in New Issue
Block a user