Merge lp:~majcherlk/widelands/bug-1243700 into lp:widelands

Proposed by Lukasz
Status: Merged
Merged at revision: 7455
Proposed branch: lp:~majcherlk/widelands/bug-1243700
Merge into: lp:widelands
Diff against target: 47 lines (+16/-21)
1 file modified
src/wui/plot_area.cc (+16/-21)
To merge this branch: bzr merge lp:~majcherlk/widelands/bug-1243700
Reviewer Review Type Date Requested Status
TiborB Approve
SirVer Needs Fixing
Review via email: mp+255765@code.launchpad.net

Description of the change

Changes in displaying statistics in order to fix bug 1243700. The time displayed in statistics is rounded to integer: game_time/ticks so everytime number of ticks was not divisible by time game we got incorrect time value. Now game time is always divisible by number of ticks. Another way to solve this bug is to display fractional time but I think the first way is more user friendly. Any suggestions?

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

Generally I think this is a good solution. A couple of comments inlined.

sorry for taking so long to answer this merge request :/.

review: Needs Fixing
Revision history for this message
Lukasz (majcherlk) wrote :

max_x is time to display on graph and how_many_ticks is number of intervals on graph. To get correct data on graph, how_many_ticks has to be a divisor of max_x.
The code tries to find a nice divisor of max_x (by nice I mean some number between 3 and 7 so data on graph are readable). To do it the while loops divide how_many_ticks by prime numbers till we get nice number. I changed the order of loops - now dividing by 5 is first and we get more readable intervals (e.g. without this change for 60min we got intervals: [0,12,24,36,48,60] and now we get [0,10,20,30,40,50,60]).

Revision history for this message
SirVer (sirver) wrote :

thanks, I understood that while reading this merge request because I had the context. What I meant is that you should add this documentation to the code, so that future readers of the code still understood your thinking.

Sorry for not being clear - generally when somebody asks for clarification in a code review, it is always best to answer in the code, not the comments.

review: Needs Fixing
Revision history for this message
TiborB (tiborb95) wrote :

Looks OK now.

Are you able to merge it to trunk?

review: Approve
Revision history for this message
Lukasz (majcherlk) wrote :

> Looks OK now.
>
> Are you able to merge it to trunk?
I don't have rights to merge it to trunk.

Revision history for this message
TiborB (tiborb95) wrote :

I was not sure so I asked. I will merge it.

Revision history for this message
TiborB (tiborb95) wrote :

Merged. Thanks for contribution

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/plot_area.cc'
2--- src/wui/plot_area.cc 2014-12-11 12:38:10 +0000
3+++ src/wui/plot_area.cc 2015-04-23 23:35:21 +0000
4@@ -155,27 +155,22 @@
5 UNIT unit = get_suggested_unit(time_ms);
6 max_x = ms_to_unit(unit, time_ms);
7
8- // Find a nice division of max_x
9- if (max_x % 5 == 0) {
10- if (max_x <= 10) {
11- how_many_ticks = 5;
12- } else {
13- how_many_ticks = max_x / 5;
14- while (how_many_ticks > 7 && how_many_ticks % 2 == 0) {
15- how_many_ticks /= 2;
16- }
17- while (how_many_ticks > 7 && how_many_ticks % 3 == 0) {
18- how_many_ticks /= 3;
19- }
20- while (how_many_ticks > 7 && how_many_ticks % 5 == 0) {
21- how_many_ticks /= 5;
22- }
23- while (how_many_ticks > 7 && how_many_ticks % 7 == 0) {
24- how_many_ticks /= 7;
25- }
26- }
27- } else {
28- how_many_ticks = 4;
29+ // Try to find a nice division of max_x (some number between 3 and 7 so data on graph are
30+ // readable) - to get correct data on graph, how_many_ticks has to be a divisor of max_x. Now
31+ // dividing by 5 is first and we get more readable intervals.
32+ how_many_ticks = max_x;
33+
34+ while (how_many_ticks > 10 && how_many_ticks % 5 == 0) {
35+ how_many_ticks /= 5;
36+ }
37+ while (how_many_ticks > 7 && how_many_ticks % 2 == 0) {
38+ how_many_ticks /= 2;
39+ }
40+ while (how_many_ticks > 7 && how_many_ticks % 3 == 0) {
41+ how_many_ticks /= 3;
42+ }
43+ while (how_many_ticks > 7 && how_many_ticks % 7 == 0) {
44+ how_many_ticks /= 7;
45 }
46
47 // first, tile the background

Subscribers

People subscribed via source and target branches

to status/vote changes: