Skip to content

Commit

Permalink
Add an ini cache to reduce file i/o
Browse files Browse the repository at this point in the history
Fix character list swapping causing a crash if your index is bigger than the charlist you are swapping into
Fix courtroom size visibly changing multiple times due to the menu bar presence
Fix subtheme reload request being respected even if the subtheme didn't change
  • Loading branch information
Crystalwarrior committed Jul 22, 2024
1 parent 3956264 commit c77ef74
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class AOApplication : public QApplication {

bool courtroom_loaded = false;

// Cache of all recently opened ini files associated by path - setting
// first arg: path, second arg: key, value
QMap<QString, QMap<QString, QVariant>> ini_cache;

//////////////////versioning///////////////

int get_release() const { return RELEASE; }
Expand Down
2 changes: 1 addition & 1 deletion include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Courtroom : public QMainWindow {

void character_loading_finished();

void set_menu_bar();
bool set_menu_bar();

//
void set_courtroom_size();
Expand Down
2 changes: 2 additions & 0 deletions src/charselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page)

void Courtroom::character_loading_finished()
{
m_cid = -1;

// Zeroeth, we'll clear any leftover characters from previous server visits.
// ao_app->generated_chars = 0;
if (ui_char_button_list.size() > 0) {
Expand Down
19 changes: 13 additions & 6 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,12 @@ void Courtroom::set_courtroom_size()
m_courtroom_width = f_courtroom.width;
m_courtroom_height = f_courtroom.height;
}
this->setFixedSize(m_courtroom_width, m_courtroom_height);
ui_background->move(0, 0);
ui_background->resize(m_courtroom_width, m_courtroom_height);
ui_background->set_image("courtroombackground");
set_menu_bar();
if (!set_menu_bar()) {
this->setFixedSize(m_courtroom_width, m_courtroom_height);
ui_background->move(0, 0);
}
}

void Courtroom::set_mute_list()
Expand Down Expand Up @@ -968,13 +969,15 @@ void Courtroom::set_pair_list()
}
}

void Courtroom::set_menu_bar()
bool Courtroom::set_menu_bar()
{
menu_bar->adjustSize();
if (Options::getInstance().menuBarLocked()) {
this->setFixedSize(m_courtroom_width, m_courtroom_height + menu_bar->height());
ui_background->move(0, menu_bar->height());
return true;
}
return false;
}

void Courtroom::set_widgets()
Expand Down Expand Up @@ -5338,8 +5341,11 @@ void Courtroom::set_iniswap_dropdown()
ui_iniswap_remove->hide();
return;
}

QString char_name = char_list.at(m_cid).name;
VPath char_path = ao_app->get_character_path(char_name, "iniswaps.ini");
QStringList iniswaps =
ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini")) +
ao_app->get_list_file(char_path) +
ao_app->get_list_file(VPath("iniswaps.ini"));

iniswaps.prepend(char_list.at(m_cid).name);
Expand Down Expand Up @@ -6432,7 +6438,8 @@ void Courtroom::on_reload_theme_clicked()
gen_char_rgb_list(ao_app->get_chat(current_char));

// to update status on the background
set_background(current_background, true);
set_background(current_background, false);
set_scene(ui_vp_desk->isVisible(), current_side);
set_character_sets("global_char_set.ini");
}

Expand Down
2 changes: 1 addition & 1 deletion src/packet_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
return;

// Reload theme request
if (f_contents.size() > 1 && f_contents.at(1) == "1") {
if (f_contents.size() > 1 && f_contents.at(1) == "1" && Options::getInstance().serverSubTheme() != subtheme) {
Options::getInstance().setServerSubTheme(subtheme);
w_courtroom->on_reload_theme_clicked();
}
Expand Down
14 changes: 11 additions & 3 deletions src/path_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,19 @@ QString AOApplication::get_config_value(QString p_identifier, QString p_config,
for (const VPath &p : paths) {
path = get_real_path(p);
if (!path.isEmpty()) {
QSettings settings(path, QSettings::IniFormat);
QVariant value;
if (!ini_cache.contains(path)) {
QSettings settings = QSettings(path, QSettings::IniFormat);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
settings.setIniCodec("UTF-8");
settings.setIniCodec("UTF-8");
#endif
QVariant value = settings.value(p_identifier);
QMap<QString, QVariant> map;
foreach (QString key, settings.allKeys()) {
map[key] = settings.value(key);
}
ini_cache[path] = map;
}
value = ini_cache[path][p_identifier];
if (value.type() == QVariant::StringList) {
return value.toStringList().join(",");
}
Expand Down

0 comments on commit c77ef74

Please sign in to comment.