OSDN Git Service

[Refactor] #3903 geometry.cpp/h に定義されていた方向定義を生配列からstd::array に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 7 Apr 2024 13:45:12 +0000 (22:45 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 20 Apr 2024 00:58:53 +0000 (09:58 +0900)
src/floor/geometry.cpp
src/floor/geometry.h

index 502a1ca..404442a 100644 (file)
 #include "util/bit-flags-calculator.h"
 
 /*!
- * キーパッドの方向を南から反時計回り順に列挙 / Global array for looping through the "keypad directions"
- */
-const int ddd[9] = { 2, 8, 6, 4, 3, 1, 9, 7, 5 };
-
-/*!
- * dddで定義した順にベクトルのX軸成分を定義 / Global arrays for converting "keypad direction" into offsets
- */
-const int ddx[10] = { 0, -1, 0, 1, -1, 0, 1, -1, 0, 1 };
-
-/*!
- * dddで定義した順にベクトルのY軸成分を定義 / Global arrays for converting "keypad direction" into offsets
- */
-const int ddy[10] = { 0, 1, 1, 1, 0, 0, 0, -1, -1, -1 };
-
-/*!
- * ddd越しにベクトルのX軸成分を定義 / Global arrays for optimizing "ddx[ddd[i]]" and "ddy[ddd[i]]"
- */
-const int ddx_ddd[9] = { 0, 0, 1, -1, 1, -1, 1, -1, 0 };
-
-/*!
- * ddd越しにベクトルのY軸成分を定義 / Global arrays for optimizing "ddx[ddd[i]]" and "ddy[ddd[i]]"
- */
-const int ddy_ddd[9] = { 1, -1, 0, 0, 1, 1, -1, -1, 0 };
-
-/*!
- * キーパッドの円環状方向配列 / Circular keypad direction array
- */
-const int cdd[8] = { 2, 3, 6, 9, 8, 7, 4, 1 };
-
-/*!
- * cdd越しにベクトルのX軸成分を定義 / Global arrays for optimizing "ddx[cdd[i]]" and "ddy[cdd[i]]"
- */
-const int ddx_cdd[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
-
-/*!
- * cdd越しにベクトルのY軸成分を定義 / Global arrays for optimizing "ddx[cdd[i]]" and "ddy[cdd[i]]"
- */
-const int ddy_cdd[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
-
-/*!
  * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
  * @param y1 1点目のy座標
  * @param x1 1点目のx座標
index 6ddbd4f..e90afd2 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "system/angband.h"
 #include "util/point-2d.h"
+#include <array>
 
 /*!
  * @brief 視界及び光源の過渡処理配列サイズ / Maximum size of the "temp" array
@@ -20,14 +21,14 @@ struct pos_list {
     POSITION x[TEMP_MAX];
 };
 
-extern const int ddd[9];
-extern const int ddx[10];
-extern const int ddy[10];
-extern const int ddx_ddd[9];
-extern const int ddy_ddd[9];
-extern const int cdd[8];
-extern const int ddx_cdd[8];
-extern const int ddy_cdd[8];
+constexpr std::array<int, 9> ddd = { { 2, 8, 6, 4, 3, 1, 9, 7, 5 } }; //!< キーパッドの方向 (南から反時計回り順).
+constexpr std::array<int, 10> ddx = { { 0, -1, 0, 1, -1, 0, 1, -1, 0, 1 } }; //!< dddで定義した順にベクトルのX軸成分.
+constexpr std::array<int, 10> ddy = { { 0, 1, 1, 1, 0, 0, 0, -1, -1, -1 } }; //!< dddで定義した順にベクトルのY軸成分.
+constexpr std::array<int, 9> ddx_ddd = { { 0, 0, 1, -1, 1, -1, 1, -1, 0 } }; //!< ddd越しにベクトルのX軸成分.
+constexpr std::array<int, 9> ddy_ddd = { { 1, -1, 0, 0, 1, 1, -1, -1, 0 } }; //!< ddd越しにベクトルのY軸成分.
+constexpr std::array<int, 8> cdd = { { 2, 3, 6, 9, 8, 7, 4, 1 } }; //!< キーパッドの円環状方向配列. */
+constexpr std::array<int, 8> ddx_cdd = { { 0, 1, 1, 1, 0, -1, -1, -1 } }; //!< cdd越しにベクトルのX軸成分.
+constexpr std::array<int, 8> ddy_cdd = { { 1, 1, 0, -1, -1, -1, 0, 1 } }; //!< cdd越しにベクトルのY軸成分.
 
 class PlayerType;
 DIRECTION coords_to_dir(PlayerType *player_ptr, POSITION y, POSITION x);