OSDN Git Service

[Refactor] #37353 ソート処理をsort.c/hに分離。 / Separate to sort.c/h.
authorDeskull <deskull@users.sourceforge.jp>
Sun, 13 Jan 2019 04:56:40 +0000 (13:56 +0900)
committerDeskull <deskull@users.sourceforge.jp>
Sun, 13 Jan 2019 04:56:40 +0000 (13:56 +0900)
15 files changed:
Hengband_vcs2017/Hengband/Hengband.vcxproj
src/Makefile.am
src/bldg.c
src/cmd-activate.c
src/cmd-item.c
src/cmd-pet.c
src/cmd4.c
src/externs.h
src/files.c
src/rooms-pitnest.c
src/save.c
src/sort.c [new file with mode: 0644]
src/sort.h [new file with mode: 0644]
src/wizard1.c
src/xtra2.c

index 88aec26..fd0a64d 100644 (file)
     <ClCompile Include="..\..\src\selfinfo.c" />\r
     <ClCompile Include="..\..\src\shoot.c" />\r
     <ClCompile Include="..\..\src\snipe.c" />\r
+    <ClCompile Include="..\..\src\sort.c" />\r
     <ClCompile Include="..\..\src\spells-summon.c" />\r
     <ClCompile Include="..\..\src\spells1.c" />\r
     <ClCompile Include="..\..\src\spells2.c" />\r
     <ClInclude Include="..\..\src\rooms-vault.h" />\r
     <ClInclude Include="..\..\src\rooms.h" />\r
     <ClInclude Include="..\..\src\selfinfo.h" />\r
+    <ClInclude Include="..\..\src\sort.h" />\r
     <ClInclude Include="..\..\src\spells-summon.h" />\r
     <ClInclude Include="..\..\src\floor-streams.h" />\r
     <ClInclude Include="..\..\src\store.h" />\r
index fbfe7cd..c71652b 100644 (file)
@@ -38,6 +38,7 @@ hengband_SOURCES = \
        rooms-special.c rooms-special.h rooms-trap.c rooms-trap.h rooms-vault.c \
        rooms-vault.h save.c scores.c selfinfo.c selfinfo.h shoot.c snipe.c \
        spells1.c spells2.c spells3.c spells-summon.c spells-summon.h \
+       sort.c sort.h \
        store.h store.c tables.c trap.c trap.h types.h util.c \
        variable.c wild.c wizard1.c wizard2.c \
        world.c world.h xtra1.c xtra2.c z-config.h \
index c4447af..fd3bd6a 100644 (file)
@@ -17,6 +17,7 @@
 #include "monsterrace-hook.h"
 #include "melee.h"
 #include "world.h"
+#include "sort.h"
 
 /*!
  * ループ中で / hack as in leave_store in store.c
index 8900d33..d847458 100644 (file)
@@ -10,6 +10,7 @@
 #include "cmd-activate.h"
 #include "object-hook.h"
 #include "spells-summon.h"
+#include "sort.h"
 
 /*!
 * @brief ペット入りモンスターボールをソートするための比較関数
index d83ef9d..1b1f0ac 100644 (file)
@@ -22,6 +22,7 @@
 #include "cmd-zapwand.h"
 
 #include "object-hook.h"
+#include "sort.h"
 
 
 /*!
index 2d0bd7c..632926a 100644 (file)
@@ -1,5 +1,6 @@
 #include "angband.h"
 #include "melee.h"
+#include "sort.h"
 
 /*!
 * @brief プレイヤーの騎乗/下馬処理判定
index 67d28bd..d99441f 100644 (file)
@@ -43,6 +43,7 @@
 #include "cmd-pet.h"
 #include "world.h"
 #include "player-status.h"
+#include "sort.h"
 
 
 /*
index 9d41563..6b396e7 100644 (file)
@@ -1269,8 +1269,6 @@ extern void redraw_window(void);
 extern bool change_panel(POSITION dy, POSITION dx);
 extern void verify_panel(void);
 extern cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode);
-extern void ang_sort_aux(vptr u, vptr v, int p, int q);
-extern void ang_sort(vptr u, vptr v, int n);
 extern bool target_able(MONSTER_IDX m_idx);
 extern bool target_okay(void);
 extern bool target_set(BIT_FLAGS mode);
index 21375de..26c66a2 100644 (file)
@@ -16,6 +16,7 @@
 #include "angband.h"
 #include "world.h"
 #include "player-status.h"
+#include "sort.h"
 
 
 /*
index 46fa897..4b61cc1 100644 (file)
@@ -4,6 +4,7 @@
 #include "rooms.h"\r
 #include "rooms-pitnest.h"\r
 #include "monsterrace-hook.h"\r
+#include "sort.h"\r
 \r
 \r
 \r
index 67ef9fe..1be5a3a 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include "angband.h"
+#include "sort.h"
 
 
 
diff --git a/src/sort.c b/src/sort.c
new file mode 100644 (file)
index 0000000..62c6102
--- /dev/null
@@ -0,0 +1,69 @@
+#include "angband.h"
+#include "sort.h"
+
+
+/*
+ * Angband sorting algorithm -- quick sort in place
+ *
+ * Note that the details of the data we are sorting is hidden,
+ * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
+ * function hooks to interact with the data, which is given as
+ * two pointers, and which may have any user-defined form.
+ */
+void ang_sort_aux(vptr u, vptr v, int p, int q)
+{
+       int z, a, b;
+
+       /* Done sort */
+       if (p >= q) return;
+
+       /* Pivot */
+       z = p;
+
+       /* Begin */
+       a = p;
+       b = q;
+
+       /* Partition */
+       while (TRUE)
+       {
+               /* Slide i2 */
+               while (!(*ang_sort_comp)(u, v, b, z)) b--;
+
+               /* Slide i1 */
+               while (!(*ang_sort_comp)(u, v, z, a)) a++;
+
+               /* Done partition */
+               if (a >= b) break;
+
+               /* Swap */
+               (*ang_sort_swap)(u, v, a, b);
+
+               /* Advance */
+               a++, b--;
+       }
+
+       /* Recurse left side */
+       ang_sort_aux(u, v, p, b);
+
+       /* Recurse right side */
+       ang_sort_aux(u, v, b + 1, q);
+}
+
+
+/*
+ * Angband sorting algorithm -- quick sort in place
+ *
+ * Note that the details of the data we are sorting is hidden,
+ * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
+ * function hooks to interact with the data, which is given as
+ * two pointers, and which may have any user-defined form.
+ */
+void ang_sort(vptr u, vptr v, int n)
+{
+       /* Sort the array */
+       ang_sort_aux(u, v, 0, n - 1);
+}
+
+
+
diff --git a/src/sort.h b/src/sort.h
new file mode 100644 (file)
index 0000000..813a5ad
--- /dev/null
@@ -0,0 +1,3 @@
+extern void ang_sort_aux(vptr u, vptr v, int p, int q);
+extern void ang_sort(vptr u, vptr v, int n);
+
index d58ad2f..198c8e9 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include "angband.h"
+#include "sort.h"
 
 
 #ifdef ALLOW_SPOILERS
index 68f1de7..2b46503 100644 (file)
@@ -16,6 +16,7 @@
 #include "object-curse.h"
 #include "monsterrace-hook.h"
 #include "objectkind-hook.h"
+#include "sort.h"
 
 #define REWARD_CHANCE 10
 
@@ -2089,71 +2090,6 @@ cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
 
 
 
-/*
- * Angband sorting algorithm -- quick sort in place
- *
- * Note that the details of the data we are sorting is hidden,
- * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
- * function hooks to interact with the data, which is given as
- * two pointers, and which may have any user-defined form.
- */
-void ang_sort_aux(vptr u, vptr v, int p, int q)
-{
-       int z, a, b;
-
-       /* Done sort */
-       if (p >= q) return;
-
-       /* Pivot */
-       z = p;
-
-       /* Begin */
-       a = p;
-       b = q;
-
-       /* Partition */
-       while (TRUE)
-       {
-               /* Slide i2 */
-               while (!(*ang_sort_comp)(u, v, b, z)) b--;
-
-               /* Slide i1 */
-               while (!(*ang_sort_comp)(u, v, z, a)) a++;
-
-               /* Done partition */
-               if (a >= b) break;
-
-               /* Swap */
-               (*ang_sort_swap)(u, v, a, b);
-
-               /* Advance */
-               a++, b--;
-       }
-
-       /* Recurse left side */
-       ang_sort_aux(u, v, p, b);
-
-       /* Recurse right side */
-       ang_sort_aux(u, v, b+1, q);
-}
-
-
-/*
- * Angband sorting algorithm -- quick sort in place
- *
- * Note that the details of the data we are sorting is hidden,
- * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
- * function hooks to interact with the data, which is given as
- * two pointers, and which may have any user-defined form.
- */
-void ang_sort(vptr u, vptr v, int n)
-{
-       /* Sort the array */
-       ang_sort_aux(u, v, 0, n-1);
-}
-
-
-
 /*** Targeting Code ***/