OSDN Git Service

[Refactor] #4158 ang_sort() をTargetSorter::sort() にクラス化した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 26 May 2024 01:10:26 +0000 (10:10 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 26 May 2024 13:34:52 +0000 (22:34 +0900)
src/target/grid-selector.cpp
src/target/target-preparation.cpp
src/target/target-sorter.cpp
src/target/target-sorter.h

index d88d178..bd4d84f 100644 (file)
@@ -82,7 +82,7 @@ static void tgt_pt_prepare(PlayerType *player_ptr, std::vector<POSITION> &ys, st
         }
     }
 
-    ang_sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::DISTANCE);
+    TargetSorter().sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::DISTANCE);
 }
 
 /*!
index 92a525f..83edba3 100644 (file)
@@ -162,13 +162,12 @@ void target_set_prepare(PlayerType *player_ptr, std::vector<POSITION> &ys, std::
     }
 
     if (mode & (TARGET_KILL)) {
-        ang_sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::DISTANCE);
+        TargetSorter().sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::DISTANCE);
     } else {
-        ang_sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::IMPORTANCE);
+        TargetSorter().sort(*player_ptr->current_floor_ptr, player_ptr->get_position(), ys, xs, SortKind::IMPORTANCE);
     }
 
     // 乗っているモンスターがターゲットリストの先頭にならないようにする調整。
-
     if (player_ptr->riding == 0 || !target_pet || (size(ys) <= 1) || !(mode & (TARGET_KILL))) {
         return;
     }
index c8abb9c..8bc95ac 100644 (file)
@@ -216,15 +216,14 @@ void exe_ang_sort(const FloorType &floor, const Pos2D &p_pos, std::vector<int> &
 }
 
 /*
- * @brief クイックソートの受け付け / Accepting auick sort in place
- * @param u アイテムやモンスター等への配列
- * @param v 条件基準IDへの参照ポインタ
- * @param a 比較対象のID1
- * @param b 比較対象のID2
- * @param ang_sort_comp 比較用の関数ポインタ
- * @param ang_sort_swap スワップ用の関数ポインタ
+ * @brief クイックソートの受け付け
+ * @param floor フロアへの参照
+ * @param p_pos プレイヤーの現在位置
+ * @param ys マップのY座標群 (歴史的経緯によりPos2D化されていない)
+ * @param xs マップのX座標群 (同上)
+ * @param kind ソート種別
  */
-void ang_sort(const FloorType &floor, const Pos2D &p_pos, std::vector<int> &ys, std::vector<int> &xs, SortKind kind)
+void TargetSorter::sort(const FloorType &floor, const Pos2D &p_pos, std::vector<int> &ys, std::vector<int> &xs, SortKind kind)
 {
     exe_ang_sort(floor, p_pos, ys, xs, 0, std::ssize(ys) - 1, kind);
 }
index a6e6ea0..8ab1b57 100644 (file)
@@ -9,4 +9,8 @@ enum class SortKind {
 };
 
 class FloorType;
-void ang_sort(const FloorType &floor, const Pos2D &p_pos, std::vector<int> &ys, std::vector<int> &xs, SortKind kind);
+class TargetSorter {
+public:
+    TargetSorter() = default;
+    void sort(const FloorType &floor, const Pos2D &p_pos, std::vector<int> &ys, std::vector<int> &xs, SortKind kind);
+};