Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More accurate/consistent blip rate functionality + punctuation slowdown fixes #305

Merged
merged 3 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/aoblipplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ class AOBlipPlayer {
int m_cycle = 0;

private:
const int max_blip_ms = 60;

QWidget *m_parent;
AOApplication *ao_app;
qreal m_volume;
QElapsedTimer delay;

void set_volume_internal(qreal p_volume);

Expand Down
4 changes: 2 additions & 2 deletions include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class Courtroom : public QMainWindow {
bool message_is_centered = false;

int current_display_speed = 3;
int message_display_speed[7] = {0, 10, 25, 40, 50, 70, 90};
int message_display_speed[7] = {5, 10, 25, 40, 50, 70, 90};

// The character ID of the character this user wants to appear alongside with.
int other_charid = -1;
Expand Down Expand Up @@ -311,7 +311,7 @@ class Courtroom : public QMainWindow {
int real_tick_pos = 0;
// used to determine how often blips sound
int blip_ticker = 0;
int blip_rate = 1;
int blip_rate = 2;
int rainbow_counter = 0;
bool rainbow_appended = false;
bool blank_blip = false;
Expand Down
4 changes: 0 additions & 4 deletions src/aoblipplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ void AOBlipPlayer::set_blips(QString p_sfx)

void AOBlipPlayer::blip_tick()
{
if (delay.isValid() && delay.elapsed() < max_blip_ms)
return;

delay.start();
int f_cycle = m_cycle++;

if (m_cycle == 5)
Expand Down
35 changes: 29 additions & 6 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2938,17 +2938,40 @@ void Courtroom::chat_tick()

ui_vp_message->ensureCursorVisible();

// Blip player and real tick pos ticker
if (!formatting_char && (f_character != ' ' || blank_blip)) {
if (blip_ticker % blip_rate == 0) {
// We blip every "blip rate" letters.
// Here's an example with blank_blip being false and blip_rate being 2:
// I am you
// ! ! ! !
// where ! is the blip sound
int b_rate = blip_rate;
// Earrape prevention without using timers, this method is more consistent.
if (msg_delay != 0 && msg_delay <= 25) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this arbitrary number 25? Is it just message_display_speed[2]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like that, it's a fine-tuned number I got to obtain the least earrapey result

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Epic.

// The default blip speed is 40ms, and if current msg_delay is 25ms,
// the formula will result in the blip rate of:
// 40/25 = 1.6 = 2
// And if it's faster than that:
// 40/10 = 4
b_rate = qMax(b_rate, qRound(static_cast<float>(message_display_speed[3])/msg_delay));
}
if (blip_ticker % b_rate == 0) {
// ignoring white space unless blank_blip is enabled.
if (!formatting_char && (f_character != ' ' || blank_blip)) {
blip_player->blip_tick();
++blip_ticker;
}
}
else
{
// Don't fully ignore whitespace still, keep ticking until
// we reached the need to play a blip sound - we also just
// need to wait for a letter to play it on.
++blip_ticker;
}

// Punctuation delayer
if (punctuation_chars.contains(f_character)) {
msg_delay *= punctuation_modifier;
// Punctuation delayer, only kicks in on speed ticks less than }}
if (current_display_speed > 1 && punctuation_chars.contains(f_character)) {
// Making the user have to wait any longer than 150ms per letter is downright unreasonable
msg_delay = qMin(150, msg_delay * punctuation_modifier);
}

// If this color is talking
Expand Down