2006-03-05 12:34:55 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/** @file direction.h */
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
#ifndef DIRECTION_H
|
|
|
|
#define DIRECTION_H
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
#include "helpers.hpp"
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
/* Direction as commonly used in v->direction, 8 way. */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum Direction {
|
2007-01-10 18:56:51 +00:00
|
|
|
DIR_BEGIN = 0,
|
2006-03-05 12:34:55 +00:00
|
|
|
DIR_N = 0,
|
2007-02-23 18:55:07 +00:00
|
|
|
DIR_NE = 1, ///< Northeast, upper right on your monitor
|
2006-03-05 12:34:55 +00:00
|
|
|
DIR_E = 2,
|
|
|
|
DIR_SE = 3,
|
|
|
|
DIR_S = 4,
|
|
|
|
DIR_SW = 5,
|
|
|
|
DIR_W = 6,
|
|
|
|
DIR_NW = 7,
|
|
|
|
DIR_END,
|
|
|
|
INVALID_DIR = 0xFF,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-05 12:34:55 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
/** Define basic enum properties */
|
|
|
|
template <> struct EnumPropsT<Direction> : MakeEnumPropsT<Direction, byte, DIR_BEGIN, DIR_END, INVALID_DIR> {};
|
2007-04-06 04:10:19 +00:00
|
|
|
typedef TinyEnumT<Direction> DirectionByte; //typedefing-enumification of Direction
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
static inline Direction ReverseDir(Direction d)
|
|
|
|
{
|
|
|
|
return (Direction)(4 ^ d);
|
|
|
|
}
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DirDiff {
|
2006-03-08 07:48:56 +00:00
|
|
|
DIRDIFF_SAME = 0,
|
|
|
|
DIRDIFF_45RIGHT = 1,
|
|
|
|
DIRDIFF_90RIGHT = 2,
|
|
|
|
DIRDIFF_REVERSE = 4,
|
|
|
|
DIRDIFF_90LEFT = 6,
|
|
|
|
DIRDIFF_45LEFT = 7
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-08 07:48:56 +00:00
|
|
|
|
|
|
|
static inline DirDiff DirDifference(Direction d0, Direction d1)
|
|
|
|
{
|
2006-03-08 08:36:00 +00:00
|
|
|
return (DirDiff)((d0 + 8 - d1) % 8);
|
2006-03-08 07:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
|
|
|
|
{
|
|
|
|
return (DirDiff)((d + delta) % 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline Direction ChangeDir(Direction d, DirDiff delta)
|
|
|
|
{
|
|
|
|
return (Direction)((d + delta) % 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DiagDirection {
|
2007-01-10 18:56:51 +00:00
|
|
|
DIAGDIR_BEGIN = 0,
|
2007-02-23 18:55:07 +00:00
|
|
|
DIAGDIR_NE = 0, ///< Northeast, upper right on your monitor
|
2006-03-05 12:34:55 +00:00
|
|
|
DIAGDIR_SE = 1,
|
|
|
|
DIAGDIR_SW = 2,
|
|
|
|
DIAGDIR_NW = 3,
|
|
|
|
DIAGDIR_END,
|
|
|
|
INVALID_DIAGDIR = 0xFF,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-05 12:34:55 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
DECLARE_POSTFIX_INCREMENT(DiagDirection);
|
|
|
|
|
|
|
|
/** Define basic enum properties */
|
|
|
|
template <> struct EnumPropsT<DiagDirection> : MakeEnumPropsT<DiagDirection, byte, DIAGDIR_BEGIN, DIAGDIR_END, INVALID_DIAGDIR> {};
|
2007-04-06 04:10:19 +00:00
|
|
|
typedef TinyEnumT<DiagDirection> DiagDirectionByte; //typedefing-enumification of DiagDirection
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
static inline DiagDirection ReverseDiagDir(DiagDirection d)
|
|
|
|
{
|
2006-03-05 12:54:22 +00:00
|
|
|
return (DiagDirection)(2 ^ d);
|
2006-03-05 12:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DiagDirDiff {
|
2006-03-08 08:51:26 +00:00
|
|
|
DIAGDIRDIFF_SAME = 0,
|
|
|
|
DIAGDIRDIFF_90RIGHT = 1,
|
|
|
|
DIAGDIRDIFF_REVERSE = 2,
|
|
|
|
DIAGDIRDIFF_90LEFT = 3
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-08 08:51:26 +00:00
|
|
|
|
|
|
|
static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
|
|
|
|
{
|
|
|
|
return (DiagDirection)((d + delta) % 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-06 20:28:28 +00:00
|
|
|
static inline DiagDirection DirToDiagDir(Direction dir)
|
2006-03-05 12:34:55 +00:00
|
|
|
{
|
|
|
|
return (DiagDirection)(dir >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-06 20:28:28 +00:00
|
|
|
static inline Direction DiagDirToDir(DiagDirection dir)
|
|
|
|
{
|
|
|
|
return (Direction)(dir * 2 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 12:34:55 +00:00
|
|
|
/* the 2 axis */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum Axis {
|
2006-03-05 12:34:55 +00:00
|
|
|
AXIS_X = 0,
|
2006-05-01 09:34:23 +00:00
|
|
|
AXIS_Y = 1,
|
|
|
|
AXIS_END
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-05 12:34:55 +00:00
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
|
2006-07-22 08:59:52 +00:00
|
|
|
static inline Axis OtherAxis(Axis a)
|
|
|
|
{
|
|
|
|
return (Axis)(a ^ 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
static inline Axis DiagDirToAxis(DiagDirection d)
|
|
|
|
{
|
|
|
|
return (Axis)(d & 1);
|
|
|
|
}
|
|
|
|
|
2006-03-15 07:10:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts an Axis to a DiagDirection
|
|
|
|
* Points always in the positive direction, i.e. S[EW]
|
|
|
|
*/
|
|
|
|
static inline DiagDirection AxisToDiagDir(Axis a)
|
|
|
|
{
|
|
|
|
return (DiagDirection)(2 - a);
|
|
|
|
}
|
|
|
|
|
2006-06-04 16:04:15 +00:00
|
|
|
/**
|
|
|
|
* Convert an axis and a flag for north/south into a DiagDirection
|
2007-04-06 04:10:19 +00:00
|
|
|
* @param xy axis to convert
|
2006-06-04 16:04:15 +00:00
|
|
|
* @param ns north -> 0, south -> 1
|
2007-04-06 04:10:19 +00:00
|
|
|
* @return the desired DiagDirection
|
2006-06-04 16:04:15 +00:00
|
|
|
*/
|
|
|
|
static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns)
|
|
|
|
{
|
|
|
|
return (DiagDirection)(xy * 3 ^ ns * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-01 09:34:23 +00:00
|
|
|
static inline bool IsValidDiagDirection(DiagDirection d)
|
|
|
|
{
|
|
|
|
return d < DIAGDIR_END;
|
|
|
|
}
|
|
|
|
|
2006-05-03 22:12:09 +00:00
|
|
|
static inline bool IsValidDirection(Direction d)
|
2006-05-01 09:34:23 +00:00
|
|
|
{
|
|
|
|
return d < DIR_END;
|
|
|
|
}
|
|
|
|
|
2006-05-03 22:12:09 +00:00
|
|
|
static inline bool IsValidAxis(Axis d)
|
2006-05-01 09:34:23 +00:00
|
|
|
{
|
|
|
|
return d < AXIS_END;
|
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* DIRECTION_H */
|