Remove math library and merge gametypes and mathtypes

This commit is contained in:
Marc Di Luzio 2014-12-30 13:24:20 +00:00
parent d9b9f3d7dd
commit 3342300324
4 changed files with 27 additions and 33 deletions

View file

@ -2,6 +2,7 @@
#define _GAME_TYPES_H_
#include <limits> // std::numeric_limits
#include "stdlib.h" // for size_t
#define GAME_POS_FORMATTER "[%u,%u]"
@ -20,11 +21,32 @@ enum class player_t : char
NUM_INVALID
};
typedef unsigned short unit_id_t; // Type for unit IDs
typedef char unitvis_c; // Typedef for unit visual representations
// Type for unit IDs
typedef unsigned short unit_id_t;
static const unit_id_t unit_id_invalid = std::numeric_limits<unit_id_t>::max();
static const unitvis_c unitvis_invalid = std::numeric_limits<unitvis_c>::max();
// Typedef for unit visual representations
typedef char unitvis_c;
static const unitvis_c unitvis_invalid = std::numeric_limits<unitvis_c>::max();
// Coordinate types
typedef short coord_t;
static const coord_t coord_invalid = std::numeric_limits<coord_t>::max();
typedef unsigned short ucoord_t;
static const ucoord_t ucoord_invalid = std::numeric_limits<ucoord_t>::max();
// Direction representation
enum class dir_c : char
{
N = 'N',
S = 'S',
E = 'E',
W = 'W'
};
// Helper function for count of an array
template<class T, size_t N>
constexpr size_t _countof(T (&)[N]) { return N; }
#endif //_GAME_TYPES_H_

84
source/ttrts/vector2.h Normal file
View file

@ -0,0 +1,84 @@
#ifndef _VECTOR2_H_
#define _VECTOR2_H_
#include "mathtypes.h"
struct uvector2;
struct vector2
{
vector2() : x (0), y (0) {}
vector2( coord_t _x, coord_t _y )
: x(_x)
, y(_y)
{}
coord_t x;
coord_t y;
inline vector2 operator-() const { return { (coord_t)-x, (coord_t)-y }; }
inline operator uvector2() const;
// vec
inline vector2 operator+(const vector2& rhs) const { return { (coord_t)(rhs.x + x) , (coord_t)(rhs.y + y) }; }
inline vector2 operator-(const vector2& rhs) const { return *this + (-rhs); }
inline const vector2& operator+=(const vector2& rhs) { *this = *this+rhs; return *this; }
inline const vector2& operator-=(const vector2& rhs) { return *this+=(-rhs); }
inline bool operator==(const vector2& rhs) const { return ( rhs.x == x) && ( rhs.y == y); }
inline bool operator!=(const vector2& rhs) const { return !(*this==rhs); }
};
struct uvector2
{
uvector2() : x (0), y (0) {}
uvector2( ucoord_t _x, ucoord_t _y )
: x(_x)
, y(_y)
{}
ucoord_t x;
ucoord_t y;
// Implicit conversion to vector 2 if needed
inline operator vector2() const { return { (coord_t)x, (coord_t)y }; }
inline uvector2 operator-() const { return { (ucoord_t)-x, (ucoord_t)-y }; }
// uvec
inline uvector2 operator+(const uvector2& rhs) const { return { (ucoord_t)(rhs.x + x) , (ucoord_t)(rhs.y + y) }; }
inline uvector2 operator-(const uvector2& rhs) const { return *this + (-rhs); }
inline const uvector2& operator+=(const uvector2& rhs) { *this = *this+rhs; return *this; }
inline const uvector2& operator-=(const uvector2& rhs) { return *this+=(-rhs); }
inline bool operator==(const uvector2& rhs) const { return ( rhs.x == x) && ( rhs.y == y); }
inline bool operator!=(const uvector2& rhs) const { return !(*this==rhs); }
};
inline vector2::operator uvector2() const { return { (ucoord_t)x, (ucoord_t)y }; }
inline vector2 vecFromDir( dir_c dir )
{
switch( dir )
{
case dir_c::N:
return { 0,1 };
case dir_c::E:
return { 1,0 };
case dir_c::S:
return { 0,-1 };
case dir_c::W:
return { -1,0 };
default:
return { 0,0 };
}
}
#endif //_VECTOR2_H_

9
source/ttrts/version.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef _TTRTS_VERSION_H_
#define _TTRTS_VERSION_H_
static const int sk_ttrts_version_major = TTRTS_VERSION_MAJOR;
static const int sk_ttrts_version_minor = TTRTS_VERSION_MINOR;
static const int sk_ttrts_version_patch = TTRTS_VERSION_PATCH;
static const char* sk_ttrts_version_string = TTRTS_VERSION_STRING;
#endif //_TTRTS_VERSION_H_