src/viewport.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6878 7d1ff2f621c7
child 10210 a2131f7a315d
equal deleted inserted replaced
10179:eec5a7dcbf61 10184:fcf5fb2548eb
     8 #include "tile_cmd.h"
     8 #include "tile_cmd.h"
     9 #include "gui.h"
     9 #include "gui.h"
    10 #include "spritecache.h"
    10 #include "spritecache.h"
    11 #include "landscape.h"
    11 #include "landscape.h"
    12 #include "viewport_func.h"
    12 #include "viewport_func.h"
    13 #include "station.h"
    13 #include "station_base.h"
    14 #include "town.h"
    14 #include "town.h"
    15 #include "signs.h"
    15 #include "signs_base.h"
       
    16 #include "signs_func.h"
    16 #include "waypoint.h"
    17 #include "waypoint.h"
    17 #include "variables.h"
    18 #include "variables.h"
    18 #include "train.h"
    19 #include "train.h"
    19 #include "roadveh.h"
    20 #include "roadveh.h"
    20 #include "vehicle_gui.h"
    21 #include "vehicle_gui.h"
    24 #include "strings_func.h"
    25 #include "strings_func.h"
    25 #include "zoom_func.h"
    26 #include "zoom_func.h"
    26 #include "vehicle_func.h"
    27 #include "vehicle_func.h"
    27 #include "player_func.h"
    28 #include "player_func.h"
    28 #include "settings_type.h"
    29 #include "settings_type.h"
       
    30 #include "station_func.h"
       
    31 #include "core/alloc_func.hpp"
    29 
    32 
    30 #include "table/sprites.h"
    33 #include "table/sprites.h"
    31 #include "table/strings.h"
    34 #include "table/strings.h"
    32 
    35 
    33 #define VIEWPORT_DRAW_MEM (65536 * 2)
    36 enum {
       
    37 	VIEWPORT_DRAW_MEM = (65536 * 2),
       
    38 	PARENT_LIST_SIZE  = 6144,
       
    39 };
    34 
    40 
    35 PlaceProc *_place_proc;
    41 PlaceProc *_place_proc;
    36 Point _tile_fract_coords;
    42 Point _tile_fract_coords;
    37 ZoomLevel _saved_scrollpos_zoom;
    43 ZoomLevel _saved_scrollpos_zoom;
    38 
    44 
   940  * @param *ti TileInfo Tile that is being drawn
   946  * @param *ti TileInfo Tile that is being drawn
   941  */
   947  */
   942 static void DrawTileSelection(const TileInfo *ti)
   948 static void DrawTileSelection(const TileInfo *ti)
   943 {
   949 {
   944 	/* Draw a red error square? */
   950 	/* Draw a red error square? */
   945 	if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
   951 	bool is_redsq = _thd.redsq != 0 && _thd.redsq == ti->tile;
   946 		DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
   952 	if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
   947 		return;
       
   948 	}
       
   949 
   953 
   950 	/* no selection active? */
   954 	/* no selection active? */
   951 	if (_thd.drawstyle == 0) return;
   955 	if (_thd.drawstyle == 0) return;
   952 
   956 
   953 	/* Inside the inner area? */
   957 	/* Inside the inner area? */
   977 				}
   981 				}
   978 			}
   982 			}
   979 			if (_thd.FSMportLayout == NULL) {
   983 			if (_thd.FSMportLayout == NULL) {
   980 				DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
   984 				DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
   981 			}
   985 			}
       
   986 			if (!is_redsq) DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE);
   982 		} else if (_thd.drawstyle & HT_POINT) {
   987 		} else if (_thd.drawstyle & HT_POINT) {
   983 			/* Figure out the Z coordinate for the single dot. */
   988 			/* Figure out the Z coordinate for the single dot. */
   984 			byte z = 0;
   989 			byte z = 0;
   985 			FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
   990 			FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
   986 			if (ti->tileh & SLOPE_N) {
   991 			if (ti->tileh & SLOPE_N) {
  1017 		}
  1022 		}
  1018 		return;
  1023 		return;
  1019 	}
  1024 	}
  1020 
  1025 
  1021 	/* Check if it's inside the outer area? */
  1026 	/* Check if it's inside the outer area? */
  1022 	if (_thd.outersize.x &&
  1027 	if (!is_redsq && _thd.outersize.x &&
  1023 			_thd.size.x < _thd.size.x + _thd.outersize.x &&
  1028 			_thd.size.x < _thd.size.x + _thd.outersize.x &&
  1024 			IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
  1029 			IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
  1025 			IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
  1030 			IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
  1026 		/* Draw a blue rect. */
  1031 		/* Draw a blue rect. */
  1027 		DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
  1032 		DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE);
  1249 static void ViewportAddSigns(DrawPixelInfo *dpi)
  1254 static void ViewportAddSigns(DrawPixelInfo *dpi)
  1250 {
  1255 {
  1251 	const Sign *si;
  1256 	const Sign *si;
  1252 	int left, top, right, bottom;
  1257 	int left, top, right, bottom;
  1253 
  1258 
  1254 	if (!HasBit(_display_opt, DO_SHOW_SIGNS))
  1259 	/* Signs are turned off or are invisible */
  1255 		return;
  1260 	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS)) return;
  1256 
  1261 
  1257 	left = dpi->left;
  1262 	left = dpi->left;
  1258 	top = dpi->top;
  1263 	top = dpi->top;
  1259 	right = left + dpi->width;
  1264 	right = left + dpi->width;
  1260 	bottom = top + dpi->height;
  1265 	bottom = top + dpi->height;
  1514 
  1519 
  1515 	do {
  1520 	do {
  1516 		uint16 colour;
  1521 		uint16 colour;
  1517 
  1522 
  1518 		if (ss->width != 0) {
  1523 		if (ss->width != 0) {
       
  1524 			/* Do not draw signs nor station names if they are set invisible */
       
  1525 			if (IsInvisibilitySet(TO_SIGNS) && ss->string != STR_2806) {
       
  1526 				ss = ss->next;
       
  1527 				continue;
       
  1528 			}
       
  1529 
  1519 			int x = UnScaleByZoom(ss->x, zoom) - 1;
  1530 			int x = UnScaleByZoom(ss->x, zoom) - 1;
  1520 			int y = UnScaleByZoom(ss->y, zoom) - 1;
  1531 			int y = UnScaleByZoom(ss->y, zoom) - 1;
  1521 			int bottom = y + 11;
  1532 			int bottom = y + 11;
  1522 			int w = ss->width;
  1533 			int w = ss->width;
  1523 
  1534 
  1564 	int mask;
  1575 	int mask;
  1565 	int x;
  1576 	int x;
  1566 	int y;
  1577 	int y;
  1567 	DrawPixelInfo *old_dpi;
  1578 	DrawPixelInfo *old_dpi;
  1568 
  1579 
  1569 	byte mem[VIEWPORT_DRAW_MEM];
  1580 	SmallStackSafeStackAlloc<byte, VIEWPORT_DRAW_MEM> mem;
  1570 	ParentSpriteToDraw *parent_list[6144];
  1581 	SmallStackSafeStackAlloc<ParentSpriteToDraw*, PARENT_LIST_SIZE> parent_list;
  1571 
  1582 
  1572 	_cur_vd = &vd;
  1583 	_cur_vd = &vd;
  1573 
  1584 
  1574 	old_dpi = _cur_dpi;
  1585 	old_dpi = _cur_dpi;
  1575 	_cur_dpi = &vd.dpi;
  1586 	_cur_dpi = &vd.dpi;
  1589 	y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
  1600 	y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
  1590 
  1601 
  1591 	vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
  1602 	vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
  1592 
  1603 
  1593 	vd.parent_list = parent_list;
  1604 	vd.parent_list = parent_list;
  1594 	vd.eof_parent_list = endof(parent_list);
  1605 	vd.eof_parent_list = parent_list.EndOf();
  1595 	vd.spritelist_mem = mem;
  1606 	vd.spritelist_mem = mem;
  1596 	vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT);
  1607 	vd.eof_spritelist_mem = mem.EndOf() - sizeof(LARGEST_SPRITELIST_STRUCT);
  1597 	vd.last_string = &vd.first_string;
  1608 	vd.last_string = &vd.first_string;
  1598 	vd.first_string = NULL;
  1609 	vd.first_string = NULL;
  1599 	vd.last_tile = &vd.first_tile;
  1610 	vd.last_tile = &vd.first_tile;
  1600 	vd.first_tile = NULL;
  1611 	vd.first_tile = NULL;
  1601 
  1612 
  1977 
  1988 
  1978 static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
  1989 static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
  1979 {
  1990 {
  1980 	const Sign *si;
  1991 	const Sign *si;
  1981 
  1992 
  1982 	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || _current_player == PLAYER_SPECTATOR) return false;
  1993 	/* Signs are turned off, or they are transparent and invisibility is ON, or player is a spectator */
       
  1994 	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS) || _current_player == PLAYER_SPECTATOR) return false;
  1983 
  1995 
  1984 	switch (vp->zoom) {
  1996 	switch (vp->zoom) {
  1985 		case ZOOM_LVL_NORMAL:
  1997 		case ZOOM_LVL_NORMAL:
  1986 			x = x - vp->left + vp->virtual_left;
  1998 			x = x - vp->left + vp->virtual_left;
  1987 			y = y - vp->top  + vp->virtual_top;
  1999 			y = y - vp->top  + vp->virtual_top;