Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #6887: Option to show zone inside local authority boundary of towns #7025

Merged
merged 1 commit into from Aug 17, 2019

Conversation

GabdaZM
Copy link
Contributor

@GabdaZM GabdaZM commented Jan 6, 2019

Can be found at town information > local authority window
Layout for button is same as Graph Keys
Turn on/off for every town individually

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 6, 2019

I need some feedback:

  • on the color
  • on the placement of the button
  • and if the logic is appropriate or not

I saw the JGR Patch Pack/Zone patch, but the small selection sprites seemed too new to add (not legacy TTD look).

@Milek7
Copy link
Contributor

Milek7 commented Jan 6, 2019

I don't think that ClosestTownFromTile(ti->tile, _settings_game.economy.dist_local_authority); is correct lookup for town authority.
Comparing with cache.squared_town_zone_radius[0] (for each town separately) is likely better one. (see #6417)

@nielsmh
Copy link
Contributor

nielsmh commented Jan 6, 2019

How does the query tile window check? It always shows Local Authority.

@nielsmh
Copy link
Contributor

nielsmh commented Jan 6, 2019

Turns out that yes, this is exactly how the Land Info window determines local authority:

OpenTTD/src/misc_gui.cpp

Lines 139 to 141 in effb7da

virtual void OnInit()
{
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);

OpenTTD/src/misc_gui.cpp

Lines 223 to 229 in effb7da

/* Local authority */
SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
if (t != NULL) {
SetDParam(0, STR_TOWN_NAME);
SetDParam(1, t->index);
}
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 6, 2019

Yes, I used the method from land info.

@Milek7
Copy link
Contributor

Milek7 commented Jan 6, 2019

Ok, nevermind. I had problems with this method 2 years ago but can't quite remember what was wrong.

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 6, 2019

I've just realised that this version requires a lot of computation, so I have to do something about it.
Is local authority a static thing, or just as Milek7 said and linked, it can change on city growth, and the land info tool sometimes deceiving?

@Milek7
Copy link
Contributor

Milek7 commented Jan 6, 2019

Causes of my confusion about tile authorities 2 years ago were:

  • ClosestTownFromTile, for houses and town owned roads directly returns town assigned to the tile, ignoring threshold.
  • local authorities refusing demolition and crediting tree planting follows logic of ClosestTownFromTile with threshold (eg. town assigned to tile regardless of distance, or closest town in dist_local_authority range otherwise)
  • but assigning stations to towns (and thus crediting local authorities ratings) is based on ClosestTownFromTile without max distance.

So using ClosestTownFromTile with dist_local_authority is correct for determining local authority jurisdiction for destruction/tree planting ratings, but invalid for purposes of determining stations influence on local authority ratings.

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 8, 2019

Note about the methods to decide what tiles gets the zone indicating tile selection sprite:

  • Calculate it every time a tile gets dirty: On big maps with lots of tiles and towns it is too much calculation.
  • Calculate it once and store the information (and update it on appropriate occasions):
    • Storing the info in _me: _me is saved and not meant to be used for data without game logic.
    • Storing a list of tile indexes for a town: dynamic array size as towns can grow, appending and searching can have hard to predict performance.
    • Using a 1 or 2 bit / tile visual overlay cache for the entire map.

Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! I'm open to any further performance improvements, but as it stands currently this is a nice feature that I've seen requested many times and is very simple to implement

src/town_gui.cpp Show resolved Hide resolved
@@ -45,6 +45,7 @@ static const NWidgetPart _nested_town_authority_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether this is a bit far out of the way in the Authority window. I suspect it's not going to be noticed here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try it as a toggle on either the global 'map' menu or 'town' menu? Dunno if it's better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe try on the "parent" town menu ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the possibility to toggle the zone display for the towns individually. This way it is not a problem when two towns are really close or even grown into one. I cannot do that in the global map. Placing a toggle button before each town name in the town list would be possible, but finding a town you already see on the viewport can be harder than the current method.
The parent town menu is really close to the original TTD look, and I don't have the heart to modify it.
I agree that it is hard to find as it is, but I think the function belongs to that windows logically. If the same function will be added to the stations to show coverage, maybe more people will look for it and search the town related windows.

src/script/api/script_window.hpp Outdated Show resolved Hide resolved
@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 11, 2019

The main performance problem is that is calculates the closes town for every tile even when none of the town zones indications are on (so I plan to add a counter, and calculate when it is not 0), and when on max zoom out, scrolling refresh all tiles, and all selections, and getting the closest tile for each tile on the screen, especially is there are a lot of town, is too much. I plan to disable this function on max zoom out.
I'll try the button placements you suggested.

src/town.h Outdated Show resolved Hide resolved
@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 13, 2019

My other approach for this issue: Add #6887: Highlight tiles within local authority of towns #7047
I would like some feedback on which approach is preferable.

@LordAro
Copy link
Member

LordAro commented Jan 13, 2019

I'm very tempted to say that this solution is the better one, just because it's so much simpler and doesn't touch the map array. I've not noticed any performance impact myself either... do you have any measurements for each solution?

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 14, 2019

This solution can have heavy impact, that is why I disabled the function in out zoom 16 and 32. The necessary calculations are proportional with the number of displayed tiles, and also proportional with the number of towns. In a 32x out zoom, the closest town check is done 250.000-300.000 times per second. When I tried it in a 4096x4096 town (it is only interesting because of the number of towns) the graphics needed ~10 ms when none of zones were turned on, and ~300 ms when I turned on one zone.
By disabling the tile highlights in 16x and 32x out zooms, the situation is not that bad, but I think it is a workaround and only hiding the symptom.
I modified the other commit, now it uses a separate cache array, not the map array.

@LordAro
Copy link
Member

LordAro commented Jan 20, 2019

Have we come to the conclusion that this solution definitely isn't workable? If so, I'd like to close it and get it out of the way :)

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 20, 2019

It is workable, but calculation heavy, and I like the other solution more.
One of the two can be closed.

@ldpl
Copy link
Contributor

ldpl commented Jan 20, 2019

I used zoning patch for many years and even programmed some new zones for it (including town ones). Yet, I'm not a big fan of zones and I'm looking for a better ways to do it. First of all there are just too many different zones. Even if we only consider towns there are two authority zones, three advertisement zones and five house zones plus growth highlight and they all have their use. Second, they are indeed computational-heavy and there doesn't seem to be an easy way of making it faster. Third, sometimes you need two-three zones at once. E.g., I always keep growth highlight in citybuilder and switch between other zones with hotkeys.

What I'm thinking of lately is to somehow switch from having to toggle zones on/off to automatically show them when they're needed. E.g. show authorities when placing stations. Industry forbidden areas when funding industries. Advertisement zones when hovering advertisement options (and building stations I guess) and so on. But I couldn't think of any good way to implement it with current UI. I'd really like to see some new elements like opaque overlays for zones, rich building tooltips for info, something along those lines.

@andythenorth
Copy link
Contributor

andythenorth commented Jan 21, 2019

I used zoning patch for many years and even programmed some new zones for it (including town ones). Yet, I'm not a big fan of zones and I'm looking for a better ways to do it. First of all there are just two many different zones.

+1 I tried the zones patch included in JGR PP, and I found it quite confusing in use. I wonder if it's simply too much information, or if it's simply a visual problem with the overlay? It might be interesting to toggle ground tile sprites between 'terrain' and 'metadata'? Then tile colours could be used, for e.g. town boundaries. Might not work, dunno :D . Be easy to mockup a fake test with objects grf though.

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jan 21, 2019

I used zoning patch for many years and even programmed some new zones for it (including town ones). Yet, I'm not a big fan of zones and I'm looking for a better ways to do it. First of all there are just two many different zones.

+1 I tried the zones patch in included in JGR PP, and I found the quite confusing in use. I wonder if it's simply too much information, or if it's simply a visual problem with the overlay? It might be interesting to toggle ground tile sprites between 'terrain' and 'metadata'? Then tile colours could be used, for e.g. town boundaries. Might not work, dunno :D . Be easy to mockup a fake test with objects grf though.

JGR PP zoning patch uses vibrant colours and smaller tile selection highlights. While it is informative, I don't know how it matches the TTD visual style, and which one is more supported:

  • keeping the visuals close the original TTD as much as possible.
  • adding new features for a more comfortable/informative UI which need new visual features as well?

@nielsmh nielsmh added the wip Work in progress. Feature branch that will require feedback during the development process label Jan 25, 2019
@GabdaZM
Copy link
Contributor Author

GabdaZM commented Feb 3, 2019

What I'm thinking of lately is to somehow switch from having to toggle zones on/off to automatically show them when they're needed. E.g. show authorities when placing stations. Industry forbidden areas when funding industries.

I like the idea, I did a demo on the industry forbidden areas part in an other PR.

@stale
Copy link

stale bot commented Mar 5, 2019

This pull request has been automatically marked as stale because it has not had any activity in the last month.
Please feel free to give a status update now, ping for review, or re-open when it's ready.
It will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@stale stale bot added the stale Stale issues label Mar 5, 2019
@stale stale bot removed the stale Stale issues label Mar 11, 2019
@GabdaZM GabdaZM force-pushed the boundary branch 2 times, most recently from 6d12072 to 4298701 Compare April 6, 2019 11:53
* Highlights tiles insede local authority of selected towns.
* @param *ti TileInfo Tile that is being drawn
*/
static void HighlightTownLocalAuthorityTiles(const TileInfo *ti)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it return with a bool, and make the drawing at DrawTileSelection? (Of course with a renamed function.)

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Apr 6, 2019

Now using a k-d tree to store the towns that have the highlight turned on. This way, when searching for closest town for a tile, most of the times it is enough to search in this small k-d tree.

@planetmaker planetmaker removed the wip Work in progress. Feature branch that will require feedback during the development process label Apr 9, 2019
@stale
Copy link

stale bot commented May 6, 2019

This pull request has been automatically marked as stale because it has not had any activity in the last month.
Please feel free to give a status update now, ping for review, or re-open when it's ready.
It will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@stale stale bot added the stale Stale issues label May 6, 2019
@GabdaZM
Copy link
Contributor Author

GabdaZM commented May 8, 2019

Can I ask someone to have a look at this PR?

@stale stale bot removed the stale Stale issues label May 8, 2019
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small things, but I'm otherwise happy with this

src/town.h Outdated Show resolved Hide resolved
src/town_gui.cpp Outdated Show resolved Hide resolved
… of towns

Can be found at town information > local authority window
Layout for button is same as Graph Keys
Turn on/off for every town individually
@GabdaZM
Copy link
Contributor Author

GabdaZM commented May 25, 2019

This visualization does not collide with the coverage display.

@GabdaZM
Copy link
Contributor Author

GabdaZM commented Jul 1, 2019

How can I indicate that the requested changes were made?

@LordAro LordAro dismissed their stale review July 1, 2019 12:51

changes made

@LordAro
Copy link
Member

LordAro commented Jul 1, 2019

By telling us :) Why GH doesn't allow the PR author to dismiss reviews, I don't know...

@LordAro LordAro merged commit b870596 into OpenTTD:master Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants