MCPcopy Create free account
hub / github.com/defold/defold / NewPreloader

Function NewPreloader

engine/resource/src/resource_preloader.cpp:449–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447 }
448
449 HPreloader NewPreloader(HFactory factory, const dmArray<const char*>& names)
450 {
451 ResourcePreloader* preloader = new ResourcePreloader();
452 // root is always allocated so we don't add index zero in the free list
453 for (uint32_t i = 0; i < MAX_PRELOADER_REQUESTS - 1; i++)
454 {
455 preloader->m_Freelist[i] = MAX_PRELOADER_REQUESTS - i - 1;
456 }
457
458 preloader->m_FreelistSize = MAX_PRELOADER_REQUESTS - 1;
459
460 preloader->m_Factory = factory;
461 preloader->m_LoadQueue = dmLoadQueue::CreateQueue(factory);
462 dmSpinlock::Create(&preloader->m_SyncedDataSpinlock);
463
464 preloader->m_PersistResourceCount = 0;
465 preloader->m_PersistedResources.SetCapacity(names.Size());
466
467 // Insert root.
468 PreloadRequest* root = &preloader->m_Request[0];
469 memset(root, 0x00, sizeof(PreloadRequest));
470
471 root->m_LoadResult = MakePathDescriptor(preloader, names[0], root->m_PathDescriptor);
472 root->m_Parent = -1;
473 root->m_FirstChild = -1;
474 root->m_NextSibling = -1;
475 preloader->m_PersistResourceCount++;
476
477 // Post create setup
478 preloader->m_PostCreateCallbacks.SetCapacity(MAX_PRELOADER_REQUESTS / 8);
479 preloader->m_LoadQueueFull = false;
480 preloader->m_CreateComplete = false;
481 preloader->m_PostCreateCallbackIndex = 0;
482
483 preloader->m_BlockAllocator = dmBlockAllocator::CreateContext();
484
485 if (root->m_LoadResult == RESULT_OK)
486 {
487 root->m_LoadResult = RESULT_PENDING;
488 }
489
490 // Add remaining items as children of root (first item).
491 // This enables optimised loading in so that resources are not loaded multiple times
492 // and are released when they can be (internally pruning and sharing the request tree).
493 for (uint32_t i = 1; i < names.Size(); ++i)
494 {
495 Result res = PreloadHintInternal(preloader, 0, names[i]);
496 if (res == RESULT_OK)
497 {
498 preloader->m_PersistResourceCount++;
499 }
500 }
501
502 return preloader;
503 }
504
505 HPreloader NewPreloader(HFactory factory, const char* name)
506 {

Callers 7

PreloaderGetMethod · 0.85
PreloaderGetMethod · 0.85
TEST_PFunction · 0.85
CompFactoryLoadFunction · 0.85
TEST_PFunction · 0.85

Calls 7

MakePathDescriptorFunction · 0.85
PreloadHintInternalFunction · 0.85
CreateFunction · 0.70
CreateContextFunction · 0.70
CreateQueueFunction · 0.50
SetCapacityMethod · 0.45
SizeMethod · 0.45

Tested by 4

PreloaderGetMethod · 0.68
PreloaderGetMethod · 0.68
TEST_PFunction · 0.68
TEST_PFunction · 0.68