diff --git a/src/gameview/entityview.cpp b/src/gameview/entityview.cpp index 8d7a4d5..db4e9c5 100644 --- a/src/gameview/entityview.cpp +++ b/src/gameview/entityview.cpp @@ -99,6 +99,9 @@ bool game::view::EntityView::ProcessPlaySoundMsg(net::InMessage& msg) if (!msg.Read(name) || !msg.Read(volume) || !msg.Read(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); diff --git a/src/gameview/vehicleview.cpp b/src/gameview/vehicleview.cpp index e47b45d..a5a6063 100644 --- a/src/gameview/vehicleview.cpp +++ b/src/gameview/vehicleview.cpp @@ -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; diff --git a/src/gameview/vehicleview.hpp b/src/gameview/vehicleview.hpp index 6f06705..db9168f 100644 --- a/src/gameview/vehicleview.hpp +++ b/src/gameview/vehicleview.hpp @@ -68,6 +68,8 @@ private: void InitHeadlights(); + void UpdateSounds(); + void UpdateWindows(); void UpdateLights(float delta_t); private: diff --git a/src/gameview/worldview.cpp b/src/gameview/worldview.cpp index 45f97e2..a80d0f6 100644 --- a/src/gameview/worldview.cpp +++ b/src/gameview/worldview.cpp @@ -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; diff --git a/src/gameview/worldview.hpp b/src/gameview/worldview.hpp index 4039313..19061ba 100644 --- a/src/gameview/worldview.hpp +++ b/src/gameview/worldview.hpp @@ -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;