src/landscape.cpp
changeset 10438 51bff16a04c9
parent 10311 44b12fe10656
equal deleted inserted replaced
10437:6d64230b9fb9 10438:51bff16a04c9
   652 	return (success) ? cost : CMD_ERROR;
   652 	return (success) ? cost : CMD_ERROR;
   653 }
   653 }
   654 
   654 
   655 
   655 
   656 TileIndex _cur_tileloop_tile;
   656 TileIndex _cur_tileloop_tile;
   657 #define TILELOOP_BITS 4
   657 #define TILELOOP_BITS 1
   658 #define TILELOOP_SIZE (1 << TILELOOP_BITS)
   658 #define TILELOOP_SIZE (1 << TILELOOP_BITS)
   659 #define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
   659 #define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
   660 #define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
   660 #define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
   661 
   661 
   662 void RunTileLoop()
   662 void RunTileLoop()
   663 {
   663 {
   664 	TileIndex tile = _cur_tileloop_tile;
   664 	TileIndex tile = _cur_tileloop_tile;
   665 
   665 
   666 	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
   666 	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
   667 	uint count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
   667 	uint count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
       
   668 
   668 	do {
   669 	do {
   669 		_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
   670 		_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
   670 
   671 
   671 		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
   672 		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
   672 			tile += TILELOOP_SIZE; // no overflow
   673 			tile += TILELOOP_SIZE; // no overflow
   673 		} else {
   674 		} else {
   674 			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
   675 			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
   675 		}
   676 		}
   676 	} while (--count != 0);
   677 	} while (count && --count != 0);
       
   678 
   677 	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
   679 	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
   678 
   680 
   679 	tile += 9;
   681 	tile += 9;
   680 	if (tile & TILELOOP_CHKMASK) {
   682 	if (tile & ~TILELOOP_ASSERTMASK) {
   681 		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
   683 		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
   682 	}
   684 	}
   683 	_cur_tileloop_tile = tile;
   685 	_cur_tileloop_tile = tile;
   684 }
   686 }
   685 
   687