Review libc dependencies and remove when possible

Just for clarification, no plans to remove libc dependency, just did some code analysis to see how much raylib depend on stardard C library. My conclusions:

 - stdlib.h: primary dependency is for malloc() and free()
 - stdio.h: primary dependency is for FILE access, maybe it could go through a custom ABI?
 - string.h: just around 8 functions required
 - math.h: just around 8 functions required
 - others: 1-2 functions required for some other headers
This commit is contained in:
Ray
2020-02-04 16:55:24 +01:00
parent 3cd9e3896a
commit b5fe41f41a
11 changed files with 73 additions and 67 deletions

View File

@@ -621,10 +621,10 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
#endif
#endif
#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
#include <stdlib.h> // Required for: malloc(), free(), rand()
#include <string.h> // Required for: strcmp(), strlen(), strtok() [Used only in extensions loading]
#include <math.h> // Required for: atan2()
#include <stdlib.h> // Required for: malloc(), free()
#include <stdio.h> // Required for: fopen(), fseek(), fread(), fclose() [LoadText]
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
#include <math.h> // Required for: atan2f()
#if !defined(RLGL_STANDALONE)
#include "raymath.h" // Required for: Vector3 and Matrix functions
@@ -677,7 +677,7 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
#endif
#if defined(RLGL_STANDALONE)
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used only on TRACELOG()]
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used in TraceLog()]
#endif
//----------------------------------------------------------------------------------
@@ -3683,10 +3683,10 @@ void SetVrConfiguration(VrDeviceInfo hmd, Shader distortion)
TRACELOGD("VR: Distortion Shader: Scale = { %f, %f }", scale[0], scale[1]);
TRACELOGD("VR: Distortion Shader: ScaleIn = { %f, %f }", scaleIn[0], scaleIn[1]);
// Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
// Fovy is normally computed with: 2*atan2f(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
// ...but with lens distortion it is increased (see Oculus SDK Documentation)
//float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale?
float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance);
//float fovy = 2.0f*atan2f(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale?
float fovy = 2.0f*(float)atan2f(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance);
// Compute camera projection matrices
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]