[PATCH] Make pieces simpler and remove unused functions

Thomas Horsten thomas@hidden
Sat Jan 10 14:23:15 CET 2009


Signed-off-by: Thomas Horsten <thomas@hidden>
---
 tools/minitris.c |  173 ++++-------------------------------------------------
 1 files changed, 13 insertions(+), 160 deletions(-)

diff --git a/tools/minitris.c b/tools/minitris.c
index 5b84886..e3016e7 100644
--- a/tools/minitris.c
+++ b/tools/minitris.c
@@ -34,168 +34,23 @@ HPEN null_pen;
 
 HWND hwnd;
 
-const char piece[] = {
+const unsigned short piece[] = {
 // straight
-	"  X "
-	"  X "
-	"  X "
-	"  X "
-
-	"    "
-	"    "
-	"XXXX"
-	"    "
-
-	" X  "
-	" X  "
-	" X  "
-	" X  "
-
-	"    "
-	"XXXX"
-	"    "
-	"    "
-
+	0x2222,
 // bent left
-	" XX "
-	"  X "
-	"  X "
-	"    "
-
-	"    "
-	" XXX"
-	" X  "
-	"    "
-
-	"    "
-	" X  "
-	" X  "
-	" XX "
-
-	"    "
-	"  X "
-	"XXX "
-	"    "
-
+	0x6220,
 // bent right
-	"    "
-	" XX "
-	" X  "
-	" X  "
-
-	"    "
-	"X   "
-	"XXX "
-	"    "
-
-	"    "
-	" X  "
-	" X  "
-	"XX  "
-
-	"    "
-	"    "
-	"XXX "
-	"  X "
-
+	0x0644,
 // T shaped
-	"    "
-	"XXX "
-	" X  "
-	"    "
-
-	"    "
-	" X  "
-	" XX "
-	" X  "
-
-	"    "
-	" X  "
-	"XXX "
-	"    "
-
-	"    "
-	" X  "
-	"XX  "
-	" X  "
-
+	0x0e40,
 // dogleg left
-	"    "
-	"    "
-	" XX "
-	"XX  "
-
-	"    "
-	" X  "
-	" XX "
-	"  X "
-
-	"    "
-	" XX "
-	"XX  "
-	"    "
-
-	"    "
-	"X   "
-	"XX  "
-	" X  "
-
+	0x006c,
 // dogleg right
-	"    "
-	"    "
-	"XX  "
-	" XX "
-
-	"    "
-	"  X "
-	" XX "
-	" X  "
-
-	"    "
-	"XX  "
-	" XX "
-	"    "
-
-	"    "
-	" X  "
-	"XX  "
-	"X   "
-
+	0x00c6,
 // square
-	"    "
-	" XX "
-	" XX "
-	"    "
-
-	"    "
-	" XX "
-	" XX "
-	"    "
-
-	"    "
-	" XX "
-	" XX "
-	"    "
-
-	"    "
-	" XX "
-	" XX "
-	"    "
+	0x0660,
 };
 
-#undef max
-#undef min
-
-static inline int max( int x, int y )
-{
-	return x<y?y:x;
-}
-
-static inline int min( int x, int y )
-{
-	return x>y?y:x;
-}
-
 ULONG *get_block_ptr( int x, int y )
 {
 	if (x < 0 || x >= board_width)
@@ -215,7 +70,11 @@ void draw_block( HDC hdc, int x, int y )
 		 (x+1)*block_size - 1, (y+1)*block_size - 1 );
 }
 
-BOOL piece_has_block( int type, int orientation, int x, int y );
+BOOL piece_has_block( int type, int orientation, int x, int y )
+{
+	int bit = (orientation & 1) ? (x+4*y) : (3-y+4*x);
+	return (piece[type] & ((orientation & 2) ? (0x8000 >> bit):(1 << bit) )) != 0;
+}
 
 void draw_next_piece_preview(HDC hdc)
 {
@@ -293,11 +152,6 @@ void set_block( int x, int y, int color )
 		*ptr = color;
 }
 
-BOOL piece_has_block( int type, int orientation, int x, int y )
-{
-	return piece[ type*64 + orientation*16 + y*4 + x] == 'X';
-}
-
 void block_at_cursor( int type, int orientation, int color )
 {
 	int i, j;
@@ -391,7 +245,6 @@ BOOL do_rotate()
 	return piece_orientation == new_orientation;
 }
 
-
 BYTE get_random_number()
 {
 	ULONG ticks = GetTickCount();
-- 
1.5.6.5



More information about the ring3k mailing list