MCPcopy Create free account
hub / github.com/axmolengine/axmol / preload

Method preload

core/audio/AudioEngineImpl.cpp:505–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

503}
504
505AudioCache* AudioEngineImpl::preload(std::string_view filePath, std::function<void(bool)> callback)
506{
507 AudioCache* audioCache = nullptr;
508
509 auto it = _audioCaches.find(filePath);
510 if (it == _audioCaches.end())
511 {
512 audioCache = new AudioCache(); // hlookup_second(it);
513 _audioCaches.emplace(filePath, std::unique_ptr<AudioCache>(audioCache));
514 audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
515 unsigned int cacheId = audioCache->_id;
516 auto isCacheDestroyed = audioCache->_isDestroyed;
517 AudioEngine::addTask([audioCache, cacheId, isCacheDestroyed]() {
518 if (*isCacheDestroyed)
519 {
520 AXLOGV("AudioCache (id={}) was destroyed, no need to launch readDataTask.", cacheId);
521 audioCache->setSkipReadDataTask(true);
522 return;
523 }
524 audioCache->readDataTask(cacheId);
525 });
526 }
527 else
528 {
529 audioCache = it->second.get();
530 }
531
532 if (audioCache && callback)
533 {
534 audioCache->addLoadCallback(callback);
535 }
536 return audioCache;
537}
538
539AUDIO_ID AudioEngineImpl::play2d(std::string_view filePath, bool loop, float volume, float time)
540{

Callers

nothing calls this directly

Calls 8

getInstanceFunction · 0.85
fullPathForFilenameMethod · 0.80
readDataTaskMethod · 0.80
addLoadCallbackMethod · 0.80
findMethod · 0.45
endMethod · 0.45
emplaceMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected