8 bool blocks_light
, visible
;
10 RGBColour fgcolour
, bgcolour
;
11 private struct _attr
{ bool reverse
, italic
, bold
, underline
; }
17 fgcolour
= RGBColour(0x4c4c4c);
19 glyph
= Glyph
.dark_square
;
20 fgcolour
= RGBColour(0x663300);
22 bgcolour
= RGBColour(0x000000);
28 private immutable maxx
= map_x
, maxy
= map_y
;
31 private struct Normalint(uint max
) {
34 // No reason you would want to negate it, deref it, or invert it; unary + literally does nothing,
35 uint opUnary(string op
)() if (op
== "++" || op
= "--") {
37 return _i
= normalized(_i
, max
);
39 uint opBinary(string op
)(int other
) {
40 int i
= mixin("_i" ~ op
~ "other");
41 return normalized(i
, max
);
45 // we don't have to normalize i. Because assignment and inc/dec already normalize it
48 @property int i(int newi
) {
49 return _i
= normalized(newi
, max
);
56 this(uint newy
, uint newx
) {
62 @property uint y() { return _y; }
63 @property uint y(int newy) { return _y = normalized(newy, maxy); }
65 @property uint x() { return _x; }
66 @property uint x(int newx) { return _x = normalized(newx, maxx); }
69 pragma(inline
, true) uint normalized(int i
, int max
) {
76 // 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)
79 * i = (i < 0) ? i : oth;
84 private Tile
[][] tiles
;
86 this(Tile
[][] tiles
= null) {
87 this.tiles
= tiles ? tiles
: new Tile
[][](map_x
+ 2, map_y
+ 2);
90 Tile
[][] get_tiles() {
94 // lambda of the form, e.g., (Tile x) => x.visible = false will return bool, not void
95 // so if we take a void function, all is lost. So take a function returning T
96 void for_all(T
)(T
delegate(ref Tile x
) fun
) {
97 foreach (ref row
; tiles
) {
98 foreach (ref tile
; row
) {
104 //ref Tile opIndexAssign(Tile value, ulong y, ulong x) { return tiles[y][x] = value; }
105 ref Tile
opIndex(uint y
, uint x
) {
106 return tiles
[y
% map_y
][x
% map_x
];
108 ref Tile
opIndex(Vector2n vec
) {
109 return tiles
[vec
.y
][vec
.x
];
111 ref Tile
opIndex(int y
, int x
) {
112 return this[Vector2n(y
, x
)];
117 ret.tiles
= tiles
.dup
;