src/smallmap_gui.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    23 #include "player.h"
    23 #include "player.h"
    24 #include "vehicle.h"
    24 #include "vehicle.h"
    25 #include "town.h"
    25 #include "town.h"
    26 #include "sound.h"
    26 #include "sound.h"
    27 #include "variables.h"
    27 #include "variables.h"
       
    28 #include "blitter/factory.hpp"
    28 
    29 
    29 static const Widget _smallmap_widgets[] = {
    30 static const Widget _smallmap_widgets[] = {
    30 {  WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
    31 {  WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
    31 {   WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   433,     0,    13, STR_00B0_MAP,            STR_018C_WINDOW_TITLE_DRAG_THIS},
    32 {   WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   433,     0,    13, STR_00B0_MAP,            STR_018C_WINDOW_TITLE_DRAG_THIS},
    32 { WWT_STICKYBOX,     RESIZE_LR,    13,   434,   445,     0,    13, 0x0,                     STR_STICKY_BUTTON},
    33 { WWT_STICKYBOX,     RESIZE_LR,    13,   434,   445,     0,    13, 0x0,                     STR_STICKY_BUTTON},
   165 	_legend_routes,
   166 	_legend_routes,
   166 	_legend_vegetation,
   167 	_legend_vegetation,
   167 	_legend_land_owners,
   168 	_legend_land_owners,
   168 };
   169 };
   169 
   170 
   170 #if defined(OTTD_ALIGNMENT)
   171 static inline void WRITE_PIXELS(void *d, uint32 val)
   171 	static inline void WRITE_PIXELS(Pixel* d, uint32 val)
   172 {
   172 	{
   173 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   173 #	if defined(TTD_BIG_ENDIAN)
   174 	uint8 *val8 = (uint8 *)&val;
   174 		d[0] = GB(val, 24, 8);
   175 
   175 		d[1] = GB(val, 16, 8);
   176 	blitter->SetPixel(d, 0, 0, val8[0]);
   176 		d[2] = GB(val,  8, 8);
   177 	blitter->SetPixel(d, 1, 0, val8[1]);
   177 		d[3] = GB(val,  0, 8);
   178 	blitter->SetPixel(d, 2, 0, val8[2]);
   178 #	elif defined(TTD_LITTLE_ENDIAN)
   179 	blitter->SetPixel(d, 3, 0, val8[3]);
   179 		d[0] = GB(val,  0, 8);
   180 }
   180 		d[1] = GB(val,  8, 8);
   181 
   181 		d[2] = GB(val, 16, 8);
   182 static inline void WRITE_PIXELS_OR(void *d, uint32 val)
   182 		d[3] = GB(val, 24, 8);
   183 {
   183 #	endif
   184 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   184 	}
   185 	uint8 *val8 = (uint8 *)&val;
   185 
   186 
   186 /* need to use OR, otherwise we will overwrite the wrong pixels at the edges :( */
   187 	blitter->SetPixelIfEmpty(d, 0, 0, val8[0]);
   187 	static inline void WRITE_PIXELS_OR(Pixel *d, uint32 val)
   188 	blitter->SetPixelIfEmpty(d, 1, 0, val8[1]);
   188 	{
   189 	blitter->SetPixelIfEmpty(d, 2, 0, val8[2]);
   189 #	if defined(TTD_BIG_ENDIAN)
   190 	blitter->SetPixelIfEmpty(d, 3, 0, val8[3]);
   190 		d[0] |= GB(val, 24, 8);
   191 }
   191 		d[1] |= GB(val, 16, 8);
       
   192 		d[2] |= GB(val,  8, 8);
       
   193 		d[3] |= GB(val,  0, 8);
       
   194 #	elif defined(TTD_LITTLE_ENDIAN)
       
   195 		d[0] |= GB(val,  0, 8);
       
   196 		d[1] |= GB(val,  8, 8);
       
   197 		d[2] |= GB(val, 16, 8);
       
   198 		d[3] |= GB(val, 24, 8);
       
   199 #	endif
       
   200 	}
       
   201 #else
       
   202 #	define WRITE_PIXELS(dst, val)   *(uint32*)(dst) = (val);
       
   203 #	define WRITE_PIXELS_OR(dst,val) *(uint32*)(dst) |= (val);
       
   204 #endif
       
   205 
   192 
   206 #define MKCOLOR(x) TO_LE32X(x)
   193 #define MKCOLOR(x) TO_LE32X(x)
   207 
   194 
   208 /* Height encodings; 16 levels XXX - needs updating for more/finer heights! */
   195 /* Height encodings; 16 levels XXX - needs updating for more/finer heights! */
   209 static const uint32 _map_height_bits[16] = {
   196 static const uint32 _map_height_bits[16] = {
   294  * @param reps Number of lines to draw
   281  * @param reps Number of lines to draw
   295  * @param mask ?
   282  * @param mask ?
   296  * @param proc Pointer to the colour function
   283  * @param proc Pointer to the colour function
   297  * @see GetSmallMapPixels(TileIndex)
   284  * @see GetSmallMapPixels(TileIndex)
   298  */
   285  */
   299 static void DrawSmallMapStuff(Pixel *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   286 static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   300 {
   287 {
   301 	Pixel *dst_ptr_end = _screen.dst_ptr + _screen.width * _screen.height - _screen.width;
   288 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
       
   289 	void *dst_ptr_end = blitter->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
   302 
   290 
   303 	do {
   291 	do {
   304 		/* check if the tile (xc,yc) is within the map range */
   292 		/* check if the tile (xc,yc) is within the map range */
   305 		if (xc < MapMaxX() && yc < MapMaxY()) {
   293 		if (xc < MapMaxX() && yc < MapMaxY()) {
   306 			/* check if the dst pointer points to a pixel inside the screen buffer */
   294 			/* check if the dst pointer points to a pixel inside the screen buffer */
   307 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   295 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   308 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   296 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   309 		}
   297 		}
   310 	/* switch to next tile in the column */
   298 	/* switch to next tile in the column */
   311 	} while (xc++, yc++, dst += pitch, --reps != 0);
   299 	} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
   312 }
   300 }
   313 
   301 
   314 
   302 
   315 static inline TileType GetEffectiveTileType(TileIndex tile)
   303 static inline TileType GetEffectiveTileType(TileIndex tile)
   316 {
   304 {
   526  * @param type type of map requested (vegetation, owners, routes, etc)
   514  * @param type type of map requested (vegetation, owners, routes, etc)
   527  * @param show_towns true if the town names should be displayed, false if not.
   515  * @param show_towns true if the town names should be displayed, false if not.
   528  */
   516  */
   529 static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
   517 static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
   530 {
   518 {
       
   519 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   531 	DrawPixelInfo *old_dpi;
   520 	DrawPixelInfo *old_dpi;
   532 	int dx,dy, x, y, x2, y2;
   521 	int dx,dy, x, y, x2, y2;
   533 	Pixel *ptr;
   522 	void *ptr;
   534 	int tile_x;
   523 	int tile_x;
   535 	int tile_y;
   524 	int tile_y;
   536 	ViewPort *vp;
   525 	ViewPort *vp;
   537 
   526 
   538 	old_dpi = _cur_dpi;
   527 	old_dpi = _cur_dpi;
   580 			tile_x--;
   569 			tile_x--;
   581 			tile_y++;
   570 			tile_y++;
   582 		}
   571 		}
   583 	}
   572 	}
   584 
   573 
   585 	ptr = dpi->dst_ptr - dx - 4;
   574 	ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
   586 	x = - dx - 4;
   575 	x = - dx - 4;
   587 	y = 0;
   576 	y = 0;
   588 
   577 
   589 	for (;;) {
   578 	for (;;) {
   590 		uint32 mask = 0xFFFFFFFF;
   579 		uint32 mask = 0xFFFFFFFF;
   607 		}
   596 		}
   608 
   597 
   609 		/* number of lines */
   598 		/* number of lines */
   610 		reps = (dpi->height - y + 1) / 2;
   599 		reps = (dpi->height - y + 1) / 2;
   611 		if (reps > 0) {
   600 		if (reps > 0) {
   612 //			assert(ptr >= dpi->dst_ptr);
       
   613 			DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[type]);
   601 			DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[type]);
   614 		}
   602 		}
   615 
   603 
   616 skip_column:
   604 skip_column:
   617 		if (y == 0) {
   605 		if (y == 0) {
   618 			tile_y++;
   606 			tile_y++;
   619 			y++;
   607 			y++;
   620 			ptr += dpi->pitch;
   608 			ptr = blitter->MoveTo(ptr, 0, 1);
   621 		} else {
   609 		} else {
   622 			tile_x--;
   610 			tile_x--;
   623 			y--;
   611 			y--;
   624 			ptr -= dpi->pitch;
   612 			ptr = blitter->MoveTo(ptr, 0, -1);
   625 		}
   613 		}
   626 		ptr += 2;
   614 		ptr = blitter->MoveTo(ptr, 2, 0);
   627 		x += 2;
   615 		x += 2;
   628 	}
   616 	}
   629 
   617 
   630 	/* draw vehicles? */
   618 	/* draw vehicles? */
   631 	if (type == 0 || type == 1) {
   619 	if (type == 0 || type == 1) {
   664 					if (x != dpi->width - 1) continue;
   652 					if (x != dpi->width - 1) continue;
   665 					skip = true;
   653 					skip = true;
   666 				}
   654 				}
   667 
   655 
   668 				/* Calculate pointer to pixel and the color */
   656 				/* Calculate pointer to pixel and the color */
   669 				ptr = dpi->dst_ptr + y * dpi->pitch + x;
       
   670 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   657 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   671 
   658 
   672 				/* And draw either one or two pixels depending on clipping */
   659 				/* And draw either one or two pixels depending on clipping */
   673 				ptr[0] = color;
   660 				blitter->SetPixel(dpi->dst_ptr, x, y, color);
   674 				if (!skip) ptr[1] = color;
   661 				if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
   675 			}
   662 			}
   676 		}
   663 		}
   677 	}
   664 	}
   678 
   665 
   679 	if (show_towns) {
   666 	if (show_towns) {