Browse Source

Use real `CalculateSoundPosition` with NOSOUND

Fixes big-endian tests, which currently build with `-DNOSOUND`
to reduce build time.
pull/5592/head
Gleb Mazovetskiy 3 years ago
parent
commit
9a1587060d
  1. 1
      Source/CMakeLists.txt
  2. 20
      Source/effects.cpp
  3. 1
      Source/effects.h
  4. 1
      Source/effects_stubs.cpp
  5. 27
      Source/engine/sound_position.cpp
  6. 9
      Source/engine/sound_position.hpp
  7. 1
      Source/monster.cpp
  8. 1
      test/effects_test.cpp

1
Source/CMakeLists.txt

@ -106,6 +106,7 @@ set(libdevilutionx_SRCS
engine/palette.cpp engine/palette.cpp
engine/path.cpp engine/path.cpp
engine/random.cpp engine/random.cpp
engine/sound_position.cpp
engine/surface.cpp engine/surface.cpp
engine/trn.cpp engine/trn.cpp

20
Source/effects.cpp

@ -8,6 +8,7 @@
#include "engine/random.hpp" #include "engine/random.hpp"
#include "engine/sound.h" #include "engine/sound.h"
#include "engine/sound_defs.hpp" #include "engine/sound_defs.hpp"
#include "engine/sound_position.hpp"
#include "init.h" #include "init.h"
#include "player.h" #include "player.h"
#include "utils/stdcompat/algorithm.hpp" #include "utils/stdcompat/algorithm.hpp"
@ -1201,25 +1202,6 @@ void stream_stop()
} }
} }
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan)
{
const auto &playerPosition = MyPlayer->position.tile;
const auto delta = soundPosition - playerPosition;
int pan = (delta.deltaX - delta.deltaY) * 256;
*plPan = clamp(pan, PAN_MIN, PAN_MAX);
int volume = playerPosition.ApproxDistance(soundPosition);
volume *= -64;
if (volume <= ATTENUATION_MIN)
return false;
*plVolume = volume;
return true;
}
void PlaySFX(_sfx_id psfx) void PlaySFX(_sfx_id psfx)
{ {
psfx = RndSFX(psfx); psfx = RndSFX(psfx);

1
Source/effects.h

@ -1177,7 +1177,6 @@ extern _sfx_id sfxdnum;
bool effect_is_playing(int nSFX); bool effect_is_playing(int nSFX);
void stream_stop(); void stream_stop();
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan);
void PlaySFX(_sfx_id psfx); void PlaySFX(_sfx_id psfx);
void PlaySfxLoc(_sfx_id psfx, Point position, bool randomizeByCategory = true); void PlaySfxLoc(_sfx_id psfx, Point position, bool randomizeByCategory = true);
void sound_stop(); void sound_stop();

1
Source/effects_stubs.cpp

@ -12,7 +12,6 @@ _sfx_id sfxdnum;
// clang-format off // clang-format off
bool effect_is_playing(int nSFX) { return false; } bool effect_is_playing(int nSFX) { return false; }
void stream_stop() { } void stream_stop() { }
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan) { return false; }
void PlaySFX(_sfx_id psfx) void PlaySFX(_sfx_id psfx)
{ {
switch (psfx) { switch (psfx) {

27
Source/engine/sound_position.cpp

@ -0,0 +1,27 @@
#include "engine/sound_position.hpp"
#include "engine/sound_defs.hpp"
#include "player.h"
namespace devilution {
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan)
{
const auto &playerPosition = MyPlayer->position.tile;
const auto delta = soundPosition - playerPosition;
int pan = (delta.deltaX - delta.deltaY) * 256;
*plPan = clamp(pan, PAN_MIN, PAN_MAX);
int volume = playerPosition.ApproxDistance(soundPosition);
volume *= -64;
if (volume <= ATTENUATION_MIN)
return false;
*plVolume = volume;
return true;
}
} // namespace devilution

9
Source/engine/sound_position.hpp

@ -0,0 +1,9 @@
#pragma once
#include "engine/point.hpp"
namespace devilution {
bool CalculateSoundPosition(Point soundPosition, int *plVolume, int *plPan);
} // namespace devilution

1
Source/monster.cpp

@ -21,6 +21,7 @@
#include "engine/points_in_rectangle_range.hpp" #include "engine/points_in_rectangle_range.hpp"
#include "engine/random.hpp" #include "engine/random.hpp"
#include "engine/render/clx_render.hpp" #include "engine/render/clx_render.hpp"
#include "engine/sound_position.hpp"
#include "engine/world_tile.hpp" #include "engine/world_tile.hpp"
#include "init.h" #include "init.h"
#include "levels/crypt.h" #include "levels/crypt.h"

1
test/effects_test.cpp

@ -1,6 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "effects.h" #include "effects.h"
#include "engine/sound_position.hpp"
#include "player.h" #include "player.h"
using namespace devilution; using namespace devilution;

Loading…
Cancel
Save