Mercurial > hg > openttd
changeset 3147:cc4d0374cee2 draft
(svn r3767) Move all direction related enums and functions to a separate header
author | tron <tron@openttd.org> |
---|---|
date | Sun, 05 Mar 2006 12:34:55 +0000 |
parents | 108fdb5aa8d4 |
children | 7adf2f6b42ae |
files | depot.h direction.h npf.c rail.c rail.h ship_cmd.c tile.h |
diffstat | 7 files changed, 58 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/depot.h +++ b/depot.h @@ -6,6 +6,7 @@ /** @file depot.h Header files for depots (not hangars) * @see depot.c */ +#include "direction.h" #include "pool.h" #include "tile.h" #include "variables.h"
new file mode 100644 --- /dev/null +++ b/direction.h @@ -0,0 +1,49 @@ +/* $Id$ */ + +#ifndef DIRECTION_H +#define DIRECTION_H + +/* Direction as commonly used in v->direction, 8 way. */ +typedef enum Direction { + DIR_N = 0, + DIR_NE = 1, /* Northeast, upper right on your monitor */ + DIR_E = 2, + DIR_SE = 3, + DIR_S = 4, + DIR_SW = 5, + DIR_W = 6, + DIR_NW = 7, + DIR_END, + INVALID_DIR = 0xFF, +} Direction; + + +/* Direction commonly used as the direction of entering and leaving tiles, 4-way */ +typedef enum DiagDirection { + DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ + DIAGDIR_SE = 1, + DIAGDIR_SW = 2, + DIAGDIR_NW = 3, + DIAGDIR_END, + INVALID_DIAGDIR = 0xFF, +} DiagDirection; + +static inline DiagDirection ReverseDiagDir(DiagDirection d) +{ + return 2 ^ d; +} + + +static inline DiagDirection DirToDiagdir(Direction dir) +{ + return (DiagDirection)(dir >> 1); +} + + +/* the 2 axis */ +typedef enum Axis { + AXIS_X = 0, + AXIS_Y = 1 +} Axis; + +#endif
--- a/npf.c +++ b/npf.c @@ -162,11 +162,11 @@ { DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction); TileIndex tile = current->tile; - if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagdir(exitdir)) { + if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagDir(exitdir)) { /* We just popped out if this tunnel, since were * facing the tunnel exit */ FindLengthOfTunnelResult flotr; - flotr = FindLengthOfTunnel(tile, ReverseDiagdir(exitdir)); + flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); return flotr.length * NPF_TILE_LENGTH; //TODO: Penalty for tunnels? } else { @@ -543,7 +543,7 @@ * otherwise (only for trains, since only with trains you can * (sometimes) reach tiles after reversing that you couldn't reach * without reversing. */ - if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL) { + if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir)) && type == TRANSPORT_RAIL) { /* We are headed inwards. We can only reverse here, so we'll not * consider this direction, but jump ahead to the reverse direction. * It would be nicer to return one neighbour here (the reverse @@ -596,7 +596,7 @@ * orientation. They are only "inwards", since we are reaching this tile * from some other tile. This prevents vehicles driving into depots from * the back */ - ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagdir(exitdir))); + ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagDir(exitdir))); } else { ts = GetTileTrackStatus(dst_tile, type); }
--- a/rail.c +++ b/rail.c @@ -99,10 +99,6 @@ TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW, }; -const DiagDirection _reverse_diagdir[] = { - DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE -}; - const Trackdir _reverse_trackdir[] = { TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_UPPER_W, TRACKDIR_LOWER_W, TRACKDIR_LEFT_N, TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_UPPER_E, TRACKDIR_LOWER_E, TRACKDIR_LEFT_S, TRACKDIR_RIGHT_S
--- a/rail.h +++ b/rail.h @@ -5,6 +5,7 @@ #ifndef RAIL_H #define RAIL_H +#include "direction.h" #include "tile.h" /* @@ -464,21 +465,6 @@ return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; } -/** - * Maps a (4-way) direction to the reverse. - */ -static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) { - extern const DiagDirection _reverse_diagdir[DIAGDIR_END]; - return _reverse_diagdir[diagdir]; -} - -/** - * Maps a (8-way) direction to a (4-way) DiagDirection - */ -static inline DiagDirection DirToDiagdir(Direction dir) { - assert(dir < DIR_END); - return (DiagDirection)(dir >> 1); -} /* Checks if a given Track is diagonal */ static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); }
--- a/ship_cmd.c +++ b/ship_cmd.c @@ -537,7 +537,7 @@ if (_patches.new_pathfinding_all) { NPFFindStationOrTileData fstd; NPFFoundTargetData ftd; - TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagdir(enterdir))); + TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir))); byte trackdir = GetVehicleTrackdir(v); assert (trackdir != 0xFF); /* Check that we are not in a depot */ @@ -564,9 +564,9 @@ tot_dist = (uint)-1; /* Let's find out how far it would be if we would reverse first */ - b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagdir(enterdir)] & v->u.ship.state; + b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagDir(enterdir)] & v->u.ship.state; if (b != 0) { - dist = FindShipTrack(v, tile2, ReverseDiagdir(enterdir), b, tile, &track); + dist = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track); if (dist != (uint)-1) tot_dist = dist + 1; }
--- a/tile.h +++ b/tile.h @@ -20,41 +20,6 @@ MP_UNMOVABLE, } TileType; -/* Direction as commonly used in v->direction, 8 way. */ -typedef enum Directions { - DIR_N = 0, - DIR_NE = 1, /* Northeast, upper right on your monitor */ - DIR_E = 2, - DIR_SE = 3, - DIR_S = 4, - DIR_SW = 5, - DIR_W = 6, - DIR_NW = 7, - DIR_END, - INVALID_DIR = 0xFF, -} Direction; - -/* Direction commonly used as the direction of entering and leaving tiles, 4-way */ -typedef enum DiagonalDirections { - DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ - DIAGDIR_SE = 1, - DIAGDIR_SW = 2, - DIAGDIR_NW = 3, - DIAGDIR_END, - INVALID_DIAGDIR = 0xFF, -} DiagDirection; - -static inline DiagDirection ReverseDiagDir(DiagDirection d) -{ - return 2 ^ d; -} - - -/* the 2 axis */ -typedef enum Axis { - AXIS_X = 0, - AXIS_Y = 1 -} Axis; void SetMapExtraBits(TileIndex tile, byte flags); uint GetMapExtraBits(TileIndex tile);