Enhanced viewport: zoom out, overlays & tooltips (r53_27127)

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Enhanced viewport: zoom out, overlays & tooltips (r53_27127)

Post by MJP »

Hello all,

I was playing on a 2048*2048 map and felt the need of the feature presented in this *very first* patch: an extension of zooming out capability of the main viewport (relying only on the smallmap was not convenient enough for me).

This patch has been initially done on top of the 1.1 branch of OpenTTD. I tried to reuse a maximum of already existing code. As I like very much how the smallmap presents things, I borrowed its "owners" (with heightmap activated) rendering method. It is obviously far from perfect but it runs quite smoothly on my computer and should help big map players.

I hope this kind of feature will find its way into trunk one day :)
  • 1/ Zoom out any viewport up to 128X
To get an overview, no need to switch to the smallmap constantly: just use your mousewheel (works with main viewport and extraviewports too).
maps.png
maps.png (92.06 KiB) Viewed 31721 times
NB: Bridges and tunnels support is glitchy.
  • 2/ Locate a viewport
When you move a viewport (not in map mode), the other viewports (in map mode) will show its location.
Image
Note that blending option is enabled only for 32bpp blitter!
  • 3/ Industry tooltips
If you are tired of the "click on industry, read info then close window" routine, this is for you!
Image
  • 4/ Plans
To ease cooperative games, this is a tool to draw lines on viewports.
By default, a plan is visible only by its owning company but you can advertise the plan and make it public (public appears in blue).
Image
Double click on a plan in the list expand its lines.
The selected line or plan is drawn in red.
The Delete button affects the selected item in the list.
  • 5/ Vehicle route
Understanding where a vehicle goes is very important.
On a big map, there are too many towns to get quickly the relation between name and location.
So to make things easier, the route steps are pointed out.
And if you want more, it can show the path and conditional branching.
Image
(there is an expert setting to chose dashed or plain lines)
  • 6/ Settings
All options are found in "Display options" and its "Viewport Map" subpage.
Also, don't forget to increase the maximum zoom out level!
advanced-settings.png
advanced-settings.png (8.54 KiB) Viewed 28857 times
  • 7/ Patch
enhanced-viewport_r53_for_r27127.zip
(205.35 KiB) Downloaded 477 times
r53:
- adapted to the "more height levels" feature (+ full heightlevel colour dithering)
- replaced dark/light heightlevels by darken/lighten lookup tables

r52:
- adapted to codechange r26623 (SettingsPage)
- sanity check for binary data length (server recv)
- fix a crash with tooltip buffer

r51:
- add ability to draw straight plan lines (in 2 clicks)
- fix plans GUI with custom fonts
- scrolling a viewport does not give it focus
- add advanced setting to specify the dash level of a vehicle's route

r50:
- fix crash when oilrig is not shown on map
- fix smallmap notification to viewports
- fix horizontal alignment of route step labels

r49:
- extend focus system to prevent useless redraw and on/off/on effect (when using dropdowns) with route steps and path (and fix marking dirty when passing from a vehicle A window to a vehicle B window)

r48:
- dynamically adjust the disabled state of the buttons of the plans window
- set plan initial visibility to true if the player works for the plan's owner
- cancel current drawing if the associated plan is remotely deleted
- fix public plans handling and some focus related things

r47:
- fix the selected item handling in plan window (possible crash after a plan gets remotely deleted)

r46:
- fix SetLine32() anim value (blinking owners are definitely not good)
- templatize map rendering with show_slope
- reworked slope colours in vegetation map mode

r45:
- the vegetation map style takes into account the transparency settings of trees
- route steps are aware of font height
- fix toggle private/public plan crash

r44:
- updated filter mark dirty (no farmfield changes in map mode)
- configurable maintoolbar hotkey "plan_list" to open the plans window
- fix plans error strings
- add tooltip to plans window buttons
- change the advertise (plan) button into Make public/Make private

r43:
- new route step graphics
- fix plans destructor (possible crash when returning to menu)

r42:
- plans feature: draw things with the mouse to ease explanations in coop games (there are 2 levels of plan visibility : local company only or public)
- changed line style of vehicle route path

r41:
- "vegetation" mode adapts itself to baseset/NewGRF
- force realtime rendering of the map
- deduplicate code in industry tooltips
- route steps use grf resource instead of uint8 _ugly_array[]
- route steps support multiple stops at the same place (ex: "A -> B -> C -> B -> A" means 2 lines for B)

r40:
- added a gcc friendly PREFETCH_NTA macro (only 01_iterator-prefetch-tile.patch is affected)

r39:
- "Scan surroundings" now relies on an inlined iterator whom prefetches tiles (ViewportMapGetMostSignificantTileType() is 2 times faster than it was)

r38:
- fix compilation with gcc

r37:
- fix wrong stopover in case of an explicit order "go to nearest depot"

r36:
- adapted to codechanges r25262, r25263 & r25264 (linkgraph)

r35:
- adapted to codechanges r25018 & r25020

r34:
- fix scrolling viewport blending (GetBytesPerPixel != GetScreenDepth)

r33:
- adapted to codechange r24206

r32:
- add "scan surroundings" (replica of the idea behind SmallMapWindow::GetTileColours())
- better bridges & tunnels support at high zoom out levels (thanks to "scan surroundings")
- fix invalid order crash (related to stopovers and path)

r31:
- vehicle refit window is now handled for stopovers and path
- transfer focus to vehicle view when closing a window like orders or timetable
- prevent news from getting focused

r30:
- fix depot stopover (was not shown)
- show a vehicle's path

r29:
- show on map the steps of a vehicle's route (only when the focused window is related to a specific vehicle)
- cleanup 2 magic constants for extraviewport tooltips (nvp->pos_x/y)

r28:
- fix coordinates of scrolling viewport box on map
- fix keynames for hotkeys.cfg
- do not show hidden players' bridges and tunnels
- show where train stations are in map owner mode
- finally enable the use of owner's colour for bridges and tunnels

r27:
- add 2 global hotkeys equivalent of ctrl+mousewheel ("previous_map_mode"/PAGEUP and "next_map_mode"/PAGEDOWN) ; it affects the first window matching criteria (a viewport at map zoomlevel): first it checks the focused window then it falls back on the main viewport

r26:
- show where the scrolling viewport is on maps (the right-clicked and dragged one)

r25:
- all advanced settings are now in Interface->Display options->Viewport Map
- doubleclick on map: depending on adv. settings, it goes directly to zoom1X or it opens an extra viewport
- line buffer is dynamically adjusted to width

r24:
- ensure that sprites are not encoded for map zoomlevels

r23:
- fix the flickering in realtime rendering mode (related to colour_index_base)

r22:
- code cleanup
- fix minor graphic bug with slopes
- fix viewport refresh when showing/hiding stuff from smallmap controls
- adapted to feature r23670

r21:
- fix freeform graphic glitch
- added 2 Advanced Settings to show/hide bridges and tunnels

r20:
- slopes influence players' colour in owner mode
- bridges and tunnels are rendered (known bug: at least one end of the bridge/tunnel must be in the redrawn block)

r19:
- town names are shown up to 32X

r18:
- split patch in 3 parts
- in map mode, town names are shown in a tooltip
- fix extraviewport tooltips (feature r23316 related)

r17:
- adapted to feature r23316 ("Add ability to zoom in to 2x and 4x level")

r16:
- adapted to codechange r23091
- reworked and simplified filter for marking tile dirty

r15:
- interactions with smallmap's legend immediately affect viewports
- the "Industry chain -> Link to smallmap" button refresh all viewports in industry mode too
- industry tooltip is now enabled for all zoom levels (I just can't play without it anymore :) )
- fix text of Advanced Option "default_viewport_map_mode"

r14:
- fix tooltip (yes, again: r12 fix broke partially the "Length: x" tooltip)

r13:
- crashfix: I forgot some basic range checking

r12:
- crashfix: a tooltip keeps StringID but not the associated params (meaning with r11: one overlap, one redraw... one crash :S)

r11:
- added a tooltip to industry mode (production info)

r10:
- patch now following trunk (r22277)
- better sync between vehicles and ground

r9:
- fix vehicle trail
- slightly better performance

r8:
- enhanced rendering (with slopes)
- better handling of owned roads color
- partially fix vehicle trail (problem occuring in realtime mode only)
- realtime option moved from "Interaction" to "Display options"
- Advanced Option to enable/disable slopes
- Advanced Option to select default map mode

r7:
- replace the full refresh every n ticks by realtime
- filtering applied on the dirty tile setting system (reduce cpu usage)
- bugfix with 32bpp-anim (forgotten ::SetLine() in v6)
- option added in Advanced Settings -> Interaction -> Render viewport map in realtime (if not: 1:n ticks)

r6:
- code clean-up
- really fix the graphic glitch (colidx init related)

r5:
- minor graphic glitch corrected (vertical lines with wrong color)
- introduce "ctrl + mousewheel" to cycle through 3 map types:
1/ owner+contour
2/ industry
3/ vegetation

r4:
- secondary viewport draws what it should
- ground heightmap looks like what smallmap does
- vehicles are rendered
Last edited by MJP on 29 Jan 2015 22:59, edited 80 times in total.
SmatZ
OpenTTD Developer
OpenTTD Developer
Posts: 351
Joined: 03 Oct 2006 18:26
Location: Prague, Czech Republic
Contact:

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by SmatZ »

Hello,

when compiling this patch applied, I get link error:

/home/smatz/openttd/anon3/src/smallmap_gui.h:19:17: warning: inline function ‘TileType GetEffectiveTileType(TileIndex)’ used but never defined

[SRC] Linking openttd
viewport.o: In function `ViewportDoDraw(ViewPort const*, int, int, int, int)':
/home/smatz/openttd/anon3/src/viewport.cpp:1448: undefined reference to `GetEffectiveTileType(unsigned int)'
Image
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

Thank you for testing.
I used MSVC and it linked well but I suppose I should have removed the inline attribute of GetEffectiveTileType().
I have updated the patch accordingly.
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

By the way, would anyone know how to manage all these refresh messages caused apparently by window overlapping?

Put a secondary viewport above a high traffic junction and you'll see that the window gets redrawn a lot more than the minimum of 1 time every n ticks stated by ontick().
I tried to doublebuffer the window to prevent cpu stress but with no success: the result being clearly worse (by absolutely killing the scrolling smoothness).
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Alberth »

MJP wrote:By the way, would anyone know how to manage all these refresh messages caused apparently by window overlapping?
Extend Window::SetDirty() with code that detects that (part of) the dirtying is not visible, and thus can be skipped.
There are however also refreshes that should not be blocked (at least the full-screen refreshes, and possibly others as well).
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

Alberth wrote:Extend Window::SetDirty() with code that detects that (part of) the dirtying is not visible, and thus can be skipped.
I followed your advice and modified SetDirtyBlocks() so a window can't mark a block dirty it that block is under another window. It seems to work but in the end, I'm not sure if this is really needed.
Attachments
zoom64_v6_with_modified_gfx.cpp-SetDirtyBlocks.patch
(26.36 KiB) Downloaded 420 times
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

Well, of all the changes the v7 brings, I wonder what you (all openttd devs) think of the extension of MarkAllViewportsDirty() and if you see a better way to achieve that result?

(on a side note, I did the DirtyTileInfo flags really quickly and there are surely tons of errors in what I put on all the callers of MarkAllViewportsDirty(), it's draft quality :) )
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Zephyris »

Could I suggest changing the appearence of the terrain in the smallmap-style views? The sudden switch from shaded to gradient shaded (i.e. the normal tile graphics) to the contour shading (i.e. the smallmap-style display) is a bit ugly. Could you change the contour shading to a more normal-tile like one? (if that makes sense at all!)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Alberth »

MJP wrote:what you (all openttd devs) think of the extension of MarkAllViewportsDirty() and if you see a better way to achieve that result?
26KB is too much to figure out quickly, especially since zoom and redraw reduction are not related.

It is much better to keep separate things separately.
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

Zephyris> Do you mean showing slope orientation rather than altitude?

Alberth> Thank you for paying attention to my patch. I will try to make a separate one (I'm new to SVN and versioning in general).

At the moment I'm working on eliminating the trail behind vehicles and regarding that, I have another question. Here is what I did.

In the v7-ViewportDrawVehiclesOnMap(), z-pos of a vehicle is ignored so when redraw occurs with z-aware dpi coordinates, some vehicle's old white pixels are out and stay. To fix that: RemapCoords() get its z-pos instead of 0 and problem is gone.

But... z-aware vehicles on a flat map... well, not good ;) So in order to "resync" the ground with vehicles, I used a cheap approximation of z in VpGetSmallMapColor() (the correct method found in TranslateXYToTileCoord() takes way too much time).

At that point, I thought it was all fixed: no rogue white pixel on my 512*512 test map. Just to be sure, I check with another savegame on a 2048*2048 map and... Surprise ! Unwanted evil white pixels.
bug.png
bug.png (1013 Bytes) Viewed 37683 times
It happens only with vehicles going up (NE or NW gives the same). The 8px intervals shows the block below does not cross the dpi to redraw. This is something I fail to understand.
Attachments
zoom64_v8T.patch
(63.41 KiB) Downloaded 538 times
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Zephyris »

Zephyris> Do you mean showing slope orientation rather than altitude?
Yup, that's exactly what I mean, sorry I didn't explain it very clearly!
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Alberth »

Alberth> Thank you for paying attention to my patch. I will try to make a separate one (I'm new to SVN and versioning in general).
Reducing redraws may be useful to have a look at, although screen/window redraw is not significant for non-viewports, I think.

For version control, SVN is quite useless unless you have commit access. It is much more useful to use hg or git for your patches. It not only gives you commit access so you can actually do versioning, but they also have patch queues which is very useful for developing a sequence of patches stacked on top of each other.
(At least, I know hg has it, I am guessing git has it too.)
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by MJP »

Alberth> I've just installed TortoiseHg. It looks nice, I will get into it after the completion of my patch v8.

Zephyris> I tried to implement what you suggested. Tell me what you think of the following results:

1/ "old" heightmap:
heightmap.png
heightmap.png (23.23 KiB) Viewed 37584 times
2/ slopes:
slopes.png
slopes.png (31.92 KiB) Viewed 37584 times
3/ heightmap combined with slopes:
heightmap-and-slopes.png
heightmap-and-slopes.png (32.72 KiB) Viewed 37584 times
Personally, I find #3 to be very easy to read in 16X and 32X but it becomes a little messy in 64X.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by Zephyris »

MJP wrote:Zephyris> I tried to implement what you suggested. Tell me what you think of the following results:
Very very nice! I think the third one looks best, but as you say I can see it would get hard to read in the 64x zoom out. The second one is probably the clearest and would fit best into the zooming out sequence.
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Patch: zooming out a viewport up to 64X with smallmap st

Post by supermop »

Wonderful solution to the graphic issues!
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X (smallmap style)

Post by MJP »

Zephyris> The vegetation mode fits almost nicely in the zooming out sequence. But for my settings, I find the owner mode more useful and I keep it as a default (though it is an option now).

supermop> Thank you! I'm glad you like what's done here! :)
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X (smallmap style)

Post by MJP »

Added in r11, a useful tooltip for industry:
industry_tooltip.png
industry_tooltip.png (7.99 KiB) Viewed 37329 times
Note that in MouseOver() of extra-viewport (line 2084 of the patch r11), I had to use x-2 and y-16 to compensate for the window. Is there a proper way to replace those hardcoded values?
Attachments
industry_tooltip.png
industry_tooltip.png (65.5 KiB) Viewed 35428 times
Last edited by MJP on 22 Jan 2012 21:56, edited 1 time in total.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1728
Joined: 30 Mar 2005 09:43

Re: Patch: zooming out a viewport up to 64X (smallmap style)

Post by peter1138 »

This crashes with freeform edges enabled; it tries to read an out-of-bounds tile.
He's like, some kind of OpenTTD developer.
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X (smallmap style)

Post by MJP »

Thank you for testing.
Indeed it crashes. And fast. Basic range checking failure. There is one only thing to say: shame on me.
This will teach me what happens when I test only with --disable-assert.
It should be fixed in r13.
MJP
Engineer
Engineer
Posts: 116
Joined: 12 Mar 2011 19:01

Re: Patch: zooming out a viewport up to 64X // r17 for 23343

Post by MJP »

To use the extra zoom out levels, you need to change the new game setting "Maximum zoom out level" to 64x.
Attachments
max_zoom_out_level.png
max_zoom_out_level.png (2.55 KiB) Viewed 35428 times
Last edited by MJP on 22 Jan 2012 21:53, edited 1 time in total.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Amazon [Bot] and 4 guests