(svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
authortron
Tue, 15 Mar 2005 18:31:38 +0000
changeset 1511 32b095e3da76
parent 1510 cc6f925bf380
child 1512 fdb91a80d3ae
(svn r2015) Use a struct and an inline function for colour masking on the mini-map - this should improve readability a bit
smallmap_gui.c
--- a/smallmap_gui.c	Tue Mar 15 16:56:05 2005 +0000
+++ b/smallmap_gui.c	Tue Mar 15 18:31:38 2005 +0000
@@ -250,7 +250,17 @@
 	MKCOLOR(0x27272727),
 };
 
-static const uint32 _smallmap_contours_andor[12][2] = {
+typedef struct AndOr {
+	uint32 mor;
+	uint32 mand;
+} AndOr;
+
+static inline uint32 ApplyMask(uint32 colour, const AndOr* mask)
+{
+	return (colour & mask->mand) | mask->mor;
+}
+
+static const AndOr _smallmap_contours_andor[] = {
 	{MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)},
 	{MKCOLOR(0x000A0A00),MKCOLOR(0xFF0000FF)},
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
@@ -265,7 +275,7 @@
 	{MKCOLOR(0x000A0A00),MKCOLOR(0xFF0000FF)},
 };
 
-static const uint32 _smallmap_vehicles_andor[12][2] = {
+static const AndOr _smallmap_vehicles_andor[] = {
 	{MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)},
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
@@ -280,7 +290,7 @@
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
 };
 
-static const uint32 _smallmap_vegetation_andor[12][2] = {
+static const AndOr _smallmap_vegetation_andor[] = {
 	{MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)},
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
 	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
@@ -312,7 +322,8 @@
 		}
 	}
 
-	return (_map_height_bits[TileHeight(tile)] & _smallmap_contours_andor[t][1]) | _smallmap_contours_andor[t][0];
+	return
+		ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]);
 }
 
 static void DrawSmallMapContours(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
@@ -341,7 +352,7 @@
 			t = MP_WATER;
 		}
 	}
-	return (MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0];
+	return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 }
 
 
@@ -398,7 +409,7 @@
 				t = MP_WATER;
 			}
 		}
-		return ((MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0]);
+		return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 	}
 }
 
@@ -438,7 +449,7 @@
 			}
 		}
 		// ground color
-		bits = ((MKCOLOR(0x54545454) & _smallmap_contours_andor[t][1]) | _smallmap_contours_andor[t][0]);
+		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
 	}
 	return bits;
 }
@@ -494,7 +505,7 @@
 				t = MP_WATER;
 			}
 		}
-		bits = ((MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0]);
+		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 	}
 
 	return bits;