widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #16350
[Merge] lp:~widelands-dev/widelands/cleanup-rendertarget into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/cleanup-rendertarget into lp:widelands.
Commit message:
Get rid of code duplication in rendertarget.h
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/cleanup-rendertarget/+merge/365000
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.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/cleanup-rendertarget into lp:widelands.
=== 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 @@
uint32_t const anim_idx = field.owner->tribe().frontier_animation();
if (field.vision) {
dst->blit_animation(
- field.rendertarget_pixel, scale, anim_idx, 0, field.owner->get_playercolor());
+ field.rendertarget_pixel, scale, anim_idx, 0, &field.owner->get_playercolor());
}
for (const auto& nf : {fields_to_draw.at(field.rn_index), fields_to_draw.at(field.bln_index),
fields_to_draw.at(field.brn_index)}) {
if ((field.vision || nf.vision) && nf.is_border &&
(field.owner == nf.owner || nf.owner == nullptr)) {
dst->blit_animation(middle(field.rendertarget_pixel, nf.rendertarget_pixel), scale,
- anim_idx, 0, field.owner->get_playercolor());
+ anim_idx, 0, &field.owner->get_playercolor());
}
}
}
=== 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 @@
}
void RenderTarget::blit_animation(const Vector2f& dst,
- const float scale,
- uint32_t animation,
- uint32_t time) {
- // TODO(unknown): Correctly calculate the stereo position for sound effects
- // TODO(unknown): The chosen semantics of animation sound effects is problematic:
- // What if the game runs very slowly or very quickly?
- const Animation& anim = g_gr->animations().get_animation(animation);
- do_blit_animation(dst, scale, anim, time, nullptr);
-}
-
-void RenderTarget::blit_animation(const Vector2f& dst,
- const float scale,
- uint32_t animation,
- uint32_t time,
- const RGBColor& player_color) {
- const Animation& anim = g_gr->animations().get_animation(animation);
- do_blit_animation(dst, scale, anim, time, &player_color);
-}
-
-void RenderTarget::blit_animation(const Vector2f& dst,
- const float scale,
- uint32_t animation,
- uint32_t time,
- const RGBColor& player_color,
- const int percent_from_bottom) {
- do_blit_animation(dst, scale, g_gr->animations().get_animation(animation), time, &player_color,
- percent_from_bottom);
-}
-
-void RenderTarget::do_blit_animation(const Vector2f& dst,
const float scale,
- const Animation& animation,
+ uint32_t animation_id,
uint32_t time,
const RGBColor* player_color,
const int percent_from_bottom) {
-
+ const Animation& animation = g_gr->animations().get_animation(animation_id);
+ // TODO(unknown): Correctly calculate the stereo position for sound effects
+ // TODO(unknown): The chosen semantics of animation sound effects is problematic:
+ // What if the game runs very slowly or very quickly?
assert(percent_from_bottom <= 100);
if (percent_from_bottom > 0) {
// Scaling for zoom and animation image size, then fit screen edges.
=== 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 @@
// Draw the 'animation' as it should appear at 'time' in this target at
// 'dst'. Optionally, the animation is tinted with 'player_color' and
// cropped to 'source_rect'.
- void blit_animation(const Vector2f& dst, float scale, uint32_t animation, uint32_t time);
- void blit_animation(const Vector2f& dst,
- float scale,
- uint32_t animation,
- uint32_t time,
- const RGBColor& player_color);
- void blit_animation(const Vector2f& dst,
- float scale,
- uint32_t animation,
- uint32_t time,
- const RGBColor& player_color,
- const int percent_from_bottom);
+ void blit_animation(const Vector2f& dst,
+ const float scale,
+ uint32_t animation_id,
+ uint32_t time,
+ const RGBColor* player_color = nullptr,
+ const int percent_from_bottom = 100);
void reset();
@@ -134,14 +128,6 @@
bool clip(Rectf& r) const;
bool to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const;
- // Does the actual blitting.
- void do_blit_animation(const Vector2f& dst,
- const float scale,
- const Animation& animation,
- uint32_t time,
- const RGBColor* player_color,
- const int percent_from_bottom = 100);
-
/// The target surface
Surface* const surface_;
/// The current clip rectangle
=== 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 @@
auto* const bob_owner = get_owner();
const Vector2f point_on_dst = calc_drawpos(egbase, field_on_dst, scale);
- if (bob_owner != nullptr) {
- dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,
- bob_owner->get_playercolor());
- } else {
- dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_);
- }
+ dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_,
+ (bob_owner == nullptr) ? nullptr : &bob_owner->get_playercolor());
}
/**
=== 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 @@
if (current_frame > 0) {
// Not the first pic, so draw the previous one in the back
dst->blit_animation(
- point_on_dst, scale, anim_, (current_frame - 1) * frametime, player_color);
+ point_on_dst, scale, anim_, (current_frame - 1) * frametime, &player_color);
}
const int percent = ((done % units_per_frame) * 100) / units_per_frame;
dst->blit_animation(
- point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);
+ point_on_dst, scale, anim_, current_frame * frametime, &player_color, percent);
// Additionally, if statistics are enabled, draw a progression string
do_draw_info(draw_text, descr().descname(),
=== 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 @@
const float scale,
RenderTarget* dst) {
dst->blit_animation(
- point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());
+ point_on_dst, scale, anim_, gametime - animstart_, &get_owner()->get_playercolor());
// door animation?
=== 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 @@
if (cur_frame) { // not the first pic
// Draw the complete prev pic , so we won't run into trouble if images have different sizes
- dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, player_color);
+ dst->blit_animation(point_on_dst, scale, anim_idx, anim_time - FRAME_LENGTH, &player_color);
} else if (was) {
// Is the first picture but there was another building here before,
// get its most fitting picture and draw it instead.
dst->blit_animation(point_on_dst, scale, was->get_unoccupied_animation(),
- anim_time - FRAME_LENGTH, player_color);
+ anim_time - FRAME_LENGTH, &player_color);
}
// Now blit a segment of the current construction phase from the bottom.
int percent = 100 * completedtime * nr_frames;
@@ -68,7 +68,7 @@
percent /= totaltime;
}
percent -= 100 * cur_frame;
- dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, player_color, percent);
+ dst->blit_animation(point_on_dst, scale, anim_idx, anim_time, &player_color, percent);
}
/**
@@ -344,7 +344,7 @@
uint32_t tanim = gametime - animstart_;
// Draw the construction site marker
const RGBColor& player_color = get_owner()->get_playercolor();
- dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);
+ dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
// Draw the partially finished building
=== 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 @@
const RGBColor& player_color = get_owner()->get_playercolor();
// Draw the construction site marker
- dst->blit_animation(point_on_dst, scale, anim_, tanim, player_color);
+ dst->blit_animation(point_on_dst, scale, anim_, tanim, &player_color);
// Blit bottom part of the animation according to dismantle progress
dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,
- player_color, 100 - ((get_built_per64k() * 100) >> 16));
+ &player_color, 100 - ((get_built_per64k() * 100) >> 16));
// Draw help strings
draw_info(draw_text, point_on_dst, scale, dst);
=== 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 @@
const RGBColor& player_color = get_owner()->get_playercolor();
dst->blit_animation(
- point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), player_color);
+ point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), &player_color);
if (WareInstance const* const carried_ware = get_carried_ware(game)) {
const Vector2f hotspot = descr().ware_hotspot().cast<float>();
const Vector2f location(
point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);
dst->blit_animation(
- location, scale, carried_ware->descr().get_animation("idle"), 0, player_color);
+ location, scale, carried_ware->descr().get_animation("idle"), 0, &player_color);
}
}
=== 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 @@
if (player_field.map_object_descr == nullptr) {
return;
}
+
if (player_field.constructionsite.becomes) {
assert(field.owner != nullptr);
player_field.constructionsite.draw(
@@ -139,18 +140,14 @@
assert(field.owner != nullptr);
// this is a building therefore we either draw unoccupied or idle animation
dst->blit_animation(field.rendertarget_pixel, scale, building->get_unoccupied_animation(), 0,
- field.owner->get_playercolor());
+ &field.owner->get_playercolor());
} else if (player_field.map_object_descr->type() == Widelands::MapObjectType::FLAG) {
assert(field.owner != nullptr);
dst->blit_animation(field.rendertarget_pixel, scale, field.owner->tribe().flag_animation(), 0,
- field.owner->get_playercolor());
+ &field.owner->get_playercolor());
} else if (const uint32_t pic = player_field.map_object_descr->main_animation()) {
- if (field.owner != nullptr) {
- dst->blit_animation(
- field.rendertarget_pixel, scale, pic, 0, field.owner->get_playercolor());
- } else {
- dst->blit_animation(field.rendertarget_pixel, scale, pic, 0);
- }
+ dst->blit_animation(
+ field.rendertarget_pixel, scale, pic, 0, (field.owner == nullptr) ? nullptr : &field.owner->get_playercolor());
}
}
=== 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 @@
constexpr float kZoom = 1.f;
dst.blit_animation(Vector2f(x + (IWD_ItemWidth / 2.f), y + (IWD_ItemHeight / 2.f)), kZoom,
tribe.get_worker_descr(it.index)->main_animation(), 0,
- player().get_playercolor());
+ &player().get_playercolor());
} else {
y += IWD_WareBaseLine;
if (tribe.get_ware_descr(it.index)->icon())
=== 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 @@
const RGBColor& player_color = owner().get_playercolor();
dst->blit_animation(
- point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, player_color);
+ point_on_dst, scale, owner().tribe().flag_animation(), gametime - animstart_, &player_color);
for (int32_t i = 0; i < ware_filled_; ++i) { // draw wares
Vector2f warepos = point_on_dst;
@@ -49,7 +49,7 @@
warepos.y -= (6.f + (i - 8.f) * 3.f) * scale;
}
dst->blit_animation(
- warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, player_color);
+ warepos, scale, wares_[i].ware->descr().get_animation("idle"), 0, &player_color);
}
}
References