Skip to content

Commit

Permalink
ChaosMod/EffectSound3D: Replace game paused native call in thread wit…
Browse files Browse the repository at this point in the history
…h ping timeouts
  • Loading branch information
pongo1231 committed Feb 14, 2025
1 parent fd7e031 commit e516c86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ChaosMod/Components/EffectSound/EffectSound3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EffectSound3D::EffectSound3D()
{
Sleep(100);

if (IS_PAUSE_MENU_ACTIVE())
if (GetTickCount64() > m_ThreadPingTimestamp + 100)
{
std::lock_guard lock(m_SoundsMutex);
for (auto &[soundId, sound] : m_Sounds)
Expand Down Expand Up @@ -55,9 +55,11 @@ void EffectSound3D::OnRun()
if (m_Sounds.empty())
return;

auto playerPed = PLAYER_PED_ID();
m_ThreadPingTimestamp = GetTickCount64();

auto adjCamCoords = GET_GAMEPLAY_CAM_COORD();
auto playerPed = PLAYER_PED_ID();

auto adjCamCoords = GET_GAMEPLAY_CAM_COORD();
ma_engine_listener_set_position(&m_maEngine, 0, adjCamCoords.x, adjCamCoords.y, adjCamCoords.z);

float camHeading = GET_GAMEPLAY_CAM_RELATIVE_HEADING();
Expand Down
2 changes: 2 additions & 0 deletions ChaosMod/Components/EffectSound/EffectSound3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <miniaudio.h>
#include <scripthookv/inc/types.h>

#include <cstdint>
#include <map>
#include <mutex>
#include <string>
Expand All @@ -23,6 +24,7 @@ class EffectSound3D : public EffectSoundManager
std::mutex m_SoundsMutex;
bool m_IsStopping = false;
std::thread m_PauseSoundsThread;
uint64_t m_ThreadPingTimestamp;

public:
EffectSound3D();
Expand Down

0 comments on commit e516c86

Please sign in to comment.