summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-02-17 20:15:20 +0000
committersmatz <smatz@openttd.org>2008-02-17 20:15:20 +0000
commitf003a257857fa27f24c4db4b9b1a18ca999c529a (patch)
tree7b8dc4f0b4f28364fcf1022c84f534db377bd32c /src
parent3d5462f10350aa9164d2b12e29adb3545efaa1f5 (diff)
downloadopenttd-f003a257857fa27f24c4db4b9b1a18ca999c529a.tar.xz
(svn r12169) -Change [FS#1696]: play sounds when there is only small part of tile/vehicle visible too (original idea by Dominik)
It improves the game appearance when playing with very small screen resolution
Diffstat (limited to 'src')
-rw-r--r--src/sound.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/sound.cpp b/src/sound.cpp
index 40d608e74..ed4651800 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -209,7 +209,7 @@ void SndCopyToPool()
}
}
-static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
+static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom)
{
Window* const *wz;
@@ -219,13 +219,13 @@ static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
const ViewPort *vp = (*wz)->viewport;
if (vp != NULL &&
- IsInsideBS(x, vp->virtual_left, vp->virtual_width) &&
- IsInsideBS(y, vp->virtual_top, vp->virtual_height)) {
- int left = (x - vp->virtual_left);
+ left < vp->virtual_left + vp->virtual_width && right > vp->virtual_left &&
+ top < vp->virtual_top + vp->virtual_height && bottom > vp->virtual_top) {
+ int screen_x = (left + right) / 2 - vp->virtual_left;
StartSound(
sound,
- left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS,
+ screen_x / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS,
(msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256
);
return;
@@ -238,16 +238,18 @@ void SndPlayTileFx(SoundFx sound, TileIndex tile)
{
/* emits sound from center of the tile */
int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
- int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
+ int y = TileY(tile) * TILE_SIZE - TILE_SIZE / 2;
Point pt = RemapCoords(x, y, GetSlopeZ(x, y));
- SndPlayScreenCoordFx(sound, pt.x, pt.y);
+ y += 2 * TILE_SIZE;
+ Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y));
+ SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y);
}
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
{
SndPlayScreenCoordFx(sound,
- (v->left_coord + v->right_coord) / 2,
- (v->top_coord + v->bottom_coord) / 2
+ v->left_coord, v->right_coord,
+ v->top_coord, v->top_coord
);
}