From ed4aef49e1263799e331ac7e0b0712a371587f7e Mon Sep 17 00:00:00 2001 From: Zak Strange Date: Sat, 20 Aug 2016 09:13:37 -0700 Subject: [PATCH] 0.4 - Removed use of CRT --- HandmadeMath.h | 63 +++++++++++++++++++++++++++++++++++++++----------- README.md | 2 +- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index 8610ce1..4cf357c 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -1,5 +1,5 @@ /* - HandmadeMath.h v0.3 + HandmadeMath.h v0.4 This is a single header file with a bunch of useful functions for basic game math operations. @@ -65,6 +65,30 @@ All other files should just #include "HandmadeMath.h" without the #define. + ========================================================================== + + To Disable the CRT, you MUST + + #define HMM_SINF MySinF + #define HMM_COSF MyCosF + #define HMM_TANF MyTanF + + Provide your own implementations of SinF, CosF, and TanF + in EXACTLY one C or C++ file that includes this header, BEFORE the + include, like this: + + #define HMM_SINF MySinF + #define HMM_COSF MyCosF + #define HMM_TANF MyTanF + #define HANDMADE_MATH_IMPLEMENTATION + #define HANDMADE_MATH_CPP_MODE + #include "HandmadeMath.h" + + If you do not define these HandmadeMath.h will use version the version + of these function that are provided by the CRT. + + ========================================================================== + Version History: 0.2 (*) Updated documentation (*) Better C compliance @@ -80,7 +104,7 @@ 0.4 (*) SSE Optimized HMM_SqrtF (*) SSE Optimized HMM_RSqrtF - () Remove CRT + (*) Removed CRT LICENSE @@ -106,6 +130,10 @@ Insofaras (@insofaras) */ +// NOTE(zak): I think this is the include for SSE 2 on +// MacOS, Windows, and Linux if im wrong just open up +// a issue and tell me, or submit a pull request +// with the fix. #include #ifndef HANDMADE_MATH_H @@ -134,6 +162,22 @@ extern "C" #define HINLINE inline #endif +#if !defined(HMM_SINF) || !defined(HMM_COSF) || !defined(HMM_TANF) +#include +#endif + +#ifndef HMM_SINF +#define HMM_SINF sinf +#endif + +#ifndef HMM_COSF +#define HMM_COSF cosf +#endif + +#ifndef HMM_TANF +#define HMM_TANF tanf +#endif + #define HMM_PI32 3.14159265359f #define HMM_PI 3.14159265358979323846 @@ -376,15 +420,12 @@ HMMDEF hmm_vec4 operator/(hmm_vec4 Left, hmm_vec4 Right); #ifdef HANDMADE_MATH_IMPLEMENTATION -#include - -// TODO(zak): Replace these functions use of the C STD HINLINE float HMM_SinF(float Angle) { float Result = 0; - Result = sinf(Angle); + Result = HMM_SINF(Angle); return(Result); } @@ -393,7 +434,7 @@ HMM_CosF(float Angle) { float Result = 0; - Result = cosf(Angle); + Result = HMM_COSF(Angle); return(Result); } @@ -402,7 +443,7 @@ HMM_TanF(float Radians) { float Result = 0; - Result = tanf(Radians); + Result = HMM_TANF(Radians); return(Result); } @@ -1239,35 +1280,30 @@ operator-=(hmm_vec4 &Left, hmm_vec4 Right) return(Left = Left - Right); } - HINLINE hmm_vec2 & operator/=(hmm_vec2 &Left, hmm_vec2 Right) { return(Left = Left / Right); } - HINLINE hmm_vec3 & operator/=(hmm_vec3 &Left, hmm_vec3 Right) { return(Left = Left / Right); } - HINLINE hmm_vec4 & operator/=(hmm_vec4 &Left, hmm_vec4 Right) { return(Left = Left / Right); } - HINLINE hmm_vec2 & operator*=(hmm_vec2 &Left, hmm_vec2 Right) { return(Left = Left * Right); } - HINLINE hmm_vec3 & operator*=(hmm_vec3 &Left, hmm_vec3 Right) { @@ -1281,7 +1317,6 @@ operator*=(hmm_vec4 &Left, hmm_vec4 Right) return(Left = Left * Right); } - #endif /* HANDMADE_MATH_CPP_MODE */ #endif /* HANDMADE_MATH_IMPLEMENTATION */ \ No newline at end of file diff --git a/README.md b/README.md index 10d5ef6..2af618c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Single-file public domain game math library for C/C++ Version | Changes | ----------------|----------------| -**0.4 (ID)** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of CRT | +**0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of CRT | **0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 | **0.2b** | Disabled warning C4201 on MSVC, Added 64bit percision on HMM_PI | **0.2a** | Prefixed Macros |