(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c

* Codechange: Move declaration of lookup arrays into the functions that need them. This doesn't pollute the global namespace with the array names.
* Add: rail.h to the openttd.vcproj and openttd.dsp for MSVC.
This commit is contained in:
matthijs 2005-06-17 11:30:50 +00:00
parent 3c133f1f53
commit 958df2b229
4 changed files with 81 additions and 44 deletions

View File

@ -229,6 +229,10 @@ SOURCE=.\players.c
SOURCE=.\queue.c SOURCE=.\queue.c
# End Source File # End Source File
# Begin Source File
SOURCE=.\rail.c
# End Source File
# Begin Source File # Begin Source File
SOURCE=.\saveload.c SOURCE=.\saveload.c
# End Source File # End Source File
@ -446,6 +450,10 @@ SOURCE=.\news.h
SOURCE=.\npf.h SOURCE=.\npf.h
# End Source File # End Source File
# Begin Source File
SOURCE=.\openttd.h
# End Source File
# Begin Source File # Begin Source File
SOURCE=.\pathfind.h SOURCE=.\pathfind.h
# End Source File # End Source File
@ -462,6 +470,10 @@ SOURCE=.\player.h
SOURCE=.\queue.h SOURCE=.\queue.h
# End Source File # End Source File
# Begin Source File
SOURCE=.\rail.h
# End Source File
# Begin Source File # Begin Source File
SOURCE=.\saveload.h SOURCE=.\saveload.h
# End Source File # End Source File
@ -498,10 +510,6 @@ SOURCE=.\tile.h
SOURCE=.\town.h SOURCE=.\town.h
# End Source File # End Source File
# Begin Source File
SOURCE=.\openttd.h
# End Source File
# Begin Source File # Begin Source File
SOURCE=.\variables.h SOURCE=.\variables.h
# End Source File # End Source File

View File

@ -256,6 +256,12 @@
<File <File
RelativePath="oldloader.c"> RelativePath="oldloader.c">
</File> </File>
<File
RelativePath="openttd.c">
</File>
<File
RelativePath="openttd.rc">
</File>
<File <File
RelativePath="pathfind.c"> RelativePath="pathfind.c">
</File> </File>
@ -268,6 +274,9 @@
<File <File
RelativePath=".\queue.c"> RelativePath=".\queue.c">
</File> </File>
<File
RelativePath=".\rail.c">
</File>
<File <File
RelativePath="saveload.c"> RelativePath="saveload.c">
</File> </File>
@ -307,12 +316,6 @@
<File <File
RelativePath=".\tile.c"> RelativePath=".\tile.c">
</File> </File>
<File
RelativePath="openttd.c">
</File>
<File
RelativePath="openttd.rc">
</File>
<File <File
RelativePath="vehicle.c"> RelativePath="vehicle.c">
</File> </File>
@ -435,6 +438,9 @@
<File <File
RelativePath=".\npf.h"> RelativePath=".\npf.h">
</File> </File>
<File
RelativePath="openttd.h">
</File>
<File <File
RelativePath="pathfind.h"> RelativePath="pathfind.h">
</File> </File>
@ -447,6 +453,9 @@
<File <File
RelativePath=".\queue.h"> RelativePath=".\queue.h">
</File> </File>
<File
RelativePath=".\rail.h">
</File>
<File <File
RelativePath="saveload.h"> RelativePath="saveload.h">
</File> </File>
@ -474,9 +483,6 @@
<File <File
RelativePath=".\town.h"> RelativePath=".\town.h">
</File> </File>
<File
RelativePath="openttd.h">
</File>
<File <File
RelativePath="variables.h"> RelativePath="variables.h">
</File> </File>

2
rail.c
View File

@ -1,3 +1,5 @@
#include "stdafx.h"
#include "openttd.h"
#include "rail.h" #include "rail.h"
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */ /* XXX: Below 3 tables store duplicate data. Maybe remove some? */

83
rail.h
View File

@ -1,8 +1,6 @@
#ifndef RAIL_H #ifndef RAIL_H
#define RAIL_H #define RAIL_H
#include "stdafx.h"
#include "openttd.h"
#include "tile.h" #include "tile.h"
/* /*
@ -95,7 +93,8 @@ typedef enum Trackdirs {
TRACKDIR_LOWER_E = 3, TRACKDIR_LOWER_E = 3,
TRACKDIR_LEFT_S = 4, TRACKDIR_LEFT_S = 4,
TRACKDIR_RIGHT_S = 5, TRACKDIR_RIGHT_S = 5,
/* Note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 7) */ /* Note the two missing values here. This enables trackdir -> track
* conversion by doing (trackdir & 7) */
TRACKDIR_DIAG1_SW = 8, TRACKDIR_DIAG1_SW = 8,
TRACKDIR_DIAG2_NW = 9, TRACKDIR_DIAG2_NW = 9,
TRACKDIR_UPPER_W = 10, TRACKDIR_UPPER_W = 10,
@ -136,12 +135,17 @@ typedef enum SignalStates {
} SignalState; } SignalState;
/**
* Maps a Trackdir to the corresponding TrackdirBits value
*/
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
/* /*
* These functions check the validity of Tracks and Trackdirs. assert against * These functions check the validity of Tracks and Trackdirs. assert against
* them when convenient. * them when convenient.
*/ */
static inline bool IsValidTrack(Track track) { return track < TRACK_END; } static inline bool IsValidTrack(Track track) { return track < TRACK_END; }
static inline bool IsValidTrackdir(Trackdir trackdir) { return trackdir < TRACKDIR_END; } static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; }
/* /*
* Functions to map tracks to the corresponding bits in the signal * Functions to map tracks to the corresponding bits in the signal
@ -160,15 +164,19 @@ static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_
* Maps a trackdir to the bit that stores its status in the map arrays, in the * Maps a trackdir to the bit that stores its status in the map arrays, in the
* direction against the trackdir. * direction against the trackdir.
*/ */
extern const byte _signal_against_trackdir[TRACKDIR_END]; static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
static inline byte SignalAgainstTrackdir(Trackdir trackdir) { return _signal_against_trackdir[trackdir]; } extern const byte _signal_against_trackdir[TRACKDIR_END];
return _signal_against_trackdir[trackdir];
}
/** /**
* Maps a Track to the bits that store the status of the two signals that can * Maps a Track to the bits that store the status of the two signals that can
* be present on the given track. * be present on the given track.
*/ */
extern const byte _signal_on_track[TRACK_END]; static inline byte SignalOnTrack(Track track) {
static inline byte SignalOnTrack(Track track) { return _signal_on_track[track]; } extern const byte _signal_on_track[TRACK_END];
return _signal_on_track[track];
}
/* /*
* Some functions to query rail tiles * Some functions to query rail tiles
@ -247,13 +255,10 @@ static inline bool HasTrack(TileIndex tile, Track track)
/** /**
* Maps a trackdir to the reverse trackdir. * Maps a trackdir to the reverse trackdir.
*/ */
extern const Trackdir _reverse_trackdir[TRACKDIR_END]; static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
static inline Trackdir ReverseTrackdir(Trackdir trackdir) { return _reverse_trackdir[trackdir]; } extern const Trackdir _reverse_trackdir[TRACKDIR_END];
return _reverse_trackdir[trackdir];
/** }
* Maps a Trackdir to the corresponding TrackdirBits value
*/
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
/* /*
* Maps a Track to the corresponding TrackBits value * Maps a Track to the corresponding TrackBits value
@ -280,42 +285,54 @@ static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = Trac
* ahead. This will be the same trackdir for diagonal trackdirs, but a * ahead. This will be the same trackdir for diagonal trackdirs, but a
* different (alternating) one for straight trackdirs * different (alternating) one for straight trackdirs
*/ */
extern const Trackdir _next_trackdir[TRACKDIR_END]; static inline Trackdir NextTrackdir(Trackdir trackdir) {
static inline Trackdir NextTrackdir(Trackdir trackdir) { return _next_trackdir[trackdir]; } extern const Trackdir _next_trackdir[TRACKDIR_END];
return _next_trackdir[trackdir];
}
/** /**
* Maps a track to all tracks that make 90 deg turns with it. * Maps a track to all tracks that make 90 deg turns with it.
*/ */
extern const TrackBits _track_crosses_tracks[TRACK_END]; static inline TrackBits TrackCrossesTracks(Track track) {
static inline TrackBits TrackCrossesTracks(Track track) { return _track_crosses_tracks[track]; } extern const TrackBits _track_crosses_tracks[TRACK_END];
return _track_crosses_tracks[track];
}
/** /**
* Maps a trackdir to the (4-way) direction the tile is exited when following * Maps a trackdir to the (4-way) direction the tile is exited when following
* that trackdir. * that trackdir.
*/ */
extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]; static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) { return _trackdir_to_exitdir[trackdir]; } extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
return _trackdir_to_exitdir[trackdir];
}
/** /**
* Maps a track and an (4-way) dir to the trackdir that represents the track * Maps a track and an (4-way) dir to the trackdir that represents the track
* with the exit in the given direction. * with the exit in the given direction.
*/ */
extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END]; static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) { return _track_exitdir_to_trackdir[track][diagdir]; } extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
return _track_exitdir_to_trackdir[track][diagdir];
}
/** /**
* Maps a track and a full (8-way) direction to the trackdir that represents * Maps a track and a full (8-way) direction to the trackdir that represents
* the track running in the given direction. * the track running in the given direction.
*/ */
extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END]; static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) { return _track_direction_to_trackdir[track][dir]; } extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
return _track_direction_to_trackdir[track][dir];
}
/** /**
* Maps a (4-way) direction to the diagonal trackdir that runs in that * Maps a (4-way) direction to the diagonal trackdir that runs in that
* direction. * direction.
*/ */
extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) { return _dir_to_diag_trackdir[diagdir]; } extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
return _dir_to_diag_trackdir[diagdir];
}
/** /**
* Maps a trackdir to the trackdirs that can be reached from it (ie, when * Maps a trackdir to the trackdirs that can be reached from it (ie, when
@ -329,14 +346,18 @@ static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return
/** /**
* Maps a trackdir to all trackdirs that make 90 deg turns with it. * Maps a trackdir to all trackdirs that make 90 deg turns with it.
*/ */
extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; } extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
}
/** /**
* Maps a (4-way) direction to the reverse. * Maps a (4-way) direction to the reverse.
*/ */
extern const DiagDirection _reverse_diagdir[DIAGDIR_END]; static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) {
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) { return _reverse_diagdir[diagdir]; } extern const DiagDirection _reverse_diagdir[DIAGDIR_END];
return _reverse_diagdir[diagdir];
}
/* Checks if a given Track is diagonal */ /* Checks if a given Track is diagonal */
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); } static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); }