Merge lp:~widelands-dev/widelands/simplify_coords into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 8446
Proposed branch: lp:~widelands-dev/widelands/simplify_coords
Merge into: lp:widelands
Diff against target: 633 lines (+96/-115)
14 files modified
src/editor/editorinteractive.cc (+2/-2)
src/editor/tools/info_tool.cc (+1/-1)
src/editor/tools/set_terrain_tool.cc (+5/-5)
src/graphic/minimap_renderer.cc (+3/-3)
src/logic/map.cc (+17/-16)
src/logic/map.h (+1/-1)
src/logic/maptriangleregion.cc (+22/-23)
src/logic/maptriangleregion.h (+7/-11)
src/logic/widelands_geometry.h (+11/-32)
src/scripting/lua_ui.cc (+4/-2)
src/wui/interactive_base.cc (+1/-1)
src/wui/interactive_base.h (+4/-3)
src/wui/interactive_player.cc (+2/-2)
src/wui/mapviewpixelfunctions.cc (+16/-13)
To merge this branch: bzr merge lp:~widelands-dev/widelands/simplify_coords
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+330119@code.launchpad.net

Commit message

Simplify widelands_geometry.h.

- Document TCoords and remove inheritance.
- Simplify FCoords
- Remove TriangleIndex::None

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

Continuous integration builds have changed state:

Travis build 2640. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/271248957.
Appveyor build 2462. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_simplify_coords-2462.

Revision history for this message
GunChleoc (gunchleoc) 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/editor/editorinteractive.cc'
2--- src/editor/editorinteractive.cc 2017-09-01 18:59:42 +0000
3+++ src/editor/editorinteractive.cc 2017-09-02 19:51:44 +0000
4@@ -617,9 +617,9 @@
5
6 // Make sure that we will start at coordinates (0,0).
7 map_view()->set_view(MapView::View{Vector2f::zero(), 1.f}, MapView::Transition::Jump);
8- set_sel_pos(Widelands::NodeAndTriangle<>(
9+ set_sel_pos(Widelands::NodeAndTriangle<>{
10 Widelands::Coords(0, 0),
11- Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)));
12+ Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)});
13 break;
14
15 case MapWas::kGloballyMutated:
16
17=== modified file 'src/editor/tools/info_tool.cc'
18--- src/editor/tools/info_tool.cc 2017-08-30 13:35:37 +0000
19+++ src/editor/tools/info_tool.cc 2017-09-02 19:51:44 +0000
20@@ -113,7 +113,7 @@
21 // *** Terrain info
22 buf += std::string("\n") + _("Terrain:") + "\n";
23
24- const Widelands::Field& tf = (*map)[center.triangle];
25+ const Widelands::Field& tf = (*map)[center.triangle.node];
26 const Widelands::TerrainDescription& ter = world.terrain_descr(
27 center.triangle.t == Widelands::TriangleIndex::D ? tf.terrain_d() : tf.terrain_r());
28
29
30=== modified file 'src/editor/tools/set_terrain_tool.cc'
31--- src/editor/tools/set_terrain_tool.cc 2017-08-31 15:22:21 +0000
32+++ src/editor/tools/set_terrain_tool.cc 2017-09-02 19:51:44 +0000
33@@ -38,12 +38,12 @@
34 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords>> mr(
35 *map, Widelands::Area<TCoords<Widelands::FCoords>>(
36 TCoords<Widelands::FCoords>(
37- Widelands::FCoords(map->get_fcoords(center.triangle)), center.triangle.t),
38+ Widelands::FCoords(map->get_fcoords(center.triangle.node)), center.triangle.t),
39 radius));
40 do {
41 args->original_terrain_type.push_back((mr.location().t == Widelands::TriangleIndex::D) ?
42- mr.location().field->terrain_d() :
43- mr.location().field->terrain_r());
44+ mr.location().node.field->terrain_d() :
45+ mr.location().node.field->terrain_r());
46 args->terrain_type.push_back(get_random_enabled());
47 } while (mr.advance(*map));
48 }
49@@ -52,7 +52,7 @@
50 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords>> mr(
51 *map, Widelands::Area<TCoords<Widelands::FCoords>>(
52 TCoords<Widelands::FCoords>(
53- Widelands::FCoords(map->get_fcoords(center.triangle)), center.triangle.t),
54+ Widelands::FCoords(map->get_fcoords(center.triangle.node)), center.triangle.t),
55 radius));
56 std::list<Widelands::DescriptionIndex>::iterator i = args->terrain_type.begin();
57 do {
58@@ -77,7 +77,7 @@
59 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords>> mr(
60 *map, Widelands::Area<TCoords<Widelands::FCoords>>(
61 TCoords<Widelands::FCoords>(
62- Widelands::FCoords(map->get_fcoords(center.triangle)), center.triangle.t),
63+ Widelands::FCoords(map->get_fcoords(center.triangle.node)), center.triangle.t),
64 radius));
65
66 std::list<Widelands::DescriptionIndex>::iterator i = args->original_terrain_type.begin();
67
68=== modified file 'src/graphic/minimap_renderer.cc'
69--- src/graphic/minimap_renderer.cc 2017-08-19 22:22:20 +0000
70+++ src/graphic/minimap_renderer.cc 2017-09-02 19:51:44 +0000
71@@ -161,10 +161,10 @@
72 const int32_t mapwidth = map.get_width();
73
74 for (uint32_t y = 0; y < surface_h; ++y) {
75- Widelands::FCoords f(
76+ Widelands::Coords coords(
77 Widelands::Coords(top_left.x, top_left.y + ((layers & MiniMapLayer::Zoom2) ? y / 2 : y)));
78- map.normalize_coords(f);
79- f.field = &map[f];
80+ map.normalize_coords(coords);
81+ Widelands::FCoords f = map.get_fcoords(coords);
82 Widelands::MapIndex i = Widelands::Map::get_index(f, mapwidth);
83 for (uint32_t x = 0; x < surface_w; ++x) {
84 if (x % 2 || !(layers & MiniMapLayer::Zoom2)) {
85
86=== modified file 'src/logic/map.cc'
87--- src/logic/map.cc 2017-08-31 15:22:21 +0000
88+++ src/logic/map.cc 2017-09-02 19:51:44 +0000
89@@ -345,7 +345,7 @@
90 // NOTE because of the triangle design, we have to take special care about cases
91 // NOTE where y is changed by an odd number
92 bool yisodd = (new_origin.y % 2) != 0;
93- for (FCoords c(Coords(0, 0)); c.y < height_; ++c.y) {
94+ for (Coords c(Coords(0, 0)); c.y < height_; ++c.y) {
95 bool cyisodd = (c.y % 2) != 0;
96 for (c.x = 0; c.x < width_; ++c.x) {
97 Coords temp;
98@@ -1737,63 +1737,64 @@
99
100 int32_t
101 Map::change_terrain(const World& world, TCoords<FCoords> const c, DescriptionIndex const terrain) {
102- c.field->set_terrain(c.t, terrain);
103+ c.node.field->set_terrain(c.t, terrain);
104
105 // remove invalid resources if necessary
106 // check vertex to which the triangle belongs
107- if (!is_resource_valid(world, c, c.field->get_resources())) {
108- clear_resources(c);
109+ if (!is_resource_valid(world, c.node, c.node.field->get_resources())) {
110+ clear_resources(c.node);
111 }
112
113 // always check south-east vertex
114- Widelands::FCoords f_se(c, c.field);
115+ Widelands::FCoords f_se(c.node);
116 get_neighbour(f_se, Widelands::WALK_SE, &f_se);
117 if (!is_resource_valid(world, f_se, f_se.field->get_resources())) {
118 clear_resources(f_se);
119 }
120
121 // check south-west vertex if d-Triangle is changed, check east vertex if r-Triangle is changed
122- Widelands::FCoords f_sw_e(c, c.field);
123- get_neighbour(f_sw_e, c.t == TriangleIndex::D ? Widelands::WALK_SW : Widelands::WALK_E, &f_sw_e);
124+ Widelands::FCoords f_sw_e(c.node);
125+ get_neighbour(
126+ f_sw_e, c.t == TriangleIndex::D ? Widelands::WALK_SW : Widelands::WALK_E, &f_sw_e);
127 if (!is_resource_valid(world, f_sw_e, f_sw_e.field->get_resources())) {
128 clear_resources(f_sw_e);
129 }
130
131- Notifications::publish(NoteFieldTerrainChanged{c, static_cast<MapIndex>(c.field - &fields_[0])});
132+ Notifications::publish(
133+ NoteFieldTerrainChanged{c.node, static_cast<MapIndex>(c.node.field - &fields_[0])});
134
135 // Changing the terrain can affect ports, which can be up to 3 fields away.
136 constexpr int kPotentiallyAffectedNeighbors = 3;
137- recalc_for_field_area(world, Area<FCoords>(c, kPotentiallyAffectedNeighbors));
138+ recalc_for_field_area(world, Area<FCoords>(c.node, kPotentiallyAffectedNeighbors));
139 return kPotentiallyAffectedNeighbors;
140 }
141
142 bool Map::is_resource_valid(const Widelands::World& world,
143- const TCoords<Widelands::FCoords>& c,
144+ const Widelands::FCoords& c,
145 DescriptionIndex curres) {
146 if (curres == Widelands::kNoResource)
147 return true;
148
149- Widelands::FCoords f(c, c.field);
150 Widelands::FCoords f1;
151
152 int32_t count = 0;
153
154 // this field
155- count += world.terrain_descr(f.field->terrain_r()).is_resource_valid(curres);
156- count += world.terrain_descr(f.field->terrain_d()).is_resource_valid(curres);
157+ count += world.terrain_descr(c.field->terrain_r()).is_resource_valid(curres);
158+ count += world.terrain_descr(c.field->terrain_d()).is_resource_valid(curres);
159
160 // If one of the neighbours is impassable, count its resource stronger.
161 // top left neigbour
162- get_neighbour(f, Widelands::WALK_NW, &f1);
163+ get_neighbour(c, Widelands::WALK_NW, &f1);
164 count += world.terrain_descr(f1.field->terrain_r()).is_resource_valid(curres);
165 count += world.terrain_descr(f1.field->terrain_d()).is_resource_valid(curres);
166
167 // top right neigbour
168- get_neighbour(f, Widelands::WALK_NE, &f1);
169+ get_neighbour(c, Widelands::WALK_NE, &f1);
170 count += world.terrain_descr(f1.field->terrain_d()).is_resource_valid(curres);
171
172 // left neighbour
173- get_neighbour(f, Widelands::WALK_W, &f1);
174+ get_neighbour(c, Widelands::WALK_W, &f1);
175 count += world.terrain_descr(f1.field->terrain_r()).is_resource_valid(curres);
176
177 return count > 1;
178
179=== modified file 'src/logic/map.h'
180--- src/logic/map.h 2017-08-28 13:37:51 +0000
181+++ src/logic/map.h 2017-09-02 19:51:44 +0000
182@@ -427,7 +427,7 @@
183 * To qualify as valid, resources need to be surrounded by at least two matching terrains.
184 */
185 bool is_resource_valid(const Widelands::World& world,
186- const Widelands::TCoords<Widelands::FCoords>& c,
187+ const Widelands::FCoords& c,
188 DescriptionIndex curres);
189
190 // The objectives that are defined in this map if it is a scenario.
191
192=== modified file 'src/logic/maptriangleregion.cc'
193--- src/logic/maptriangleregion.cc 2017-08-30 13:35:37 +0000
194+++ src/logic/maptriangleregion.cc 2017-09-02 19:51:44 +0000
195@@ -23,20 +23,19 @@
196
197 template <>
198 MapTriangleRegion<>::MapTriangleRegion(const Map& map, Area<TCoords<>> area)
199- : radius_is_odd_(area.radius & 1) {
200- assert(area.t == TriangleIndex::R || area.t == TriangleIndex::D);
201+ : radius_is_odd_(area.radius & 1), location_(area) {
202 const uint16_t radius_plus_1 = area.radius + 1;
203 const uint16_t half_radius_rounded_down = area.radius / 2;
204 row_length_ = radius_plus_1;
205 for (uint32_t i = half_radius_rounded_down; i; --i)
206- map.get_tln(area, &area);
207+ map.get_tln(area.node, &area.node);
208 if (area.t == TriangleIndex::R) {
209- left_ = area;
210+ left_ = area.node;
211 if (area.radius) {
212 remaining_rows_in_upper_phase_ = half_radius_rounded_down + 1;
213 remaining_rows_in_lower_phase_ = (area.radius - 1) / 2;
214 if (radius_is_odd_) {
215- map.get_trn(area, &area);
216+ map.get_trn(area.node, &area.node);
217 phase_ = Top;
218 row_length_ = area.radius + 2;
219 remaining_in_row_ = radius_plus_1 / 2;
220@@ -56,13 +55,13 @@
221 remaining_rows_in_upper_phase_ = radius_plus_1 / 2;
222 remaining_rows_in_lower_phase_ = half_radius_rounded_down;
223 if (radius_is_odd_) {
224- map.get_ln(area, &area);
225- left_ = area;
226+ map.get_ln(area.node, &area.node);
227+ left_ = area.node;
228 phase_ = Upper;
229 remaining_in_row_ = row_length_ = area.radius + 2;
230 area.t = TriangleIndex::R;
231 } else {
232- map.get_bln(area, &left_);
233+ map.get_bln(area.node, &left_);
234 phase_ = Top;
235 row_length_ = area.radius + 3;
236 remaining_in_row_ = half_radius_rounded_down + (0 < area.radius);
237@@ -80,7 +79,7 @@
238 switch (phase_) {
239 case Top:
240 if (remaining_in_row_)
241- map.get_rn(location_, &location_);
242+ map.get_rn(location_.node, &location_.node);
243 else if (remaining_rows_in_upper_phase_) {
244 phase_ = Upper;
245 remaining_in_row_ = row_length_;
246@@ -93,7 +92,7 @@
247 if (location_.t == TriangleIndex::D)
248 location_.t = TriangleIndex::R;
249 else
250- location_ = TCoords<>(map.r_n(location_), TriangleIndex::D);
251+ location_ = TCoords<>(map.r_n(location_.node), TriangleIndex::D);
252 } else {
253 if (--remaining_rows_in_upper_phase_) {
254 row_length_ += 2;
255@@ -119,7 +118,7 @@
256 if (location_.t == TriangleIndex::D)
257 location_.t = TriangleIndex::R;
258 else
259- location_ = TCoords<>(map.r_n(location_), TriangleIndex::D);
260+ location_ = TCoords<>(map.r_n(location_.node), TriangleIndex::D);
261 } else {
262 if (--remaining_rows_in_lower_phase_) {
263 assert(row_length_ >= 2);
264@@ -135,7 +134,7 @@
265 break;
266 case Bottom:
267 if (remaining_in_row_)
268- map.get_rn(location_, &location_);
269+ map.get_rn(location_.node, &location_.node);
270 break;
271 }
272 assert(remaining_in_row_ < 10000); // Catch wrapping (integer underflow)
273@@ -144,20 +143,20 @@
274
275 template <>
276 MapTriangleRegion<TCoords<FCoords>>::MapTriangleRegion(const Map& map, Area<TCoords<FCoords>> area)
277- : radius_is_odd_(area.radius & 1) {
278+ : radius_is_odd_(area.radius & 1), location_(area) {
279 assert(area.t == TriangleIndex::R || area.t == TriangleIndex::D);
280 const uint16_t radius_plus_1 = area.radius + 1;
281 const uint16_t half_radius_rounded_down = area.radius / 2;
282 row_length_ = radius_plus_1;
283 for (uint32_t i = half_radius_rounded_down; i; --i)
284- map.get_tln(area, &area);
285+ map.get_tln(area.node, &area.node);
286 if (area.t == TriangleIndex::R) {
287- left_ = area;
288+ left_ = area.node;
289 if (area.radius) {
290 remaining_rows_in_upper_phase_ = half_radius_rounded_down + 1;
291 remaining_rows_in_lower_phase_ = (area.radius - 1) / 2;
292 if (radius_is_odd_) {
293- map.get_trn(area, &area);
294+ map.get_trn(area.node, &area.node);
295 phase_ = Top;
296 row_length_ = area.radius + 2;
297 remaining_in_row_ = radius_plus_1 / 2;
298@@ -176,13 +175,13 @@
299 remaining_rows_in_upper_phase_ = radius_plus_1 / 2;
300 remaining_rows_in_lower_phase_ = half_radius_rounded_down;
301 if (radius_is_odd_) {
302- map.get_ln(area, &area);
303- left_ = area;
304+ map.get_ln(area.node, &area.node);
305+ left_ = area.node;
306 phase_ = Upper;
307 remaining_in_row_ = row_length_ = area.radius + 2;
308 area.t = TriangleIndex::R;
309 } else {
310- map.get_bln(area, &left_);
311+ map.get_bln(area.node, &left_);
312 phase_ = Top;
313 row_length_ = area.radius + 3;
314 remaining_in_row_ = half_radius_rounded_down + (0 < area.radius);
315@@ -201,7 +200,7 @@
316 switch (phase_) {
317 case Top:
318 if (remaining_in_row_)
319- map.get_rn(location_, &location_);
320+ map.get_rn(location_.node, &location_.node);
321 else if (remaining_rows_in_upper_phase_) {
322 phase_ = Upper;
323 remaining_in_row_ = row_length_;
324@@ -214,7 +213,7 @@
325 if (location_.t == TriangleIndex::D)
326 location_.t = TriangleIndex::R;
327 else
328- location_ = TCoords<FCoords>(map.r_n(location_), TriangleIndex::D);
329+ location_ = TCoords<FCoords>(map.r_n(location_.node), TriangleIndex::D);
330 } else {
331 if (--remaining_rows_in_upper_phase_) {
332 row_length_ += 2;
333@@ -240,7 +239,7 @@
334 if (location_.t == TriangleIndex::D)
335 location_.t = TriangleIndex::R;
336 else
337- location_ = TCoords<FCoords>(map.r_n(location_), TriangleIndex::D);
338+ location_ = TCoords<FCoords>(map.r_n(location_.node), TriangleIndex::D);
339 } else {
340 if (--remaining_rows_in_lower_phase_) {
341 assert(row_length_ >= 2);
342@@ -256,7 +255,7 @@
343 break;
344 case Bottom:
345 if (remaining_in_row_)
346- map.get_rn(location_, &location_);
347+ map.get_rn(location_.node, &location_.node);
348 break;
349 }
350 assert(remaining_in_row_ < 10000); // Catch wrapping (integer underflow)
351
352=== modified file 'src/logic/maptriangleregion.h'
353--- src/logic/maptriangleregion.h 2017-08-30 13:35:37 +0000
354+++ src/logic/maptriangleregion.h 2017-09-02 19:51:44 +0000
355@@ -35,10 +35,6 @@
356 * Note that the order in which locations are returned is not guarantueed. (But
357 * in fact the triangles are returned row by row from top to bottom and from
358 * left to right in each row and I see no reason why that would ever change.)
359- *
360- * The initial coordinates must refer to a triangle
361- * (TriangleIndex::D or TriangleIndex::R). Use MapRegion instead for nodes
362- * (TriangleIndex::None).
363 */
364 template <typename CoordsType = TCoords<>, typename RadiusType = uint16_t>
365 struct MapTriangleRegion {
366@@ -69,8 +65,8 @@
367 remaining_in_row_(rowwidth_),
368 remaining_rows_(area_.radius * 2) {
369 for (uint8_t r = area_.radius; r; --r)
370- map.get_tln(area_, &area_);
371- left_ = area_;
372+ map.get_tln(area_.node, &area_.node);
373+ left_ = area_.node;
374 }
375
376 const TCoords<FCoords>& location() const {
377@@ -83,16 +79,16 @@
378 area_.t = TriangleIndex::R;
379 else {
380 area_.t = TriangleIndex::D;
381- map.get_rn(area_, &area_);
382+ map.get_rn(area_.node, &area_.node);
383 }
384 } else if (area_.radius < --remaining_rows_) {
385- map.get_bln(left_, &area_);
386- left_ = area_;
387+ map.get_bln(left_, &area_.node);
388+ left_ = area_.node;
389 area_.t = TriangleIndex::D;
390 remaining_in_row_ = rowwidth_ += 2;
391 } else if (remaining_rows_) {
392- map.get_brn(left_, &area_);
393- left_ = area_;
394+ map.get_brn(left_, &area_.node);
395+ left_ = area_.node;
396 area_.t = TriangleIndex::D;
397 remaining_in_row_ = rowwidth_ -= 2;
398 } else
399
400=== modified file 'src/logic/widelands_geometry.h'
401--- src/logic/widelands_geometry.h 2017-08-30 13:35:37 +0000
402+++ src/logic/widelands_geometry.h 2017-09-02 19:51:44 +0000
403@@ -109,54 +109,33 @@
404 }
405 FCoords(const Coords& nc, Field* const nf) : Coords(nc), field(nf) {
406 }
407-
408- /**
409- * Used in RenderTarget::rendermap where this is first called, then the
410- * coordinates are normalized and after that field is set.
411- *
412- * \note You really want to use \ref Map::get_fcoords instead.
413- */
414- explicit FCoords(const Coords& nc) : Coords(nc), field(nullptr) {
415- }
416-
417 Field* field;
418 };
419
420-enum class TriangleIndex { D, R, None };
421+enum class TriangleIndex { D, R };
422
423-// TODO(sirver): This should not derive from CoordsType. Replace with NodeAndTriangle.
424-template <typename CoordsType = Coords> struct TCoords : public CoordsType {
425- TCoords() : t() {
426- }
427- TCoords(const CoordsType C, const TriangleIndex T = TriangleIndex::None) : CoordsType(C), t(T) {
428+// This uniquely indexes a single Triangle on the map. A Triangle is identified
429+// by its owning node and the triangle index (down or right).
430+template <typename CoordsType = Coords> struct TCoords {
431+ TCoords(const CoordsType C, const TriangleIndex T) : node(C), t(T) {
432 }
433
434 bool operator==(const TCoords& other) const {
435- return CoordsType::operator==(other) && t == other.t;
436+ return node == other.node && t == other.t;
437 }
438 bool operator!=(const TCoords& other) const {
439- return CoordsType::operator!=(other) || t != other.t;
440+ return !(*this == other);
441 }
442
443+ CoordsType node;
444 TriangleIndex t;
445 };
446
447+// A pair of a coord and a triangle, used to signify which field and which
448+// triangle the cursor is closest to. The triangle might belong to another
449+// field.
450 template <typename NodeCoordsType = Coords, typename TriangleCoordsType = Coords>
451 struct NodeAndTriangle {
452- NodeAndTriangle() {
453- }
454- NodeAndTriangle(const NodeCoordsType Node, const TCoords<TriangleCoordsType>& Triangle)
455-
456- : node(Node), triangle(Triangle) {
457- }
458-
459- bool operator==(const NodeAndTriangle<>& other) const {
460- return node == other.node && triangle == other.triangle;
461- }
462- bool operator!=(const NodeAndTriangle<>& other) const {
463- return !(*this == other);
464- }
465-
466 NodeCoordsType node;
467 TCoords<TriangleCoordsType> triangle;
468 };
469
470=== modified file 'src/scripting/lua_ui.cc'
471--- src/scripting/lua_ui.cc 2017-08-19 20:55:57 +0000
472+++ src/scripting/lua_ui.cc 2017-09-02 19:51:44 +0000
473@@ -578,8 +578,10 @@
474 const auto field = *get_user_class<LuaMaps::LuaField>(L, 2);
475 get()->map_view()->mouse_to_field(field->coords(), MapView::Transition::Jump);
476
477- Widelands::NodeAndTriangle<> node_and_triangle;
478- node_and_triangle.node = field->coords();
479+ // We fake the triangle here, since we only support clicking on Nodes from
480+ // Lua.
481+ Widelands::NodeAndTriangle<> node_and_triangle{
482+ field->coords(), Widelands::TCoords<>(field->coords(), Widelands::TriangleIndex::D)};
483 get()->map_view()->field_clicked(node_and_triangle);
484 return 0;
485 }
486
487=== modified file 'src/wui/interactive_base.cc'
488--- src/wui/interactive_base.cc 2017-09-01 18:59:42 +0000
489+++ src/wui/interactive_base.cc 2017-09-02 19:51:44 +0000
490@@ -167,7 +167,7 @@
491 Widelands::MapTriangleRegion<> mr(map, Area<TCoords<>>(center.triangle, sel_.radius));
492 do
493 field_overlay_manager_->register_overlay(
494- mr.location(), sel_.pic, OverlayLevel::kSelection, Vector2i::invalid(), jobid);
495+ mr.location().node, sel_.pic, OverlayLevel::kSelection, Vector2i::invalid(), jobid);
496 while (mr.advance(map));
497 } else {
498 Widelands::MapRegion<> mr(map, Area<>(center.node, sel_.radius));
499
500=== modified file 'src/wui/interactive_base.h'
501--- src/wui/interactive_base.h 2017-09-01 18:59:42 +0000
502+++ src/wui/interactive_base.h 2017-09-02 19:51:44 +0000
503@@ -224,9 +224,10 @@
504 struct SelData {
505 SelData(const bool Freeze = false,
506 const bool Triangles = false,
507- const Widelands::NodeAndTriangle<>& Pos = Widelands::NodeAndTriangle<>(
508- Widelands::Coords(0, 0),
509- Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)),
510+ const Widelands::NodeAndTriangle<>& Pos =
511+ Widelands::NodeAndTriangle<>{
512+ Widelands::Coords(0, 0),
513+ Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)},
514 const uint32_t Radius = 0,
515 const Image* Pic = nullptr,
516 const FieldOverlayManager::OverlayId Jobid = 0)
517
518=== modified file 'src/wui/interactive_player.cc'
519--- src/wui/interactive_player.cc 2017-09-02 18:28:08 +0000
520+++ src/wui/interactive_player.cc 2017-09-02 19:51:44 +0000
521@@ -282,9 +282,9 @@
522 // fieldaction window before entering roadbuilding mode here.
523 fieldaction_.destroy();
524 map_view()->mouse_to_field(flag_to_connect_, MapView::Transition::Jump);
525- set_sel_pos(Widelands::NodeAndTriangle<>(
526+ set_sel_pos(Widelands::NodeAndTriangle<>{
527 flag_to_connect_,
528- Widelands::TCoords<>(flag_to_connect_, Widelands::TriangleIndex::D)));
529+ Widelands::TCoords<>(flag_to_connect_, Widelands::TriangleIndex::D)});
530 start_build_road(flag_to_connect_, field.get_owned_by());
531 }
532 flag_to_connect_ = Widelands::Coords::null();
533
534=== modified file 'src/wui/mapviewpixelfunctions.cc'
535--- src/wui/mapviewpixelfunctions.cc 2017-08-30 13:35:37 +0000
536+++ src/wui/mapviewpixelfunctions.cc 2017-09-02 19:51:44 +0000
537@@ -118,7 +118,7 @@
538 x -= map_end_screen_x;
539 while (y >= map_end_screen_y)
540 y -= map_end_screen_y;
541- NodeAndTriangle<> result;
542+ Coords result_node;
543
544 const uint16_t col_number = x / (kTriangleWidth / 2);
545 uint16_t row_number = y / kTriangleHeight, next_row_number;
546@@ -172,11 +172,14 @@
547 }
548 if (upper_screen_dx * upper_screen_dx + upper_screen_dy * upper_screen_dy <
549 lower_screen_dx * lower_screen_dx + lower_screen_dy * lower_screen_dy)
550- result.node = Coords(upper_x, row_number);
551+ result_node = Coords(upper_x, row_number);
552 else
553- result.node = Coords(lower_x, next_row_number);
554+ result_node = Coords(lower_x, next_row_number);
555 }
556
557+ // This will be overwritten in all cases below.
558+ TCoords<> result_triangle(Coords::null(), TriangleIndex::D);
559+
560 // Find out which of the 4 possible triangles (x, y) is in.
561 if (slash) {
562 int32_t Y_a =
563@@ -190,14 +193,14 @@
564 assert(pdx > 0);
565 if (pdy * kTriangleWidth > ldy * pdx) {
566 // (x, y) is in the upper triangle.
567- result.triangle = TCoords<>(
568+ result_triangle = TCoords<>(
569 Coords(left_col, (row_number == 0 ? mapheight : row_number) - 1), TriangleIndex::D);
570 } else {
571 Y_a = screen_y_base - map[Coords(left_col, next_row_number)].get_height() * kHeightFactor;
572 ldy = Y_b - Y_a;
573 if (pdy * (kTriangleWidth / 2) > ldy * pdx) {
574 // (x, y) is in the second triangle.
575- result.triangle = TCoords<>(
576+ result_triangle = TCoords<>(
577 Coords((right_col == 0 ? mapwidth : right_col) - 1, row_number), TriangleIndex::R);
578 } else {
579 Y_b = screen_y_base -
580@@ -209,10 +212,10 @@
581 pdx = (col_number + 2) * (kTriangleWidth / 2) - x;
582 if (pdy * kTriangleWidth > ldy * pdx) {
583 // (x, y) is in the third triangle.
584- result.triangle = TCoords<>(Coords(right_col, row_number), TriangleIndex::D);
585+ result_triangle = TCoords<>(Coords(right_col, row_number), TriangleIndex::D);
586 } else {
587 // (x, y) is in the lower triangle.
588- result.triangle = TCoords<>(Coords(left_col, next_row_number), TriangleIndex::R);
589+ result_triangle = TCoords<>(Coords(left_col, next_row_number), TriangleIndex::R);
590 }
591 }
592 }
593@@ -228,7 +231,7 @@
594 assert(pdx > 0);
595 if (pdy * kTriangleWidth > ldy * pdx) {
596 // (x, y) is in the upper triangle.
597- result.triangle = TCoords<>(
598+ result_triangle = TCoords<>(
599 Coords(right_col, (row_number == 0 ? mapheight : row_number) - 1), TriangleIndex::D);
600 } else {
601 Y_b = screen_y_base - map[Coords(right_col, next_row_number)].get_height() * kHeightFactor;
602@@ -237,7 +240,7 @@
603 pdx = (col_number + 1) * (kTriangleWidth / 2) - x;
604 if (pdy * (kTriangleWidth / 2) > ldy * pdx) {
605 // (x, y) is in the second triangle.
606- result.triangle = TCoords<>(Coords(left_col, row_number), TriangleIndex::R);
607+ result_triangle = TCoords<>(Coords(left_col, row_number), TriangleIndex::R);
608 } else {
609 Y_a = screen_y_base -
610 map[Coords((right_col == 0 ? mapwidth : right_col) - 1, next_row_number)]
611@@ -246,18 +249,18 @@
612 ldy = Y_b - Y_a;
613 if (pdy * kTriangleWidth > ldy * pdx) {
614 // (x, y) is in the third triangle.
615- result.triangle = TCoords<>(Coords(left_col, row_number), TriangleIndex::D);
616+ result_triangle = TCoords<>(Coords(left_col, row_number), TriangleIndex::D);
617 } else {
618 // (x, y) is in the lower triangle.
619- result.triangle =
620+ result_triangle =
621 TCoords<>(Coords((right_col == 0 ? mapwidth : right_col) - 1, next_row_number),
622 TriangleIndex::R);
623 }
624 }
625 }
626 }
627-
628- return result;
629+ assert(result_triangle.node != Coords::null());
630+ return NodeAndTriangle<>{result_node, result_triangle};
631 }
632
633 /**

Subscribers

People subscribed via source and target branches

to status/vote changes: