Please.
I don't know if I am on correct way.
Works baddly, as it loads 2x2 tile, its pops up on screen when you is coming from bottom or right.
Code: Select all
void updateMap(VDPPlane plane, TileMap *tileMap, s16 xt, s16 yt)
{
	s16 curPosX = mapMetaTilePosX[plane];
	s16 curPosY = mapMetaTilePosY[plane];
	s16 deltaX = xt - curPosX;
	s16 deltaY = yt - curPosY;
	u8 palleteBG = PAL0;
	// no update --> exit
	if ((deltaX == 0) && (deltaY == 0))
		return;
	SYS_disableInts();
	// many row/column updates ? --> better to do a full screen update
	if ((abs(deltaX * 2) + abs(deltaY)) > 20)
	{
		VDP_setTileMapEx(plane, tileMap, TILE_ATTR_FULL(palleteBG, FALSE, FALSE, FALSE, bgBaseTileIndex[plane]),
						 xt & 0x003F, yt & 0x001F, xt, yt, 42, 30, DMA_QUEUE);
	}
	else
	{
		if (indBarrel == 0)
		{
			VDP_loadTileSet(barrel_tile.tileset, ind, DMA_QUEUE);
			mapBarrel = unpackTileMap(barrel_tile.tilemap, NULL);
			indBarrel = ind;
			ind = barrel_tile.tileset->numTile;
		}
		if (xt <= 32)
		{
			if (deltaX > 0)
			{
				// need to update map column on right
				while (deltaX--)
				{
					VDP_setTileMapColumnEx(plane, tileMap, TILE_ATTR_FULL(palleteBG, FALSE, FALSE, FALSE, bgBaseTileIndex[plane]),
										   (curPosX + 42) & 0x3F, curPosX + 42, yt, 30, DMA_QUEUE);
					if (plane == BG_A)
					{
						for (u8 i = 0; i < 30; i++)
						{
							if (groundGrid[curPosX + 42][yt + i] == OBJECT_BARREL)
							{
								VDP_setTileMapEx(BG_A, mapBarrel, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, indBarrel), curPosX + 42, yt + i, 0, 0, 2, 2, DMA_QUEUE);
							}
						}
					}
					curPosX++;
				}
			}
			else if (deltaX < 0)
			{
				// need to update map column on left
				while (deltaX++)
				{
					curPosX--;
					VDP_setTileMapColumnEx(plane, tileMap, TILE_ATTR_FULL(palleteBG, FALSE, FALSE, FALSE, bgBaseTileIndex[plane]),
										   curPosX & 0x3F, curPosX, yt, 30, DMA_QUEUE);
					if (plane == BG_A)
					{
						for (u8 i = 0; i < 30; i++)
						{
							if (groundGrid[curPosX][yt + i] == OBJECT_BARREL)
							{
								VDP_setTileMapEx(BG_A, mapBarrel, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, indBarrel), curPosX, yt + i, 0, 0, 2, 2, DMA_QUEUE);
							}
						}
					}
				}
			}
		}
		if (deltaY > 0)
		{
			// need to update map row on bottom
			while (deltaY--)
			{
				VDP_setTileMapRowEx(plane, tileMap, TILE_ATTR_FULL(palleteBG, FALSE, FALSE, FALSE, bgBaseTileIndex[plane]),
									(curPosY + 30) & 0x1F, xt, curPosY + 30, 42, DMA_QUEUE);
				if (plane == BG_A)
				{
					for (u8 i = 0; i < 42; i++)
					{
						if (groundGrid[xt + i][curPosY + 30] == OBJECT_BARREL)
						{
							VDP_setTileMapEx(BG_A, mapBarrel, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, indBarrel), xt + i, curPosY + 30, 0, 0, 2, 2, DMA_QUEUE);
						}
					}
				}
				curPosY++;
			}
		}
		else if (deltaY < 0)
		{
			// need to update map row on top
			while (deltaY++)
			{
				curPosY--;
				VDP_setTileMapRowEx(plane, tileMap, TILE_ATTR_FULL(palleteBG, FALSE, FALSE, FALSE, bgBaseTileIndex[plane]),
									curPosY & 0x1F, xt, curPosY, 42, DMA_QUEUE);
				if (plane == BG_A)
				{
					for (u8 i = 0; i < 42; i++)
					{
						if (groundGrid[xt + i][curPosY] == OBJECT_BARREL)
						{
							VDP_setTileMapEx(BG_A, mapBarrel, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, indBarrel), xt + i, curPosY, 0, 0, 2, 2, DMA_QUEUE);
						}
					}
				}
			}
		}
	}
	SYS_enableInts();
	mapMetaTilePosX[plane] = xt;
	mapMetaTilePosY[plane] = yt;
}