Dont play sounds when map not yet loaded
This commit is contained in:
parent
0ac395b1fb
commit
9c0a062e80
@ -99,6 +99,9 @@ bool game::view::EntityView::ProcessPlaySoundMsg(net::InMessage& msg)
|
|||||||
if (!msg.Read(name) || !msg.Read<net::SoundVolumeQ>(volume) || !msg.Read<net::SoundPitchQ>(pitch))
|
if (!msg.Read(name) || !msg.Read<net::SoundVolumeQ>(volume) || !msg.Read<net::SoundPitchQ>(pitch))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!world_.IsLoaded())
|
||||||
|
return true; // dont play if not loaded yet
|
||||||
|
|
||||||
auto sound = assets::CacheManager::GetSound("data/" + std::string(name) + ".snd");
|
auto sound = assets::CacheManager::GetSound("data/" + std::string(name) + ".snd");
|
||||||
auto snd = audioplayer_.PlaySound(sound, &root_.local.position);
|
auto snd = audioplayer_.PlaySound(sound, &root_.local.position);
|
||||||
snd->SetVolume(volume);
|
snd->SetVolume(volume);
|
||||||
|
|||||||
@ -93,33 +93,8 @@ void game::view::VehicleView::Update(const UpdateInfo& info)
|
|||||||
wheels_[i].node.UpdateMatrix();
|
wheels_[i].node.UpdateMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update snds
|
UpdateSounds();
|
||||||
bool accel = flags_ & VF_ACCELERATING;
|
UpdateWindows();
|
||||||
|
|
||||||
if (accel && !snd_accel_src_)
|
|
||||||
{
|
|
||||||
snd_accel_src_ = audioplayer_.PlaySound(snd_accel_, &root_.local.position);
|
|
||||||
snd_accel_src_->SetLooping(true);
|
|
||||||
}
|
|
||||||
else if (!accel && snd_accel_src_)
|
|
||||||
{
|
|
||||||
snd_accel_src_->Delete();
|
|
||||||
snd_accel_src_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update windows
|
|
||||||
if ((flags_ & VF_BROKENWINDOWS) && !windows_broken_)
|
|
||||||
{
|
|
||||||
windows_broken_ = true;
|
|
||||||
|
|
||||||
auto it = mesh_.surface_names.find("carwindows");
|
|
||||||
if (it != mesh_.surface_names.end())
|
|
||||||
{
|
|
||||||
size_t idx = it->second;
|
|
||||||
mesh_.surfaces[idx].texture = assets::CacheManager::GetTexture("data/carbrokenwindows.png");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateLights(info.delta_time);
|
UpdateLights(info.delta_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,6 +378,40 @@ void game::view::VehicleView::InitHeadlights()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game::view::VehicleView::UpdateSounds()
|
||||||
|
{
|
||||||
|
if (!world_.IsLoaded())
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool accel = flags_ & VF_ACCELERATING;
|
||||||
|
|
||||||
|
if (accel && !snd_accel_src_)
|
||||||
|
{
|
||||||
|
snd_accel_src_ = audioplayer_.PlaySound(snd_accel_, &root_.local.position);
|
||||||
|
snd_accel_src_->SetLooping(true);
|
||||||
|
}
|
||||||
|
else if (!accel && snd_accel_src_)
|
||||||
|
{
|
||||||
|
snd_accel_src_->Delete();
|
||||||
|
snd_accel_src_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void game::view::VehicleView::UpdateWindows()
|
||||||
|
{
|
||||||
|
if ((flags_ & VF_BROKENWINDOWS) && !windows_broken_)
|
||||||
|
{
|
||||||
|
windows_broken_ = true;
|
||||||
|
|
||||||
|
auto it = mesh_.surface_names.find("carwindows");
|
||||||
|
if (it != mesh_.surface_names.end())
|
||||||
|
{
|
||||||
|
size_t idx = it->second;
|
||||||
|
mesh_.surfaces[idx].texture = assets::CacheManager::GetTexture("data/carbrokenwindows.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void game::view::VehicleView::UpdateLights(float delta_t)
|
void game::view::VehicleView::UpdateLights(float delta_t)
|
||||||
{
|
{
|
||||||
float max_delta = delta_t * 10.0f;
|
float max_delta = delta_t * 10.0f;
|
||||||
|
|||||||
@ -68,6 +68,8 @@ private:
|
|||||||
|
|
||||||
void InitHeadlights();
|
void InitHeadlights();
|
||||||
|
|
||||||
|
void UpdateSounds();
|
||||||
|
void UpdateWindows();
|
||||||
void UpdateLights(float delta_t);
|
void UpdateLights(float delta_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -124,6 +124,11 @@ game::view::EntityView* game::view::WorldView::GetEntity(net::EntNum entnum)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool game::view::WorldView::IsLoaded() const
|
||||||
|
{
|
||||||
|
return map_ && map_->IsLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
void game::view::WorldView::DrawLoadingScreen(const DrawArgs& args) const
|
void game::view::WorldView::DrawLoadingScreen(const DrawArgs& args) const
|
||||||
{
|
{
|
||||||
float margin = 50.0f;
|
float margin = 50.0f;
|
||||||
|
|||||||
@ -40,6 +40,8 @@ public:
|
|||||||
float GetTime() const { return time_; }
|
float GetTime() const { return time_; }
|
||||||
audio::Master& GetAudioMaster() const { return audiomaster_; }
|
audio::Master& GetAudioMaster() const { return audiomaster_; }
|
||||||
|
|
||||||
|
bool IsLoaded() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawLoadingScreen(const DrawArgs& args) const;
|
void DrawLoadingScreen(const DrawArgs& args) const;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user