| 114 | } |
| 115 | |
| 116 | u16 XYMap::mapToIndex(const u16 &x, const u16 &y) const { |
| 117 | u16 index; |
| 118 | switch (type) { |
| 119 | case kSerpentine: { |
| 120 | u16 xx = x % width; |
| 121 | u16 yy = y % height; |
| 122 | index = xy_serpentine(xx, yy, width, height); |
| 123 | break; |
| 124 | } |
| 125 | case kLineByLine: { |
| 126 | u16 xx = x % width; |
| 127 | u16 yy = y % height; |
| 128 | index = xy_line_by_line(xx, yy, width, height); |
| 129 | break; |
| 130 | } |
| 131 | case kFunction: |
| 132 | if (xyFunction) { |
| 133 | index = xyFunction(x, y, width, height); |
| 134 | } else { |
| 135 | // Null function pointer — fall back to line-by-line to avoid crash. |
| 136 | // This can happen due to cross-DLL static initialization order issues. |
| 137 | index = xy_line_by_line(x, y, width, height); |
| 138 | } |
| 139 | break; |
| 140 | case kLookUpTable: |
| 141 | index = mLookUpTable->getData()[y * width + x]; |
| 142 | break; |
| 143 | default: |
| 144 | return 0; |
| 145 | } |
| 146 | return index + mOffset; |
| 147 | } |
| 148 | |
| 149 | u16 XYMap::getWidth() const { return width; } |
| 150 | |