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

Method Load

src/openrct2/object/MusicObject.cpp:35–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 constexpr size_t kDefaultBytesPerTick = 1378;
34
35 void MusicObject::Load()
36 {
37 GetStringTable().Sort();
38 NameStringId = LanguageAllocateObjectString(GetName());
39
40 // Start with base images
41 _loadedSampleTable.LoadFrom(_sampleTable, 0, _sampleTable.GetCount());
42
43 // Override samples from asset packs
44 auto context = GetContext();
45 auto assetManager = context->GetAssetPackManager();
46 if (assetManager != nullptr)
47 {
48 assetManager->LoadSamplesForObject(GetIdentifier(), _loadedSampleTable);
49 }
50
51 // Load metadata of samples
52 auto& audioContext = GetContext()->GetAudioContext();
53 for (auto& track : _tracks)
54 {
55 auto stream = track.Asset.GetStream();
56 if (stream != nullptr)
57 {
58 auto source = audioContext.CreateStreamFromWAV(std::move(stream));
59 if (source != nullptr)
60 {
61 track.BytesPerTick = source->GetBytesPerSecond() / 40;
62 track.Size = source->GetLength();
63 source->Release();
64 }
65 else
66 {
67 track.BytesPerTick = kDefaultBytesPerTick;
68 track.Size = track.Asset.GetSize();
69 }
70 }
71 else
72 {
73 track.BytesPerTick = kDefaultBytesPerTick;
74 track.Size = track.Asset.GetSize();
75 }
76 }
77
78 _hasPreview = !!GetImageTable().GetCount();
79 _previewImageId = LoadImages();
80 }
81
82 void MusicObject::Unload()
83 {

Callers

nothing calls this directly

Calls 14

GetContextFunction · 0.85
LoadFromMethod · 0.80
GetAssetPackManagerMethod · 0.80
GetStreamMethod · 0.80
ReleaseMethod · 0.80
GetNameFunction · 0.50
SortMethod · 0.45
GetCountMethod · 0.45
LoadSamplesForObjectMethod · 0.45
CreateStreamFromWAVMethod · 0.45
GetBytesPerSecondMethod · 0.45

Tested by

no test coverage detected