src/road_func.h
author rubidium
Sat, 22 Dec 2007 21:01:49 +0000
changeset 8120 7128bb2b57a3
parent 8113 31b7784db761
child 8138 dbfdc08fa6b9
permissions -rw-r--r--
(svn r11681) -Fix (r11674): hopefully fix the compile error on big endian machines.
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     1
/* $Id$ */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     2
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     3
/** @file road_func.h Functions related to roads. */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     4
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     5
#ifndef ROAD_FUNC_H
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     6
#define ROAD_FUNC_H
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     7
8113
31b7784db761 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8102
diff changeset
     8
#include "core/bitmath_func.hpp"
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
     9
#include "road_type.h"
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    10
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    11
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    12
 * Whether the given roadtype is valid.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    13
 * @param rt the roadtype to check for validness
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    14
 * @return true if and only if valid
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    15
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    16
static inline bool IsValidRoadType(RoadType rt)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    17
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    18
	return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    19
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    20
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    21
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    22
 * Are the given bits pointing to valid roadtypes?
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    23
 * @param rts the roadtypes to check for validness
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    24
 * @return true if and only if valid
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    25
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    26
static inline bool AreValidRoadTypes(RoadTypes rts)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    27
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    28
	return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    29
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    30
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    31
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    32
 * Maps a RoadType to the corresponding RoadTypes value
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    33
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    34
 * @param rt the roadtype to get the roadtypes from
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    35
 * @return the roadtypes with the given roadtype
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    36
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    37
static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    38
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    39
	return (RoadTypes)(1 << rt);
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    40
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    41
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    42
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    43
 * Returns the RoadTypes which are not present in the given RoadTypes
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    44
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    45
 * This function returns the complement of a given RoadTypes.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    46
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    47
 * @param r The given RoadTypes
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    48
 * @return The complement of the given RoadTypes
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    49
 * @note The unused value ROADTYPES_HWAY will be used, too.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    50
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    51
static inline RoadTypes ComplementRoadTypes(RoadTypes r)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    52
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    53
	return (RoadTypes)(ROADTYPES_ALL ^ r);
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    54
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    55
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    56
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    57
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    58
 * Calculate the complement of a RoadBits value
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    59
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    60
 * Simply flips all bits in the RoadBits value to get the complement
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    61
 * of the RoadBits.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    62
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    63
 * @param r The given RoadBits value
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    64
 * @return the complement
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    65
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    66
static inline RoadBits ComplementRoadBits(RoadBits r)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    67
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    68
	return (RoadBits)(ROAD_ALL ^ r);
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    69
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    70
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    71
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    72
 * Calculate the mirrored RoadBits
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    73
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    74
 * Simply move the bits to their new position.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    75
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    76
 * @param r The given RoadBits value
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    77
 * @return the mirrored
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    78
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    79
static inline RoadBits MirrorRoadBits(RoadBits r)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    80
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    81
	return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    82
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    83
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    84
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    85
 * Calculate rotated RoadBits
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    86
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    87
 * Move the Roadbits clockwise til they are in their final position.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    88
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    89
 * @param r The given RoadBits value
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    90
 * @param rot The given Rotation angle
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    91
 * @return the rotated
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    92
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    93
static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    94
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    95
	for (; rot > (DiagDirDiff)0; rot--){
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    96
		r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    97
	}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    98
	return r;
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
    99
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   100
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   101
/**
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   102
 * Create the road-part which belongs to the given DiagDirection
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   103
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   104
 * This function returns a RoadBits value which belongs to
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   105
 * the given DiagDirection.
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   106
 *
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   107
 * @param d The DiagDirection
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   108
 * @return The result RoadBits which the selected road-part set
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   109
 */
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   110
static inline RoadBits DiagDirToRoadBits(DiagDirection d)
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   111
{
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   112
	return (RoadBits)(ROAD_NW << (3 ^ d));
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   113
}
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   114
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
diff changeset
   115
#endif /* ROAD_FUNC_H */