159 |
159 |
160 /** Define basic enum properties */ |
160 /** Define basic enum properties */ |
161 template <> struct EnumPropsT<TrackdirBits> : MakeEnumPropsT<TrackdirBits, uint16, TRACKDIR_BIT_NONE, TRACKDIR_BIT_MASK, INVALID_TRACKDIR_BIT> {}; |
161 template <> struct EnumPropsT<TrackdirBits> : MakeEnumPropsT<TrackdirBits, uint16, TRACKDIR_BIT_NONE, TRACKDIR_BIT_MASK, INVALID_TRACKDIR_BIT> {}; |
162 typedef TinyEnumT<TrackdirBits> TrackdirBitsShort; |
162 typedef TinyEnumT<TrackdirBits> TrackdirBitsShort; |
163 DECLARE_ENUM_AS_BIT_SET(TrackdirBits); |
163 DECLARE_ENUM_AS_BIT_SET(TrackdirBits); |
164 DECLARE_ENUM_AS_BIT_INDEX(Trackdir, TrackdirBits); |
|
165 |
164 |
166 /** This struct contains all the info that is needed to draw and construct tracks. |
165 /** This struct contains all the info that is needed to draw and construct tracks. |
167 */ |
166 */ |
168 typedef struct RailtypeInfo { |
167 typedef struct RailtypeInfo { |
169 /** Struct containing the main sprites. @note not all sprites are listed, but only |
168 /** Struct containing the main sprites. @note not all sprites are listed, but only |
238 * Offset to add to ground sprite when drawing custom waypoints / stations |
237 * Offset to add to ground sprite when drawing custom waypoints / stations |
239 */ |
238 */ |
240 byte custom_ground_offset; |
239 byte custom_ground_offset; |
241 } RailtypeInfo; |
240 } RailtypeInfo; |
242 |
241 |
243 extern RailtypeInfo _railtypes[RAILTYPE_END]; |
|
244 |
242 |
245 // these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block |
243 // these are the maximums used for updating signal blocks, and checking if a depot is in a pbs block |
246 enum { |
244 enum { |
247 NUM_SSD_ENTRY = 256, // max amount of blocks |
245 NUM_SSD_ENTRY = 256, // max amount of blocks |
248 NUM_SSD_STACK = 32, // max amount of blocks to check recursively |
246 NUM_SSD_STACK = 32, // max amount of blocks to check recursively |
290 /** |
288 /** |
291 * Converts TrackBits to Track. TrackBits must contain just one Track or INVALID_TRACK_BIT! |
289 * Converts TrackBits to Track. TrackBits must contain just one Track or INVALID_TRACK_BIT! |
292 */ |
290 */ |
293 static inline Track TrackBitsToTrack(TrackBits tracks) |
291 static inline Track TrackBitsToTrack(TrackBits tracks) |
294 { |
292 { |
295 assert (tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KILL_FIRST_BIT(tracks) == 0)); |
293 assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KILL_FIRST_BIT(tracks) == 0)); |
296 return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK; |
294 return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK; |
297 } |
295 } |
298 |
296 |
299 /** |
297 /** |
300 * Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR |
298 * Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR |
320 |
318 |
321 /** |
319 /** |
322 * Maps a trackdir to the bit that stores its status in the map arrays, in the |
320 * Maps a trackdir to the bit that stores its status in the map arrays, in the |
323 * direction along with the trackdir. |
321 * direction along with the trackdir. |
324 */ |
322 */ |
325 extern const byte _signal_along_trackdir[TRACKDIR_END]; |
323 static inline byte SignalAlongTrackdir(Trackdir trackdir) |
326 static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];} |
324 { |
|
325 extern const byte _signal_along_trackdir[TRACKDIR_END]; |
|
326 return _signal_along_trackdir[trackdir]; |
|
327 } |
327 |
328 |
328 /** |
329 /** |
329 * Maps a trackdir to the bit that stores its status in the map arrays, in the |
330 * Maps a trackdir to the bit that stores its status in the map arrays, in the |
330 * direction against the trackdir. |
331 * direction against the trackdir. |
331 */ |
332 */ |
332 static inline byte SignalAgainstTrackdir(Trackdir trackdir) { |
333 static inline byte SignalAgainstTrackdir(Trackdir trackdir) |
|
334 { |
333 extern const byte _signal_against_trackdir[TRACKDIR_END]; |
335 extern const byte _signal_against_trackdir[TRACKDIR_END]; |
334 return _signal_against_trackdir[trackdir]; |
336 return _signal_against_trackdir[trackdir]; |
335 } |
337 } |
336 |
338 |
337 /** |
339 /** |
338 * Maps a Track to the bits that store the status of the two signals that can |
340 * Maps a Track to the bits that store the status of the two signals that can |
339 * be present on the given track. |
341 * be present on the given track. |
340 */ |
342 */ |
341 static inline byte SignalOnTrack(Track track) { |
343 static inline byte SignalOnTrack(Track track) |
|
344 { |
342 extern const byte _signal_on_track[TRACK_END]; |
345 extern const byte _signal_on_track[TRACK_END]; |
343 return _signal_on_track[track]; |
346 return _signal_on_track[track]; |
344 } |
347 } |
345 |
348 |
346 |
349 |
347 /* |
350 /* |
348 * Functions describing logical relations between Tracks, TrackBits, Trackdirs |
351 * Functions describing logical relations between Tracks, TrackBits, Trackdirs |
349 * TrackdirBits, Direction and DiagDirections. |
352 * TrackdirBits, Direction and DiagDirections. |
350 * |
|
351 * TODO: Add #unndefs or something similar to remove the arrays used below |
|
352 * from the global scope and expose direct uses of them. |
|
353 */ |
353 */ |
354 |
354 |
355 /** |
355 /** |
356 * Maps a trackdir to the reverse trackdir. |
356 * Maps a trackdir to the reverse trackdir. |
357 */ |
357 */ |
461 { |
461 { |
462 extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; |
462 extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; |
463 return _dir_to_diag_trackdir[diagdir]; |
463 return _dir_to_diag_trackdir[diagdir]; |
464 } |
464 } |
465 |
465 |
466 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
|
467 |
|
468 /** |
466 /** |
469 * Returns all trackdirs that can be reached when entering a tile from a given |
467 * Returns all trackdirs that can be reached when entering a tile from a given |
470 * (diagonal) direction. This will obviously include 90 degree turns, since no |
468 * (diagonal) direction. This will obviously include 90 degree turns, since no |
471 * information is available about the exact angle of entering */ |
469 * information is available about the exact angle of entering */ |
472 static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) { return _exitdir_reaches_trackdirs[diagdir]; } |
470 static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) |
|
471 { |
|
472 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
|
473 return _exitdir_reaches_trackdirs[diagdir]; |
|
474 } |
473 |
475 |
474 /** |
476 /** |
475 * Returns all tracks that can be reached when entering a tile from a given |
477 * Returns all tracks that can be reached when entering a tile from a given |
476 * (diagonal) direction. This will obviously include 90 degree turns, since no |
478 * (diagonal) direction. This will obviously include 90 degree turns, since no |
477 * information is available about the exact angle of entering */ |
479 * information is available about the exact angle of entering */ |
479 |
481 |
480 /** |
482 /** |
481 * Maps a trackdir to the trackdirs that can be reached from it (ie, when |
483 * Maps a trackdir to the trackdirs that can be reached from it (ie, when |
482 * entering the next tile. This will include 90 degree turns! |
484 * entering the next tile. This will include 90 degree turns! |
483 */ |
485 */ |
484 static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; } |
486 static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) |
|
487 { |
|
488 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
|
489 return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; |
|
490 } |
|
491 |
485 /* Note that there is no direct table for this function (there used to be), |
492 /* Note that there is no direct table for this function (there used to be), |
486 * but it uses two simpeler tables to achieve the result */ |
493 * but it uses two simpeler tables to achieve the result */ |
487 |
494 |
488 |
495 |
489 /** |
496 /** |
490 * Maps a trackdir to all trackdirs that make 90 deg turns with it. |
497 * Maps a trackdir to all trackdirs that make 90 deg turns with it. |
491 */ |
498 */ |
492 static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { |
499 static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) |
|
500 { |
493 extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; |
501 extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; |
494 return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; |
502 return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; |
495 } |
503 } |
496 |
504 |
497 |
505 |
507 * @param railtype the rail type which the information is requested for |
515 * @param railtype the rail type which the information is requested for |
508 * @return The pointer to the RailtypeInfo |
516 * @return The pointer to the RailtypeInfo |
509 */ |
517 */ |
510 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype) |
518 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype) |
511 { |
519 { |
|
520 extern RailtypeInfo _railtypes[RAILTYPE_END]; |
512 assert(railtype < RAILTYPE_END); |
521 assert(railtype < RAILTYPE_END); |
513 return &_railtypes[railtype]; |
522 return &_railtypes[railtype]; |
514 } |
523 } |
515 |
524 |
516 /** |
525 /** |