mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-01 20:03:26 +00:00
(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:
parent
3c133f1f53
commit
958df2b229
16
openttd.dsp
16
openttd.dsp
@ -229,6 +229,10 @@ SOURCE=.\players.c
|
||||
SOURCE=.\queue.c
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\rail.c
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\saveload.c
|
||||
# End Source File
|
||||
@ -446,6 +450,10 @@ SOURCE=.\news.h
|
||||
SOURCE=.\npf.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\openttd.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\pathfind.h
|
||||
# End Source File
|
||||
@ -462,6 +470,10 @@ SOURCE=.\player.h
|
||||
SOURCE=.\queue.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\rail.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\saveload.h
|
||||
# End Source File
|
||||
@ -498,10 +510,6 @@ SOURCE=.\tile.h
|
||||
SOURCE=.\town.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\openttd.h
|
||||
# End Source File
|
||||
|
||||
# Begin Source File
|
||||
SOURCE=.\variables.h
|
||||
# End Source File
|
||||
|
@ -256,6 +256,12 @@
|
||||
<File
|
||||
RelativePath="oldloader.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.rc">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="pathfind.c">
|
||||
</File>
|
||||
@ -268,6 +274,9 @@
|
||||
<File
|
||||
RelativePath=".\queue.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\rail.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="saveload.c">
|
||||
</File>
|
||||
@ -307,12 +316,6 @@
|
||||
<File
|
||||
RelativePath=".\tile.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.rc">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="vehicle.c">
|
||||
</File>
|
||||
@ -435,6 +438,9 @@
|
||||
<File
|
||||
RelativePath=".\npf.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="pathfind.h">
|
||||
</File>
|
||||
@ -447,6 +453,9 @@
|
||||
<File
|
||||
RelativePath=".\queue.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\rail.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="saveload.h">
|
||||
</File>
|
||||
@ -474,9 +483,6 @@
|
||||
<File
|
||||
RelativePath=".\town.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="openttd.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="variables.h">
|
||||
</File>
|
||||
|
2
rail.c
2
rail.c
@ -1,3 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "openttd.h"
|
||||
#include "rail.h"
|
||||
|
||||
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */
|
||||
|
61
rail.h
61
rail.h
@ -1,8 +1,6 @@
|
||||
#ifndef RAIL_H
|
||||
#define RAIL_H
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "openttd.h"
|
||||
#include "tile.h"
|
||||
|
||||
/*
|
||||
@ -95,7 +93,8 @@ typedef enum Trackdirs {
|
||||
TRACKDIR_LOWER_E = 3,
|
||||
TRACKDIR_LEFT_S = 4,
|
||||
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_DIAG2_NW = 9,
|
||||
TRACKDIR_UPPER_W = 10,
|
||||
@ -136,12 +135,17 @@ typedef enum SignalStates {
|
||||
} 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
|
||||
* them when convenient.
|
||||
*/
|
||||
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
|
||||
@ -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
|
||||
* direction against the trackdir.
|
||||
*/
|
||||
static inline byte SignalAgainstTrackdir(Trackdir trackdir) {
|
||||
extern const byte _signal_against_trackdir[TRACKDIR_END];
|
||||
static inline byte SignalAgainstTrackdir(Trackdir trackdir) { return _signal_against_trackdir[trackdir]; }
|
||||
return _signal_against_trackdir[trackdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a Track to the bits that store the status of the two signals that can
|
||||
* be present on the given track.
|
||||
*/
|
||||
static inline byte SignalOnTrack(Track track) {
|
||||
extern const byte _signal_on_track[TRACK_END];
|
||||
static inline byte SignalOnTrack(Track track) { return _signal_on_track[track]; }
|
||||
return _signal_on_track[track];
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static inline Trackdir ReverseTrackdir(Trackdir trackdir) {
|
||||
extern const Trackdir _reverse_trackdir[TRACKDIR_END];
|
||||
static inline Trackdir ReverseTrackdir(Trackdir trackdir) { return _reverse_trackdir[trackdir]; }
|
||||
|
||||
/**
|
||||
* Maps a Trackdir to the corresponding TrackdirBits value
|
||||
*/
|
||||
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); }
|
||||
return _reverse_trackdir[trackdir];
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
* different (alternating) one for straight trackdirs
|
||||
*/
|
||||
static inline Trackdir NextTrackdir(Trackdir trackdir) {
|
||||
extern const Trackdir _next_trackdir[TRACKDIR_END];
|
||||
static inline Trackdir NextTrackdir(Trackdir trackdir) { return _next_trackdir[trackdir]; }
|
||||
return _next_trackdir[trackdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a track to all tracks that make 90 deg turns with it.
|
||||
*/
|
||||
static inline TrackBits TrackCrossesTracks(Track track) {
|
||||
extern const TrackBits _track_crosses_tracks[TRACK_END];
|
||||
static inline TrackBits TrackCrossesTracks(Track track) { return _track_crosses_tracks[track]; }
|
||||
return _track_crosses_tracks[track];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a trackdir to the (4-way) direction the tile is exited when following
|
||||
* that trackdir.
|
||||
*/
|
||||
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
|
||||
extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
|
||||
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) { return _trackdir_to_exitdir[trackdir]; }
|
||||
return _trackdir_to_exitdir[trackdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a track and an (4-way) dir to the trackdir that represents the track
|
||||
* with the exit in the given direction.
|
||||
*/
|
||||
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
|
||||
extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
|
||||
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) { return _track_exitdir_to_trackdir[track][diagdir]; }
|
||||
return _track_exitdir_to_trackdir[track][diagdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a track and a full (8-way) direction to the trackdir that represents
|
||||
* the track running in the given direction.
|
||||
*/
|
||||
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
|
||||
extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
|
||||
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) { return _track_direction_to_trackdir[track][dir]; }
|
||||
return _track_direction_to_trackdir[track][dir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a (4-way) direction to the diagonal trackdir that runs in that
|
||||
* direction.
|
||||
*/
|
||||
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
|
||||
extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
|
||||
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) { return _dir_to_diag_trackdir[diagdir]; }
|
||||
return _dir_to_diag_trackdir[diagdir];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
|
||||
extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END];
|
||||
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; }
|
||||
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];
|
||||
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) { return _reverse_diagdir[diagdir]; }
|
||||
return _reverse_diagdir[diagdir];
|
||||
}
|
||||
|
||||
/* Checks if a given Track is diagonal */
|
||||
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); }
|
||||
|
Loading…
Reference in New Issue
Block a user