MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / LoadSfxList

Method LoadSfxList

Sources/Jazz2/UI/Cinematics.cpp:195–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193 }
194
195 bool Cinematics::LoadSfxList(StringView path)
196 {
197#if defined(WITH_AUDIO)
198 auto& resolver = ContentResolver::Get();
199 auto s = resolver.OpenContentFile(fs::CombinePath("Cinematics"_s, String(path + ".j2sfx"_s)));
200 if (!s->IsValid()) {
201 return false;
202 }
203
204 if (s->GetSize() <= 16 || s->GetSize() >= 64 * 1024 * 1024) {
205 LOGE("Cannot load SFX playlist for \"{}.j2v\" - unexpected file size", path);
206 return false;
207 }
208
209 std::uint64_t signature = s->ReadValueAsLE<std::uint64_t>();
210 std::uint8_t fileType = s->ReadValue<std::uint8_t>();
211 std::uint16_t version = s->ReadValueAsLE<std::uint16_t>();
212 if (signature != 0x2095A59FF0BFBBEF || fileType != ContentResolver::SfxListFile || version > SfxListVersion) {
213 LOGE("Cannot load SFX playlist for \"{}.j2v\" - invalid signature", path);
214 return false;
215 }
216
217 std::uint32_t sampleCount = s->ReadValueAsLE<std::uint16_t>();
218 for (std::uint32_t i = 0; i < sampleCount; i++) {
219 std::uint8_t stringSize = s->ReadValue<std::uint8_t>();
220 String samplePath = String(NoInit, stringSize);
221 s->Read(samplePath.data(), stringSize);
222
223 String samplePathNormalized = fs::ToNativeSeparators(samplePath);
224 String fullPath = fs::CombinePath("Animations"_s, samplePathNormalized);
225 auto sample = resolver.OpenContentFile(fullPath);
226 if (sample->IsValid()) {
227 _sfxSamples.emplace_back(std::move(sample), fullPath);
228 } else {
229 _sfxSamples.emplace_back(); // Sample not found
230 }
231 }
232
233 std::uint32_t itemCount = s->ReadValueAsLE<std::uint16_t>();
234 for (std::uint32_t i = 0; i < itemCount; i++) {
235 auto& item = _sfxPlaylist.emplace_back();
236 item.Frame = s->ReadVariableUint32();
237 item.Sample = s->ReadValueAsLE<std::uint16_t>();
238 item.Gain = s->ReadValue<std::uint8_t>() / 255.0f;
239 item.Panning = s->ReadValue<std::int8_t>() / 127.0f;
240 }
241
242 return true;
243#else
244 return false;
245#endif
246 }
247
248 void Cinematics::PrepareNextFrame()
249 {

Callers

nothing calls this directly

Calls 8

OpenContentFileMethod · 0.80
emplace_backMethod · 0.80
ReadVariableUint32Method · 0.80
StringClass · 0.50
IsValidMethod · 0.45
GetSizeMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected