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

Method loadStrat

framework/apocresources/pck.cpp:333–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333sp<ImageSet> PCKLoader::loadStrat(Data &data, UString PckFilename, UString TabFilename)
334{
335 auto imageSet = mksp<ImageSet>();
336 auto tabFile = data.fs.open(TabFilename);
337 if (!tabFile)
338 {
339 LogWarning("Failed to open tab \"%s\"", TabFilename);
340 return nullptr;
341 }
342 auto pckFile = data.fs.open(PckFilename);
343 if (!pckFile)
344 {
345 LogWarning("Failed to open tab \"%s\"", TabFilename);
346 return nullptr;
347 }
348
349 uint32_t offset = 0;
350 unsigned idx = 0;
351 while (tabFile.read(reinterpret_cast<char *>(&offset), sizeof(offset)))
352 {
353 pckFile.seekg(offset, std::ios::beg);
354 if (!pckFile)
355 {
356 LogError("Failed to seek to offset %u", offset);
357 return nullptr;
358 }
359 auto img = loadStrategy(pckFile);
360 if (!img)
361 {
362 LogError("Failed to load image");
363 return nullptr;
364 }
365 if (img->size != Vec2<unsigned int>{8, 8})
366 {
367 LogError("Invalid size of {%d,%d} in stratmap image", img->size.x, img->size.y);
368 return nullptr;
369 }
370 imageSet->images.push_back(img);
371 img->owningSet = imageSet;
372 img->calculateBounds();
373 img->indexInSet = idx++;
374 }
375
376 imageSet->maxSize = {8, 8};
377
378 LogInfo("Loaded %u images", static_cast<unsigned>(imageSet->images.size()));
379
380 return imageSet;
381}
382
383struct ShadowHeader
384{

Callers

nothing calls this directly

Calls 5

loadStrategyFunction · 0.85
openMethod · 0.80
readMethod · 0.80
calculateBoundsMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected