Merge branch 'master' into enhanced_viewport_overlay

Notes on conflict resolution:
* MarkTileDirtyByTile gained an extra param on both sides of the merge
  Move bridge level offset to be after zoom level param, as it's used less.
* Add zoom level params to MarkBridgeDirty functions
* Fix undefined behaviour in colour_index cycling in ViewportMapDraw

Conflicts:
	src/clear_cmd.cpp
	src/pbs.cpp
	src/rail_cmd.cpp
	src/toolbar_gui.cpp
	src/train_cmd.cpp
	src/vehicle.cpp
	src/viewport.cpp
	src/viewport_func.h
This commit is contained in:
Jonathan G Rennison
2015-08-05 21:25:13 +01:00
220 changed files with 5428 additions and 4324 deletions

View File

@@ -29,6 +29,8 @@
#include "table/strings.h"
#include <bitset>
#include "safeguards.h"
static int _smallmap_industry_count; ///< Number of used industries
@@ -167,7 +169,7 @@ void BuildIndustriesLegend()
uint j = 0;
/* Add each name */
for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
IndustryType ind = _sorted_industry_types[i];
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (indsp->enabled) {
@@ -752,7 +754,7 @@ void SmallMapWindow::DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) co
if (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) continue;
/* Remap into flat coordinates. */
Point pt = this->RemapTile(v->x_pos / TILE_SIZE, v->y_pos / TILE_SIZE);
Point pt = this->RemapTile(v->x_pos / (int)TILE_SIZE, v->y_pos / (int)TILE_SIZE);
int y = pt.y - dpi->top;
if (!IsInsideMM(y, 0, dpi->height)) continue; // y is out of bounds.
@@ -804,30 +806,6 @@ void SmallMapWindow::DrawTowns(const DrawPixelInfo *dpi) const
}
}
/**
* Convert a coordinate of the viewport to essentially a tile on the map,
* taking care of the different location due to height.
* @param viewport_coord The coordinate in the viewport.
* @return The tile location.
*/
Point SmallMapWindow::GetSmallMapCoordIncludingHeight(Point viewport_coord) const
{
/* First find out which tile would be there if we ignore height */
Point pt = InverseRemapCoords(viewport_coord.x, viewport_coord.y);
Point pt_without_height = {pt.x / TILE_SIZE, pt.y / TILE_SIZE};
/* Problem: There are mountains. So the tile actually displayed at the given position
* might be the high mountain of 30 tiles south.
* Unfortunately, there is no closed formula for finding such a tile.
* We call GetRowAtTile originally implemented for the viewport code, which performs
* a interval search. For details, see its documentation. */
int row_without_height = pt_without_height.x + pt_without_height.y;
int row_with_height = GetRowAtTile(viewport_coord.y, pt_without_height, false);
int row_offset = row_with_height - row_without_height;
Point pt_with_height = {pt_without_height.x + row_offset / 2, pt_without_height.y + row_offset / 2};
return pt_with_height;
}
/**
* Adds map indicators to the smallmap.
*/
@@ -836,15 +814,13 @@ void SmallMapWindow::DrawMapIndicators() const
/* Find main viewport. */
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
Point upper_left_viewport_coord = {vp->virtual_left, vp->virtual_top};
Point upper_left_small_map_coord = GetSmallMapCoordIncludingHeight(upper_left_viewport_coord);
Point upper_left = this->RemapTile(upper_left_small_map_coord.x, upper_left_small_map_coord.y);
Point upper_left_smallmap_coord = TranslateXYToTileCoord(vp, vp->left, vp->top, false);
Point lower_right_smallmap_coord = TranslateXYToTileCoord(vp, vp->left + vp->width - 1, vp->top + vp->height - 1, false);
Point upper_left = this->RemapTile(upper_left_smallmap_coord.x / (int)TILE_SIZE, upper_left_smallmap_coord.y / (int)TILE_SIZE);
upper_left.x -= this->subscroll;
Point lower_right_viewport_coord = {vp->virtual_left + vp->virtual_width, vp->virtual_top + vp->virtual_height};
Point lower_right_smallmap_coord = GetSmallMapCoordIncludingHeight(lower_right_viewport_coord);
Point lower_right = this->RemapTile(lower_right_smallmap_coord.x, lower_right_smallmap_coord.y);
/* why do we do this? in my tests subscroll was zero */
Point lower_right = this->RemapTile(lower_right_smallmap_coord.x / (int)TILE_SIZE, lower_right_smallmap_coord.y / (int)TILE_SIZE);
lower_right.x -= this->subscroll;
SmallMapWindow::DrawVertMapIndicator(upper_left.x, upper_left.y, lower_right.y);
@@ -1321,24 +1297,7 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
int sub;
pt = this->PixelToTile(pt.x - wid->pos_x, pt.y - wid->pos_y, &sub);
pt = RemapCoords(this->scroll_x + pt.x * TILE_SIZE + this->zoom * (TILE_SIZE - sub * TILE_SIZE / 4),
this->scroll_y + pt.y * TILE_SIZE + sub * this->zoom * TILE_SIZE / 4, 0);
/* correct y coordinate according to the height level at the chosen tile
* - so far we assumed height zero. Calculations here according to
* TranslateXYToTileCoord in viewport.cpp */
Point pt_scaled = {pt.x / (int)(4 * TILE_SIZE), pt.y / (int)(2 * TILE_SIZE)};
Point tile_coord = {pt_scaled.y - pt_scaled.x, pt_scaled.y + pt_scaled.x};
if (tile_coord.x >= 0 && tile_coord.y >= 0
&& tile_coord.x < (int)MapMaxX() && tile_coord.y < (int)MapMaxY()) {
int clicked_tile_height = TileHeight(TileXY(tile_coord.x, tile_coord.y));
pt.y -= clicked_tile_height * TILE_HEIGHT;
}
w->viewport->follow_vehicle = INVALID_VEHICLE;
w->viewport->dest_scrollpos_x = pt.x - (w->viewport->virtual_width >> 1);
w->viewport->dest_scrollpos_y = pt.y - (w->viewport->virtual_height >> 1);
ScrollWindowTo(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, -1, w);
this->SetDirty();
break;
@@ -1460,11 +1419,11 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
break;
case 0: {
extern uint64 _displayed_industries;
extern std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
for (int i = 0; i != _smallmap_industry_count; i++) {
_legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].type);
_legend_from_industries[i].show_on_map = _displayed_industries.test(_legend_from_industries[i].type);
}
break;
}
@@ -1572,19 +1531,12 @@ void SmallMapWindow::SetNewScroll(int sx, int sy, int sub)
*/
void SmallMapWindow::SmallMapCenterOnCurrentPos()
{
/* Goal: Given the viewport coordinates of the middle of the map window, find
* out which tile is displayed there. */
/* First find out which tile would be there if we ignore height */
const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
Point viewport_center = {vp->virtual_left + vp->virtual_width / 2, vp->virtual_top + vp->virtual_height / 2};
Point pt_with_height = GetSmallMapCoordIncludingHeight(viewport_center);
/* And finally scroll to that position. */
Point viewport_center = TranslateXYToTileCoord(vp, vp->left + vp->width / 2, vp->top + vp->height / 2);
int sub;
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
Point sxy = this->ComputeScroll(pt_with_height.x, pt_with_height.y,
Point sxy = this->ComputeScroll(viewport_center.x / (int)TILE_SIZE, viewport_center.y / (int)TILE_SIZE,
max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
this->SetNewScroll(sxy.x, sxy.y, sub);
this->SetDirty();