9 private immutable maxx
= map_x
, maxy
= map_y
;
12 private struct Normalint(uint max
) {
15 // No reason you would want to negate it, deref it, or invert it; unary + literally does nothing,
16 uint opUnary(string op
)() if (op
== "++" || op
= "--") {
18 return _i
= normalized(_i
, max
);
20 uint opBinary(string op
)(int other
) {
21 return normalized(mixin("_i" ~ op
~ "other"), max
);
25 // we don't have to normalize i. Because assignment and inc/dec already normalize it
28 @property uint i(int newi
) {
29 return _i
= normalized(newi
, max
);
36 this(uint newy
, uint newx
) {
41 pragma(inline
, true) uint normalized(int i
, int max
) {
48 // If this function is a perf problem, use the following to trigger a cmov (compiler should be smart enough to do it that way already though)
51 * i = (i < 0) ? i : oth;
56 private Tile
[][] tiles
;
58 this(Tile
[][] tiles
) {
62 tiles
= new Tile
[][](map_x
, map_y
);
65 Tile
[][] get_tiles() {
69 // lambda of the form, e.g., (Tile x) => x.visible = false will return bool, not void
70 // so if we take a void function, all is lost. So take a function returning T
71 void for_all(T
)(T
delegate(ref Tile x
) fun
) {
72 foreach (ref row
; tiles
) {
73 foreach (ref tile
; row
) {
79 //ref Tile opIndexAssign(Tile value, ulong y, ulong x) { return tiles[y][x] = value; }
80 ref Tile
opIndex(uint y
, uint x
) {
81 return tiles
[y
% map_y
][x
% map_x
];
83 ref Tile
opIndex(Vector2n vec
) {
84 return tiles
[vec
.y
][vec
.x
];
86 ref Tile
opIndex(int y
, int x
) {
87 return this[Vector2n(y
, x
)];
92 ret.tiles
= tiles
.dup
;