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

Proposed by SirVer
Status: Merged
Merged at revision: 8452
Proposed branch: lp:~widelands-dev/widelands/reduce_overlay_manager_use3
Merge into: lp:widelands
Diff against target: 201 lines (+35/-33)
6 files modified
src/ui_basic/window.cc (+1/-1)
src/wui/field_overlay_manager.h (+2/-4)
src/wui/interactive_base.cc (+6/-17)
src/wui/interactive_base.h (+12/-7)
src/wui/interactive_player.cc (+11/-3)
src/wui/interactive_spectator.cc (+3/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/reduce_overlay_manager_use3
Reviewer Review Type Date Requested Status
kaputtnik (community) testing Approve
Review via email: mp+330496@code.launchpad.net

Commit message

Draw build help slope indicators in the draw routine directly, not using the FieldOverlayManager.

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

For testing: this changes the way the help icons for road buildings are displayed. I mean the red, yellow and green indicators while building a road that shows the steepness of the road.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, 2 nits. Needs testing.

Is there a reason you can't
remove enum class OverlayLevel {} right now? If the answer is "yes",
ignore this comment, otherwise remove.

The roads that are displayed
while a road is being build. -> built.

Sorry for the review format,
just a quick check-in during lunch break ;)

Revision history for this message
SirVer (sirver) wrote :

> Is there a reason you can't
remove enum class OverlayLevel {} right now? If the answer is "yes",
ignore this comment, otherwise remove.

No, it could be removed. but since it is part of the public API of the class it would entail further changes. Since the whole class is deleted in the next change after this one is merged (already done, just waiting for this to get in) I did not want to do the work.

> while a road is being build. -> built.

done.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2661. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/274208112.
Appveyor build 2482. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_reduce_overlay_manager_use3-2482.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Sounds good to me :)

Revision history for this message
kaputtnik (franku) wrote :

Works when testing a release build :-)

Did also ran all regression tests.

review: Approve (testing)
Revision history for this message
SirVer (sirver) wrote :

Thanks!

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/window.cc'
2--- src/ui_basic/window.cc 2017-09-04 15:02:05 +0000
3+++ src/ui_basic/window.cc 2017-09-11 19:19:33 +0000
4@@ -399,7 +399,7 @@
5 return true;
6 }
7
8-bool Window::handle_mousewheel(uint32_t which, int32_t x, int32_t y) {
9+bool Window::handle_mousewheel(uint32_t, int32_t, int32_t) {
10 // Mouse wheel events should not propagate to objects below us, so we claim
11 // that they have been handled.
12 return true;
13
14=== modified file 'src/wui/field_overlay_manager.h'
15--- src/wui/field_overlay_manager.h 2017-08-28 20:44:08 +0000
16+++ src/wui/field_overlay_manager.h 2017-09-11 19:19:33 +0000
17@@ -51,10 +51,8 @@
18 // Levels for the overlay registers. This defines in which order they will be
19 // drawn. Buildhelp is special and has the value 5, i.e. every smaller will be
20 // drawn below the buildhelp, everything higher above.
21-enum class OverlayLevel {
22- kWorkAreaPreview = 0,
23- kRoadBuildSlope = 8,
24-};
25+// TODO(sirver): no longer used. remove.
26+enum class OverlayLevel {};
27
28 struct FieldOverlayManager {
29 /// A unique id identifying a registered overlay.
30
31=== modified file 'src/wui/interactive_base.cc'
32--- src/wui/interactive_base.cc 2017-09-11 16:57:25 +0000
33+++ src/wui/interactive_base.cc 2017-09-11 19:19:33 +0000
34@@ -83,7 +83,6 @@
35 lastframe_(SDL_GetTicks()),
36 frametime_(0),
37 avg_usframetime_(0),
38- road_buildhelp_overlay_jobid_(0),
39 buildroad_(nullptr),
40 road_build_player_(0),
41 unique_window_handler_(new UniqueWindowHandler()),
42@@ -670,7 +669,8 @@
43 */
44 void InteractiveBase::roadb_add_overlay() {
45 assert(buildroad_);
46- assert(road_building_preview_.empty());
47+ assert(road_building_overlays_.road_previews.empty());
48+ assert(road_building_overlays_.steepness_indicators.empty());
49
50 const Map& map = egbase().map();
51
52@@ -685,14 +685,12 @@
53 dir = Widelands::get_reverse_dir(dir);
54 }
55 int32_t const shift = 2 * (dir - Widelands::WALK_E);
56- road_building_preview_[c] |= (Widelands::RoadType::kNormal << shift);
57+ road_building_overlays_.road_previews[c] |= (Widelands::RoadType::kNormal << shift);
58 }
59
60 // build hints
61 Widelands::FCoords endpos = map.get_fcoords(buildroad_->get_end());
62
63- assert(!road_buildhelp_overlay_jobid_);
64- road_buildhelp_overlay_jobid_ = field_overlay_manager_->next_overlay_id();
65 for (int32_t dir = 1; dir <= 6; ++dir) {
66 Widelands::FCoords neighb;
67 int32_t caps;
68@@ -733,10 +731,7 @@
69 name = "images/wui/overlays/roadb_yellow.png";
70 else
71 name = "images/wui/overlays/roadb_red.png";
72-
73- field_overlay_manager_->register_overlay(neighb, g_gr->images().get(name),
74- OverlayLevel::kRoadBuildSlope, Vector2i::invalid(),
75- road_buildhelp_overlay_jobid_);
76+ road_building_overlays_.steepness_indicators[neighb] = g_gr->images().get(name);
77 }
78 }
79
80@@ -747,14 +742,8 @@
81 */
82 void InteractiveBase::roadb_remove_overlay() {
83 assert(buildroad_);
84-
85- road_building_preview_.clear();
86-
87- // build hints
88- if (road_buildhelp_overlay_jobid_) {
89- field_overlay_manager_->remove_overlay(road_buildhelp_overlay_jobid_);
90- }
91- road_buildhelp_overlay_jobid_ = 0;
92+ road_building_overlays_.road_previews.clear();
93+ road_building_overlays_.steepness_indicators.clear();
94 }
95
96 bool InteractiveBase::handle_key(bool const down, SDL_Keysym const code) {
97
98=== modified file 'src/wui/interactive_base.h'
99--- src/wui/interactive_base.h 2017-09-10 18:17:55 +0000
100+++ src/wui/interactive_base.h 2017-09-11 19:19:33 +0000
101@@ -63,6 +63,15 @@
102 dfDebug = 4, ///< general debugging info
103 };
104
105+ // Overlays displayed while a road is under construction.
106+ struct RoadBuildingOverlays {
107+ // The roads that are displayed while a road is being built. They are not
108+ // yet logically in the game, but need to be displayed for the user as
109+ // visual guide. The data type is the same as for Field::road.
110+ std::map<Widelands::Coords, uint8_t> road_previews;
111+ std::map<Widelands::Coords, const Image*> steepness_indicators;
112+ };
113+
114 // Manages all UniqueWindows.
115 UniqueWindowHandler& unique_windows();
116
117@@ -162,8 +171,8 @@
118 // Sets the landmark for the keyboard 'key' to 'point'
119 void set_landmark(size_t key, const MapView::View& view);
120
121- const std::map<Widelands::Coords, uint8_t>& road_building_preview() const {
122- return road_building_preview_;
123+ const RoadBuildingOverlays& road_building_overlays() const {
124+ return road_building_overlays_;
125 }
126
127 MapView* map_view() {
128@@ -267,10 +276,7 @@
129 // coordinate that the building that shows the work area is positioned.
130 std::map<Widelands::Coords, const WorkareaInfo*> work_area_previews_;
131
132- // The roads that are displayed while a road is being built. They are not
133- // yet logically in the game, but need to be displayed for the user as
134- // visual guide. The data type is the same as for Field::road.
135- std::map<Widelands::Coords, uint8_t> road_building_preview_;
136+ RoadBuildingOverlays road_building_overlays_;
137
138 std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>>
139 graphic_resolution_changed_subscriber_;
140@@ -281,7 +287,6 @@
141 uint32_t frametime_; // in millseconds
142 uint32_t avg_usframetime_; // in microseconds!
143
144- FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;
145 Widelands::CoordPath* buildroad_; // path for the new road
146 Widelands::PlayerNumber road_build_player_;
147
148
149=== modified file 'src/wui/interactive_player.cc'
150--- src/wui/interactive_player.cc 2017-09-03 13:03:56 +0000
151+++ src/wui/interactive_player.cc 2017-09-11 19:19:33 +0000
152@@ -330,7 +330,7 @@
153 const uint32_t gametime = gbase.get_gametime();
154
155 auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst);
156- const auto& roads_preview = road_building_preview();
157+ const auto& road_building = road_building_overlays();
158 const std::map<Widelands::Coords, const Image*> work_area_overlays = get_work_area_overlays(map);
159
160 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
161@@ -355,8 +355,8 @@
162
163 // Add road building overlays if applicable.
164 {
165- const auto it = roads_preview.find(f->fcoords);
166- if (it != roads_preview.end()) {
167+ const auto it = road_building.road_previews.find(f->fcoords);
168+ if (it != road_building.road_previews.end()) {
169 f->roads |= it->second;
170 }
171 }
172@@ -398,6 +398,14 @@
173 const Image* pic = get_sel_picture();
174 blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
175 }
176+
177+ // Draw road building slopes.
178+ {
179+ const auto it = road_building.steepness_indicators.find(f->fcoords);
180+ if (it != road_building.steepness_indicators.end()) {
181+ blit_overlay(it->second, Vector2i(it->second->width() / 2, it->second->height() / 2));
182+ }
183+ }
184 }
185 }
186
187
188=== modified file 'src/wui/interactive_spectator.cc'
189--- src/wui/interactive_spectator.cc 2017-08-31 20:58:02 +0000
190+++ src/wui/interactive_spectator.cc 2017-09-11 19:19:33 +0000
191@@ -110,7 +110,9 @@
192
193 void InteractiveSpectator::draw_map_view(MapView* given_map_view, RenderTarget* dst) {
194 // A spectator cannot build roads.
195- assert(road_building_preview().empty());
196+ assert(road_building_overlays().steepness_indicators.empty());
197+ assert(road_building_overlays().road_previews.empty());
198+
199 // In-game, selection can never be on triangles or have a radius.
200 assert(get_sel_radius() == 0);
201 assert(!get_sel_triangles());

Subscribers

People subscribed via source and target branches

to status/vote changes: