Less insane debugging; minor refactoring (!75)

This commit is contained in:
David Skoland 2019-07-12 23:00:25 +00:00 committed by oldmud0
parent 621aa1adac
commit 5eccabcad1
12 changed files with 60 additions and 53 deletions

View File

@ -22,6 +22,7 @@
#include <QTextStream>
#include <QStringList>
#include <QColor>
#include <QScreen>
class NetworkManager;
class Lobby;

View File

@ -35,8 +35,10 @@ protected:
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
/*
void dragLeaveEvent(QMouseEvent *e);
void dragEnterEvent(QMouseEvent *e);
*/
signals:
void evidence_clicked(int p_id);

View File

@ -35,7 +35,6 @@
#include <QSlider>
#include <QVector>
#include <QCloseEvent>
#include <QSignalMapper>
#include <QMap>
#include <QTextBrowser>
#include <QSpinBox>
@ -273,8 +272,6 @@ private:
QVector<QString> arup_cms;
QVector<QString> arup_locks;
QSignalMapper *char_button_mapper;
QVector<chatlogpiece> ic_chatlog_history;
// These map music row items and area row items to their actual IDs.
@ -538,6 +535,7 @@ private:
void construct_char_select();
void set_char_select();
void set_char_select_page();
void char_clicked(int n_char);
void put_button_in_place(int starting, int chars_on_this_page);
void filter_character_list();
@ -652,14 +650,12 @@ private slots:
void on_char_select_left_clicked();
void on_char_select_right_clicked();
void on_char_search_changed(const QString& newtext);
void on_char_taken_clicked(int newstate);
void on_char_passworded_clicked(int newstate);
void on_char_search_changed();
void on_char_taken_clicked();
void on_char_passworded_clicked();
void on_spectator_clicked();
void char_clicked(int n_char);
void on_switch_area_music_clicked();
void on_casing_clicked();

View File

@ -44,13 +44,14 @@ public:
QString ms_nosrv_hostname = "master.aceattorneyonline.com";
#endif
const int ms_port = 27016;
const quint16 ms_port = 27016;
const int timeout_milliseconds = 2000;
const int ms_reconnect_delay_ms = 7000;
// in seconds
const int ms_reconnect_delay = 7;
// kind of arbitrary max buffer size
const size_t buffer_max_size = 16384;
#define BUFFER_MAX_SIZE 16384
bool ms_partial_packet = false;
QString ms_temp_packet = "";

View File

@ -37,9 +37,9 @@ void AOApplication::construct_lobby()
w_lobby = new Lobby(this);
lobby_constructed = true;
QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width()-w_lobby->width()) / 2;
int y = (screenGeometry.height()-w_lobby->height()) / 2;
QRect geometry = QGuiApplication::primaryScreen()->geometry();
int x = (geometry.width()-w_lobby->width()) / 2;
int y = (geometry.height()-w_lobby->height()) / 2;
w_lobby->move(x, y);
if (is_discord_enabled())
@ -72,9 +72,9 @@ void AOApplication::construct_courtroom()
w_courtroom = new Courtroom(this);
courtroom_constructed = true;
QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width()-w_courtroom->width()) / 2;
int y = (screenGeometry.height()-w_courtroom->height()) / 2;
QRect geometry = QGuiApplication::primaryScreen()->geometry();
int x = (geometry.width()-w_courtroom->width()) / 2;
int y = (geometry.height()-w_courtroom->height()) / 2;
w_courtroom->move(x, y);
}
@ -161,7 +161,7 @@ void AOApplication::ms_connect_finished(bool connected, bool will_retry)
{
if (lobby_constructed)
w_lobby->append_error("Error connecting to master server. Will try again in "
+ QString::number(net_manager->ms_reconnect_delay_ms / 1000.f) + " seconds.");
+ QString::number(net_manager->ms_reconnect_delay) + " seconds.");
}
else
{

View File

@ -86,6 +86,7 @@ void AOEvidenceButton::mouseDoubleClickEvent(QMouseEvent *e)
evidence_double_clicked(m_id);
}
/*
void AOEvidenceButton::dragLeaveEvent(QMouseEvent *e)
{
//QWidget::dragLeaveEvent(e);
@ -99,6 +100,7 @@ void AOEvidenceButton::dragEnterEvent(QMouseEvent *e)
qDebug() << "drag enter event";
}
*/
void AOEvidenceButton::enterEvent(QEvent * e)
{

View File

@ -44,7 +44,6 @@ void Courtroom::construct_char_select()
set_size_and_pos(ui_char_buttons, "char_buttons");
connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int)));
connect(ui_back_to_lobby, SIGNAL(clicked()), this, SLOT(on_back_to_lobby_clicked()));
connect(ui_char_select_left, SIGNAL(clicked()), this, SLOT(on_char_select_left_clicked()));
@ -52,9 +51,9 @@ void Courtroom::construct_char_select()
connect(ui_spectator, SIGNAL(clicked()), this, SLOT(on_spectator_clicked()));
connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed(const QString&)));
connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked(int)));
connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked(int)));
connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed()));
connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked()));
connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked()));
}
void Courtroom::set_char_select()
@ -197,14 +196,15 @@ void Courtroom::character_loading_finished()
// Later on, we'll be revealing buttons as we need them.
for (int n = 0; n < char_list.size(); n++)
{
AOCharButton* character = new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken);
character->reset();
character->hide();
character->set_image(char_list.at(n).name);
ui_char_button_list.append(character);
AOCharButton* char_button = new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken);
char_button->reset();
char_button->hide();
char_button->set_image(char_list.at(n).name);
ui_char_button_list.append(char_button);
connect(character, SIGNAL(clicked()), char_button_mapper, SLOT(map()));
char_button_mapper->setMapping(character, ui_char_button_list.size() - 1);
connect(char_button, &AOCharButton::clicked, [this, n](){
this->char_clicked(n);
});
// This part here serves as a way of showing to the player that the game is still running, it is
// just loading the pictures of the characters.
@ -252,17 +252,17 @@ void Courtroom::filter_character_list()
set_char_select_page();
}
void Courtroom::on_char_search_changed(const QString& newtext)
void Courtroom::on_char_search_changed()
{
filter_character_list();
}
void Courtroom::on_char_passworded_clicked(int newstate)
void Courtroom::on_char_passworded_clicked()
{
filter_character_list();
}
void Courtroom::on_char_taken_clicked(int newstate)
void Courtroom::on_char_taken_clicked()
{
filter_character_list();
}

View File

@ -6,7 +6,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
// Change the default audio output device to be the one the user has given
// in his config.ini file for now.
int a = 0;
unsigned int a = 0;
BASS_DEVICEINFO info;
if (ao_app->get_audio_output_device() == "default")
@ -21,7 +21,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
if (ao_app->get_audio_output_device() == info.name)
{
BASS_SetDevice(a);
BASS_Init(a, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr);
BASS_Init(static_cast<int>(a), 48000, BASS_DEVICE_LATENCY, nullptr, nullptr);
load_bass_opus_plugin();
qDebug() << info.name << "was set as the default audio output device.";
break;
@ -49,8 +49,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
testimony_hide_timer = new QTimer(this);
testimony_hide_timer->setSingleShot(true);
char_button_mapper = new QSignalMapper(this);
music_player = new AOMusicPlayer(this, ao_app);
music_player->set_volume(0);
sfx_player = new AOSfxPlayer(this, ao_app);
@ -2223,11 +2221,7 @@ void Courtroom::chat_tick()
case INLINE_GREY:
ui_vp_message->insertHtml("<font color=\""+ get_text_color("_inline_grey").name() +"\">" + f_character + "</font>");
break;
default:
ui_vp_message->insertHtml(f_character);
break;
}
}
else
{

View File

@ -11,10 +11,10 @@ Discord::Discord()
qInfo() << "Discord RPC ready";
};
handlers.disconnected = [](int errorCode, const char* message) {
qInfo() << "Discord RPC disconnected! " << message;
qInfo() << "Discord RPC disconnected! " << message << errorCode;
};
handlers.errored = [](int errorCode, const char* message) {
qWarning() << "Discord RPC errored out! " << message;
qWarning() << "Discord RPC errored out! " << message << errorCode;
};
qInfo() << "Initializing Discord RPC";
Discord_Initialize(APPLICATION_ID, &handlers, 1, nullptr);

View File

@ -5,12 +5,12 @@
#if (defined (_WIN32) || defined (_WIN64))
#include <windows.h>
DWORD dwVolSerial;
BOOL bIsRetrieved;
static DWORD dwVolSerial;
static BOOL bIsRetrieved;
QString get_hdid()
{
bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL);
bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), nullptr, 0, &dwVolSerial, nullptr, nullptr, nullptr, 0);
if (bIsRetrieved)
return QString::number(dwVolSerial, 16);
@ -18,7 +18,6 @@ QString get_hdid()
//a totally random string
//what could possibly go wrong
return "gxsps32sa9fnwic92mfbs0";
}
#elif (defined (LINUX) || defined (__linux__))

View File

@ -78,9 +78,9 @@ void NetworkManager::ship_server_packet(QString p_packet)
void NetworkManager::handle_ms_packet()
{
char buffer[buffer_max_size];
std::memset(buffer, 0, buffer_max_size);
ms_socket->read(buffer, buffer_max_size);
char buffer[BUFFER_MAX_SIZE];
std::memset(buffer, 0, BUFFER_MAX_SIZE);
ms_socket->read(buffer, BUFFER_MAX_SIZE);
QString in_data = buffer;
@ -137,7 +137,9 @@ void NetworkManager::on_srv_lookup()
for (const QDnsServiceRecord &record : srv_records)
{
#ifdef DEBUG_NETWORK
qDebug() << "Connecting to " << record.target() << ":" << record.port();
#endif
ms_socket->connectToHost(record.target(), record.port());
QTime timer;
timer.start();
@ -206,7 +208,7 @@ void NetworkManager::on_ms_socket_error(QAbstractSocket::SocketError error)
emit ms_connect_finished(false, true);
ms_reconnect_timer->start(ms_reconnect_delay_ms);
ms_reconnect_timer->start(ms_reconnect_delay * 1000);
}
void NetworkManager::retry_ms_connect()
@ -217,9 +219,9 @@ void NetworkManager::retry_ms_connect()
void NetworkManager::handle_server_packet()
{
char buffer[buffer_max_size];
std::memset(buffer, 0, buffer_max_size);
server_socket->read(buffer, buffer_max_size);
char buffer[BUFFER_MAX_SIZE];
std::memset(buffer, 0, BUFFER_MAX_SIZE);
server_socket->read(buffer, BUFFER_MAX_SIZE);
QString in_data = buffer;

View File

@ -14,8 +14,10 @@ void AOApplication::ms_packet_received(AOPacket *p_packet)
QString header = p_packet->get_header();
QStringList f_contents = p_packet->get_contents();
#ifdef DEBUG_NETWORK
if (header != "CHECK")
qDebug() << "R(ms):" << p_packet->to_string();
#endif
if (header == "ALL")
{
@ -127,8 +129,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
QStringList f_contents = p_packet->get_contents();
QString f_packet = p_packet->to_string();
#ifdef DEBUG_NETWORK
if (header != "checkconnection")
qDebug() << "R:" << f_packet;
#endif
if (header == "decryptor")
{
@ -677,7 +681,9 @@ void AOApplication::send_ms_packet(AOPacket *p_packet)
net_manager->ship_ms_packet(f_packet);
#ifdef DEBUG_NETWORK
qDebug() << "S(ms):" << f_packet;
#endif
delete p_packet;
}
@ -691,14 +697,18 @@ void AOApplication::send_server_packet(AOPacket *p_packet, bool encoded)
if (encryption_needed)
{
#ifdef DEBUG_NETWORK
qDebug() << "S(e):" << f_packet;
#endif
p_packet->encrypt_header(s_decryptor);
f_packet = p_packet->to_string();
}
else
{
#ifdef DEBUG_NETWORK
qDebug() << "S:" << f_packet;
#endif
}
net_manager->ship_server_packet(f_packet);