sp<ImageSet> PCKLoader::loadStrat(Data &data, UString PckFilename, UString TabFilename) { auto imageSet = mksp<ImageSet>(); auto tabFile = data.fs.open(TabFilename); if (!tabFile) { LogWarning("Failed to open tab \"%s\"", TabFilename); return nullptr; } auto pckFile = data.fs.open(PckFilename); if (!pckFile) { LogWarning("Failed to open tab \"%s\"", TabFilename); return nullptr; } uint32_t offset = 0; unsigned idx = 0; while (tabFile.read(reinterpret_cast<char *>(&offset), sizeof(offset))) { pckFile.seekg(offset, std::ios::beg); if (!pckFile) { LogError("Failed to seek to offset %u", offset); return nullptr; } auto img = loadStrategy(pckFile); if (!img) { LogError("Failed to load image"); return nullptr; } if (img->size != Vec2<unsigned int>{8, 8}) { LogError("Invalid size of {%d,%d} in stratmap image", img->size.x, img->size.y); return nullptr; } imageSet->images.push_back(img); img->owningSet = imageSet; img->calculateBounds(); img->indexInSet = idx++; } imageSet->maxSize = {8, 8}; LogInfo("Loaded %u images", static_cast<unsigned>(imageSet->images.size())); return imageSet; }
Canvas::Canvas(int width, int height) : width(width), height(height) { float w = static_cast<float>(width); float h = static_cast<float>(height); // world coordinates vertices[0].x = 0; vertices[0].y = 0; vertices[1].x = 0; vertices[1].y = h; vertices[2].x = w; vertices[2].y = h; vertices[3].x = w; vertices[3].y = 0; // texture coordinates vertices[0].s = 0; vertices[0].t = 1; vertices[1].s = 0; vertices[1].t = 0; vertices[2].s = 1; vertices[2].t = 0; vertices[3].s = 1; vertices[3].t = 1; loadStrategy(); loadVolatile(); }
bool Canvas::isSupported() { loadStrategy(); return (strategy != &strategyNone); }