Subversion Repositories Games.Carmageddon

Rev

Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef MACROS_H
  2. #define MACROS_H
  3.  
  4. #define DR_JOIN2(A,B) A##B
  5. #define DR_JOIN(A,B) DR_JOIN2(A, B)
  6. #define DR_STATIC_ASSERT(V) typedef int DR_JOIN(dr_static_assert_, __COUNTER__)[(V)?1:-1]
  7.  
  8. #define VEHICLE_TYPE_FROM_ID(id) ((tVehicle_type)(id >> 8))
  9. #define VEHICLE_INDEX_FROM_ID(id) ((id)&0x00ff)
  10.  
  11. // #define VEC3_TRANSLATE(mat) (*(br_vector3*)(&mat->m[3][0]))
  12.  
  13. #define SLOBYTE(x) (*((signed char*)&(x)))
  14.  
  15. #define STR_STARTS_WITH(haystack, needle) strncmp(haystack, needle, strlen(needle))
  16. #define STR_ENDS_WITH(haystack, needle) strcmp(haystack + strlen(haystack) - strlen(needle), needle)
  17.  
  18. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  19. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  20. #define CONSTRAIN_BETWEEN(lowerbound, upperbound, val) (MIN((upperbound), MAX((lowerbound), (val))))
  21.  
  22. #define COUNT_OF(array) (sizeof((array)) / sizeof((array)[0]))
  23. #define LEN(array) (sizeof((array)) / sizeof((array)[0]))
  24.  
  25. #define DEG_TO_RAD(degrees) ((degrees)*3.141592653589793 / 180.0)
  26.  
  27. #define V11MODEL(model) (((struct v11model*)model->prepared))
  28. #define CAR(c) ((tCar_spec*)c)
  29.  
  30. #define Vector3Div(v1, v2, v3)                \
  31.     do {                                      \
  32.         (v1)->v[0] = (v2)->v[0] / (v3)->v[0]; \
  33.         (v1)->v[1] = (v2)->v[1] / (v3)->v[1]; \
  34.         (v1)->v[2] = (v2)->v[2] / (v3)->v[2]; \
  35.     } while (0)
  36.  
  37. #define Vector3DistanceSquared(V1, V2) \
  38.     ((((V1)->v[0] - (V2)->v[0])) * (((V1)->v[0] - (V2)->v[0])) + (((V1)->v[1] - (V2)->v[1])) * (((V1)->v[1] - (V2)->v[1])) + (((V1)->v[2] - (V2)->v[2])) * (((V1)->v[2] - (V2)->v[2])))
  39.  
  40. #define Vector3Distance(V1, V2) sqrtf(Vector3DistanceSquared((V1), (V2)))
  41. #define Vector3AreEqual(V1, V2) \
  42.     ((V1)->v[0] == (V2)->v[0] && (V1)->v[1] == (V2)->v[1] && (V1)->v[2] == (V2)->v[2])
  43. #define Vector3EqualElements(V, A, B, C) \
  44.     ((V)->v[0] == (A) && (V)->v[1] == (B) && (V)->v[2] == (C))
  45. #define Vector3IsZero(V) Vector3EqualElements((V), 0.f, 0.f, 0.f)
  46. #define Vector3AddFloats(V1, V2, X, Y, Z) \
  47.     do {                                  \
  48.         (V1)->v[0] = (V2)->v[0] + (X);    \
  49.         (V1)->v[1] = (V2)->v[1] + (Y);    \
  50.         (V1)->v[2] = (V2)->v[2] + (Z);    \
  51.     } while (0)
  52. #define SwapValuesUsingTemporary(V1, V2, T) \
  53.     do {                                    \
  54.         (T) = (V1);                         \
  55.         (V1) = (V2);                        \
  56.         (V2) = (T);                         \
  57.     } while (0)
  58.  
  59. #endif
  60.