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
=== modified file 'src/graphic/game_renderer.cc'
--- src/graphic/game_renderer.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/game_renderer.cc 2019-03-23 13:48:46 +0000
@@ -44,14 +44,14 @@
44 uint32_t const anim_idx = field.owner->tribe().frontier_animation();44 uint32_t const anim_idx = field.owner->tribe().frontier_animation();
45 if (field.vision) {45 if (field.vision) {
46 dst->blit_animation(46 dst->blit_animation(
47 field.rendertarget_pixel, scale, anim_idx, 0, field.owner->get_playercolor());47 field.rendertarget_pixel, scale, anim_idx, 0, &field.owner->get_playercolor());
48 }48 }
49 for (const auto& nf : {fields_to_draw.at(field.rn_index), fields_to_draw.at(field.bln_index),49 for (const auto& nf : {fields_to_draw.at(field.rn_index), fields_to_draw.at(field.bln_index),
50 fields_to_draw.at(field.brn_index)}) {50 fields_to_draw.at(field.brn_index)}) {
51 if ((field.vision || nf.vision) && nf.is_border &&51 if ((field.vision || nf.vision) && nf.is_border &&
52 (field.owner == nf.owner || nf.owner == nullptr)) {52 (field.owner == nf.owner || nf.owner == nullptr)) {
53 dst->blit_animation(middle(field.rendertarget_pixel, nf.rendertarget_pixel), scale,53 dst->blit_animation(middle(field.rendertarget_pixel, nf.rendertarget_pixel), scale,
54 anim_idx, 0, field.owner->get_playercolor());54 anim_idx, 0, &field.owner->get_playercolor());
55 }55 }
56 }56 }
57}57}
5858
=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc 2019-02-23 11:00:49 +0000
+++ src/graphic/rendertarget.cc 2019-03-23 13:48:46 +0000
@@ -286,42 +286,15 @@
286}286}
287287
288void RenderTarget::blit_animation(const Vector2f& dst,288void RenderTarget::blit_animation(const Vector2f& dst,
289 const float scale,
290 uint32_t animation,
291 uint32_t time) {
292 // TODO(unknown): Correctly calculate the stereo position for sound effects
293 // TODO(unknown): The chosen semantics of animation sound effects is problematic:
294 // What if the game runs very slowly or very quickly?
295 const Animation& anim = g_gr->animations().get_animation(animation);
296 do_blit_animation(dst, scale, anim, time, nullptr);
297}
298
299void RenderTarget::blit_animation(const Vector2f& dst,
300 const float scale,
301 uint32_t animation,
302 uint32_t time,
303 const RGBColor& player_color) {
304 const Animation& anim = g_gr->animations().get_animation(animation);
305 do_blit_animation(dst, scale, anim, time, &player_color);
306}
307
308void RenderTarget::blit_animation(const Vector2f& dst,
309 const float scale,
310 uint32_t animation,
311 uint32_t time,
312 const RGBColor& player_color,
313 const int percent_from_bottom) {
314 do_blit_animation(dst, scale, g_gr->animations().get_animation(animation), time, &player_color,
315 percent_from_bottom);
316}
317
318void RenderTarget::do_blit_animation(const Vector2f& dst,
319 const float scale,289 const float scale,
320 const Animation& animation,290 uint32_t animation_id,
321 uint32_t time,291 uint32_t time,
322 const RGBColor* player_color,292 const RGBColor* player_color,
323 const int percent_from_bottom) {293 const int percent_from_bottom) {
324294 const Animation& animation = g_gr->animations().get_animation(animation_id);
295 // TODO(unknown): Correctly calculate the stereo position for sound effects
296 // TODO(unknown): The chosen semantics of animation sound effects is problematic:
297 // What if the game runs very slowly or very quickly?
325 assert(percent_from_bottom <= 100);298 assert(percent_from_bottom <= 100);
326 if (percent_from_bottom > 0) {299 if (percent_from_bottom > 0) {
327 // Scaling for zoom and animation image size, then fit screen edges.300 // Scaling for zoom and animation image size, then fit screen edges.
328301
=== modified file 'src/graphic/rendertarget.h'
--- src/graphic/rendertarget.h 2019-02-23 11:00:49 +0000
+++ src/graphic/rendertarget.h 2019-03-23 13:48:46 +0000
@@ -105,18 +105,12 @@
105 // Draw the 'animation' as it should appear at 'time' in this target at105 // Draw the 'animation' as it should appear at 'time' in this target at
106 // 'dst'. Optionally, the animation is tinted with 'player_color' and106 // 'dst'. Optionally, the animation is tinted with 'player_color' and
107 // cropped to 'source_rect'.107 // cropped to 'source_rect'.
108 void blit_animation(const Vector2f& dst, float scale, uint32_t animation, uint32_t time);108 void blit_animation(const Vector2f& dst,
109 void blit_animation(const Vector2f& dst,109 const float scale,
110 float scale,110 uint32_t animation_id,
111 uint32_t animation,111 uint32_t time,
112 uint32_t time,112 const RGBColor* player_color = nullptr,
113 const RGBColor& player_color);113 const int percent_from_bottom = 100);
114 void blit_animation(const Vector2f& dst,
115 float scale,
116 uint32_t animation,
117 uint32_t time,
118 const RGBColor& player_color,
119 const int percent_from_bottom);
120114
121 void reset();115 void reset();
122116
@@ -134,14 +128,6 @@
134 bool clip(Rectf& r) const;128 bool clip(Rectf& r) const;
135 bool to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const;129 bool to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const;
136130
137 // Does the actual blitting.
138 void do_blit_animation(const Vector2f& dst,
139 const float scale,
140 const Animation& animation,
141 uint32_t time,
142 const RGBColor* player_color,
143 const int percent_from_bottom = 100);
144
145 /// The target surface131 /// The target surface
146 Surface* const surface_;132 Surface* const surface_;
147 /// The current clip rectangle133 /// The current clip rectangle
148134
=== modified file 'src/logic/map_objects/bob.cc'
--- src/logic/map_objects/bob.cc 2019-02-27 17:19:00 +0000
+++ src/logic/map_objects/bob.cc 2019-03-23 13:48:46 +0000
@@ -767,12 +767,8 @@
767767
768 auto* const bob_owner = get_owner();768 auto* const bob_owner = get_owner();
769 const Vector2f point_on_dst = calc_drawpos(egbase, field_on_dst, scale);769 const Vector2f point_on_dst = calc_drawpos(egbase, field_on_dst, scale);
770 if (bob_owner != nullptr) {770 dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,
771 dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,771 (bob_owner == nullptr) ? nullptr : &bob_owner->get_playercolor());
772 bob_owner->get_playercolor());
773 } else {
774 dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_);
775 }
776}772}
777773
778/**774/**
779775
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc 2019-02-27 17:19:00 +0000
+++ src/logic/map_objects/immovable.cc 2019-03-23 13:48:46 +0000
@@ -504,13 +504,13 @@
504 if (current_frame > 0) {504 if (current_frame > 0) {
505 // Not the first pic, so draw the previous one in the back505 // Not the first pic, so draw the previous one in the back
506 dst->blit_animation(506 dst->blit_animation(
507 point_on_dst, scale, anim_, (current_frame - 1) * frametime, player_color);507 point_on_dst, scale, anim_, (current_frame - 1) * frametime, &player_color);
508 }508 }
509509
510 const int percent = ((done % units_per_frame) * 100) / units_per_frame;510 const int percent = ((done % units_per_frame) * 100) / units_per_frame;
511511
512 dst->blit_animation(512 dst->blit_animation(
513 point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);513 point_on_dst, scale, anim_, current_frame * frametime, &player_color, percent);
514514
515 // Additionally, if statistics are enabled, draw a progression string515 // Additionally, if statistics are enabled, draw a progression string
516 do_draw_info(draw_text, descr().descname(),516 do_draw_info(draw_text, descr().descname(),
517517
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc 2019-02-28 12:22:36 +0000
+++ src/logic/map_objects/tribes/building.cc 2019-03-23 13:48:46 +0000
@@ -611,7 +611,7 @@
611 const float scale,611 const float scale,
612 RenderTarget* dst) {612 RenderTarget* dst) {
613 dst->blit_animation(613 dst->blit_animation(
614 point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());614 point_on_dst, scale, anim_, gametime - animstart_, &get_owner()->get_playercolor());
615615
616 // door animation?616 // door animation?
617617
618618
=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
--- src/logic/map_objects/tribes/constructionsite.cc 2019-02-27 17:19:00 +0000
+++ src/logic/map_objects/tribes/constructionsite.cc 2019-03-23 13:48:46 +0000
@@ -55,12 +55,12 @@
5555
56 if (cur_frame) { // not the first pic56 if (cur_frame) { // not the first pic
57 // Draw the complete prev pic , so we won't run into trouble if images have different sizes57 // Draw the complete prev pic , so we won't run into trouble if images have different sizes
58 dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, player_color);58 dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, &player_color);
59 } else if (was) {59 } else if (was) {
60 // Is the first picture but there was another building here before,60 // Is the first picture but there was another building here before,
61 // get its most fitting picture and draw it instead.61 // get its most fitting picture and draw it instead.
62 dst->blit_animation(point_on_dst, scale, was->get_unoccupied_animation(),62 dst->blit_animation(point_on_dst, scale, was->get_unoccupied_animation(),
63 anim_time - FRAME_LENGTH, player_color);63 anim_time - FRAME_LENGTH, &player_color);
64 }64 }
65 // Now blit a segment of the current construction phase from the bottom.65 // Now blit a segment of the current construction phase from the bottom.
66 int percent = 100 * completedtime * nr_frames;66 int percent = 100 * completedtime * nr_frames;
@@ -68,7 +68,7 @@
68 percent /= totaltime;68 percent /= totaltime;
69 }69 }
70 percent -= 100 * cur_frame;70 percent -= 100 * cur_frame;
71 dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, player_color, percent);71 dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, &player_color, percent);
72}72}
7373
74/**74/**
@@ -344,7 +344,7 @@
344 uint32_t tanim = gametime - animstart_;344 uint32_t tanim = gametime - animstart_;
345 // Draw the construction site marker345 // Draw the construction site marker
346 const RGBColor& player_color = get_owner()->get_playercolor();346 const RGBColor& player_color = get_owner()->get_playercolor();
347 dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);347 dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
348348
349 // Draw the partially finished building349 // Draw the partially finished building
350350
351351
=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc 2019-02-27 17:19:00 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-03-23 13:48:46 +0000
@@ -225,11 +225,11 @@
225 const RGBColor& player_color = get_owner()->get_playercolor();225 const RGBColor& player_color = get_owner()->get_playercolor();
226226
227 // Draw the construction site marker227 // Draw the construction site marker
228 dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);228 dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
229229
230 // Blit bottom part of the animation according to dismantle progress230 // Blit bottom part of the animation according to dismantle progress
231 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,231 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,
232 player_color, 100 - ((get_built_per64k() * 100) >> 16));232 &player_color, 100 - ((get_built_per64k() * 100) >> 16));
233233
234 // Draw help strings234 // Draw help strings
235 draw_info(draw_text, point_on_dst, scale, dst);235 draw_info(draw_text, point_on_dst, scale, dst);
236236
=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc 2019-03-17 10:30:24 +0000
+++ src/logic/map_objects/tribes/worker.cc 2019-03-23 13:48:46 +0000
@@ -2991,14 +2991,14 @@
2991 const RGBColor& player_color = get_owner()->get_playercolor();2991 const RGBColor& player_color = get_owner()->get_playercolor();
29922992
2993 dst->blit_animation(2993 dst->blit_animation(
2994 point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), player_color);2994 point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), &player_color);
29952995
2996 if (WareInstance const* const carried_ware = get_carried_ware(game)) {2996 if (WareInstance const* const carried_ware = get_carried_ware(game)) {
2997 const Vector2f hotspot = descr().ware_hotspot().cast<float>();2997 const Vector2f hotspot = descr().ware_hotspot().cast<float>();
2998 const Vector2f location(2998 const Vector2f location(
2999 point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);2999 point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);
3000 dst->blit_animation(3000 dst->blit_animation(
3001 location, scale, carried_ware->descr().get_animation("idle"), 0, player_color);3001 location, scale, carried_ware->descr().get_animation("idle"), 0, &player_color);
3002 }3002 }
3003}3003}
30043004
30053005
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2019-03-01 04:29:12 +0000
+++ src/wui/interactive_player.cc 2019-03-23 13:48:46 +0000
@@ -130,6 +130,7 @@
130 if (player_field.map_object_descr == nullptr) {130 if (player_field.map_object_descr == nullptr) {
131 return;131 return;
132 }132 }
133
133 if (player_field.constructionsite.becomes) {134 if (player_field.constructionsite.becomes) {
134 assert(field.owner != nullptr);135 assert(field.owner != nullptr);
135 player_field.constructionsite.draw(136 player_field.constructionsite.draw(
@@ -139,18 +140,14 @@
139 assert(field.owner != nullptr);140 assert(field.owner != nullptr);
140 // this is a building therefore we either draw unoccupied or idle animation141 // this is a building therefore we either draw unoccupied or idle animation
141 dst->blit_animation(field.rendertarget_pixel, scale, building->get_unoccupied_animation(), 0,142 dst->blit_animation(field.rendertarget_pixel, scale, building->get_unoccupied_animation(), 0,
142 field.owner->get_playercolor());143 &field.owner->get_playercolor());
143 } else if (player_field.map_object_descr->type() == Widelands::MapObjectType::FLAG) {144 } else if (player_field.map_object_descr->type() == Widelands::MapObjectType::FLAG) {
144 assert(field.owner != nullptr);145 assert(field.owner != nullptr);
145 dst->blit_animation(field.rendertarget_pixel, scale, field.owner->tribe().flag_animation(), 0,146 dst->blit_animation(field.rendertarget_pixel, scale, field.owner->tribe().flag_animation(), 0,
146 field.owner->get_playercolor());147 &field.owner->get_playercolor());
147 } else if (const uint32_t pic = player_field.map_object_descr->main_animation()) {148 } else if (const uint32_t pic = player_field.map_object_descr->main_animation()) {
148 if (field.owner != nullptr) {149 dst->blit_animation(
149 dst->blit_animation(150 field.rendertarget_pixel, scale, pic, 0, (field.owner == nullptr) ? nullptr : &field.owner->get_playercolor());
150 field.rendertarget_pixel, scale, pic, 0, field.owner->get_playercolor());
151 } else {
152 dst->blit_animation(field.rendertarget_pixel, scale, pic, 0);
153 }
154 }151 }
155}152}
156153
157154
=== modified file 'src/wui/itemwaresdisplay.cc'
--- src/wui/itemwaresdisplay.cc 2019-02-23 11:00:49 +0000
+++ src/wui/itemwaresdisplay.cc 2019-03-23 13:48:46 +0000
@@ -121,7 +121,7 @@
121 constexpr float kZoom = 1.f;121 constexpr float kZoom = 1.f;
122 dst.blit_animation(Vector2f(x + (IWD_ItemWidth / 2.f), y + (IWD_ItemHeight / 2.f)), kZoom,122 dst.blit_animation(Vector2f(x + (IWD_ItemWidth / 2.f), y + (IWD_ItemHeight / 2.f)), kZoom,
123 tribe.get_worker_descr(it.index)->main_animation(), 0,123 tribe.get_worker_descr(it.index)->main_animation(), 0,
124 player().get_playercolor());124 &player().get_playercolor());
125 } else {125 } else {
126 y += IWD_WareBaseLine;126 y += IWD_WareBaseLine;
127 if (tribe.get_ware_descr(it.index)->icon())127 if (tribe.get_ware_descr(it.index)->icon())
128128
=== modified file 'src/wui/transport_draw.cc'
--- src/wui/transport_draw.cc 2019-02-27 17:19:00 +0000
+++ src/wui/transport_draw.cc 2019-03-23 13:48:46 +0000
@@ -38,7 +38,7 @@
3838
39 const RGBColor& player_color = owner().get_playercolor();39 const RGBColor& player_color = owner().get_playercolor();
40 dst->blit_animation(40 dst->blit_animation(
41 point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, player_color);41 point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, &player_color);
4242
43 for (int32_t i = 0; i < ware_filled_; ++i) { // draw wares43 for (int32_t i = 0; i < ware_filled_; ++i) { // draw wares
44 Vector2f warepos = point_on_dst;44 Vector2f warepos = point_on_dst;
@@ -49,7 +49,7 @@
49 warepos.y -= (6.f + (i - 8.f) * 3.f) * scale;49 warepos.y -= (6.f + (i - 8.f) * 3.f) * scale;
50 }50 }
51 dst->blit_animation(51 dst->blit_animation(
52 warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, player_color);52 warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, &player_color);
53 }53 }
54}54}
5555

Subscribers

People subscribed via source and target branches

to status/vote changes: