Skip to content

Commit 93cb5c9

Browse files
committed
numbers denote ms instead of multiplier
also removes unnecessary variables, as well as adds validation
1 parent 3bd6646 commit 93cb5c9

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

src/courtroom.cpp

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,23 +3508,32 @@ void Courtroom::handle_ic_speaking()
35083508

35093509
struct PauseInfo
35103510
{
3511-
int multiplier;
3511+
int ms;
35123512
int digit_count;
3513+
bool valid;
35133514
};
35143515

3515-
// returns multiplier and number of digits to skip
3516-
static PauseInfo parse_pause_multiplier(const QString &text, int start_pos)
3516+
static PauseInfo parse_pause_duration(const QString &text, int start_pos)
35173517
{
3518-
// matches upto 999 (and 1000) and also prevents leading zeros
3519-
static QRegularExpression pause_regex("^([1-9]\\d{0,2}|1000)");
3518+
static const int max_digits = QString::number(10000).length();
3519+
static const QRegularExpression pause_regex(QString("^([1-9]\\d{0,%1})").arg(max_digits - 1));
3520+
35203521
QRegularExpressionMatch match = pause_regex.match(text.mid(start_pos));
3521-
if (match.hasMatch())
3522+
if (!match.hasMatch())
35223523
{
3523-
int value = match.captured(1).toInt();
3524-
int length = match.capturedLength(0);
3525-
return {value, length};
3524+
return {0, 0, false};
35263525
}
3527-
return {1, 0}; // default: multiplier=1, no digits to skip
3526+
3527+
bool ok = false;
3528+
int value = match.captured(1).toInt(&ok);
3529+
int length = match.capturedLength(0);
3530+
3531+
if (!ok || value < 1 || value > 10000)
3532+
{
3533+
return {0, 0, false};
3534+
}
3535+
3536+
return {value, length, true};
35283537
}
35293538

35303539
QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int default_color)
@@ -3744,11 +3753,13 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int
37443753
if (f_character == "s" || f_character == "f" || f_character == "p") // screenshake/flash/pause
37453754
{
37463755
skip = true;
3747-
// also skip any following digits
3748-
if (f_character == "p")
3756+
if (f_character == "p") // also skip any following digits
37493757
{
3750-
PauseInfo info = parse_pause_multiplier(p_text, check_pos + f_char_bytes);
3751-
check_pos += info.digit_count;
3758+
PauseInfo info = parse_pause_duration(p_text, check_pos + f_char_bytes);
3759+
if (info.valid)
3760+
{
3761+
check_pos += info.digit_count;
3762+
}
37523763
}
37533764
}
37543765

@@ -4228,7 +4239,6 @@ void Courtroom::start_chat_ticking()
42284239

42294240
tick_pos = 0;
42304241
blip_ticker = 0;
4231-
pause_multiplier = 1;
42324242
text_crawl = Options::getInstance().textCrawlSpeed();
42334243
blip_rate = Options::getInstance().blipRate();
42344244
blank_blip = Options::getInstance().blankBlip();
@@ -4448,9 +4458,14 @@ void Courtroom::chat_tick()
44484458
if (f_character == "p")
44494459
{
44504460
formatting_char = true;
4451-
PauseInfo info = parse_pause_multiplier(f_message, tick_pos);
4452-
pause_multiplier = info.multiplier;
4453-
tick_pos += info.digit_count;
4461+
PauseInfo info = parse_pause_duration(f_message, tick_pos);
4462+
if (info.valid)
4463+
{
4464+
tick_pos += info.digit_count;
4465+
real_tick_pos += f_char_length;
4466+
chat_tick_timer->start(info.ms);
4467+
return;
4468+
}
44544469
}
44554470
next_character_is_not_special = false;
44564471
}
@@ -4472,15 +4487,8 @@ void Courtroom::chat_tick()
44724487

44734488
if ((msg_delay <= 0 && tick_pos < f_message.size() - 1) || formatting_char)
44744489
{
4475-
if (f_character == "p")
4476-
{
4477-
chat_tick_timer->start(pause_base_ms * pause_multiplier);
4478-
}
4479-
else
4480-
{
4481-
chat_tick_timer->start(0); // Don't bother rendering anything out as we're
4482-
// doing the SPEED. (there's latency otherwise)
4483-
}
4490+
chat_tick_timer->start(0); // Don't bother rendering anything out as we're
4491+
// doing the SPEED. (there's latency otherwise)
44844492
if (!formatting_char || f_character == "n" || f_character == "f" || f_character == "s" || f_character == "p")
44854493
{
44864494
real_tick_pos += f_char_length; // Adjust the tick position for the

src/courtroom.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ class Courtroom : public QMainWindow
378378
int real_tick_pos = 0;
379379
// used to determine how often blips sound
380380
int blip_ticker = 0;
381-
// pause multiplier for \p{numbers}
382-
int pause_multiplier = 1;
383381
int blip_rate = 2;
384382
int rainbow_counter = 0;
385383
bool rainbow_appended = false;
@@ -452,10 +450,7 @@ class Courtroom : public QMainWindow
452450
// amount by which we multiply the delay when we parse punctuation chars
453451
const int punctuation_modifier = 3;
454452

455-
// maximum pause multiplier for \p{numbers} so it does not just pause forever
456-
const int pause_multiplier_max = 1000;
457-
// base pause duration for a \p with no digits
458-
const int pause_base_ms = 100;
453+
const int max_pause_duration = 10000;
459454

460455
// amount of ghost blocks
461456
int ghost_blocks = 0;

0 commit comments

Comments
 (0)