Difference between revisions of "Common Types"

From wowdev
Jump to: navigation, search
m (langstringref)
m (C3Vector)
 
(24 intermediate revisions by 4 users not shown)
Line 11: Line 11:
 
  using stringref = uint32_t;
 
  using stringref = uint32_t;
 
==langstringref==
 
==langstringref==
A field for localized strings, consisting of an array of stringrefs followed by a field of flags. The amount of language entries depends on the version, with Cataclysm dropping all but the client's language. See [[Localization]] for details.
+
A field for localized strings, consisting of an array of stringrefs followed by a field of flags. The amount of language entries depends on the version, with Cataclysm dropping all but the client's language. See [[Localization]] for details.  
 
  struct langstringref
 
  struct langstringref
 
  {
 
  {
//! \todo verify that pre-wotlk locales hadn't changed
 
 
  #if {{Template:Sandbox/VersionRange|max_expansionlevel=4|max_exclusive=1}}
 
  #if {{Template:Sandbox/VersionRange|max_expansionlevel=4|max_exclusive=1}}
   stringref enUS; // also enGB
+
   stringref enUS;   // also enGB
 
   stringref koKR;
 
   stringref koKR;
 
   stringref frFR;
 
   stringref frFR;
 
   stringref deDE;
 
   stringref deDE;
   stringref enCN; // also zhCN
+
   stringref enCN;   // also zhCN
   stringref enTW; // also zhTW
+
   stringref enTW;   // also zhTW
 
   stringref esES;
 
   stringref esES;
 
   stringref esMX;
 
   stringref esMX;
  #if {{Template:Sandbox/VersionRange|min_expansionlevel=3}}
+
//! \todo verify that pre->8 locales hadn't changed
 +
  #if {{Template:Sandbox/VersionRange|min_expansionlevel=2|min_build=2.1.0.6692}}
 
   stringref ruRU;
 
   stringref ruRU;
   stringref unknown_9;
+
   stringref {{Template:Unverified|jaJP}}; // unknowns are still unused as of 8.0.1.26095
   stringref ptPT; // also ptBR
+
   stringref ptPT;   // also ptBR
 
   stringref itIT;
 
   stringref itIT;
 
   stringref unknown_12;
 
   stringref unknown_12;
Line 46: Line 46:
 
   float x;
 
   float x;
 
   float y;
 
   float y;
 +
};
 +
=C2iVector=
 +
A two component int vector.
 +
struct C2iVector
 +
{
 +
  int x;
 +
  int y;
 
  };
 
  };
 
=C3Vector=
 
=C3Vector=
Line 51: Line 58:
 
  struct C3Vector
 
  struct C3Vector
 
  {
 
  {
   float x;
+
/*0x00*/  float x;
   float y;
+
/*0x04*/  float y;
   float z;
+
/*0x08*/  float z;
 +
};
 +
 
 +
= C3iVector =
 +
 
 +
A three component int vector.
 +
 
 +
struct C3iVector
 +
{
 +
   int x;
 +
   int y;
 +
   int z;
 
  };
 
  };
 +
 
=C4Vector=
 
=C4Vector=
 
A four component float vector.
 
A four component float vector.
Line 64: Line 83:
 
   float w;
 
   float w;
 
  };
 
  };
 +
 +
=C4iVector=
 +
A four component int vector.
 +
  struct C4iVector
 +
  {
 +
    int x;
 +
    int y;
 +
    int z;
 +
    int w;
 +
  };
 +
 
=C33Matrix=
 
=C33Matrix=
 
A three by three matrix.
 
A three by three matrix.
Line 69: Line 99:
 
  {
 
  {
 
   {{Template:Type|C3Vector}} columns[3];
 
   {{Template:Type|C3Vector}} columns[3];
 +
};
 +
=C34Matrix=
 +
A three by four matrix.
 +
struct C34Matrix // todo: row or column?
 +
{
 +
  {{Template:Type|C3Vector}} columns[4];
 
  };
 
  };
 
=C44Matrix=
 
=C44Matrix=
Line 97: Line 133:
  
 
=CRange=
 
=CRange=
A one dimensional range defined by the bounds.
+
A one dimensional float range defined by the bounds.
 
  struct Range
 
  struct Range
 
  {
 
  {
 
   float min;
 
   float min;
 
   float max;
 
   float max;
 +
};
 +
=CiRange=
 +
A one dimensional int range defined by the bounds.
 +
struct Range
 +
{
 +
  int min;
 +
  int max;
 
  };
 
  };
 
=CAaBox=
 
=CAaBox=
Line 146: Line 189:
 
   int16_t z;
 
   int16_t z;
 
  };
 
  };
 +
 +
=C3Segment=
 +
  struct C3Segment
 +
  {
 +
    C3Vector start;
 +
    C3Vector end;
 +
  };
 +
 +
=CFacet=
 +
  struct CFacet
 +
  {
 +
    C4Plane plane;
 +
    C3Vector vertices[3];
 +
  };
 +
 +
=C3Ray=
 +
A ray defined by an origin and direction.
 +
  struct C3Ray
 +
  {
 +
    C3Vector origin;
 +
    C3Vector dir;
 +
  };
 +
 +
=CRect=
 +
  struct CRect
 +
  {
 +
    float top;
 +
    float miny;
 +
    float left;
 +
    float minx;
 +
    float bottom;
 +
    float maxy;
 +
    float right;
 +
    float maxx;
 +
  };
 +
 +
=CiRect=
 +
  struct CiRect
 +
  {
 +
    int top;
 +
    int miny;
 +
    int left;
 +
    int minx;
 +
    int bottom;
 +
    int maxy;
 +
    int right;
 +
    int maxx;
 +
  };
 +
 
=fixed_point=
 
=fixed_point=
A fixed point real number, opposed to a floating point.
+
A fixed point real number, opposed to a floating point. A <tt>sign</tt> bit, a given number of <tt>integer_bits</tt> and <tt>decimal_bits</tt>, adding up to the bit count of the <tt>Base</tt> type.
  template<typename Base, size_t integer_bits, size_t decimal_bits> struct fixed_point
+
 
 +
For conversion, essentially ignore the <tt>sign</tt> and divide by <tt>2^decimal_bits</tt>, then multiply with the <tt>sign</tt> again. In the inverse direction, again mask the <tt>sign</tt>, divide by the factor, and multiply the <tt>sign</tt>.
 +
 
 +
For the special case if there are no <tt>integer_bits</tt>, i.e. <tt>{{Type|fixed16}}</tt>, use the factor of <tt>(2^(decimal_bits + 1) - 1)</tt> instead in order to use the full range.
 +
 
 +
As follows, a generic C++11 implementation of this. Yes, this could be one single function, but it was written to be generic and to be used inside structs where `to_float()` is `operator float()` instead to allow for easy use.
 +
 
 +
  template<typename Base, size_t integer_bits, size_t decimal_bits>
 +
  struct fixed_point
 
  {
 
  {
   Base decimal : decimal_bits;
+
   static const float constexpr factor = integer_bits
   Base integer : integer_bits;
+
                                      ? (1 <<  decimal_bits    )
  Base sign : 1;
+
                                      : (1 << (decimal_bits + 1)) - 1
   float to_float() const { return (sign ? -1.0f : 1.0f) * (integer + decimal / float (1 << decimal_bits)); }
+
                                      ;
 +
 +
   union {
 +
    struct {
 +
      Base integer_and_decimal : integer_bits + decimal_bits;
 +
      Base sign : 1;
 +
    };
 +
    Base raw;
 +
   };
 +
 +
  constexpr operator float() const {
 +
    return (sign ? -1.f : 1.f) * integer_and_decimal / factor;
 +
  }
 +
  constexpr fixed_point (float x)
 +
    : sign (x < 0.f)
 +
    , integer_and_decimal (std::abs (x) * factor)
 +
  {}
 
  };
 
  };
 +
 
=fixed16=
 
=fixed16=
A fixed point number without integer part.
+
A fixed point number without integer part. Trivially implemented using
  using fixed16 = short; // divide by 0x7fff to get float value
+
  using fixed16 = int16_t; // divide by 0x7fff to get float value
or semantically (0 is not a valid bit size in bitfields) equivalent to
+
or correctly implemented as
  using fixed16 = {{Template:Type|fixed_point}}<uint16_t, 0, 15>;
+
  using fixed16 = {{Type|fixed_point}}<uint16_t, 0, 15>;

Latest revision as of 23:21, 12 June 2018

This page lists types commonly used in WoW, but not specific to a file format.

foreign_key

A reference into a DBC or DB2 database file. E.g.

foreign_key<uint16_t, &LiquidTypeRec::m_spellID> liquid_spell_id;
            ^ type of reference
                       ^ table referenced
                                      ^ variable referenced

stringref

A reference into the string block of a DBC or DB2 database file. See DBC#String_Block.

using stringref = uint32_t;

langstringref

A field for localized strings, consisting of an array of stringrefs followed by a field of flags. The amount of language entries depends on the version, with Cataclysm dropping all but the client's language. See Localization for details.

struct langstringref
{
#if < Cata
  stringref enUS;   // also enGB
  stringref koKR;
  stringref frFR;
  stringref deDE;
  stringref enCN;   // also zhCN
  stringref enTW;   // also zhTW
  stringref esES;
  stringref esMX;
//! \todo verify that pre->8 locales hadn't changed
#if ≥ BC (2.1.0.6692)
  stringref ruRU;
  stringref jaJP; // unknowns are still unused as of 8.0.1.26095
  stringref ptPT;   // also ptBR
  stringref itIT;
  stringref unknown_12;
  stringref unknown_13;
  stringref unknown_14;
  stringref unknown_15;
#endif
  uint32_t flags;
#else
  stringref client_locale;
#endif
};

C2Vector

A two component float vector.

struct C2Vector
{
  float x;
  float y;
};

C2iVector

A two component int vector.

struct C2iVector
{
  int x;
  int y;
};

C3Vector

A three component float vector.

struct C3Vector
{
/*0x00*/  float x;
/*0x04*/  float y;
/*0x08*/  float z;
};

C3iVector

A three component int vector.

struct C3iVector
{
  int x;
  int y;
  int z;
};

C4Vector

A four component float vector.

struct C4Vector
{
  float x;
  float y;
  float z;
  float w;
};

C4iVector

A four component int vector.

 struct C4iVector
 {
   int x;
   int y;
   int z;
   int w;
 };

C33Matrix

A three by three matrix.

struct C33Matrix // todo: row or column?
{
  C3Vector columns[3];
};

C34Matrix

A three by four matrix.

struct C34Matrix // todo: row or column?
{
  C3Vector columns[4];
};

C44Matrix

A four by four matrix.

struct C44Matrix // todo: row or column?
{
  C4Vector columns[4];
};

C4Plane

A 3D plane defined by four floats.

struct C4Plane // todo: verify
{
  C3Vector normal;
  float distance;
};

Those 4 floats are a, b, c, d variables from General form of the equation of a plane

C4Quaternion

A quaternion.

struct C4Quaternion
{
  float x;
  float y;
  float z;
  float w; // Unlike Quaternions elsewhere, the scalar part ('w') is the last element in the struct instead of the first
};

CRange

A one dimensional float range defined by the bounds.

struct Range
{
  float min;
  float max;
};

CiRange

A one dimensional int range defined by the bounds.

struct Range
{
  int min;
  int max;
};

CAaBox

An axis aligned box described by the minimum and maximum point.

struct CAaBox
{
  C3Vector min;
  C3Vector max;
};

CAaSphere

An axis aligned sphere described by position and radius.

struct CAaSphere
{
  C3Vector position;
  float radius;
};

CArgb

A color given in values of red, green, blue and alpha. Either

using CArgb = uint32_t;

or

struct CArgb // todo: verify, add CRgba, ..?
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
  unsigned char a;
};

CImVector

A color given in values of blue, green, red and alpha

struct CImVector
{
  unsigned char b;
  unsigned char g;
  unsigned char r;
  unsigned char a;
};

C3sVector

A three component vector of shorts.

struct C3sVector
{
  int16_t x;
  int16_t y;
  int16_t z;
};

C3Segment

 struct C3Segment
 {
   C3Vector start;
   C3Vector end;
 };

CFacet

 struct CFacet
 {
   C4Plane plane;
   C3Vector vertices[3];
 };

C3Ray

A ray defined by an origin and direction.

 struct C3Ray
 {
   C3Vector origin;
   C3Vector dir;
 };

CRect

 struct CRect
 {
   float top;
   float miny;
   float left;
   float minx;
   float bottom;
   float maxy;
   float right;
   float maxx;
 };

CiRect

 struct CiRect
 {
   int top;
   int miny;
   int left;
   int minx;
   int bottom;
   int maxy;
   int right;
   int maxx;
 };

fixed_point

A fixed point real number, opposed to a floating point. A sign bit, a given number of integer_bits and decimal_bits, adding up to the bit count of the Base type.

For conversion, essentially ignore the sign and divide by 2^decimal_bits, then multiply with the sign again. In the inverse direction, again mask the sign, divide by the factor, and multiply the sign.

For the special case if there are no integer_bits, i.e. fixed16, use the factor of (2^(decimal_bits + 1) - 1) instead in order to use the full range.

As follows, a generic C++11 implementation of this. Yes, this could be one single function, but it was written to be generic and to be used inside structs where `to_float()` is `operator float()` instead to allow for easy use.

template<typename Base, size_t integer_bits, size_t decimal_bits>
  struct fixed_point
{
  static const float constexpr factor = integer_bits
                                      ? (1 <<  decimal_bits     )
                                      : (1 << (decimal_bits + 1)) - 1
                                      ;

  union {
    struct {
      Base integer_and_decimal : integer_bits + decimal_bits;
      Base sign : 1;
    };
    Base raw;
  };

  constexpr operator float() const {
   return (sign ? -1.f : 1.f) * integer_and_decimal / factor;
  }
  constexpr fixed_point (float x) 
    : sign (x < 0.f)
    , integer_and_decimal (std::abs (x) * factor)
  {}
};

fixed16

A fixed point number without integer part. Trivially implemented using

using fixed16 = int16_t; // divide by 0x7fff to get float value

or correctly implemented as

using fixed16 = fixed_point<uint16_t, 0, 15>;