diff options
| author | raysan5 <[email protected]> | 2021-07-30 13:44:52 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-07-30 13:44:52 +0200 |
| commit | b4fddf146b1f3d7c0548263594ad7283e6a9ac71 (patch) | |
| tree | fce34d8b6d2049806f598ac59ffa6673d361a6b5 /src/raymath.h | |
| parent | aeb1a0da84adc9e6987e1436431ea9cf495c8802 (diff) | |
| download | raylib-b4fddf146b1f3d7c0548263594ad7283e6a9ac71.tar.gz raylib-b4fddf146b1f3d7c0548263594ad7283e6a9ac71.zip | |
REVIEWED: Added new mechanism to avoid data types collision between modules that share same data types and can be used in standalone mode
Diffstat (limited to 'src/raymath.h')
| -rw-r--r-- | src/raymath.h | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/src/raymath.h b/src/raymath.h index ffdd2c27..2eb7bbd0 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -9,14 +9,10 @@ * If not defined, the library is in header only mode and can be included in other headers * or source files without problems. But only ONE file should hold the implementation. * -* #define RAYMATH_HEADER_ONLY +* #define RAYMATH_STATIC_INLINE * Define static inline functions code, so #include header suffices for use. * This may use up lots of memory. * -* #define RAYMATH_STANDALONE -* Avoid raylib.h header inclusion in this file. -* Vector3 and Matrix data types are defined internally in raymath module. -* * * LICENSE: zlib/libpng * @@ -42,15 +38,8 @@ #ifndef RAYMATH_H #define RAYMATH_H -//#define RAYMATH_STANDALONE // NOTE: To use raymath as standalone lib, just uncomment this line -//#define RAYMATH_HEADER_ONLY // NOTE: To compile functions as static inline, uncomment this line - -#ifndef RAYMATH_STANDALONE - #include "raylib.h" // Required for: Vector3, Matrix structs definition -#endif - -#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_HEADER_ONLY) - #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_HEADER_ONLY is contradictory" +#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE) + #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory" #endif #if defined(RAYMATH_IMPLEMENTATION) @@ -61,7 +50,7 @@ #else #define RMDEF extern inline // Provide external definition #endif -#elif defined(RAYMATH_HEADER_ONLY) +#elif defined(RAYMATH_STATIC_INLINE) #define RMDEF static inline // Functions may be inlined, no external out-of-line definition #else #if defined(__TINYC__) @@ -100,38 +89,51 @@ // Types and Structures Definition //---------------------------------------------------------------------------------- -#if defined(RAYMATH_STANDALONE) - // Vector2 type - typedef struct Vector2 { - float x; - float y; - } Vector2; - - // Vector3 type - typedef struct Vector3 { - float x; - float y; - float z; - } Vector3; - - // Vector4 type - typedef struct Vector4 { - float x; - float y; - float z; - float w; - } Vector4; - - // Quaternion type - typedef Vector4 Quaternion; - - // Matrix type (OpenGL style 4x4 - right handed, column major) - typedef struct Matrix { - float m0, m4, m8, m12; - float m1, m5, m9, m13; - float m2, m6, m10, m14; - float m3, m7, m11, m15; - } Matrix; +#if !defined(RL_VECTOR2_TYPE) +// Vector2 type +typedef struct Vector2 { + float x; + float y; +} Vector2; +#define RL_VECTOR2_TYPE +#endif + +#if !defined(RL_VECTOR3_TYPE) +// Vector3 type +typedef struct Vector3 { + float x; + float y; + float z; +} Vector3; +#define RL_VECTOR3_TYPE +#endif + +#if !defined(RL_VECTOR4_TYPE) +// Vector4 type +typedef struct Vector4 { + float x; + float y; + float z; + float w; +} Vector4; +#define RL_VECTOR4_TYPE +#endif + +#if !defined(RL_QUATERNION_TYPE) +// Quaternion type +typedef Vector4 Quaternion; +#define RL_QUATERNION_TYPE +#endif + +#if !defined(RL_MATRIX_TYPE) +// Matrix type (OpenGL style 4x4 - right handed, column major) +typedef struct Matrix { + float m0, m4, m8, m12; // Matrix first row (4 components) + float m1, m5, m9, m13; // Matrix second row (4 components) + float m2, m6, m10, m14; // Matrix third row (4 components) + float m3, m7, m11, m15; // Matrix fourth row (4 components) +} Matrix; +#define RL_MATRIX_TYPE #endif // NOTE: Helper types to be used instead of array return types for *ToFloat functions |
