-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathFractalLoopIsland.hpp
More file actions
333 lines (287 loc) · 19.1 KB
/
FractalLoopIsland.hpp
File metadata and controls
333 lines (287 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*#######################################################################################
Copyright (c) 2017-2019 Kasugaccho
Copyright (c) 2018-2019 As Project
https://github.com/Kasugaccho/DungeonTemplateLibrary
wanotaitei@gmail.com
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#######################################################################################*/
#ifndef INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_SHAPE_FRACTAL_LOOP_ISLAND_HPP
#define INCLUDED_DUNGEON_TEMPLATE_LIBRARY_DTL_SHAPE_FRACTAL_LOOP_ISLAND_HPP
/*#######################################################################################
日本語リファレンス (Reference-JP)
https://github.com/Kasugaccho/DungeonTemplateLibrary/wiki/dtl::shape::FractalLoopIsland-(形状クラス)/
#######################################################################################*/
#include <array>
#include <utility>
#include <DTL/Base/Struct.hpp>
#include <DTL/Macros/constexpr.hpp>
#include <DTL/Macros/nodiscard.hpp>
#include <DTL/Random/RandomEngine.hpp>
#include <DTL/Range/RectBaseFractal.hpp>
#include <DTL/Shape/DiamondSquareAverage.hpp>
#include <DTL/Type/Forward.hpp>
#include <DTL/Type/New.hpp>
#include <DTL/Type/SizeT.hpp>
#include <DTL/Type/SSizeT.hpp>
#include <DTL/Type/UniquePtr.hpp>
/*#######################################################################################
[概要] "dtl名前空間"とは"DungeonTemplateLibrary"の全ての機能が含まれる名前空間である。
[Summary] The "dtl" is a namespace that contains all the functions of "DungeonTemplateLibrary".
#######################################################################################*/
namespace dtl {
inline namespace shape { //"dtl::shape"名前空間に属する
constexpr ::dtl::type::size fli_chunk_size{ 16 };
//マスを指定した数値で埋める
template<typename Matrix_Var_, typename UniquePtr_ = DTL_TYPE_UNIQUE_PTR<::dtl::type::ssize[]>>
class FractalLoopIsland : public ::dtl::range::RectBaseFractal<FractalLoopIsland<Matrix_Var_, UniquePtr_>, Matrix_Var_> {
private:
///// エイリアス (Alias) /////
using Index_Size = ::dtl::type::size;
using ShapeBase_t = ::dtl::range::RectBaseFractal<FractalLoopIsland, Matrix_Var_>;
///// 基本処理 /////
//チャンク生成の呼び出し・実行
template<typename Matrix2_, typename Function_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimple(Matrix2_&& matrix_, Function_&& function_) const noexcept {
createDiamondSquareAverageSTL<Matrix_Var_, Matrix2_>(matrix_, 0, 0, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, matrix_[0][0], matrix_[::dtl::shape::fli_chunk_size][0], matrix_[0][::dtl::shape::fli_chunk_size], matrix_[::dtl::shape::fli_chunk_size][::dtl::shape::fli_chunk_size], this->min_value + this->altitude, this->add_altitude, function_);
}
template<typename Matrix2_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimple(Matrix2_&& matrix_) const noexcept {
createWorldMapSimple(matrix_, [](const Matrix_Var_ & value_) {return value_ / 2; });
}
//チャンク生成の呼び出し・実行
template<typename Matrix2_, typename Function_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimpleLayer(Matrix2_&& matrix_, const Index_Size layer_, Function_&& function_) const noexcept {
createDiamondSquareAverageLayer<Matrix_Var_, Matrix2_>(matrix_, layer_, 0, 0, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, matrix_[0][0][layer_], matrix_[::dtl::shape::fli_chunk_size][0][layer_], matrix_[0][::dtl::shape::fli_chunk_size][layer_], matrix_[::dtl::shape::fli_chunk_size][::dtl::shape::fli_chunk_size][layer_], this->min_value + this->altitude, this->add_altitude, function_);
}
template<typename Matrix2_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimpleLayer(Matrix2_&& matrix_, const Index_Size layer_) const noexcept {
createWorldMapSimpleLayer(matrix_, layer_, [](const Matrix_Var_ & value_) {return value_ / 2; });
}
//チャンク生成の呼び出し・実行
template<typename Matrix2_, typename Function_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimpleArray(Matrix2_&& matrix_, const Index_Size max_x_, Function_&& function_) const noexcept {
createDiamondSquareAverageArray<Matrix_Var_, Matrix2_>(matrix_, max_x_, 0, 0, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, ::dtl::shape::fli_chunk_size / 2, matrix_[0], matrix_[::dtl::shape::fli_chunk_size * max_x_], matrix_[::dtl::shape::fli_chunk_size], matrix_[::dtl::shape::fli_chunk_size * max_x_ + ::dtl::shape::fli_chunk_size], this->min_value + this->altitude, this->add_altitude, function_);
}
template<typename Matrix2_>
DTL_VERSIONING_CPP14_CONSTEXPR
void createWorldMapSimpleArray(Matrix2_ && matrix_, const Index_Size max_x_) const noexcept {
createWorldMapSimpleArray(matrix_, max_x_, [](const Matrix_Var_ & value_) {return value_ / 2; });
}
//Normal
template<typename Matrix_, typename ...Args_>
bool drawNormal(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept {
if (this->altitude < 2) return false;
::std::array< ::std::array<Matrix_Var_, ::dtl::shape::fli_chunk_size + 1>, ::dtl::shape::fli_chunk_size + 1> chunk_matrix{ {} };
const ::dtl::type::size chunk_x{ ((end_x_ - this->start_x) / ::dtl::shape::fli_chunk_size) };
const ::dtl::type::size chunk_y{ ((end_y_ - this->start_y) / ::dtl::shape::fli_chunk_size) };
UniquePtr_ rand_up{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_up) return false;
UniquePtr_ rand_down{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_down) return false;
UniquePtr_ rand_first_row{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_first_row) return false;
for (::dtl::type::size col{}; col < chunk_x; ++col) {
rand_up[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_first_row[col] = rand_up[col];
}
rand_first_row[chunk_x] = rand_up[chunk_x] = rand_up[0];
for (::dtl::type::size row{}; row < chunk_y; ++row) {
if ((row + 1) == chunk_y) rand_down = ::std::move(rand_first_row);
else {
for (::dtl::type::size col{}; col < chunk_x; ++col)
rand_down[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_down[chunk_x] = rand_down[0];
}
for (::dtl::type::size col{}; col < chunk_x; ++col) {
//四角形の4点の高さを決定
chunk_matrix[0][0] = static_cast<Matrix_Var_>(rand_up[col]);
chunk_matrix[::dtl::shape::fli_chunk_size][0] = static_cast<Matrix_Var_>(rand_down[col]);
chunk_matrix[0][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_up[col + 1]);
chunk_matrix[::dtl::shape::fli_chunk_size][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_down[col + 1]);
//チャンク生成
this->createWorldMapSimple(chunk_matrix, args_...);
//生成したチャンクをワールドマップにコピペ
for (::dtl::type::size row2{}; row2 < ::dtl::shape::fli_chunk_size; ++row2)
for (::dtl::type::size col2{}; col2 < ::dtl::shape::fli_chunk_size; ++col2)
matrix_[this->start_y + row * ::dtl::shape::fli_chunk_size + row2][this->start_x + col * ::dtl::shape::fli_chunk_size + col2] = chunk_matrix[row2][col2];
}
for (::dtl::type::size col{}; col <= chunk_x; ++col)
rand_up[col] = rand_down[col];
}
return true;
}
//LayerNormal
template<typename Matrix_, typename ...Args_>
bool drawLayerNormal(Matrix_ && matrix_, const Index_Size layer_, const Index_Size end_x_, const Index_Size end_y_, Args_ && ... args_) const noexcept {
if (this->altitude < 2) return false;
::std::array< ::std::array<Matrix_Var_, ::dtl::shape::fli_chunk_size + 1>, ::dtl::shape::fli_chunk_size + 1> chunk_matrix{ {} };
const ::dtl::type::size chunk_x{ ((end_x_ - this->start_x) / ::dtl::shape::fli_chunk_size) };
const ::dtl::type::size chunk_y{ ((end_y_ - this->start_y) / ::dtl::shape::fli_chunk_size) };
UniquePtr_ rand_up{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_up) return false;
UniquePtr_ rand_down{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_down) return false;
UniquePtr_ rand_first_row{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_first_row) return false;
for (::dtl::type::size col{}; col < chunk_x; ++col) {
rand_up[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_first_row[col] = rand_up[col];
}
rand_first_row[chunk_x] = rand_up[chunk_x] = rand_up[0];
for (::dtl::type::size row{}; row < chunk_y; ++row) {
if ((row + 1) == chunk_y) rand_down = ::std::move(rand_first_row);
else {
for (::dtl::type::size col{}; col < chunk_x; ++col)
rand_down[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_down[chunk_x] = rand_down[0];
}
for (::dtl::type::size col{}; col < chunk_x; ++col) {
//四角形の4点の高さを決定
chunk_matrix[0][0] = static_cast<Matrix_Var_>(rand_up[col]);
chunk_matrix[::dtl::shape::fli_chunk_size][0] = static_cast<Matrix_Var_>(rand_down[col]);
chunk_matrix[0][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_up[col + 1]);
chunk_matrix[::dtl::shape::fli_chunk_size][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_down[col + 1]);
//チャンク生成
this->createWorldMapSimple(chunk_matrix, args_...);
//生成したチャンクをワールドマップにコピペ
for (::dtl::type::size row2{}; row2 < ::dtl::shape::fli_chunk_size; ++row2)
for (::dtl::type::size col2{}; col2 < ::dtl::shape::fli_chunk_size; ++col2)
matrix_[this->start_y + row * ::dtl::shape::fli_chunk_size + row2][this->start_x + col * ::dtl::shape::fli_chunk_size + col2][layer_] = chunk_matrix[row2][col2];
}
for (::dtl::type::size col{}; col <= chunk_x; ++col)
rand_up[col] = rand_down[col];
}
return true;
}
//Array
template<typename Matrix_, typename ...Args_>
bool drawArray(Matrix_ && matrix_, const Index_Size end_x_, const Index_Size end_y_, const Index_Size max_x_, Args_ && ... args_) const noexcept {
if (this->altitude < 2) return false;
::std::array< ::std::array<Matrix_Var_, ::dtl::shape::fli_chunk_size + 1>, ::dtl::shape::fli_chunk_size + 1> chunk_matrix{ {} };
const ::dtl::type::size chunk_x{ ((end_x_ - this->start_x) / ::dtl::shape::fli_chunk_size) };
const ::dtl::type::size chunk_y{ ((end_y_ - this->start_y) / ::dtl::shape::fli_chunk_size) };
UniquePtr_ rand_up{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_up) return false;
UniquePtr_ rand_down{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_down) return false;
UniquePtr_ rand_first_row{ DTL_TYPE_NEW ::dtl::type::ssize[chunk_x + 1] };
if (!rand_first_row) return false;
for (::dtl::type::size col{}; col < chunk_x; ++col) {
rand_up[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_first_row[col] = rand_up[col];
}
rand_first_row[chunk_x] = rand_up[chunk_x] = rand_up[0];
for (::dtl::type::size row{}; row < chunk_y; ++row) {
if ((row + 1) == chunk_y) rand_down = ::std::move(rand_first_row);
else {
for (::dtl::type::size col{}; col < chunk_x; ++col)
rand_down[col] = DTL_RANDOM_ENGINE.get<::dtl::type::ssize>(this->altitude);
rand_down[chunk_x] = rand_down[0];
}
for (::dtl::type::size col{}; col < chunk_x; ++col) {
//四角形の4点の高さを決定
chunk_matrix[0][0] = static_cast<Matrix_Var_>(rand_up[col]);
chunk_matrix[::dtl::shape::fli_chunk_size][0] = static_cast<Matrix_Var_>(rand_down[col]);
chunk_matrix[0][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_up[col + 1]);
chunk_matrix[::dtl::shape::fli_chunk_size][::dtl::shape::fli_chunk_size] = static_cast<Matrix_Var_>(rand_down[col + 1]);
//チャンク生成
this->createWorldMapSimple(chunk_matrix, args_...);
//生成したチャンクをワールドマップにコピペ
for (::dtl::type::size row2{}; row2 < ::dtl::shape::fli_chunk_size; ++row2)
for (::dtl::type::size col2{}; col2 < ::dtl::shape::fli_chunk_size; ++col2)
matrix_[(this->start_y + row * ::dtl::shape::fli_chunk_size + row2) * max_x_ + this->start_x + col * ::dtl::shape::fli_chunk_size + col2] = chunk_matrix[row2][col2];
}
for (::dtl::type::size col{}; col <= chunk_x; ++col)
rand_up[col] = rand_down[col];
}
return true;
}
public:
///// 生成呼び出し (Drawing Function Call) /////
//STL
template<typename Matrix_>
constexpr bool draw(Matrix_ && matrix_) const noexcept {
return this->drawNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= ((matrix_.size() == 0) ? 0 : matrix_[0].size())) ? ((matrix_.size() == 0) ? 0 : matrix_[0].size()) : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height);
}
template<typename Matrix_, typename Function_>
constexpr bool drawOperator(Matrix_ && matrix_, Function_ && function_) const noexcept {
return this->drawNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= ((matrix_.size() == 0) ? 0 : matrix_[0].size())) ? ((matrix_.size() == 0) ? 0 : matrix_[0].size()) : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_);
}
//LayerSTL
template<typename Matrix_>
constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_) const noexcept {
return this->drawLayerNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= ((matrix_.size() == 0) ? 0 : matrix_[0].size())) ? ((matrix_.size() == 0) ? 0 : matrix_[0].size()) : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height);
}
template<typename Matrix_, typename Function_>
constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, Function_ && function_) const noexcept {
return this->drawLayerNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= ((matrix_.size() == 0) ? 0 : matrix_[0].size())) ? ((matrix_.size() == 0) ? 0 : matrix_[0].size()) : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= matrix_.size()) ? matrix_.size() : this->start_y + this->height, function_);
}
//Normal
template<typename Matrix_>
constexpr bool draw(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->drawNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height);
}
template<typename Matrix_, typename Function_>
constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept {
return this->drawNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_);
}
//LayerNormal
template<typename Matrix_>
constexpr bool draw(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->drawLayerNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height);
}
template<typename Matrix_, typename Function_>
constexpr bool drawOperator(Matrix_ && matrix_, const Index_Size layer_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept {
return this->drawLayerNormal(DTL_TYPE_FORWARD<Matrix_>(matrix_), layer_, (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, function_);
}
//Array
template<typename Matrix_>
constexpr bool drawArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_) const noexcept {
return this->drawArray(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_);
}
template<typename Matrix_, typename Function_>
constexpr bool drawOperatorArray(Matrix_ && matrix_, const Index_Size max_x_, const Index_Size max_y_, Function_ && function_) const noexcept {
return this->drawArray(DTL_TYPE_FORWARD<Matrix_>(matrix_), (this->width == 0 || this->start_x + this->width >= max_x_) ? max_x_ : this->start_x + this->width, (this->height == 0 || this->start_y + this->height >= max_y_) ? max_y_ : this->start_y + this->height, max_x_, function_);
}
///// 生成呼び出しファンクタ (Drawing Functor) /////
template<typename Matrix_, typename ...Args_>
constexpr bool operator()(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
return this->draw(DTL_TYPE_FORWARD<Matrix_>(matrix_), DTL_TYPE_FORWARD<Args_>(args_)...);
}
///// ダンジョン行列生成 (Create Dungeon Matrix) /////
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& create(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
this->draw(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
this->drawArray(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createOperator(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
this->drawOperator(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
template<typename Matrix_, typename ...Args_>
DTL_VERSIONING_CPP14_CONSTEXPR
Matrix_&& createOperatorArray(Matrix_ && matrix_, Args_ && ... args_) const noexcept {
this->drawOperatorArray(matrix_, DTL_TYPE_FORWARD<Args_>(args_)...);
return DTL_TYPE_FORWARD<Matrix_>(matrix_);
}
///// コンストラクタ (Constructor) /////
using ShapeBase_t::ShapeBase_t;
};
} //namespace
}
#endif //Included Dungeon Template Library