ソースを参照

Code format and organization. Better output. GUI adapted to recent changes.

Iñigo Valentin 4 年 前
コミット
e65ebc7b01

+ 8 - 0
src/cli/runeoptimizer/error/error.h

@@ -561,3 +561,11 @@
  * Error reading from tables teams, units, or units_teams.
  */
 #define ERROR_DB_VERIFY_TEAM_UNIT -228
+
+/**
+ * Memory error.
+ *
+ * It usually indicates that there is not enough memory to perform some
+ * operation
+ */
+#define ERROR_MEMORY -300;

+ 48 - 30
src/cli/runeoptimizer/help/help.c

@@ -135,55 +135,73 @@ void help(){
       "\n"
       "      [unit] can be a unit ID or a unit name (case sensitive)\n"
       "\n"
-      "      Options: \n"
-      "\n"
-      "        -h | --min_hp <NUM>          Minumum HP to consider in the optimization.\n"
+      "      Output options: \n"
+      "\n"
+      "        -o | --output <file|screen>  Output mode. 'screen' print the results to the console,\n"
+      "                                     'file' will save them to a file with the name formatted as\n"
+      "                                     <monster_id>_<monster_name>_<datetime>.<format>\n"
+      "                                     The format extension will be txt or json, depemnding on \n"
+      "                                     the selected formatting option.\n"
+      "                                     If not specified, results will be printed to console.\n"
+      "        -f | --format <human|json>   Output mode. 'human' will show the results a human,\n"
+      "                                     readable format, while 'json' will show them in JSON.\n"
+      "                                     If not specified, results will be printed in human format.\n"
+      "        -q | --quiet                 Decrease verbosity. When printing to the screen, only the\n"
+      "                                     results will be displayed. When saving the results to a\n"
+      "                                     file, nothing will be printed on screen. Error messages will\n"
+      "                                     always be displayed.\n"
+      "        -v | --verbose               Increase verbosity. Displays some extra info during\n"
+      "                                     optimization.\n"
+      "        -d | --debug                 Greatly increase verbosity. Displays a lot of (probably\n"
+      "                                     useless) information. Expect thousands of lines, and notice\n"
+      "                                     that will REALLY slow down the optimization process.\n"
+      "\n"
+      "      System options: \n"
+      "\n"
+      "        -t | --threads <NUM>         Use <NUM> threads for optimizaton (1-8). The more threads,\n"
+      "                                     the faster the optimization will be, but it's usually a good\n"
+      "                                     idea to limit it to the number of CPUs in your machine. The\n"
+      "                                     default value is 1, and the maximum, 8.\n"
+      "\n"
+      "      Optimization options: \n"
+      "\n"
+      "        -H | --min_hp <NUM>          Minumum HP to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -a | --min_atk <NUM>         Minumum ATK to consider in the optimization.\n"
+      "        -A | --min_atk <NUM>         Minumum ATK to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -d | --min_def <NUM>         Minumum DEF to consider in the optimization.\n"
+      "        -D | --min_def <NUM>         Minumum DEF to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -s | --min_spd <NUM>         Minumum SPD to consider in the optimization.\n"
+      "        -S | --min_spd <NUM>         Minumum SPD to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -c | --min_crr <NUM>         Minumum CRIT RATE to consider in the optimization.\n"
+      "        -C | --min_crr <NUM>         Minumum CRIT RATE to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -d | --min_crd <NUM>         Minumum CRIT DAMAGE to consider in the optimization.\n"
+      "        -I | --min_crd <NUM>         Minumum CRIT DAMAGE to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -r | --min_res <NUM>         Minumum RES to consider in the optimization.\n"
+      "        -R | --min_res <NUM>         Minumum RES to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -f | --min_acc <NUM>         Minumum ACC to consider in the optimization.\n"
+      "        -F | --min_acc <NUM>         Minumum ACC to consider in the optimization.\n"
       "                                     It defaults to the unit's current value.\n"
-      "        -p | --min_ehp <NUM>         Minumum effective HP to consider in the optimization.\n"
+      "        -E | --min_ehp <NUM>         Minumum effective HP to consider in the optimization.\n"
       "                                     It defaults to 0.\n"
-      "        -m | --min_dmg <NUM>         Minumum computed damage to consider in the optimization.\n"
+      "        -G | --min_dmg <NUM>         Minumum computed damage to consider in the optimization.\n"
       "                                     It defaults to 0.\n"
-      "        -l | --level <LV>            Level to consider the runes during the optimization.\n"
+      "        -L | --level <LV>            Level to consider the runes during the optimization.\n"
       "                                     It only affects the rune main stats. Valid values are\n"
       "                                     'current', '12' and '15'. Default is 'current'\n"
-      "        -t | --stats <ST1>,<ST2>...  Stats than can be selected as mains for slots 2, 4 and 6.\n"
+      "        -T | --stats <ST1>,<ST2>...  Stats than can be selected as mains for slots 2, 4 and 6.\n"
       "                                     Only the selected stats will be included, so this option\n"
       "                                     is mandatory. Accepted values are 'hp', 'atk', 'def',\n"
       "                                     'hpflat', 'atkflat', 'defflat', 'spd', 'crr', 'crd',\n"
       "                                     'res' and 'acc'. Values must be comma-separated, and up\n"
       "                                     to 12 can be included.\n"
-      "        -e | --sets <S1>,<S2>...     Rune sets that than the unit being optimized must have.\n"
-      "        -i | --opt-sets <S1>,<S2>... Other rune sets that can be used to complement the required ones.\n"
-      "        -k | --broken                Allow the unit to have broken sets, other than the required ones.\n"
-      "        -o | --storage               Use only runes not assigned to units.\n"
-      "        -x | --no-teams <T1>,<T2>... Exclude runes assigned to units in selected teams.\n"
+      "        -N | --sets <S1>,<S2>...     Rune sets that than the unit being optimized must have.\n"
+      "        -O | --opt-sets <S1>,<S2>... Other rune sets that can be used to complement the required ones.\n"
+      "        -K | --broken                Allow the unit to have broken sets, other than the required ones.\n"
+      "        -B | --storage               Use only runes not assigned to units.\n"
+      "        -X | --no-teams <T1>,<T2>... Exclude runes assigned to units in selected teams.\n"
       "                                     Team IDs can be supplied, comma-separated.\n"
-      "        -u | --no-units <U1>,<U2>... Exclude runes assigned to units in selected units.\n"
+      "        -U | --no-units <U1>,<U2>... Exclude runes assigned to selected units.\n"
       "                                     Unit IDs can be supplied, comma-separated.\n"
-      "        -g | --gui                   Formats the output to be consumed by the GUI.\n"
-      "        -b | --threads <NUM>         Use <NUM> threads for optimizaton (1-8).\n"
-      "        -z | --output <MODE>         Use MODE to generate optimization report.\n"
-      "                                     Valid modes are:\n"
-      "                                       none: Print the best result on screen, discard the rest.\n"
-      "                                       screen: Print every result on screen on a human readable format.\n"
-      "                                       plain: Save results to a text file, in a human readable format.\n"
-      "                                       json: Save results to a text file, in JSON format.\n"
-      "                                       html: Save results to a interactive HTML file.\n"
-
     );
     return;
 }

ファイルの差分が大きいため隠しています
+ 360 - 424
src/cli/runeoptimizer/optimize/optimize.c


+ 49 - 3
src/cli/runeoptimizer/optimize/optimize.h

@@ -53,6 +53,11 @@
  */
 #define MAX_SETS 3
 
+#define OUT_Q 0
+#define OUT_S 1
+#define OUT_V 2
+#define OUT_D 3
+
 /**
  * A rune.
  *
@@ -345,18 +350,59 @@ typedef struct Result {
     struct Stats stats;
 } Result;
 
+/**
+ * Options for output level, format and target.
+ */
 typedef struct Optimizer_Output{
-    // TODO: Document, maybe separate
+
+    /**
+     * Flag to indicate verbose output.
+     */
     unsigned char verbose;
+
+    /**
+     * Flag to indicate quiet output.
+     */
     unsigned char quiet;
+
+    /**
+     * Flag to indicate debug output.
+     */
     unsigned char debug;
+
+    /**
+     * Output format indicator.
+     */
     unsigned char format;
+
+    /**
+     * Output target indicator.
+     */
     unsigned char output;
+
+    /**
+     * Verbosity level.
+     */
+    unsigned char level;
 } Optimizer_Output;
 
+/**
+ * System options for the optimizer.
+ */
 typedef struct Optimizer_Options{
-    // TODO: Document, maybe separate
+
+    /**
+     * Help flag.
+     *
+     * Currently ignored.
+     */
     unsigned char help;
+
+    /**
+     * Number of threads to use.
+     *
+     * Limited to {@link MAX_THREADS}.
+     */
     unsigned char threads;
 } Optimizer_Options;
 
@@ -677,7 +723,7 @@ typedef struct Optimizer_Data {
      *
      * A set count to compare every rune combination against.
      */
-    Rune_Set_Count requested_set_count;
+    Rune_Set_Count *requested_set_count;
 
     /**
      * The optimized unit

+ 41 - 65
src/cli/runeoptimizer/optimize/output/output.c

@@ -1,3 +1,20 @@
+/*
+ * This file is part of RuneOptimizer.
+ *
+ * RuneOptimizer is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
+ */
+
 #include <stdio.h>
 #include <string.h>
 #include "../optimize.h"
@@ -88,12 +105,9 @@ static int generate_filename(Optimizer_Data *data, char *ext, char *filename){
           (data->unit->name[i] >= 'a' && data->unit->name[i] <= 'z')
           || (data->unit->name[i] >= 'A' && data->unit->name[i] <= 'Z')
           || (data->unit->name[i] >= '0' && data->unit->name[i] <= '9')
-        ){
+        )
             unit_name[i] = data->unit->name[i];
-        }
-        else{
-            unit_name[i] = '-';
-        }
+        else unit_name[i] = '-';
     }
     unit_name[i] = '\0';
     strcpy(filename, data->unit->id);
@@ -113,10 +127,7 @@ static int diff_string(
     int diff = modified - current;
     int i;
     if (diff == 0){
-        for (i = 0; i < padding + 1; i ++){
-            string[i] = ' ';
-        }
-
+        for (i = 0; i < padding + 1; i ++) string[i] = ' ';
         string[i] = '\0';
     }
     else if (diff > 0){
@@ -165,9 +176,8 @@ extern int output(Optimizer_Data *data){
         }
     }
     else if (format == OUTPUT_JSON){
-        if (output == OUTPUT_SCREEN){
+        if (output == OUTPUT_SCREEN)
             return print_json(data, stdout, MAX_RESULTS_SCREEN_JSON);
-        }
         else if (output == OUTPUT_FILE){
             char filename[128];
             generate_filename(data, "json", filename);
@@ -206,10 +216,8 @@ extern void output_summary(Optimizer_Data *data){
     );
     printf(" | %*s |      ", -37, data->unit->name);
     for (int i = 0; i < MAX_SETS; i ++){
-        if (data->filters->sets[i] != 0){
-            //printf(" %d ", data->filters->sets[i]);
+        if (data->filters->sets[i] != 0)
             printf(" %s ", SET_NAMES[data->filters->sets[i]]);
-        }
         else break;
     }
     printf("\n");
@@ -297,13 +305,9 @@ static int print_human(
     int i;
     if (order == ORDER_ASC){
         i = data->total_results - 1;
-        if (i > max){
-            i = max;
-        }
-    }
-    else{
-        i = 0;
+        if (i > max) i = max;
     }
+    else i = 0;
 
     while (1){
         if (i != data->total_results){
@@ -340,9 +344,7 @@ static int print_human(
               result.rating, "\033[39m"
             );
         }
-        else{
-            sprintf(rating, "%d", result.rating);
-        }
+        else sprintf(rating, "%d", result.rating);
         fprintf(
           target,
           "| DEF: | %*u  | %*u  | %s |      Rating: %s \n",
@@ -398,9 +400,7 @@ static int print_human(
           "------------------------------------------\n"
         );
         char lines[10][190];
-        for (int l = 0; l < 10; l ++){
-            strcpy(lines[l], "");
-        }
+        for (int l = 0; l < 10; l ++) strcpy(lines[l], "");
 
         // Print all the runes in the result
         int start_pos = 0;
@@ -449,9 +449,8 @@ static int print_human(
             strcat(lines[1], rune_id);
 
             // Row 2, rune location
-            if (strlen(sqlite3_column_text(stmt_rune, 0)) == 0){
+            if (strlen(sqlite3_column_text(stmt_rune, 0)) == 0)
                 strcat(lines[2], "| In inventory");
-            }
             else{
                 if (strcmp(sqlite3_column_text(stmt_rune, 0), unit->id) == 0){
                     if (color == TRUE)
@@ -477,9 +476,7 @@ static int print_human(
                         strncpy(tmp + 2, sqlite3_column_text(stmt_rune, 0), 11);
                     }
                     sqlite3_finalize(stmt_unit);
-                    while (strlen(tmp) < 13){
-                        strcat(tmp, " ");
-                    }
+                    while (strlen(tmp) < 13) strcat(tmp, " ");
                     strcat(lines[2], "|");
                     strcat(lines[2], tmp);
                 }
@@ -503,18 +500,11 @@ static int print_human(
                 if (
                   stat == 2 || stat == 4 || stat == 6 || stat == 8
                   || stat == 9 || stat == 10 || stat == 11
-                ){
+                )
                     percentile = TRUE;
-                }
-                else{
-                    percentile = FALSE;
-                }
-                if (slot == 0){
-                    has_innate = TRUE;
-                }
-                else if (slot > total_subs){
-                    total_subs = slot;
-                }
+                else percentile = FALSE;
+                if (0 == slot) has_innate = TRUE;
+                else if (slot > total_subs) total_subs = slot;
                 // Stat name and value.
                 sprintf(
                   tmp, "%3s%4d%c",
@@ -546,36 +536,28 @@ static int print_human(
                     strcat(tmp, tmp2);
                     if (color == TRUE) strcat(tmp, "\033[39m");
                 }
-                else{
-                    strcat(tmp, "     ");
-                }
+                else strcat(tmp, "     ");
                 strcat(lines[slot + 4], "|");
                 strcat(lines[slot + 4], tmp);
             }
             sqlite3_finalize(stmt_stat);
             // It the rune has no innate stat, add empty space.
-            if (has_innate == FALSE){
-                strcat(lines[4], "|             ");
-            }
+            if (has_innate == FALSE) strcat(lines[4], "|             ");
             // Add empty space for each subsstat the runes doeesn't have.
-            for (; total_subs < 4; total_subs ++){
+            for (; total_subs < 4; total_subs ++)
                 strcat(lines[5 + total_subs], "|             ");
-            }
+
             // Row 9: Efficiency
             sprintf(
               tmp, "|E: %2.1f/%2.1fX", sqlite3_column_double(stmt_rune, 5),
               sqlite3_column_double(stmt_rune, 6)
             );
             strcat(lines[9], tmp);
-
             sqlite3_finalize(stmt_rune);
         }
         for (int l = 3; l < 10; l ++){
-            for (int x = 0; x < strlen(lines[l]); x ++){
-                if (lines[l][x] == 'X'){
-                    lines[l][x] = '%';
-                }
-            }
+            for (int x = 0; x < strlen(lines[l]); x ++)
+                if (lines[l][x] == 'X') lines[l][x] = '%';
         }
 
         for (int l = 0; l < 10; l ++){
@@ -591,15 +573,11 @@ static int print_human(
         total_printed ++;
         // Break conditions
         if (order == ORDER_ASC){
-            if (0 == i){
-                break;
-            }
+            if (0 == i) break;
             i --;
         }
         else{
-            if (i == data->total_results - 1 || i == max - 1){
-                break;
-            }
+            if (i == data->total_results - 1 || i == max - 1) break;
             i ++;
         }
     }
@@ -654,9 +632,7 @@ static int print_json(Optimizer_Data *data, FILE *target, unsigned int max){
         strcat(json, "]},");
 
         // If last result, remove last comma
-        if (i == data->total_results - 1 || i == max - 1){
-            json[strlen(json) - 1] = 0;
-        }
+        if (i == data->total_results - 1 || i == max - 1) json[strlen(json) - 1] = 0;
         total_printed ++;
         fprintf(target, json);
     }

+ 17 - 0
src/cli/runeoptimizer/optimize/output/output.h

@@ -1,3 +1,20 @@
+/*
+ * This file is part of RuneOptimizer.
+ *
+ * RuneOptimizer is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
+ */
+
 #include "../optimize.h"
 
 /**

+ 1 - 1
src/gui/runeoptimizer_gui/gui/PanelOptimizer.py

@@ -854,7 +854,7 @@ class PanelOptimizer(wx.Panel):
                 command += str(self._team_ids[team]) + ","
             command = command[:-1]
 
-        command += (" --gui ")
+        command += (" --quiet --output screen --format json ")
         print("Command: " + command)
         self._progress_label.SetLabel("")
         self._progress_gauge.SetValue(0)

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません