Browse Source

Fix warnings in raylib project from MSVC (#2871)

Jeffery Myers 2 years ago
parent
commit
edaca16d7c
4 changed files with 56 additions and 27 deletions
  1. 13 4
      src/raudio.c
  2. 28 17
      src/rmodels.c
  3. 6 6
      src/rshapes.c
  4. 9 0
      src/rtextures.c

+ 13 - 4
src/raudio.c

@@ -198,7 +198,6 @@ typedef struct tagBITMAPINFOHEADER {
 
 
 #if defined(SUPPORT_FILEFORMAT_OGG)
 #if defined(SUPPORT_FILEFORMAT_OGG)
     // TODO: Remap stb_vorbis malloc()/free() calls to RL_MALLOC/RL_FREE
     // TODO: Remap stb_vorbis malloc()/free() calls to RL_MALLOC/RL_FREE
-
     #define STB_VORBIS_IMPLEMENTATION
     #define STB_VORBIS_IMPLEMENTATION
     #include "external/stb_vorbis.h"    // OGG loading functions
     #include "external/stb_vorbis.h"    // OGG loading functions
 #endif
 #endif
@@ -207,8 +206,18 @@ typedef struct tagBITMAPINFOHEADER {
     #define JARXM_MALLOC RL_MALLOC
     #define JARXM_MALLOC RL_MALLOC
     #define JARXM_FREE RL_FREE
     #define JARXM_FREE RL_FREE
 
 
+#if defined(_MSC_VER ) // jar xm has  warnings on windows, so disable them just for this file
+#pragma warning( push )
+#pragma warning( disable : 4244)
+#endif
+
     #define JAR_XM_IMPLEMENTATION
     #define JAR_XM_IMPLEMENTATION
     #include "external/jar_xm.h"        // XM loading functions
     #include "external/jar_xm.h"        // XM loading functions
+
+#if defined(_MSC_VER )
+#pragma warning( pop )
+#endif
+
 #endif
 #endif
 
 
 #if defined(SUPPORT_FILEFORMAT_MOD)
 #if defined(SUPPORT_FILEFORMAT_MOD)
@@ -1756,7 +1765,7 @@ void UpdateMusicStream(Music music)
                 {
                 {
                     while (true)
                     while (true)
                     {
                     {
-                        int frameCountRed = drwav_read_pcm_frames_s16((drwav *)music.ctxData, frameCountStillNeeded, (short *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
+                        int frameCountRed = (int)drwav_read_pcm_frames_s16((drwav *)music.ctxData, frameCountStillNeeded, (short *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
                         frameCountRedTotal += frameCountRed;
                         frameCountRedTotal += frameCountRed;
                         frameCountStillNeeded -= frameCountRed;
                         frameCountStillNeeded -= frameCountRed;
                         if (frameCountStillNeeded == 0) break;
                         if (frameCountStillNeeded == 0) break;
@@ -1767,7 +1776,7 @@ void UpdateMusicStream(Music music)
                 {
                 {
                     while (true)
                     while (true)
                     {
                     {
-                        int frameCountRed = drwav_read_pcm_frames_f32((drwav *)music.ctxData, frameCountStillNeeded, (float *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
+                        int frameCountRed = (int)drwav_read_pcm_frames_f32((drwav *)music.ctxData, frameCountStillNeeded, (float *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
                         frameCountRedTotal += frameCountRed;
                         frameCountRedTotal += frameCountRed;
                         frameCountStillNeeded -= frameCountRed;
                         frameCountStillNeeded -= frameCountRed;
                         if (frameCountStillNeeded == 0) break;
                         if (frameCountStillNeeded == 0) break;
@@ -1807,7 +1816,7 @@ void UpdateMusicStream(Music music)
             {
             {
                 while (true)
                 while (true)
                 {
                 {
-                    int frameCountRed = drmp3_read_pcm_frames_f32((drmp3 *)music.ctxData, frameCountStillNeeded, (float *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
+                    int frameCountRed = (int)drmp3_read_pcm_frames_f32((drmp3 *)music.ctxData, frameCountStillNeeded, (float *)((char *)AUDIO.System.pcmBuffer + frameCountRedTotal*frameSize));
                     frameCountRedTotal += frameCountRed;
                     frameCountRedTotal += frameCountRed;
                     frameCountStillNeeded -= frameCountRed;
                     frameCountStillNeeded -= frameCountRed;
                     if (frameCountStillNeeded == 0) break;
                     if (frameCountStillNeeded == 0) break;

+ 28 - 17
src/rmodels.c

@@ -102,8 +102,19 @@
     #define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
     #define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
     #define PAR_FREE RL_FREE
     #define PAR_FREE RL_FREE
 
 
+#if defined(_MSC_VER ) // par shapes has 2 warnings on windows, so disable them just fof this file
+#pragma warning( push )
+#pragma warning( disable : 4244)
+#pragma warning( disable : 4305)
+#endif
+
     #define PAR_SHAPES_IMPLEMENTATION
     #define PAR_SHAPES_IMPLEMENTATION
     #include "external/par_shapes.h"    // Shapes 3d parametric generation
     #include "external/par_shapes.h"    // Shapes 3d parametric generation
+
+#if defined(_MSC_VER )  // disable MSVC warning suppression for par shapes
+#pragma warning( pop ) 
+#endif
+
 #endif
 #endif
 
 
 #if defined(_WIN32)
 #if defined(_WIN32)
@@ -690,7 +701,7 @@ void DrawCapsule(Vector3 startPos, Vector3 endPos, float radius, int slices, int
     Vector3 capCenter = endPos;
     Vector3 capCenter = endPos;
 
 
     float baseSliceAngle = (2.0f*PI)/slices;
     float baseSliceAngle = (2.0f*PI)/slices;
-    float baseRingAngle  = PI * 0.5 / rings; 
+    float baseRingAngle  = PI * 0.5f / rings; 
 
 
     rlBegin(RL_TRIANGLES);
     rlBegin(RL_TRIANGLES);
         rlColor4ub(color.r, color.g, color.b, color.a);
         rlColor4ub(color.r, color.g, color.b, color.a);
@@ -833,7 +844,7 @@ void DrawCapsuleWires(Vector3 startPos, Vector3 endPos, float radius, int slices
     Vector3 capCenter = endPos;
     Vector3 capCenter = endPos;
 
 
     float baseSliceAngle = (2.0f*PI)/slices;
     float baseSliceAngle = (2.0f*PI)/slices;
-    float baseRingAngle  = PI * 0.5 / rings; 
+    float baseRingAngle  = PI * 0.5f / rings; 
 
 
     rlBegin(RL_LINES);
     rlBegin(RL_LINES);
         rlColor4ub(color.r, color.g, color.b, color.a);
         rlColor4ub(color.r, color.g, color.b, color.a);
@@ -4697,7 +4708,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
 // Load bone info from GLTF skin data
 // Load bone info from GLTF skin data
 static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, int *boneCount)
 static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, int *boneCount)
 {
 {
-    *boneCount = skin.joints_count;
+    *boneCount = (int)skin.joints_count;
     BoneInfo *bones = RL_MALLOC(skin.joints_count*sizeof(BoneInfo));
     BoneInfo *bones = RL_MALLOC(skin.joints_count*sizeof(BoneInfo));
 
 
     for (unsigned int i = 0; i < skin.joints_count; i++)
     for (unsigned int i = 0; i < skin.joints_count; i++)
@@ -5097,7 +5108,7 @@ static Model LoadGLTF(const char *fileName)
             model.bones = LoadBoneInfoGLTF(skin, &model.boneCount);
             model.bones = LoadBoneInfoGLTF(skin, &model.boneCount);
             model.bindPose = RL_MALLOC(model.boneCount*sizeof(Transform));
             model.bindPose = RL_MALLOC(model.boneCount*sizeof(Transform));
 
 
-            for (unsigned int i = 0; i < model.boneCount; i++)
+            for (int i = 0; i < model.boneCount; i++)
             {
             {
                 cgltf_node node = *skin.joints[i];
                 cgltf_node node = *skin.joints[i];
                 model.bindPose[i].translation.x = node.translation[0];
                 model.bindPose[i].translation.x = node.translation[0];
@@ -5275,7 +5286,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, unsigned in
         if (data->skins_count == 1)
         if (data->skins_count == 1)
         {
         {
             cgltf_skin skin = data->skins[0];
             cgltf_skin skin = data->skins[0];
-            *animCount = data->animations_count;
+            *animCount = (int)data->animations_count;
             animations = RL_MALLOC(data->animations_count*sizeof(ModelAnimation));
             animations = RL_MALLOC(data->animations_count*sizeof(ModelAnimation));
             
             
             for (unsigned int i = 0; i < data->animations_count; i++)
             for (unsigned int i = 0; i < data->animations_count; i++)
@@ -5349,12 +5360,12 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, unsigned in
                 animations[i].frameCount = (int)(animDuration*1000.0f/GLTF_ANIMDELAY);
                 animations[i].frameCount = (int)(animDuration*1000.0f/GLTF_ANIMDELAY);
                 animations[i].framePoses = RL_MALLOC(animations[i].frameCount*sizeof(Transform *));
                 animations[i].framePoses = RL_MALLOC(animations[i].frameCount*sizeof(Transform *));
 
 
-                for (unsigned int j = 0; j < animations[i].frameCount; j++)
+                for (int j = 0; j < animations[i].frameCount; j++)
                 {
                 {
                     animations[i].framePoses[j] = RL_MALLOC(animations[i].boneCount*sizeof(Transform));
                     animations[i].framePoses[j] = RL_MALLOC(animations[i].boneCount*sizeof(Transform));
                     float time = ((float) j*GLTF_ANIMDELAY)/1000.0f;
                     float time = ((float) j*GLTF_ANIMDELAY)/1000.0f;
                     
                     
-                    for (unsigned int k = 0; k < animations[i].boneCount; k++)
+                    for (int k = 0; k < animations[i].boneCount; k++)
                     {
                     {
                         Vector3 translation = {0, 0, 0};
                         Vector3 translation = {0, 0, 0};
                         Quaternion rotation = {0, 0, 0, 1};
                         Quaternion rotation = {0, 0, 0, 1};
@@ -5567,7 +5578,7 @@ static Model LoadM3D(const char *fileName)
         // Map no material to index 0 with default shader, everything else materialid + 1
         // Map no material to index 0 with default shader, everything else materialid + 1
         model.materials[0] = LoadMaterialDefault();
         model.materials[0] = LoadMaterialDefault();
 
 
-        for (i = l = 0, k = -1; i < m3d->numface; i++, l++)
+        for (i = l = 0, k = -1; i < (int)m3d->numface; i++, l++)
         {
         {
             // Materials are grouped together
             // Materials are grouped together
             if (mi != m3d->face[i].materialid)
             if (mi != m3d->face[i].materialid)
@@ -5584,7 +5595,7 @@ static Model LoadM3D(const char *fileName)
                 k++;
                 k++;
                 mi = m3d->face[i].materialid;
                 mi = m3d->face[i].materialid;
 
 
-                for (j = i, l = 0; (j < m3d->numface) && (mi == m3d->face[j].materialid); j++, l++);
+                for (j = i, l = 0; (j < (int)m3d->numface) && (mi == m3d->face[j].materialid); j++, l++);
 
 
                 model.meshes[k].vertexCount = l*3;
                 model.meshes[k].vertexCount = l*3;
                 model.meshes[k].triangleCount = l;
                 model.meshes[k].triangleCount = l;
@@ -5636,11 +5647,11 @@ static Model LoadM3D(const char *fileName)
             if (m3d->face[i].texcoord[0] != M3D_UNDEF)
             if (m3d->face[i].texcoord[0] != M3D_UNDEF)
             {
             {
                 model.meshes[k].texcoords[l*6 + 0] = m3d->tmap[m3d->face[i].texcoord[0]].u;
                 model.meshes[k].texcoords[l*6 + 0] = m3d->tmap[m3d->face[i].texcoord[0]].u;
-                model.meshes[k].texcoords[l*6 + 1] = 1.0 - m3d->tmap[m3d->face[i].texcoord[0]].v;
+                model.meshes[k].texcoords[l*6 + 1] = 1.0f - m3d->tmap[m3d->face[i].texcoord[0]].v;
                 model.meshes[k].texcoords[l*6 + 2] = m3d->tmap[m3d->face[i].texcoord[1]].u;
                 model.meshes[k].texcoords[l*6 + 2] = m3d->tmap[m3d->face[i].texcoord[1]].u;
-                model.meshes[k].texcoords[l*6 + 3] = 1.0 - m3d->tmap[m3d->face[i].texcoord[1]].v;
+                model.meshes[k].texcoords[l*6 + 3] = 1.0f - m3d->tmap[m3d->face[i].texcoord[1]].v;
                 model.meshes[k].texcoords[l*6 + 4] = m3d->tmap[m3d->face[i].texcoord[2]].u;
                 model.meshes[k].texcoords[l*6 + 4] = m3d->tmap[m3d->face[i].texcoord[2]].u;
-                model.meshes[k].texcoords[l*6 + 5] = 1.0 - m3d->tmap[m3d->face[i].texcoord[2]].v;
+                model.meshes[k].texcoords[l*6 + 5] = 1.0f - m3d->tmap[m3d->face[i].texcoord[2]].v;
             }
             }
 
 
             if (m3d->face[i].normal[0] != M3D_UNDEF)
             if (m3d->face[i].normal[0] != M3D_UNDEF)
@@ -5664,7 +5675,7 @@ static Model LoadM3D(const char *fileName)
                     int skinid = m3d->vertex[m3d->face[i].vertex[n]].skinid;
                     int skinid = m3d->vertex[m3d->face[i].vertex[n]].skinid;
 
 
                     // Check if there is a skin for this mesh, should be, just failsafe
                     // Check if there is a skin for this mesh, should be, just failsafe
-                    if (skinid != M3D_UNDEF && skinid < m3d->numskin)
+                    if (skinid != M3D_UNDEF && skinid < (int)m3d->numskin)
                     {
                     {
                         for (j = 0; j < 4; j++)
                         for (j = 0; j < 4; j++)
                         {
                         {
@@ -5684,7 +5695,7 @@ static Model LoadM3D(const char *fileName)
         }
         }
 
 
         // Load materials
         // Load materials
-        for (i = 0; i < m3d->nummaterial; i++)
+        for (i = 0; i < (int)m3d->nummaterial; i++)
         {
         {
             model.materials[i + 1] = LoadMaterialDefault();
             model.materials[i + 1] = LoadMaterialDefault();
 
 
@@ -5761,7 +5772,7 @@ static Model LoadM3D(const char *fileName)
             model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo));
             model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo));
             model.bindPose = RL_CALLOC(model.boneCount, sizeof(Transform));
             model.bindPose = RL_CALLOC(model.boneCount, sizeof(Transform));
 
 
-            for (i = 0; i < m3d->numbone; i++)
+            for (i = 0; i < (int)m3d->numbone; i++)
             {
             {
                 model.bones[i].parent = m3d->bone[i].parent;
                 model.bones[i].parent = m3d->bone[i].parent;
                 strncpy(model.bones[i].name, m3d->bone[i].name, sizeof(model.bones[i].name));
                 strncpy(model.bones[i].name, m3d->bone[i].name, sizeof(model.bones[i].name));
@@ -5864,7 +5875,7 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int
             // strncpy(animations[a].name, m3d->action[a].name, sizeof(animations[a].name));
             // strncpy(animations[a].name, m3d->action[a].name, sizeof(animations[a].name));
             TRACELOG(LOG_INFO, "MODEL: [%s] animation #%i: %i msec, %i frames", fileName, a, m3d->action[a].durationmsec, animations[a].frameCount);
             TRACELOG(LOG_INFO, "MODEL: [%s] animation #%i: %i msec, %i frames", fileName, a, m3d->action[a].durationmsec, animations[a].frameCount);
 
 
-            for (i = 0; i < m3d->numbone; i++)
+            for (i = 0; i < (int)m3d->numbone; i++)
             {
             {
                 animations[a].bones[i].parent = m3d->bone[i].parent;
                 animations[a].bones[i].parent = m3d->bone[i].parent;
                 strncpy(animations[a].bones[i].name, m3d->bone[i].name, sizeof(animations[a].bones[i].name));
                 strncpy(animations[a].bones[i].name, m3d->bone[i].name, sizeof(animations[a].bones[i].name));
@@ -5884,7 +5895,7 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int
                 
                 
                 if (pose != NULL)
                 if (pose != NULL)
                 {
                 {
-                    for (j = 0; j < m3d->numbone; j++)
+                    for (j = 0; j < (int)m3d->numbone; j++)
                     {
                     {
                         animations[a].framePoses[i][j].translation.x = m3d->vertex[pose[j].pos].x*m3d->scale;
                         animations[a].framePoses[i][j].translation.x = m3d->vertex[pose[j].pos].x*m3d->scale;
                         animations[a].framePoses[i][j].translation.y = m3d->vertex[pose[j].pos].y*m3d->scale;
                         animations[a].framePoses[i][j].translation.y = m3d->vertex[pose[j].pos].y*m3d->scale;

+ 6 - 6
src/rshapes.c

@@ -105,7 +105,7 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
 // Draw a pixel
 // Draw a pixel
 void DrawPixel(int posX, int posY, Color color)
 void DrawPixel(int posX, int posY, Color color)
 {
 {
-  DrawPixelV((Vector2){ posX, posY }, color);
+  DrawPixelV((Vector2){ (float)posX, (float)posY }, color);
 }
 }
 
 
 // Draw a pixel (Vector version)
 // Draw a pixel (Vector version)
@@ -156,8 +156,8 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo
 {
 {
     rlBegin(RL_LINES);
     rlBegin(RL_LINES);
         rlColor4ub(color.r, color.g, color.b, color.a);
         rlColor4ub(color.r, color.g, color.b, color.a);
-        rlVertex2f(startPosX, startPosY);
-        rlVertex2f(endPosX, endPosY);
+        rlVertex2f((float)startPosX, (float)startPosY);
+        rlVertex2f((float)endPosX, (float)endPosY);
     rlEnd();
     rlEnd();
 }
 }
 
 
@@ -209,7 +209,7 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
 
 
         float dy = current.y-previous.y;
         float dy = current.y-previous.y;
         float dx = current.x-previous.x;
         float dx = current.x-previous.x;
-        float size = 0.5*thick/sqrt(dx*dx+dy*dy);
+        float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
 
 
         if (i==1)
         if (i==1)
         {
         {
@@ -254,7 +254,7 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
 
 
         float dy = current.y-previous.y;
         float dy = current.y-previous.y;
         float dx = current.x-previous.x;
         float dx = current.x-previous.x;
-        float size = 0.5*thick/sqrt(dx*dx+dy*dy);
+        float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
 
 
         if (i==1)
         if (i==1)
         {
         {
@@ -299,7 +299,7 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP
 
 
         float dy = current.y-previous.y;
         float dy = current.y-previous.y;
         float dx = current.x-previous.x;
         float dx = current.x-previous.x;
-        float size = 0.5*thick/sqrt(dx*dx+dy*dy);
+        float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
         
         
         if (i==1)
         if (i==1)
         {
         {

+ 9 - 0
src/rtextures.c

@@ -163,8 +163,17 @@
     #define QOI_MALLOC RL_MALLOC
     #define QOI_MALLOC RL_MALLOC
     #define QOI_FREE RL_FREE
     #define QOI_FREE RL_FREE
 
 
+#if defined(_MSC_VER ) // qoi has warnings on windows, so disable them just for this file
+#pragma warning( push )
+#pragma warning( disable : 4267)
+#endif
     #define QOI_IMPLEMENTATION
     #define QOI_IMPLEMENTATION
     #include "external/qoi.h"
     #include "external/qoi.h"
+
+#if defined(_MSC_VER )
+#pragma warning( pop )
+#endif
+
 #endif
 #endif
 
 
 #if defined(SUPPORT_IMAGE_EXPORT)
 #if defined(SUPPORT_IMAGE_EXPORT)