Merge lp:~widelands-dev/widelands/bug-1592692-production_sounds into lp:widelands

Proposed by kaputtnik
Status: Merged
Merged at revision: 8027
Proposed branch: lp:~widelands-dev/widelands/bug-1592692-production_sounds
Merge into: lp:widelands
Diff against target: 61 lines (+19/-12)
1 file modified
src/sound/sound_handler.cc (+19/-12)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1592692-production_sounds
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+299186@code.launchpad.net

Commit message

Corrected function stereo_position() regarding sound sources which are near the edge of map_end/map_start.

Description of the change

Corrected function stereo_position() regarding sound sources which are near the edge of map_end/map_start.

The only functional difference is that stereo_position gets a call to

MapviewPixelFunctions::normalize_pix()

This should recalculate the positions of the sound source to pay attention where a map starts/ends

Other changes are:

* Refactor some variables
* Added small comments

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1171. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/142499476.
Appveyor build 1009. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1592692_production_sounds-1009.

Revision history for this message
SirVer (sirver) wrote :

lgtm.

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sound/sound_handler.cc'
2--- src/sound/sound_handler.cc 2016-04-03 12:35:43 +0000
3+++ src/sound/sound_handler.cc 2016-07-05 15:38:51 +0000
4@@ -314,31 +314,39 @@
5 * \note This function can also be used to check whether a logical coordinate is
6 * visible at all
7 */
8-int32_t SoundHandler::stereo_position(Widelands::Coords const position)
9+int32_t SoundHandler::stereo_position(Widelands::Coords const position_map)
10 {
11- // Screen x, y (without clipping applied, might well be invisible)
12- int32_t sx, sy;
13-
14 if (nosound_)
15 return -1;
16
17 assert(egbase_);
18- assert(position);
19+ assert(position_map);
20
21+ // Viewpoint is the point of the map in pixel which is shown in the upper
22+ // left corner of window or fullscreen
23 const InteractiveBase & ibase = *egbase_->get_ibase();
24 Point const vp = ibase.get_viewpoint();
25
26+ // Resolution of window or fullscreen
27 int32_t const xres = g_gr->get_xres();
28 int32_t const yres = g_gr->get_yres();
29
30- MapviewPixelFunctions::get_pix(egbase_->map(), position, sx, sy);
31- sx -= vp.x;
32- sy -= vp.y;
33+ // Get pixel coordinates of sound source from map coordinates
34+ Point position_pix;
35+ MapviewPixelFunctions::get_pix(egbase_->map(), position_map, position_pix.x, position_pix.y);
36+
37+ // Adjust pixel coordinates to viewpoint
38+ position_pix.x -= vp.x;
39+ position_pix.y -= vp.y;
40+ // Normalizing correct invalid pixel coordinates
41+ MapviewPixelFunctions::normalize_pix(egbase_->map(), position_pix);
42
43 // Make sure position is inside viewport
44-
45- if (sx >= 0 && sx <= xres && sy >= 0 && sy <= yres)
46- return sx * 254 / xres;
47+ if (position_pix.x >= 0 &&
48+ position_pix.x <= xres &&
49+ position_pix.y >= 0 &&
50+ position_pix.y <= yres)
51+ return position_pix.x * 254 / xres;
52
53 return -1;
54 }
55@@ -440,7 +448,6 @@
56 {
57 if (nosound_)
58 return;
59-
60 play_fx(fx_name, stereo_position(map_position), priority);
61 }
62

Subscribers

People subscribed via source and target branches

to status/vote changes: