Ver a proveniência

Make MatrixToFloat and Vector3ToFloat reentrant

Besides making it thread-safe, it suppresses a GCC warning
when making them static inline in an upcoming patch.
pull/480/head
Ahmad Fatoum há 6 anos
ascendente
cometimento
e4d7bbec1e
Não foi encontrada uma chave conhecida para esta assinatura, na base de dados ID da chave GPG: C3EAC3DE9321D59B
2 ficheiros alterados com 55 adições e 29 eliminações
  1. +16
    -2
      src/raylib.h
  2. +39
    -27
      src/raymath.h

+ 16
- 2
src/raylib.h Ver ficheiro

@ -338,6 +338,14 @@ typedef struct Matrix {
float m3, m7, m11, m15;
} Matrix;
typedef struct Float3 {
float f[3];
} Float3;
typedef struct Float16 {
float f[16];
} Float16;
// Color type, RGBA (32bit)
typedef struct Color {
unsigned char r;
@ -743,11 +751,17 @@ RLAPI Color GetColor(int hexValue); // Returns a C
RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
// Math useful functions (available from raymath.h)
RLAPI float *Vector3ToFloat(Vector3 vec); // Returns Vector3 as float array
RLAPI float *MatrixToFloat(Matrix mat); // Returns Matrix as float array
RLAPI Vector3 Vector3Zero(void); // Vector with components value 0.0f
RLAPI Vector3 Vector3One(void); // Vector with components value 1.0f
RLAPI Matrix MatrixIdentity(void); // Returns identity matrix
#ifndef Vector3ToFloat
#define Vector3ToFloat(vec) (Vector3ToFloat_(vec).f) // Returns Vector3 as float array
RLAPI Float3 Vector3ToFloat_(Vector3 vec); // don't use, use above
#endif
#ifndef MatrixToFloat
#define MatrixToFloat(mat) (MatrixToFloat_(mat).f) // Returns Matrix as float array
RLAPI Float16 MatrixToFloat_(Matrix mat); // don't use, use above
#endif
// Misc. functions
RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags)

+ 39
- 27
src/raymath.h Ver ficheiro

@ -100,6 +100,12 @@
float m2, m6, m10, m14;
float m3, m7, m11, m15;
} Matrix;
typedef struct Float3 {
float f[3];
} Float3;
typedef struct Float16 {
float f[16];
} Float16;
#endif
// Quaternion type
@ -156,7 +162,7 @@ RMDEF Vector3 Vector3Reflect(Vector3 vector, Vector3 normal); // Calculate re
RMDEF Vector3 Vector3Min(Vector3 vec1, Vector3 vec2); // Return min value for each pair of components
RMDEF Vector3 Vector3Max(Vector3 vec1, Vector3 vec2); // Return max value for each pair of components
RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); // Barycenter coords for p in triangle abc
RMDEF kt">float *Vector3ToFloat(Vector3 vec); // Returns Vector3 as float array
RMDEF n">Float3 Vector3ToFloat_(Vector3 vec); // Returns Vector3 as float array
//------------------------------------------------------------------------------------
// Functions Declaration to work with Matrix
@ -180,7 +186,7 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top,
RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far); // Returns perspective projection matrix
RMDEF Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); // Returns orthographic projection matrix
RMDEF Matrix MatrixLookAt(Vector3 position, Vector3 target, Vector3 up); // Returns camera look-at matrix (view matrix)
RMDEF kt">float *MatrixToFloat(Matrix mat); // Returns float array of Matrix data
RMDEF n">Float16 MatrixToFloat_(Matrix mat); // Returns float array of Matrix data
//------------------------------------------------------------------------------------
// Functions Declaration to work with Quaternions
@ -548,16 +554,19 @@ RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
}
// Returns Vector3 as float array
RMDEF kt">float *Vector3ToFloat(Vector3 vec)
RMDEF n">Float3 Vector3ToFloat_(Vector3 vec)
{
k">static float buffer[3];
n">Float3 buffer;
buffer[0] = vec.x;
buffer[1] = vec.y;
buffer[2] = vec.z;
buffer.f[0] = vec.x;
buffer.f[1] = vec.y;
buffer.f[2] = vec.z;
return buffer;
}
#ifndef Vector3ToFloat
#define Vector3ToFloat(vec) (Vector3ToFloat_(vec).f)
#endif
//----------------------------------------------------------------------------------
// Module Functions Definition - Matrix math
@ -993,29 +1002,32 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
}
// Returns float array of matrix data
RMDEF kt">float *MatrixToFloat(Matrix mat)
{
k">static float buffer[16];
buffer[0] = mat.m0;
buffer[1] = mat.m1;
buffer[2] = mat.m2;
buffer[3] = mat.m3;
buffer[4] = mat.m4;
buffer[5] = mat.m5;
buffer[6] = mat.m6;
buffer[7] = mat.m7;
buffer[8] = mat.m8;
buffer[9] = mat.m9;
buffer[10] = mat.m10;
buffer[11] = mat.m11;
buffer[12] = mat.m12;
buffer[13] = mat.m13;
buffer[14] = mat.m14;
buffer[15] = mat.m15;
RMDEF n">Float16 MatrixToFloat_(Matrix mat)
{
n">Float16 buffer;
buffer.f[0] = mat.m0;
buffer.f[1] = mat.m1;
buffer.f[2] = mat.m2;
buffer.f[3] = mat.m3;
buffer.f[4] = mat.m4;
buffer.f[5] = mat.m5;
buffer.f[6] = mat.m6;
buffer.f[7] = mat.m7;
buffer.f[8] = mat.m8;
buffer.f[9] = mat.m9;
buffer.f[10] = mat.m10;
buffer.f[11] = mat.m11;
buffer.f[12] = mat.m12;
buffer.f[13] = mat.m13;
buffer.f[14] = mat.m14;
buffer.f[15] = mat.m15;
return buffer;
}
#ifndef MatrixToFloat
#define MatrixToFloat(mat) (MatrixToFloat_(mat).f)
#endif
//----------------------------------------------------------------------------------
// Module Functions Definition - Quaternion math

Carregando…
Cancelar
Guardar