Multithreaded filtering of the character list

This commit is contained in:
iamgoofball 2019-01-23 01:07:20 -08:00
parent 906c9016bb
commit f750328404
2 changed files with 35 additions and 24 deletions

View File

@ -91,6 +91,9 @@ public:
QSignalMapper *char_button_mapper; QSignalMapper *char_button_mapper;
QVector<AOCharButton*> ui_char_button_list; QVector<AOCharButton*> ui_char_button_list;
QVector<AOCharButton*> ui_char_button_list_filtered; QVector<AOCharButton*> ui_char_button_list_filtered;
QLineEdit *ui_char_search;
QCheckBox *ui_char_passworded;
QCheckBox *ui_char_taken;
void mt_pre_framegetter(int frameNumber); void mt_pre_framegetter(int frameNumber);
void mt_framegetter(int frameNumber); void mt_framegetter(int frameNumber);
void reset_music_list() void reset_music_list()
@ -548,10 +551,6 @@ private:
AOButton *ui_spectator; AOButton *ui_spectator;
QLineEdit *ui_char_search;
QCheckBox *ui_char_passworded;
QCheckBox *ui_char_taken;
void construct_char_select(); void construct_char_select();
void set_char_select(); void set_char_select();
void set_char_select_page(); void set_char_select_page();

View File

@ -29,6 +29,35 @@ public:
} }
}; };
class AOCharSelectFilterThreading : public QRunnable
{
public:
Courtroom *mycourt_fuck;
int char_num;
AOCharSelectFilterThreading(Courtroom *my_courtroom, int character_number){
mycourt_fuck = my_courtroom;
char_num = character_number;
}
void run()
{
AOCharButton* current_char = mycourt_fuck->ui_char_button_list.at(char_num);
if (!mycourt_fuck->ui_char_taken->isChecked() && mycourt_fuck->char_list.at(char_num).taken)
return;
if (!mycourt_fuck->char_list.at(char_num).name.contains(mycourt_fuck->ui_char_search->text(), Qt::CaseInsensitive))
return;
// We only really need to update the fact that a character is taken
// for the buttons that actually appear.
// You'd also update the passwordedness and etc. here later.
current_char->reset();
current_char->set_taken(mycourt_fuck->char_list.at(char_num).taken);
mycourt_fuck->ui_char_button_list_filtered.append(current_char);
}
};
void Courtroom::construct_char_select() void Courtroom::construct_char_select()
{ {
ui_char_select_background = new AOImage(this, ao_app); ui_char_select_background = new AOImage(this, ao_app);
@ -234,27 +263,10 @@ void Courtroom::filter_character_list()
ui_char_button_list_filtered.clear(); ui_char_button_list_filtered.clear();
for (int i = 0; i < char_list.size(); i++) for (int i = 0; i < char_list.size(); i++)
{ {
AOCharButton* current_char = ui_char_button_list.at(i); AOCharSelectFilterThreading *char_filter = new AOCharSelectFilterThreading(this, i);
QThreadPool::globalInstance()->start(char_filter);
// It seems passwording characters is unimplemented yet?
// Until then, this will stay here, I suppose.
//if (ui_char_passworded->isChecked() && character_is_passworded??)
// continue;
if (!ui_char_taken->isChecked() && char_list.at(i).taken)
continue;
if (!char_list.at(i).name.contains(ui_char_search->text(), Qt::CaseInsensitive))
continue;
// We only really need to update the fact that a character is taken
// for the buttons that actually appear.
// You'd also update the passwordedness and etc. here later.
current_char->reset();
current_char->set_taken(char_list.at(i).taken);
ui_char_button_list_filtered.append(current_char);
} }
QThreadPool::globalInstance()->waitForDone();
current_char_page = 0; current_char_page = 0;
set_char_select_page(); set_char_select_page();