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

Proposed by Benedikt Straub
Status: Merged
Merged at revision: 8765
Proposed branch: lp:~widelands-dev/widelands/inputwarequeue_display
Merge into: lp:widelands
Diff against target: 75 lines (+31/-5)
3 files modified
src/economy/input_queue.cc (+8/-0)
src/economy/input_queue.h (+8/-0)
src/wui/inputqueuedisplay.cc (+15/-5)
To merge this branch: bzr merge lp:~widelands-dev/widelands/inputwarequeue_display
Reviewer Review Type Date Requested Status
Notabilis Approve
Review via email: mp+350385@code.launchpad.net

Commit message

Missing wares (and workers) are indicated differently in InputQueueDisplays if the ware is on the way to the building than if it's really missing

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

Good feature, I like it.

The structure of the code looks good, but there might be a bug in the calculations. When testing I reduced the maximum amount of requested wares for a building. It seems as if the number of darker shadow (the wares on their way?) is always the number of wares I reduced it by (e.g., building can store 10 logs, I clicked "store less" twice, now there are two darker shadows and 8 lighter ones).
Not quite sure whether the darker ones really are the requested ones, but it looks strange either way. From an UI perspective I would prefer the icon-order "wares currently stored", "wares on their way" (darker/more visible), "wares (possibly requested but) not on their way" (lighter/more transparent).

Also, I would prefer to not make the "lighter shadows" more transparent that they are in trunk. For some wares they are pretty hard to see and recognize at it is (blackwood, I think) and it becomes even more difficult with this branch.

Revision history for this message
Benedikt Straub (nordfriese) wrote :

The bug was that request_->get_open_count() also seems to count wares that could be brought to the building at once if suddenly needed. Fixed this now by defining in the GUI that all wares beyond the player-defined limit are shown as missing unless they´re present.

From left to right in the queue: Wares in the building (normal); wares on their way (dark); missing completely (light). I reset the transparency for missing wares to the trunk value.

Please also check wares that are already more or less monochrome (like coal, wheat, cloth), do you think the three states are distinguishable enough?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3702. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/406665001.
Appveyor build 3501. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_inputwarequeue_display-3501.

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks, it seems much more logical now. Mostly, that is, sometimes the "dark" section changes its size based on the current max-amount (i.e., 2 cloth requested -> 2 dark; 3 cloth requested -> only 1 dark). Might be correct inside the code based on how requests are calculated, guess you can't do much about that.

I think coal is fine, wheat and cloth are a bit hard to differ but in my opinion it is good enough. You can see the difference, so I think you can leave it as it is now.

An unfortunate bug I noticed: I have 1 cloth in my whole economy (based on ware statistics). With two shipyards each requesting 2 cloth, all the 2*2=4 cloth is displayed as "on their way" which just can't be the case. In the end, only 1 cloth is delivered while the rest is still reported as "on their way". I guess request_->get_num_transfers() should have better been called request_->get_num_requests() ? I haven't looked in the code, maybe there is some method which really returns the number of "wares on their way to fulfill this request". :-/

Revision history for this message
Benedikt Straub (nordfriese) wrote :

I´ll look into that bug… it can´t be the fault of get_num_transfers() because although I provide that function, I don´t use it for the calculations, so the problem is probably that request_->get_open_count() doesn´t do what it should…

Revision history for this message
Benedikt Straub (nordfriese) wrote :

I think I found it. request_->get_num_transfers() is actually the right function here, but merely passing through it´s return value isn´t enough. I made InputQueue::get_missing() more intelligent to account for capacity and existing inputs itself. I can´t reproduce the bug anymore now.
I also added an assert to check that the calculations at least make sense.

Revision history for this message
GunChleoc (gunchleoc) wrote :

1 small comment for performance

Revision history for this message
Benedikt Straub (nordfriese) wrote :

Implemented your suggestion. WaresQueue returns only a variable, but WorkersQueue calls std::vector::size(), so this is more efficient.

Revision history for this message
Notabilis (notabilis27) wrote :

I can't reproduce my bug any longer either, so as far as I am concerned this can go in. Thanks!

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/input_queue.cc'
2--- src/economy/input_queue.cc 2018-04-07 16:59:00 +0000
3+++ src/economy/input_queue.cc 2018-07-22 15:42:30 +0000
4@@ -120,6 +120,14 @@
5 update();
6 }
7
8+uint32_t InputQueue::get_missing() const {
9+ const auto filled = get_filled();
10+ if (filled >= max_fill_ || request_ == nullptr || !request_->is_open()) {
11+ return 0;
12+ }
13+ return max_fill_ - filled - std::min(max_fill_, request_->get_num_transfers());
14+}
15+
16 constexpr uint16_t kCurrentPacketVersion = 3;
17
18 void InputQueue::read(FileRead& fr, Game& game, MapObjectLoader& mol) {
19
20=== modified file 'src/economy/input_queue.h'
21--- src/economy/input_queue.h 2018-04-07 16:59:00 +0000
22+++ src/economy/input_queue.h 2018-07-22 15:42:30 +0000
23@@ -102,6 +102,14 @@
24 virtual Quantity get_filled() const = 0;
25
26 /**
27+ * The amount of missing wares or workers which have been requested
28+ * but are not yet being transported to this building.
29+ * This will never be larger than (get_max_fill()-get_filled()).
30+ * @return The amount at this moment.
31+ */
32+ uint32_t get_missing() const;
33+
34+ /**
35 * Clear the queue appropriately.
36 * Implementing classes should call update() at the end to remove the request.
37 */
38
39=== modified file 'src/wui/inputqueuedisplay.cc'
40--- src/wui/inputqueuedisplay.cc 2018-04-27 06:11:05 +0000
41+++ src/wui/inputqueuedisplay.cc 2018-07-22 15:42:30 +0000
42@@ -129,7 +129,12 @@
43 cache_max_fill_ = queue_->get_max_fill();
44
45 uint32_t nr_inputs_to_draw = std::min(queue_->get_filled(), cache_size_);
46- uint32_t nr_empty_to_draw = cache_size_ - nr_inputs_to_draw;
47+ uint32_t nr_missing_to_draw = std::min(queue_->get_missing(), cache_max_fill_) + cache_size_ - cache_max_fill_;
48+ if (nr_inputs_to_draw > cache_max_fill_) {
49+ nr_missing_to_draw -= nr_inputs_to_draw - cache_max_fill_;
50+ }
51+ uint32_t nr_coming_to_draw = cache_size_ - nr_inputs_to_draw - nr_missing_to_draw;
52+ assert(nr_inputs_to_draw + nr_missing_to_draw + nr_coming_to_draw == cache_size_);
53
54 Vector2i point = Vector2i::zero();
55 point.x = Border + (show_only_ ? 0 : CellWidth + CellSpacing);
56@@ -139,10 +144,15 @@
57 dst.blitrect(Vector2i(point.x, point.y), icon_, Recti(0, 0, icon_->width(), icon_->height()),
58 BlendMode::UseAlpha);
59 }
60- for (; nr_empty_to_draw; --nr_empty_to_draw, point.x += CellWidth + CellSpacing) {
61- dst.blitrect_scale_monochrome(Rectf(point.x, point.y, icon_->width(), icon_->height()), icon_,
62- Recti(0, 0, icon_->width(), icon_->height()),
63- RGBAColor(166, 166, 166, 127));
64+ for (; nr_coming_to_draw; --nr_coming_to_draw, point.x += CellWidth + CellSpacing) {
65+ dst.blitrect_scale_monochrome(Rectf(point.x, point.y, icon_->width(), icon_->height()), icon_,
66+ Recti(0, 0, icon_->width(), icon_->height()),
67+ RGBAColor(127, 127, 127, 191));
68+ }
69+ for (; nr_missing_to_draw; --nr_missing_to_draw, point.x += CellWidth + CellSpacing) {
70+ dst.blitrect_scale_monochrome(Rectf(point.x, point.y, icon_->width(), icon_->height()), icon_,
71+ Recti(0, 0, icon_->width(), icon_->height()),
72+ RGBAColor(191, 191, 191, 127));
73 }
74
75 if (!show_only_) {

Subscribers

People subscribed via source and target branches

to status/vote changes: