Merge lp:~widelands-dev/widelands/cleanup-rendertarget into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9066
Proposed branch: lp:~widelands-dev/widelands/cleanup-rendertarget
Merge into: lp:widelands
Diff against target: 313 lines (+34/-82)
12 files modified
src/graphic/game_renderer.cc (+2/-2)
src/graphic/rendertarget.cc (+5/-32)
src/graphic/rendertarget.h (+6/-20)
src/logic/map_objects/bob.cc (+2/-6)
src/logic/map_objects/immovable.cc (+2/-2)
src/logic/map_objects/tribes/building.cc (+1/-1)
src/logic/map_objects/tribes/constructionsite.cc (+4/-4)
src/logic/map_objects/tribes/dismantlesite.cc (+2/-2)
src/logic/map_objects/tribes/worker.cc (+2/-2)
src/wui/interactive_player.cc (+5/-8)
src/wui/itemwaresdisplay.cc (+1/-1)
src/wui/transport_draw.cc (+2/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/cleanup-rendertarget
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+365000@code.launchpad.net

Commit message

Get rid of code duplication in rendertarget.h

Description of the change

This is for Build 21.

Some housekeeping where I squashed 4 functions that do the same into 1.

Prerequisite for https://code.launchpad.net/~widelands-dev/widelands/cleanup-soundhandler, so all testing can be done with the other branch.

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

Continuous integration builds have changed state:

Travis build 4625. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/510312741.
Appveyor build 4412. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_cleanup_rendertarget-4412.

Revision history for this message
GunChleoc (gunchleoc) wrote :

This has been tested with the sound handler branch.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/graphic/game_renderer.cc'
2--- src/graphic/game_renderer.cc 2019-02-23 11:00:49 +0000
3+++ src/graphic/game_renderer.cc 2019-03-23 13:48:46 +0000
4@@ -44,14 +44,14 @@
5 uint32_t const anim_idx = field.owner->tribe().frontier_animation();
6 if (field.vision) {
7 dst->blit_animation(
8- field.rendertarget_pixel, scale, anim_idx, 0, field.owner->get_playercolor());
9+ field.rendertarget_pixel, scale, anim_idx, 0, &field.owner->get_playercolor());
10 }
11 for (const auto& nf : {fields_to_draw.at(field.rn_index), fields_to_draw.at(field.bln_index),
12 fields_to_draw.at(field.brn_index)}) {
13 if ((field.vision || nf.vision) && nf.is_border &&
14 (field.owner == nf.owner || nf.owner == nullptr)) {
15 dst->blit_animation(middle(field.rendertarget_pixel, nf.rendertarget_pixel), scale,
16- anim_idx, 0, field.owner->get_playercolor());
17+ anim_idx, 0, &field.owner->get_playercolor());
18 }
19 }
20 }
21
22=== modified file 'src/graphic/rendertarget.cc'
23--- src/graphic/rendertarget.cc 2019-02-23 11:00:49 +0000
24+++ src/graphic/rendertarget.cc 2019-03-23 13:48:46 +0000
25@@ -286,42 +286,15 @@
26 }
27
28 void RenderTarget::blit_animation(const Vector2f& dst,
29- const float scale,
30- uint32_t animation,
31- uint32_t time) {
32- // TODO(unknown): Correctly calculate the stereo position for sound effects
33- // TODO(unknown): The chosen semantics of animation sound effects is problematic:
34- // What if the game runs very slowly or very quickly?
35- const Animation& anim = g_gr->animations().get_animation(animation);
36- do_blit_animation(dst, scale, anim, time, nullptr);
37-}
38-
39-void RenderTarget::blit_animation(const Vector2f& dst,
40- const float scale,
41- uint32_t animation,
42- uint32_t time,
43- const RGBColor& player_color) {
44- const Animation& anim = g_gr->animations().get_animation(animation);
45- do_blit_animation(dst, scale, anim, time, &player_color);
46-}
47-
48-void RenderTarget::blit_animation(const Vector2f& dst,
49- const float scale,
50- uint32_t animation,
51- uint32_t time,
52- const RGBColor& player_color,
53- const int percent_from_bottom) {
54- do_blit_animation(dst, scale, g_gr->animations().get_animation(animation), time, &player_color,
55- percent_from_bottom);
56-}
57-
58-void RenderTarget::do_blit_animation(const Vector2f& dst,
59 const float scale,
60- const Animation& animation,
61+ uint32_t animation_id,
62 uint32_t time,
63 const RGBColor* player_color,
64 const int percent_from_bottom) {
65-
66+ const Animation& animation = g_gr->animations().get_animation(animation_id);
67+ // TODO(unknown): Correctly calculate the stereo position for sound effects
68+ // TODO(unknown): The chosen semantics of animation sound effects is problematic:
69+ // What if the game runs very slowly or very quickly?
70 assert(percent_from_bottom <= 100);
71 if (percent_from_bottom > 0) {
72 // Scaling for zoom and animation image size, then fit screen edges.
73
74=== modified file 'src/graphic/rendertarget.h'
75--- src/graphic/rendertarget.h 2019-02-23 11:00:49 +0000
76+++ src/graphic/rendertarget.h 2019-03-23 13:48:46 +0000
77@@ -105,18 +105,12 @@
78 // Draw the 'animation' as it should appear at 'time' in this target at
79 // 'dst'. Optionally, the animation is tinted with 'player_color' and
80 // cropped to 'source_rect'.
81- void blit_animation(const Vector2f& dst, float scale, uint32_t animation, uint32_t time);
82- void blit_animation(const Vector2f& dst,
83- float scale,
84- uint32_t animation,
85- uint32_t time,
86- const RGBColor& player_color);
87- void blit_animation(const Vector2f& dst,
88- float scale,
89- uint32_t animation,
90- uint32_t time,
91- const RGBColor& player_color,
92- const int percent_from_bottom);
93+ void blit_animation(const Vector2f& dst,
94+ const float scale,
95+ uint32_t animation_id,
96+ uint32_t time,
97+ const RGBColor* player_color = nullptr,
98+ const int percent_from_bottom = 100);
99
100 void reset();
101
102@@ -134,14 +128,6 @@
103 bool clip(Rectf& r) const;
104 bool to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const;
105
106- // Does the actual blitting.
107- void do_blit_animation(const Vector2f& dst,
108- const float scale,
109- const Animation& animation,
110- uint32_t time,
111- const RGBColor* player_color,
112- const int percent_from_bottom = 100);
113-
114 /// The target surface
115 Surface* const surface_;
116 /// The current clip rectangle
117
118=== modified file 'src/logic/map_objects/bob.cc'
119--- src/logic/map_objects/bob.cc 2019-02-27 17:19:00 +0000
120+++ src/logic/map_objects/bob.cc 2019-03-23 13:48:46 +0000
121@@ -767,12 +767,8 @@
122
123 auto* const bob_owner = get_owner();
124 const Vector2f point_on_dst = calc_drawpos(egbase, field_on_dst, scale);
125- if (bob_owner != nullptr) {
126- dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,
127- bob_owner->get_playercolor());
128- } else {
129- dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_);
130- }
131+ dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,
132+ (bob_owner == nullptr) ? nullptr : &bob_owner->get_playercolor());
133 }
134
135 /**
136
137=== modified file 'src/logic/map_objects/immovable.cc'
138--- src/logic/map_objects/immovable.cc 2019-02-27 17:19:00 +0000
139+++ src/logic/map_objects/immovable.cc 2019-03-23 13:48:46 +0000
140@@ -504,13 +504,13 @@
141 if (current_frame > 0) {
142 // Not the first pic, so draw the previous one in the back
143 dst->blit_animation(
144- point_on_dst, scale, anim_, (current_frame - 1) * frametime, player_color);
145+ point_on_dst, scale, anim_, (current_frame - 1) * frametime, &player_color);
146 }
147
148 const int percent = ((done % units_per_frame) * 100) / units_per_frame;
149
150 dst->blit_animation(
151- point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);
152+ point_on_dst, scale, anim_, current_frame * frametime, &player_color, percent);
153
154 // Additionally, if statistics are enabled, draw a progression string
155 do_draw_info(draw_text, descr().descname(),
156
157=== modified file 'src/logic/map_objects/tribes/building.cc'
158--- src/logic/map_objects/tribes/building.cc 2019-02-28 12:22:36 +0000
159+++ src/logic/map_objects/tribes/building.cc 2019-03-23 13:48:46 +0000
160@@ -611,7 +611,7 @@
161 const float scale,
162 RenderTarget* dst) {
163 dst->blit_animation(
164- point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());
165+ point_on_dst, scale, anim_, gametime - animstart_, &get_owner()->get_playercolor());
166
167 // door animation?
168
169
170=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
171--- src/logic/map_objects/tribes/constructionsite.cc 2019-02-27 17:19:00 +0000
172+++ src/logic/map_objects/tribes/constructionsite.cc 2019-03-23 13:48:46 +0000
173@@ -55,12 +55,12 @@
174
175 if (cur_frame) { // not the first pic
176 // Draw the complete prev pic , so we won't run into trouble if images have different sizes
177- dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, player_color);
178+ dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, &player_color);
179 } else if (was) {
180 // Is the first picture but there was another building here before,
181 // get its most fitting picture and draw it instead.
182 dst->blit_animation(point_on_dst, scale, was->get_unoccupied_animation(),
183- anim_time - FRAME_LENGTH, player_color);
184+ anim_time - FRAME_LENGTH, &player_color);
185 }
186 // Now blit a segment of the current construction phase from the bottom.
187 int percent = 100 * completedtime * nr_frames;
188@@ -68,7 +68,7 @@
189 percent /= totaltime;
190 }
191 percent -= 100 * cur_frame;
192- dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, player_color, percent);
193+ dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, &player_color, percent);
194 }
195
196 /**
197@@ -344,7 +344,7 @@
198 uint32_t tanim = gametime - animstart_;
199 // Draw the construction site marker
200 const RGBColor& player_color = get_owner()->get_playercolor();
201- dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);
202+ dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
203
204 // Draw the partially finished building
205
206
207=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
208--- src/logic/map_objects/tribes/dismantlesite.cc 2019-02-27 17:19:00 +0000
209+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-03-23 13:48:46 +0000
210@@ -225,11 +225,11 @@
211 const RGBColor& player_color = get_owner()->get_playercolor();
212
213 // Draw the construction site marker
214- dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);
215+ dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
216
217 // Blit bottom part of the animation according to dismantle progress
218 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,
219- player_color, 100 - ((get_built_per64k() * 100) >> 16));
220+ &player_color, 100 - ((get_built_per64k() * 100) >> 16));
221
222 // Draw help strings
223 draw_info(draw_text, point_on_dst, scale, dst);
224
225=== modified file 'src/logic/map_objects/tribes/worker.cc'
226--- src/logic/map_objects/tribes/worker.cc 2019-03-17 10:30:24 +0000
227+++ src/logic/map_objects/tribes/worker.cc 2019-03-23 13:48:46 +0000
228@@ -2991,14 +2991,14 @@
229 const RGBColor& player_color = get_owner()->get_playercolor();
230
231 dst->blit_animation(
232- point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), player_color);
233+ point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), &player_color);
234
235 if (WareInstance const* const carried_ware = get_carried_ware(game)) {
236 const Vector2f hotspot = descr().ware_hotspot().cast<float>();
237 const Vector2f location(
238 point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);
239 dst->blit_animation(
240- location, scale, carried_ware->descr().get_animation("idle"), 0, player_color);
241+ location, scale, carried_ware->descr().get_animation("idle"), 0, &player_color);
242 }
243 }
244
245
246=== modified file 'src/wui/interactive_player.cc'
247--- src/wui/interactive_player.cc 2019-03-01 04:29:12 +0000
248+++ src/wui/interactive_player.cc 2019-03-23 13:48:46 +0000
249@@ -130,6 +130,7 @@
250 if (player_field.map_object_descr == nullptr) {
251 return;
252 }
253+
254 if (player_field.constructionsite.becomes) {
255 assert(field.owner != nullptr);
256 player_field.constructionsite.draw(
257@@ -139,18 +140,14 @@
258 assert(field.owner != nullptr);
259 // this is a building therefore we either draw unoccupied or idle animation
260 dst->blit_animation(field.rendertarget_pixel, scale, building->get_unoccupied_animation(), 0,
261- field.owner->get_playercolor());
262+ &field.owner->get_playercolor());
263 } else if (player_field.map_object_descr->type() == Widelands::MapObjectType::FLAG) {
264 assert(field.owner != nullptr);
265 dst->blit_animation(field.rendertarget_pixel, scale, field.owner->tribe().flag_animation(), 0,
266- field.owner->get_playercolor());
267+ &field.owner->get_playercolor());
268 } else if (const uint32_t pic = player_field.map_object_descr->main_animation()) {
269- if (field.owner != nullptr) {
270- dst->blit_animation(
271- field.rendertarget_pixel, scale, pic, 0, field.owner->get_playercolor());
272- } else {
273- dst->blit_animation(field.rendertarget_pixel, scale, pic, 0);
274- }
275+ dst->blit_animation(
276+ field.rendertarget_pixel, scale, pic, 0, (field.owner == nullptr) ? nullptr : &field.owner->get_playercolor());
277 }
278 }
279
280
281=== modified file 'src/wui/itemwaresdisplay.cc'
282--- src/wui/itemwaresdisplay.cc 2019-02-23 11:00:49 +0000
283+++ src/wui/itemwaresdisplay.cc 2019-03-23 13:48:46 +0000
284@@ -121,7 +121,7 @@
285 constexpr float kZoom = 1.f;
286 dst.blit_animation(Vector2f(x + (IWD_ItemWidth / 2.f), y + (IWD_ItemHeight / 2.f)), kZoom,
287 tribe.get_worker_descr(it.index)->main_animation(), 0,
288- player().get_playercolor());
289+ &player().get_playercolor());
290 } else {
291 y += IWD_WareBaseLine;
292 if (tribe.get_ware_descr(it.index)->icon())
293
294=== modified file 'src/wui/transport_draw.cc'
295--- src/wui/transport_draw.cc 2019-02-27 17:19:00 +0000
296+++ src/wui/transport_draw.cc 2019-03-23 13:48:46 +0000
297@@ -38,7 +38,7 @@
298
299 const RGBColor& player_color = owner().get_playercolor();
300 dst->blit_animation(
301- point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, player_color);
302+ point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, &player_color);
303
304 for (int32_t i = 0; i < ware_filled_; ++i) { // draw wares
305 Vector2f warepos = point_on_dst;
306@@ -49,7 +49,7 @@
307 warepos.y -= (6.f + (i - 8.f) * 3.f) * scale;
308 }
309 dst->blit_animation(
310- warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, player_color);
311+ warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, &player_color);
312 }
313 }
314

Subscribers

People subscribed via source and target branches

to status/vote changes: