(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
authorcelestar
Mon, 17 Apr 2006 19:09:30 +0000
changeset 3575 867df1ec208a
parent 3574 bf5f6c1af32c
child 3576 007e6b163bf5
(svn r4461) -Codechange: Add and make use of map accessor functions for signal drawing. Includes some basic cleanup of the drawing functions
rail.h
rail_cmd.c
rail_map.h
--- a/rail.h	Mon Apr 17 18:47:50 2006 +0000
+++ b/rail.h	Mon Apr 17 19:09:30 2006 +0000
@@ -50,15 +50,6 @@
 	INVALID_TRACKDIR_BIT  = 0xFFFF,
 } TrackdirBits;
 
-/** These are states in which a signal can be. Currently these are only two, so
- * simple boolean logic will do. But do try to compare to this enum instead of
- * normal boolean evaluation, since that will make future additions easier.
- */
-typedef enum SignalStates {
-	SIGNAL_STATE_RED = 0,
-	SIGNAL_STATE_GREEN = 1,
-} SignalState;
-
 /** This struct contains all the info that is needed to draw and construct tracks.
  */
 typedef struct RailtypeInfo {
--- a/rail_cmd.c	Mon Apr 17 18:47:50 2006 +0000
+++ b/rail_cmd.c	Mon Apr 17 19:09:30 2006 +0000
@@ -1015,9 +1015,9 @@
 
 #include "table/track_land.h"
 
-static void DrawSingleSignal(TileIndex tile, byte condition, uint32 image_and_pos)
+static void DrawSingleSignal(TileIndex tile, byte condition, uint image, uint pos)
 {
-	bool otherside = _opt.road_side & _patches.signal_side;
+	bool side = _opt.road_side & _patches.signal_side;
 	static const Point SignalPositions[2][12] = {
 		{      /* Signals on the left side */
 		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
@@ -1044,9 +1044,11 @@
 		}
 	};
 
-	uint x = TileX(tile) * TILE_SIZE + SignalPositions[otherside][image_and_pos & 0xF].x;
-	uint y = TileY(tile) * TILE_SIZE + SignalPositions[otherside][image_and_pos & 0xF].y;
-	SpriteID sprite = SignalBase[otherside][GetSignalVariant(tile)][GetSignalType(tile)] + (image_and_pos>>4) + ((condition != 0) ? 1 : 0);
+	uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
+	uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
+
+	SpriteID sprite = SignalBase[side][GetSignalVariant(tile)][GetSignalType(tile)] + image + condition;
+
 	AddSortableSpriteToDraw(sprite, x, y, 1, 1, 10, GetSlopeZ(x,y));
 }
 
@@ -1248,13 +1250,7 @@
 
 static void DrawSignals(TileIndex tile, TrackBits rails)
 {
-#define HAS_SIGNAL(x) (m23 & (byte)(0x1 << (x)))
-#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
-#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSingleSignal(tile, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
-
-	byte m23;
-
-	m23 = (_m[tile].m3 >> 4) | (_m[tile].m2 & 0xF0);
+#define MAYBE_DRAW_SIGNAL(x,y,z) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, GetSingleSignalState(tile, x), y - 0x4FB, z)
 
 	if (!(rails & TRACK_BIT_Y)) {
 		if (!(rails & TRACK_BIT_X)) {
--- a/rail_map.h	Mon Apr 17 18:47:50 2006 +0000
+++ b/rail_map.h	Mon Apr 17 19:09:30 2006 +0000
@@ -211,6 +211,25 @@
 	SB(_m[t].m4, 2, 1, v);
 }
 
+static inline bool IsSignalPresent(TileIndex t, byte signalbit)
+{
+	return HASBIT(_m[t].m3, signalbit + 4);
+}
+
+/** These are states in which a signal can be. Currently these are only two, so
+ * simple boolean logic will do. But do try to compare to this enum instead of
+ * normal boolean evaluation, since that will make future additions easier.
+ */
+typedef enum SignalStates {
+	SIGNAL_STATE_RED = 0,
+	SIGNAL_STATE_GREEN = 1,
+} SignalState;
+
+static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit)
+{
+	return HASBIT(_m[t].m2, signalbit + 4);
+}
+
 
 typedef enum RailGroundType {
 	RAIL_MAP2LO_GROUND_MASK = 0xF,