|
|
@@ -190,12 +190,10 @@ static void set_default_mins(Optimizer_Data *data);
|
|
|
* order and in descending direction, and it will be limited to
|
|
|
* {@link LIMIT_RUNES_PER_SLOT} per slot.
|
|
|
*
|
|
|
- * @param[in] options Options passed to the optimizer.
|
|
|
+ * @param[in] data Optimizer data package. Unit member must be populated.
|
|
|
* @param[out] query String with the query.
|
|
|
*/
|
|
|
-static void query_for_even_slots(
|
|
|
- Optimizer_Filters *options, char query[RUNE_QUERY_LEN]
|
|
|
-);
|
|
|
+static void query_for_even_slots(Optimizer_Data *data, char *query);
|
|
|
|
|
|
/**
|
|
|
* Generates the query to get the runes from the database for odd slots.
|
|
|
@@ -209,12 +207,10 @@ static void query_for_even_slots(
|
|
|
* order and in descending direction, and it will be limited to
|
|
|
* {@link LIMIT_RUNES_PER_SLOT} per slot.
|
|
|
*
|
|
|
- * @param[in] options Options passed to the optimizer.
|
|
|
+ * @param[in] data Optimizer data package. Unit member must be populated.
|
|
|
* @param[out] query String with the query.
|
|
|
*/
|
|
|
-static void query_for_odd_slots(
|
|
|
- Optimizer_Filters *options, char query[RUNE_QUERY_LEN]
|
|
|
-);
|
|
|
+static void query_for_odd_slots(Optimizer_Data *data, char *query);
|
|
|
|
|
|
/**
|
|
|
* Gets the list of runes to test during the optimization from the database.
|
|
|
@@ -241,8 +237,7 @@ static void query_for_odd_slots(
|
|
|
* Negative values are error codes defined in {@link error.h}.
|
|
|
*/
|
|
|
static int select_runes(
|
|
|
- char query_even[RUNE_QUERY_LEN], char query_odd[RUNE_QUERY_LEN],
|
|
|
- Optimizer_Data * data
|
|
|
+ char *query_even, char *query_odd, Optimizer_Data *data
|
|
|
);
|
|
|
|
|
|
|
|
|
@@ -491,8 +486,8 @@ extern int optimize(int argc, char *argv[]){
|
|
|
// Set minimum values for filters on stats not set manually.
|
|
|
set_default_mins(&opt_data);
|
|
|
if ((status = calculate_rune_count(&opt_data)) < 0) return status;
|
|
|
- query_for_odd_slots(opt_data.filters, query_odd);
|
|
|
- query_for_even_slots(opt_data.filters, query_even);
|
|
|
+ query_for_odd_slots(&opt_data, query_odd);
|
|
|
+ query_for_even_slots(&opt_data, query_even);
|
|
|
// Get selected runes.
|
|
|
select_runes(query_even, query_odd, &opt_data);
|
|
|
for (int i = 1; i < RUNE_SLOTS + 1; i ++){
|
|
|
@@ -1028,14 +1023,12 @@ static int read_unit(unsigned char id[UNIT_NAME_LEN], Unit *unit){
|
|
|
return(SUCCESS);
|
|
|
}
|
|
|
|
|
|
-static void query_for_even_slots(
|
|
|
- Optimizer_Filters *options, char query[RUNE_QUERY_LEN]
|
|
|
-){
|
|
|
+static void query_for_even_slots(Optimizer_Data *data, char *query){
|
|
|
char column[10];
|
|
|
char cur_set[MAX_SETS];
|
|
|
char stat_set[DIFFERENT_STATS];
|
|
|
- if (options->level == LV12) strcpy(column, "lv12_");
|
|
|
- else if (options->level == LV15) strcpy(column, "lv15_");
|
|
|
+ if (data->filters->level == LV12) strcpy(column, "lv12_");
|
|
|
+ else if (data->filters->level == LV15) strcpy(column, "lv15_");
|
|
|
else strcpy(column, "current_");
|
|
|
strcpy(query, "SELECT id, unit, slot, type, ");
|
|
|
strcat(query, column);
|
|
|
@@ -1062,15 +1055,15 @@ static void query_for_even_slots(
|
|
|
strcat(query, "acc\nFROM runes\nWHERE\n slot = ? -- Slot\n");
|
|
|
strcat(query, " AND type IN (");
|
|
|
for (int i = 0; i < MAX_SETS; i ++){
|
|
|
- if (options->sets[i] != 0){
|
|
|
- sprintf(cur_set, "%d", options->sets[i]);
|
|
|
+ if (data->filters->sets[i] != 0){
|
|
|
+ sprintf(cur_set, "%d", data->filters->sets[i]);
|
|
|
strcat(query, cur_set);
|
|
|
strcat(query, ", ");
|
|
|
}
|
|
|
}
|
|
|
- if (options->full_set == FALSE){
|
|
|
+ if (data->filters->full_set == FALSE){
|
|
|
for (int i = 0; i < DIFFERENT_SETS; i ++){
|
|
|
- if (options->optional_sets[i] == TRUE){
|
|
|
+ if (data->filters->optional_sets[i] == TRUE){
|
|
|
sprintf(cur_set, "%d", i);
|
|
|
strcat(query, cur_set);
|
|
|
strcat(query, ", ");
|
|
|
@@ -1079,36 +1072,39 @@ static void query_for_even_slots(
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
strcat(query, ") -- Sets\n");
|
|
|
- if (options->storage == TRUE){
|
|
|
+ if (data->filters->storage == TRUE){
|
|
|
// They are not null, are empty!
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(query, "') -- Only storage\n");
|
|
|
}
|
|
|
// Excluded teams (overriden by storage option)
|
|
|
- if (options->storage == FALSE && options->total_excluded_teams > 0){
|
|
|
+ if (
|
|
|
+ data->filters->storage == FALSE && data->filters->total_excluded_teams > 0
|
|
|
+ ){
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(
|
|
|
query, "' OR unit NOT IN (SELECT unit FROM units_teams WHERE team IN("
|
|
|
);
|
|
|
- for (int i = 0; i < options->total_excluded_teams; i ++){
|
|
|
+ for (int i = 0; i < data->filters->total_excluded_teams; i ++){
|
|
|
strcat(query, "'");
|
|
|
- strcat(query, (const char *) options->excluded_teams[i]);
|
|
|
+ strcat(query, (const char *) data->filters->excluded_teams[i]);
|
|
|
strcat(query, "', ");
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
strcat(query, "))) -- Excluded teams\n ");
|
|
|
}
|
|
|
// Excluded units (overriden by storage option)
|
|
|
- if (options->storage == FALSE && options->total_excluded_units > 0){
|
|
|
- printf("EVEN ERROR\n");
|
|
|
+ if (
|
|
|
+ data->filters->storage == FALSE && data->filters->total_excluded_units > 0
|
|
|
+ ){
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(query, "' OR unit NOT IN (");
|
|
|
- for (int i = 0; i < options->total_excluded_units; i ++){
|
|
|
+ for (int i = 0; i < data->filters->total_excluded_units; i ++){
|
|
|
strcat(query, "'");
|
|
|
- strcat(query, (const char *) options->excluded_units[i]);
|
|
|
+ strcat(query, (const char *) data->filters->excluded_units[i]);
|
|
|
strcat(query, "', ");
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
@@ -1116,7 +1112,7 @@ static void query_for_even_slots(
|
|
|
}
|
|
|
strcat(query, " AND main_stat IN (");
|
|
|
for (int i = 0; i < DIFFERENT_STATS; i ++){
|
|
|
- if (options->stats[i] == TRUE){
|
|
|
+ if (data->filters->stats[i] == TRUE){
|
|
|
sprintf(stat_set, "%d", i);
|
|
|
strcat(query, stat_set);
|
|
|
strcat(query, ", ");
|
|
|
@@ -1134,13 +1130,11 @@ static void query_for_even_slots(
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-static void query_for_odd_slots(
|
|
|
- Optimizer_Filters *options, char query[RUNE_QUERY_LEN]
|
|
|
-){
|
|
|
+static void query_for_odd_slots(Optimizer_Data *data, char *query){
|
|
|
char column[10];
|
|
|
char cur_set[MAX_SETS];
|
|
|
- if (options->level == LV12) strcpy(column, "lv12_");
|
|
|
- else if (options->level == LV15) strcpy(column, "lv15_");
|
|
|
+ if (data->filters->level == LV12) strcpy(column, "lv12_");
|
|
|
+ else if (data->filters->level == LV15) strcpy(column, "lv15_");
|
|
|
else strcpy(column, "current_");
|
|
|
strcpy(query, "SELECT id, unit, slot, type, ");
|
|
|
strcat(query, column);
|
|
|
@@ -1167,15 +1161,15 @@ static void query_for_odd_slots(
|
|
|
strcat(query, "acc\nFROM runes\nWHERE\n slot = ? -- Slot\n");
|
|
|
strcat(query, " AND type IN (");
|
|
|
for (int i = 0; i < MAX_SETS; i ++){
|
|
|
- if (options->sets[i] != 0){
|
|
|
- sprintf(cur_set, "%d", options->sets[i]);
|
|
|
+ if (data->filters->sets[i] != 0){
|
|
|
+ sprintf(cur_set, "%d", data->filters->sets[i]);
|
|
|
strcat(query, cur_set);
|
|
|
strcat(query, ", ");
|
|
|
}
|
|
|
}
|
|
|
- if (options->full_set == FALSE){
|
|
|
+ if (data->filters->full_set == FALSE){
|
|
|
for (int i = 0; i < DIFFERENT_SETS; i ++){
|
|
|
- if (options->optional_sets[i] == TRUE){
|
|
|
+ if (data->filters->optional_sets[i] == TRUE){
|
|
|
sprintf(cur_set, "%d", i);
|
|
|
strcat(query, cur_set);
|
|
|
strcat(query, ", ");
|
|
|
@@ -1184,35 +1178,39 @@ static void query_for_odd_slots(
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
strcat(query, ") -- Sets\n");
|
|
|
- if (options->storage == TRUE){
|
|
|
+ if (data->filters->storage == TRUE){
|
|
|
// They are not null, are empty!
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(query, "') -- Only storage\n");
|
|
|
}
|
|
|
// Excluded teams (overriden by storage option)
|
|
|
- if (options->storage == FALSE && options->total_excluded_teams > 0){
|
|
|
+ if (
|
|
|
+ data->filters->storage == FALSE && data->filters->total_excluded_teams > 0
|
|
|
+ ){
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(
|
|
|
query, "' OR unit NOT IN (SELECT unit FROM units_teams WHERE team IN("
|
|
|
);
|
|
|
- for (int i = 0; i < options->total_excluded_teams; i ++){
|
|
|
+ for (int i = 0; i < data->filters->total_excluded_teams; i ++){
|
|
|
strcat(query, "'");
|
|
|
- strcat(query, (const char *) options->excluded_teams[i]);
|
|
|
+ strcat(query, (const char *) data->filters->excluded_teams[i]);
|
|
|
strcat(query, "', ");
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
strcat(query, "))) -- Excluded teams\n ");
|
|
|
}
|
|
|
// Excluded units (overriden by storage option)
|
|
|
- if (options->storage == FALSE && options->total_excluded_units > 0){
|
|
|
+ if (
|
|
|
+ data->filters->storage == FALSE && data->filters->total_excluded_units > 0
|
|
|
+ ){
|
|
|
strcat(query, " AND (unit = '' OR unit = '");
|
|
|
- strcat(query, (const char *) options->id);
|
|
|
+ strcat(query, (const char *) data->unit->id);
|
|
|
strcat(query, "' OR unit NOT IN (");
|
|
|
- for (int i = 0; i < options->total_excluded_units; i ++){
|
|
|
+ for (int i = 0; i < data->filters->total_excluded_units; i ++){
|
|
|
strcat(query, "'");
|
|
|
- strcat(query, (const char *) options->excluded_units[i]);
|
|
|
+ strcat(query, (const char *) data->filters->excluded_units[i]);
|
|
|
strcat(query, "', ");
|
|
|
}
|
|
|
query[strlen(query) - 2] = '\0'; // Remove last coma
|
|
|
@@ -1230,8 +1228,7 @@ static void query_for_odd_slots(
|
|
|
}
|
|
|
|
|
|
static int select_runes(
|
|
|
- char query_even[RUNE_QUERY_LEN], char query_odd[RUNE_QUERY_LEN],
|
|
|
- Optimizer_Data * data
|
|
|
+ char *query_even, char *query_odd, Optimizer_Data *data
|
|
|
){
|
|
|
int total = 0;
|
|
|
char **query;
|
|
|
@@ -1291,14 +1288,13 @@ static void *optimize_thread(void *tid){
|
|
|
int thread_id = (int) (uintptr_t) tid;
|
|
|
int start_at = thread_id * ceil((float) opt_data.count[1]
|
|
|
/ (float) opt_data.options->threads);
|
|
|
- int end_at = start_at + (opt_data.count[1] / opt_data.options->threads);
|
|
|
+ int end_at = start_at + ceil((float) opt_data.count[1] / (float) opt_data.options->threads);
|
|
|
|
|
|
// Initialize arrys and some counters
|
|
|
unsigned int index[RUNE_SLOTS + 1] = {0, start_at, 0, 0, 0, 0};
|
|
|
unsigned long valid_sets = 0;
|
|
|
Rune_Set_Count set_count;
|
|
|
unsigned char progress_printed = FALSE;
|
|
|
-
|
|
|
while(
|
|
|
index[1] < end_at
|
|
|
&& index[1] < opt_data.count[1]
|