Got rid of a lot of extra PD_ stuff.
This commit is contained in:
		
							
								
								
									
										29
									
								
								Pieces.cpp
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								Pieces.cpp
									
									
									
									
									
								
							@@ -418,35 +418,10 @@ unsigned PD_PieceWidth(const PieceData &data)
 | 
				
			|||||||
	return rtn;
 | 
						return rtn;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned PD_PieceHeight(const Piece &piece, Rotation rotation)
 | 
					void PD_DrawPiece(const PieceData &data, int y, int x, int color)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	switch(rotation)
 | 
						attrset(COLOR_PAIR(static_cast<int>(color) % 8));
 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
	case Rotation::ROTATION_NONE:
 | 
					 | 
				
			||||||
	case Rotation::ROTATION_180:
 | 
					 | 
				
			||||||
		return pieces.at(piece).size();
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case Rotation::ROTATION_90:
 | 
					 | 
				
			||||||
	case Rotation::ROTATION_270:
 | 
					 | 
				
			||||||
		return PD_PieceHeight(RotatePieceData(pieces.at(piece), Rotation::ROTATION_90));
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned PD_PieceWidth(const Piece &piece, Rotation rotation)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	size_t rtn = 0;
 | 
					 | 
				
			||||||
	for(auto row : pieces.at(piece))
 | 
					 | 
				
			||||||
		rtn = std::max(rtn, row.size());
 | 
					 | 
				
			||||||
	return rtn;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void PD_DrawPiece(const Piece &piece, int y, int x, Rotation rotation)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	attrset(COLOR_PAIR(static_cast<int>(piece) % 8));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	auto data = RotatePieceData(pieces.at(piece), rotation);
 | 
					 | 
				
			||||||
	for(size_t row = 0; row < data.size(); ++row)
 | 
						for(size_t row = 0; row < data.size(); ++row)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		for(size_t col = 0; col < data[row].size(); ++col)
 | 
							for(size_t col = 0; col < data[row].size(); ++col)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								Pieces.h
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								Pieces.h
									
									
									
									
									
								
							@@ -149,12 +149,8 @@ void DrawPiece(const Piece &piece, int y, int x,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
PieceData RotatePieceData(const PieceData &data, Rotation rotation);
 | 
					PieceData RotatePieceData(const PieceData &data, Rotation rotation);
 | 
				
			||||||
unsigned PD_PieceHeight(const PieceData &data);
 | 
					unsigned PD_PieceHeight(const PieceData &data);
 | 
				
			||||||
unsigned PD_PieceHeight(const Piece &piece,
 | 
					 | 
				
			||||||
                     Rotation rotation = Rotation::ROTATION_NONE);
 | 
					 | 
				
			||||||
unsigned PD_PieceWidth(const PieceData &data);
 | 
					unsigned PD_PieceWidth(const PieceData &data);
 | 
				
			||||||
unsigned PD_PieceWidth(const Piece &piece,
 | 
					void PD_DrawPiece(const PieceData &data, int y, int x, int color = 0);
 | 
				
			||||||
                    Rotation rotation = Rotation::ROTATION_NONE);
 | 
					
 | 
				
			||||||
void PD_DrawPiece(const Piece &piece, int y, int x,
 | 
					 | 
				
			||||||
                  Rotation rotation = Rotation::ROTATION_NONE);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								main.cpp
									
									
									
									
									
								
							@@ -38,8 +38,8 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				Piece piece = 0b111 & std::atoi(argv[input]);
 | 
									Piece piece = 0b111 & std::atoi(argv[input]);
 | 
				
			||||||
				PD_DrawPiece(piece, y, 1);
 | 
									PD_DrawPiece(pieces.at(piece), y, 1);
 | 
				
			||||||
				y += PD_PieceHeight(piece) + 1;
 | 
									y += PD_PieceHeight(pieces.at(piece)) + 1;
 | 
				
			||||||
			} catch(const std::exception &e) {
 | 
								} catch(const std::exception &e) {
 | 
				
			||||||
				mvaddstr(y, 1, "std::atoi error");
 | 
									mvaddstr(y, 1, "std::atoi error");
 | 
				
			||||||
				y += 2;
 | 
									y += 2;
 | 
				
			||||||
@@ -104,8 +104,9 @@ void DemoPieces()
 | 
				
			|||||||
		y = 2;
 | 
							y = 2;
 | 
				
			||||||
		for(auto i = 0; i < 8; ++i)
 | 
							for(auto i = 0; i < 8; ++i)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Piece piece = static_cast<Piece>(i);
 | 
								PieceData data = pieces.at(i);
 | 
				
			||||||
			PD_DrawPiece(piece, y, x, rotation);
 | 
								data = RotatePieceData(data, rotation);
 | 
				
			||||||
 | 
								PD_DrawPiece(data, y, x, i);
 | 
				
			||||||
			mvaddstr(y-1, x, "Piece");
 | 
								mvaddstr(y-1, x, "Piece");
 | 
				
			||||||
			mvaddstr(y-1, x + 6, std::to_string(i + 1).c_str());
 | 
								mvaddstr(y-1, x + 6, std::to_string(i + 1).c_str());
 | 
				
			||||||
			x += 12;
 | 
								x += 12;
 | 
				
			||||||
@@ -116,18 +117,25 @@ void DemoPieces()
 | 
				
			|||||||
		y = 10;
 | 
							y = 10;
 | 
				
			||||||
		for(auto i = 0; i < 8; ++i)
 | 
							for(auto i = 0; i < 8; ++i)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Piece piece = static_cast<Piece>(i);
 | 
								PieceData data = pieces.at(i);
 | 
				
			||||||
			PD_DrawPiece(piece, y, x, rotation);
 | 
								data = RotatePieceData(data, rotation);
 | 
				
			||||||
			x += PD_PieceWidth(piece, rotation) * 2 + 2;
 | 
								PD_DrawPiece(data, y, x, i);
 | 
				
			||||||
 | 
								x += PD_PieceWidth(data) * 2 + 2;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// Always same height apart, sharing first piece with same-width row:
 | 
							// Always same height apart, sharing first piece with same-width row:
 | 
				
			||||||
		x = 2;
 | 
							x = 2;
 | 
				
			||||||
		y = 10 + PD_PieceHeight(0, rotation) + 1;
 | 
							y = 10;
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								auto data = pieces.at(0);
 | 
				
			||||||
 | 
								data = RotatePieceData(data, rotation);
 | 
				
			||||||
 | 
								y += PD_PieceHeight(data) + 1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		for(auto i = 1; i < 8; ++i) // skip first
 | 
							for(auto i = 1; i < 8; ++i) // skip first
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Piece piece = static_cast<Piece>(i);
 | 
								PieceData data = pieces.at(i);
 | 
				
			||||||
			PD_DrawPiece(piece, y, x, rotation);
 | 
								data = RotatePieceData(data, rotation);
 | 
				
			||||||
			y += PD_PieceHeight(piece, rotation) + 1;
 | 
								PD_DrawPiece(data, y, x, i);
 | 
				
			||||||
 | 
								y += PD_PieceHeight(data) + 1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		getch();
 | 
							getch();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user