Convert hot-loop functions to be inline
This commit is contained in:
6 files changed
+78
-87
No files matched your search
+18
-1
@@ -24,6 +24,8 @@ struct ColorF32
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// OPERATORS
|
||||
// c1 + c2
|
||||
inline ColorF32 operator+(ColorF32 const &c1, ColorF32 const &c2)
|
||||
@@ -107,7 +109,22 @@ inline ColorF32 &operator/=(ColorF32 &c, float f)
|
||||
|
||||
|
||||
// PUBLIC FUNCTIONS
|
||||
void ScaleColor(ColorF32 &c);
|
||||
inline void ScaleColor(ColorF32 &c)
|
||||
{
|
||||
float blue = MAX(c.b, 0.0f);
|
||||
float green = MAX(c.g, 0.0f);
|
||||
float red = MAX(c.r, 0.0f);
|
||||
float alpha = MAX(c.a, 0.0f);
|
||||
float max = MAX(MAX(MAX(blue,green),red),1.0f);
|
||||
|
||||
ColorF32 scaled = {blue, green, red, alpha};
|
||||
scaled /= max;
|
||||
|
||||
c.b = scaled.b;
|
||||
c.g = scaled.g;
|
||||
c.r = scaled.r;
|
||||
c.a = scaled.a;
|
||||
}
|
||||
|
||||
|
||||
#define COLOR_H
|
||||
|
||||
+56
-4
@@ -1,5 +1,8 @@
|
||||
#ifndef VEC_H
|
||||
|
||||
#include "util.h"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
// STRUCTURE
|
||||
struct Vector
|
||||
@@ -100,10 +103,59 @@ inline Vector &operator/=(Vector &v, float f)
|
||||
|
||||
|
||||
// PUBLIC FUNCTIONS
|
||||
void VectorNormalize(Vector &v);
|
||||
float VectorLength(Vector &v);
|
||||
float VectorDot(Vector &v1, Vector &v2);
|
||||
Vector VectorCross(Vector &v1, Vector &v2);
|
||||
inline float VectorLength(Vector &v)
|
||||
{
|
||||
float result = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||
|
||||
// zero length
|
||||
if (result < EPSILON_E3)
|
||||
{
|
||||
result = 0.0f;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void VectorNormalize(Vector &v)
|
||||
{
|
||||
float length = VectorLength(v);
|
||||
|
||||
// zero length
|
||||
if (length == 0.0f)
|
||||
{
|
||||
v.x = 0.0f;
|
||||
v.y = 0.0f;
|
||||
v.z = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float lengthInv = 1.0f / length;
|
||||
|
||||
v.x *= lengthInv;
|
||||
v.y *= lengthInv;
|
||||
v.z *= lengthInv;
|
||||
}
|
||||
}
|
||||
|
||||
inline Vector VectorCross(Vector &v1, Vector &v2)
|
||||
{
|
||||
Vector result;
|
||||
|
||||
result.x = (v1.y * v2.z) - (v1.z * v2.y);
|
||||
result.y = (v1.z * v2.x) - (v1.x * v2.z);
|
||||
result.z = (v1.x * v2.y) - (v1.y * v2.x);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline float VectorDot(Vector &v1, Vector &v2)
|
||||
{
|
||||
float result;
|
||||
|
||||
result = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#define VEC_H
|
||||
|
||||
Reference in new issue
Block a user