MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / EnsureCooked

Method EnsureCooked

modules/tools/tool_core/src/asset/cook_system.cpp:325–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323 }
324
325skr::task::event_t SCookSystemImpl::EnsureCooked(skr_guid_t guid)
326{
327 SkrZoneScoped;
328 {
329 skr::task::event_t result{ nullptr };
330 cooking.if_contains(guid, [&](const auto& ctx_kv) {
331 result = ctx_kv.second->GetCounter();
332 });
333 if (result)
334 return result;
335 }
336 auto metaAsset = GetAssetRecord(guid);
337 if (!metaAsset)
338 {
339 SKR_LOG_ERROR(u8"[SCookSystemImpl::EnsureCooked] resource not exist! asset path: %s", metaAsset->path.u8string().c_str());
340 return nullptr;
341 }
342 auto resourcePath = metaAsset->project->GetOutputPath() / skr::format(u8"{}.bin", metaAsset->guid).u8_str();
343 auto dependencyPath = metaAsset->project->GetDependencyPath() / skr::format(u8"{}.d", metaAsset->guid).u8_str();
344 auto checkUpToDate = [&]() -> bool {
345 auto cooker = GetCooker(metaAsset);
346 if (!cooker)
347 {
348 SKR_LOG_INFO(u8"[SCookSystemImpl::EnsureCooked] cooker not found! asset path: %s", metaAsset->path.u8string().c_str());
349 return true;
350 }
351 std::error_code ec = {};
352 if (!skr::filesystem::is_regular_file(resourcePath, ec))
353 {
354 SKR_LOG_INFO(u8"[SCookSystemImpl::EnsureCooked] resource not exist! asset path: %s", metaAsset->path.u8string().c_str());
355 return false;
356 }
357 if (!skr::filesystem::is_regular_file(dependencyPath, ec))
358 {
359 SKR_LOG_INFO(u8"[SCookSystemImpl::EnsureCooked] dependency file not exist! asset path: %s}", dependencyPath.string().c_str());
360 return false;
361 }
362 auto timestamp = skr::filesystem::last_write_time(resourcePath, ec);
363 if (skr::filesystem::last_write_time(metaAsset->path, ec) > timestamp)
364 {
365 SKR_LOG_INFO(u8"[SCookSystemImpl::EnsureCooked] meta file modified! resource path: %s", metaAsset->path.u8string().c_str());
366 return false;
367 }
368 simdjson::ondemand::parser parser;
369 auto json = simdjson::padded_string::load(dependencyPath.string());
370 auto doc = parser.iterate(json);
371 if (doc.error() != simdjson::SUCCESS)
372 {
373 SKR_LOG_INFO(u8"[SCookSystemImpl::EnsureCooked] dependency file parse failed! asset path: %s", metaAsset->path.u8string().c_str());
374 return false;
375 }
376 simdjson::ondemand::parser metaParser;
377 auto metaDoc = metaParser.iterate(metaAsset->meta);
378 SKR_CHECK_RESULT(metaDoc, "meta")
379 auto importer = metaDoc["importer"];
380 SKR_CHECK_RESULT(importer, "meta")
381 auto importerType = importer["importerType"];
382 SKR_CHECK_RESULT(importerType, "meta")

Callers 4

compile_projectFunction · 0.80
AddRuntimeDependencyMethod · 0.80
AddStaticDependencyMethod · 0.80

Calls 15

GetImporterRegistryFunction · 0.85
existsClass · 0.85
if_containsMethod · 0.80
GetOutputPathMethod · 0.80
get_uint64Method · 0.80
ReadWithoutDepsMethod · 0.80
get_arrayMethod · 0.80
formatFunction · 0.50
loadFunction · 0.50
ReadFunction · 0.50
moveFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected