MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / SimulateSpeedOfSound

Method SimulateSpeedOfSound

engine/Poseidon/Audio/SoundScene.cpp:368–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366{
367
368void SoundScene::SimulateSpeedOfSound(IWave* sound)
369{
370 float distance = sound->GetPosition().Distance(GScene->GetCamera()->Position());
371 // sound will not start playing between frames
372 // it is therefore more accurate to subtract half of expected frame duration
373 // from wait time. This way we are effectively rounding to nearest frame instead
374 // of rounding to next one
375 float halfFrame = GEngine->GetAvgFrameDuration(4) * (0.001f * 0.5f);
376 float skip = -distance * InvSpeedOfSound + halfFrame;
377 // avoid skipping sound start, only delay is allowed
378 if (skip < 0)
379 {
380 sound->Skip(skip);
381 }
382}
383
384// FindSound lives in OptionsUI.cpp (mission -> campaign -> global config
385// resolution incl. mission-dir prefix and the per-language voice suffix);

Callers 15

SoundMethod · 0.80
ScreamMethod · 0.80
GetOutAnyMethod · 0.80
GetInAnyMethod · 0.80
SoundMethod · 0.80
SimulateMethod · 0.80
FireWeaponMethod · 0.80
SimulateOneIterMethod · 0.80
FireWeaponMethod · 0.80
SoundMethod · 0.80
SimulateMethod · 0.80

Calls 6

GetCameraMethod · 0.80
GetAvgFrameDurationMethod · 0.80
DistanceMethod · 0.45
GetPositionMethod · 0.45
PositionMethod · 0.45
SkipMethod · 0.45

Tested by

no test coverage detected