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))
|
||||
return false;
|
||||
|
||||
if (!world_.IsLoaded())
|
||||
return true; // dont play if not loaded yet
|
||||
|
||||
auto sound = assets::CacheManager::GetSound("data/" + std::string(name) + ".snd");
|
||||
auto snd = audioplayer_.PlaySound(sound, &root_.local.position);
|
||||
snd->SetVolume(volume);
|
||||
|
||||
@ -93,33 +93,8 @@ void game::view::VehicleView::Update(const UpdateInfo& info)
|
||||
wheels_[i].node.UpdateMatrix();
|
||||
}
|
||||
|
||||
// update snds
|
||||
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;
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
|
||||
UpdateSounds();
|
||||
UpdateWindows();
|
||||
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)
|
||||
{
|
||||
float max_delta = delta_t * 10.0f;
|
||||
|
||||
@ -68,6 +68,8 @@ private:
|
||||
|
||||
void InitHeadlights();
|
||||
|
||||
void UpdateSounds();
|
||||
void UpdateWindows();
|
||||
void UpdateLights(float delta_t);
|
||||
|
||||
private:
|
||||
|
||||
@ -124,6 +124,11 @@ game::view::EntityView* game::view::WorldView::GetEntity(net::EntNum entnum)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool game::view::WorldView::IsLoaded() const
|
||||
{
|
||||
return map_ && map_->IsLoaded();
|
||||
}
|
||||
|
||||
void game::view::WorldView::DrawLoadingScreen(const DrawArgs& args) const
|
||||
{
|
||||
float margin = 50.0f;
|
||||
|
||||
@ -40,6 +40,8 @@ public:
|
||||
float GetTime() const { return time_; }
|
||||
audio::Master& GetAudioMaster() const { return audiomaster_; }
|
||||
|
||||
bool IsLoaded() const;
|
||||
|
||||
private:
|
||||
void DrawLoadingScreen(const DrawArgs& args) const;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user