MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / LoadObjectImages

Method LoadObjectImages

src/openrct2/object/ImageTable.cpp:288–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286 }
287
288 std::vector<std::unique_ptr<ImageTable::RequiredImage>> ImageTable::LoadObjectImages(
289 IReadObjectContext* context, const std::string& name, const std::vector<int32_t>& range)
290 {
291 std::vector<std::unique_ptr<RequiredImage>> result;
292 Object* obj;
293
294 auto cached = _objDataCache.find(name);
295 if (cached != _objDataCache.end())
296 {
297 obj = cached->second.get();
298 }
299 else
300 {
301 auto objectPath = FindLegacyObject(name);
302 auto tmp = ObjectFactory::CreateObjectFromLegacyFile(objectPath.c_str(), context->ShouldLoadImages());
303 auto inserted = _objDataCache.insert({ name, std::move(tmp) });
304 obj = inserted.first->second.get();
305 }
306
307 if (obj != nullptr)
308 {
309 auto& imgTable = static_cast<const Object*>(obj)->GetImageTable();
310 auto numImages = static_cast<int32_t>(imgTable.GetCount());
311 auto images = imgTable.GetImages();
312 size_t placeHoldersAdded = 0;
313 for (auto i : range)
314 {
315 if (i >= 0 && i < numImages)
316 {
317 result.push_back(
318 std::make_unique<RequiredImage>(
319 static_cast<uint32_t>(i), [images](uint32_t idx) -> const G1Element* { return &images[idx]; }));
320 }
321 else
322 {
323 result.push_back(std::make_unique<RequiredImage>());
324 placeHoldersAdded++;
325 }
326 }
327
328 // Log place holder information
329 if (placeHoldersAdded > 0)
330 {
331 std::string msg = "Adding " + std::to_string(placeHoldersAdded) + " placeholders";
332 context->LogWarning(ObjectError::invalidProperty, msg.c_str());
333 }
334 }
335 else
336 {
337 std::string msg = "Unable to open '" + name + "'";
338 context->LogWarning(ObjectError::invalidProperty, msg.c_str());
339 for (size_t i = 0; i < range.size(); i++)
340 {
341 result.push_back(std::make_unique<RequiredImage>());
342 }
343 }
344 return result;
345 }

Callers

nothing calls this directly

Calls 10

findMethod · 0.80
GetImagesMethod · 0.80
endMethod · 0.65
getMethod · 0.65
ShouldLoadImagesMethod · 0.45
GetCountMethod · 0.45
push_backMethod · 0.45
LogWarningMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected