-
Notifications
You must be signed in to change notification settings - Fork 6
/
Base.q.yml
335 lines (289 loc) · 11.2 KB
/
Base.q.yml
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
properties:
- name: type
type: std::string
init_with: AllegroFlare::TileMaps::AutoTile::Filters::Base::TYPE
constructor_arg: true
getter: true
- name: input_matrix
type: AllegroFlare::TileMaps::AutoTile::FilterMatrix
init_with: '{}'
constructor_arg: true
getter: true
getter_ref: true
setter: true
- name: result_matrix
type: AllegroFlare::TileMaps::AutoTile::FilterMatrix
init_with: '{}'
getter: true
getter_ref: true
- name: OUT_OF_BOUNDS_MATCH_TYPE_POSITIVE
type: char*
init_with: '(char*)"positive"'
static: true
constexpr: true
- name: OUT_OF_BOUNDS_MATCH_TYPE_NEGATIVE
type: char*
init_with: '(char*)"negative"'
static: true
constexpr: true
- name: OUT_OF_BOUNDS_MATCH_TYPE_EXTRUDED_EDGE
type: char*
init_with: '(char*)"extruded_edge"'
static: true
constexpr: true
- name: DEFAULT_OUT_OF_BOUNDS_MATCH_TYPE
type: char*
init_with: AllegroFlare::TileMaps::AutoTile::Filters::Base::OUT_OF_BOUNDS_MATCH_TYPE_EXTRUDED_EDGE
static: true
constexpr: true
- name: TYPE
type: char*
init_with: '(char*)"Filters/Base"'
static: true
constexpr: true
documentation:
- body: |
Note that a lot of logic in this initial concept is derived from
https://github.com/MarkOates/tilemap/blob/master/include/tilemap, for example
https://github.com/MarkOates/tilemap/blob/master/include/tilemap/lib/SixteenEdgeTileSet.hpp
todos:
- Integrate SixteenEdgeTileSet concept for a quick draft at design
functions:
- name: process
type: bool
virtual: true
body: |
return true;
- name: iterate_through_input_and_apply_to_result_if_match
parameters:
- name: match_matrix
type: std::vector<std::vector<int>>
default_argument: '{}'
- name: apply_matrix
type: std::vector<std::vector<int>>
default_argument: '{}'
- name: match_matrix_offset_x
type: int
default_argument: 0
- name: match_matrix_offset_y
type: int
default_argument: 0
- name: apply_matrix_offset_x
type: int
default_argument: 0
- name: apply_matrix_offset_y
type: int
default_argument: 0
- name: out_of_bounds_match_type
type: std::string
default_argument: DEFAULT_OUT_OF_BOUNDS_MATCH_TYPE
- name: ignore_if_negative_tile_value_on_match_matrix
type: bool
default_argument: true
- name: ignore_write_if_negative_tile_value_on_stamp_tile
type: bool
default_argument: true
- name: ignore_if_stamp_tile_is_out_of_bounds_on_result_matrix
type: bool
default_argument: true
guards:
- "AllegroFlare::TileMaps::AutoTile::FilterMatrix::STATIC_is_valid(match_matrix)"
- "AllegroFlare::TileMaps::AutoTile::FilterMatrix::STATIC_is_valid(apply_matrix)"
body: |
// TODO: come up with a better name for this function
AllegroFlare::TileMaps::AutoTile::FilterMatrix &input_matrix = get_input_matrix_ref();
AllegroFlare::TileMaps::AutoTile::FilterMatrix &result_matrix = get_result_matrix_ref();
// Comb through the input_matrix and stamp the result if there is a match
for (int y=0; y<input_matrix.get_height(); y++)
for (int x=0; x<input_matrix.get_width(); x++)
{
bool matrix_match_is_positive = false;
bool matrix_match_processed = false;
//if (out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_POSITIVE
//|| out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_NEGATIVE
//)
//{
// NOTE: this logic is a little clunky, assuming that if it's not _MATCH_TYPE_POSITIVE then implicitly
// assuming it will be negative.
//bool out_of_bounds_on_input_matrix_is_positive_match =
//(out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_POSITIVE) ? true : false;
matrix_match_is_positive = matrix_matches(
match_matrix,
x,
y,
match_matrix_offset_x,
match_matrix_offset_y,
ignore_if_negative_tile_value_on_match_matrix,
out_of_bounds_match_type
);
//matrix_match_processed = true;
//}
//if (!matrix_match_processed)
//{
//throw std::runtime_error("AutoTile::Filters::Base::iterate_through_input_and_apply_to_result_if_match: "
//"error: Unexpected behavior, matrix match not processed as expected.");
//}
if (matrix_match_is_positive)
{
stamp_to_result(
apply_matrix,
x,
y,
apply_matrix_offset_x,
apply_matrix_offset_y,
ignore_write_if_negative_tile_value_on_stamp_tile,
ignore_if_stamp_tile_is_out_of_bounds_on_result_matrix
);
}
}
return;
- name: matrix_matches
type: bool
parameters:
- name: match_matrix
type: std::vector<std::vector<int>>
default_argument: '{}'
- name: at_coord_x
type: int
default_argument: 0
- name: at_coord_y
type: int
default_argument: 0
- name: match_matrix_offset_x
type: int
default_argument: 0
- name: match_matrix_offset_y
type: int
default_argument: 0
- name: ignore_if_negative_tile_value_on_match_matrix
type: bool
default_argument: true
- name: out_of_bounds_match_type
type: std::string
default_argument: DEFAULT_OUT_OF_BOUNDS_MATCH_TYPE
guards: [ "AllegroFlare::TileMaps::AutoTile::FilterMatrix::STATIC_is_valid(match_matrix)" ]
body: |
// TODO: un-hardcode this function (note is done, just leaving commented code preserved in case of needed revert)
AllegroFlare::TileMaps::AutoTile::FilterMatrix &input_matrix = get_input_matrix_ref();
int match_matrix_width = match_matrix[0].size();
int match_matrix_height = match_matrix.size();
int out_of_bounds_match_type_i = 0;
if (out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_POSITIVE) out_of_bounds_match_type_i = 1;
if (out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_NEGATIVE) out_of_bounds_match_type_i = 2;
if (out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_EXTRUDED_EDGE) out_of_bounds_match_type_i = 3;
// NOTE: This code is fragmented; Consider a refactor that does not have so many branching cases
bool out_of_bounds_on_input_is_positive_match =
(out_of_bounds_match_type == OUT_OF_BOUNDS_MATCH_TYPE_POSITIVE) ? true : false;
for (int y=0; y<match_matrix_height; y++)
for (int x=0; x<match_matrix_width; x++)
{
int match_matrix_tile_value = match_matrix[y][x];
if (ignore_if_negative_tile_value_on_match_matrix && match_matrix_tile_value < 0) continue;
switch (out_of_bounds_match_type_i)
{
case 1:
// no break;
case 2:
if (!input_matrix.tile_matches(
at_coord_x + x - match_matrix_offset_x,
at_coord_y + y - match_matrix_offset_y,
match_matrix_tile_value,
out_of_bounds_on_input_is_positive_match
)
) return false;
break;
case 3:
if (!input_matrix.tile_matches_with_extruded_boundaries(
at_coord_x + x - match_matrix_offset_x,
at_coord_y + y - match_matrix_offset_y,
match_matrix_tile_value
)
) return false;
break;
default:
throw std::runtime_error("AutoTile::Filters::Base::matrix_matches: error: Unhandled case for "
"out_of_bounds_match_type.");
break;
}
}
return true;
//return (
//input_matrix.tile_matches(at_coord_x, at_coord_y, match_matrix[0][0]) // WARNING: this is hard-coded (0, 0)
//&& input_matrix.tile_matches(at_coord_x, at_coord_y+1, match_matrix[1][0]) // WARNING: this is hard-coded (0, 0)
//);
- name: stamp_to_result
parameters:
- name: stamp_matrix
type: std::vector<std::vector<int>>
default_argument: '{}'
- name: at_coord_x
type: int
default_argument: 0
- name: at_coord_y
type: int
default_argument: 0
- name: apply_matrix_offset_x
type: int
default_argument: 0
- name: apply_matrix_offset_y
type: int
default_argument: 0
- name: ignore_write_if_negative_tile_value_on_stamp_tile
type: bool
default_argument: true
- name: ignore_if_stamp_tile_is_out_of_bounds_on_result_matrix
type: bool
default_argument: true
guards: [ "AllegroFlare::TileMaps::AutoTile::FilterMatrix::STATIC_is_valid(stamp_matrix)" ]
body: |
// TODO: consider removing "STATIC_is_valid" guard for performance
AllegroFlare::TileMaps::AutoTile::FilterMatrix &result_matrix = get_result_matrix_ref();
int stamp_matrix_width = stamp_matrix[0].size();
int stamp_matrix_height = stamp_matrix.size();
for (int y=0; y<stamp_matrix_height; y++)
for (int x=0; x<stamp_matrix_width; x++)
{
// Get the stamp value
int stamp_tile_value = stamp_matrix[y][x];
// Skip if we don't want negative stamp values
if (ignore_write_if_negative_tile_value_on_stamp_tile && stamp_tile_value < 0) continue;
if (ignore_if_stamp_tile_is_out_of_bounds_on_result_matrix)
{
// TODO: use "apply_matrix_offset_x" and "apply_matrix_offset_y"
result_matrix.set_tile_ignore_if_out_of_bounds(
at_coord_x + x - apply_matrix_offset_x,
at_coord_y + y - apply_matrix_offset_y,
stamp_tile_value
);
}
else
{
// TODO: use "apply_matrix_offset_x" and "apply_matrix_offset_y"
// TODO: test this case
result_matrix.set_tile(
at_coord_x + x - apply_matrix_offset_x,
at_coord_y + y - apply_matrix_offset_y,
stamp_tile_value
);
}
}
return;
- name: tile_coord_to_contiguous
type: int
static: true
parameters:
- name: tile_x
type: int
default_argument: 0
- name: tile_y
type: int
default_argument: 0
- name: tile_atlas_num_columns
type: int
default_argument: 0
guards: [ (tile_atlas_num_columns > 0), (tile_x < tile_atlas_num_columns) ]
body: |
return tile_x + tile_y * tile_atlas_num_columns;
dependencies:
- symbol: AllegroFlare::TileMaps::AutoTile::FilterMatrix
headers: [ AllegroFlare/TileMaps/AutoTile/FilterMatrix.hpp ]