MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RebuildColourIndexIfNecessary

Method RebuildColourIndexIfNecessary

src/smallmap_gui.cpp:745–765  ·  view source on GitHub ↗

* Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightlevel. */

Source from the content-addressed store, hash-verified

743 * Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightlevel.
744 */
745 void RebuildColourIndexIfNecessary()
746 {
747 /* Rebuild colour indices if necessary. */
748 if (SmallMapWindow::map_height_limit == _settings_game.construction.map_height_limit) return;
749
750 for (auto &heightmap_scheme : _heightmap_schemes) {
751 /* The heights go from 0 up to and including maximum. */
752 size_t heights = _settings_game.construction.map_height_limit + 1;
753 heightmap_scheme.height_colours.resize(heights);
754
755 for (size_t z = 0; z < heights; z++) {
756 size_t access_index = (heightmap_scheme.height_colours_base.size() * z) / heights;
757
758 /* Choose colour by mapping the range (0..max heightlevel) on the complete colour table. */
759 heightmap_scheme.height_colours[z] = heightmap_scheme.height_colours_base[access_index];
760 }
761 }
762
763 SmallMapWindow::map_height_limit = _settings_game.construction.map_height_limit;
764 BuildLandLegend();
765 }
766
767 /**
768 * Get the number of rows in the legend from the number of columns. Those

Callers 2

SmallMapWindowMethod · 0.95
OnInvalidateDataMethod · 0.95

Calls 3

BuildLandLegendFunction · 0.85
resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected