MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / loadStrategy

Function loadStrategy

framework/apocresources/pck.cpp:295–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293static_assert(sizeof(struct StratHeader) == 4, "Invalid strat_header size");
294
295static sp<PaletteImage> loadStrategy(IFile &file)
296{
297 auto img = mksp<PaletteImage>(Vec2<int>{8, 8}); // All strategy map tiles are 8x8
298 unsigned int offset = 0;
299
300 struct StratHeader header;
301 file.read(reinterpret_cast<char *>(&header), sizeof(header));
302 PaletteImageLock region(img);
303 while (file && header.pixel_skip != 0xffff)
304 {
305 unsigned int count = header.count;
306 offset = header.pixel_skip;
307 while (file && count--)
308 {
309 uint8_t idx = 0;
310#define STRIDE 640
311 unsigned int x = offset % STRIDE;
312 unsigned int y = offset / STRIDE;
313#undef STRIDE
314
315 file.read(reinterpret_cast<char *>(&idx), 1);
316
317 if (x >= 8 || y >= 8)
318 {
319 LogInfo("Writing to {%d,%d} in 8x8 stratmap image", x, y);
320 }
321 else
322 {
323 region.set(Vec2<int>{x, y}, idx);
324 }
325
326 offset++;
327 }
328 file.read(reinterpret_cast<char *>(&header), sizeof(header));
329 }
330 return img;
331}
332
333sp<ImageSet> PCKLoader::loadStrat(Data &data, UString PckFilename, UString TabFilename)
334{

Callers 1

loadStratMethod · 0.85

Calls 2

readMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected