FIXME: move to centralized data code
| 11 | |
| 12 | // FIXME: move to centralized data code |
| 13 | void CMultiMap::LoadMap(CGumpMap *gump, CGUIExternalTexture *mapObject) |
| 14 | { |
| 15 | auto &file = g_FileManager.m_MultiMap; |
| 16 | if (file.Size == 0u) |
| 17 | { |
| 18 | Warning(Data, "MultiMap.rle is not loaded!"); |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | file.ResetPtr(); |
| 23 | int Width = file.ReadInt32LE(); |
| 24 | int Height = file.ReadInt32LE(); |
| 25 | if (Width < 1 || Height < 1) |
| 26 | { |
| 27 | Warning(Data, "Failed to load bounds from MultiMap.rle"); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | int mapSize = gump->Width * gump->Height; |
| 32 | std::vector<uint8_t> byteMap(mapSize, 0); |
| 33 | int startX = gump->StartX / 2; |
| 34 | int endX = gump->EndX / 2; |
| 35 | int widthDivizor = endX - startX; |
| 36 | if (widthDivizor == 0) |
| 37 | { |
| 38 | widthDivizor++; |
| 39 | } |
| 40 | |
| 41 | int startY = gump->StartY / 2; |
| 42 | int endY = gump->EndY / 2; |
| 43 | int heightDivizor = endY - startY; |
| 44 | if (heightDivizor == 0) |
| 45 | { |
| 46 | heightDivizor++; |
| 47 | } |
| 48 | |
| 49 | int width = (gump->Width << 8) / widthDivizor; |
| 50 | int height = (gump->Height << 8) / heightDivizor; |
| 51 | int x = 0; |
| 52 | int y = 0; |
| 53 | int maxPixelValue = 1; |
| 54 | while (!file.IsEOF()) |
| 55 | { |
| 56 | uint8_t pic = file.ReadUInt8(); |
| 57 | uint8_t size = pic & 0x7F; |
| 58 | |
| 59 | bool colored = (pic & 0x80) != 0u; |
| 60 | int startHeight = startY * height; |
| 61 | int currentHeight = y * height; |
| 62 | int posY = gump->Width * ((currentHeight - startHeight) >> 8); |
| 63 | for (int i = 0; i < size; i++) |
| 64 | { |
| 65 | if (colored && x >= startX && x < endX && y >= startY && y < endY) |
| 66 | { |
| 67 | int position = posY + ((width * (x - startX)) >> 8); |
| 68 | uint8_t &pixel = byteMap[position]; |
| 69 | if (pixel < 0xFF) |
| 70 | { |
nothing calls this directly
no test coverage detected