Skip to content

Commit

Permalink
Fix warnings in raylib project from MSVC (#2871)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffM2501 authored Jan 20, 2023
1 parent 116603e commit edaca16
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
17 changes: 13 additions & 4 deletions src/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ typedef struct tagBITMAPINFOHEADER {

#if defined(SUPPORT_FILEFORMAT_OGG)
// TODO: Remap stb_vorbis malloc()/free() calls to RL_MALLOC/RL_FREE

#define STB_VORBIS_IMPLEMENTATION
#include "external/stb_vorbis.h" // OGG loading functions
#endif
Expand All @@ -207,8 +206,18 @@ typedef struct tagBITMAPINFOHEADER {
#define JARXM_MALLOC RL_MALLOC
#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
#include "external/jar_xm.h" // XM loading functions

#if defined(_MSC_VER )
#pragma warning( pop )
#endif

#endif

#if defined(SUPPORT_FILEFORMAT_MOD)
Expand Down Expand Up @@ -1756,7 +1765,7 @@ void UpdateMusicStream(Music music)
{
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;
frameCountStillNeeded -= frameCountRed;
if (frameCountStillNeeded == 0) break;
Expand All @@ -1767,7 +1776,7 @@ void UpdateMusicStream(Music music)
{
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;
frameCountStillNeeded -= frameCountRed;
if (frameCountStillNeeded == 0) break;
Expand Down Expand Up @@ -1807,7 +1816,7 @@ void UpdateMusicStream(Music music)
{
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;
frameCountStillNeeded -= frameCountRed;
if (frameCountStillNeeded == 0) break;
Expand Down
45 changes: 28 additions & 17 deletions src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,19 @@
#define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
#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
#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

#if defined(_WIN32)
Expand Down Expand Up @@ -690,7 +701,7 @@ void DrawCapsule(Vector3 startPos, Vector3 endPos, float radius, int slices, int
Vector3 capCenter = endPos;

float baseSliceAngle = (2.0f*PI)/slices;
float baseRingAngle = PI * 0.5 / rings;
float baseRingAngle = PI * 0.5f / rings;

rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -833,7 +844,7 @@ void DrawCapsuleWires(Vector3 startPos, Vector3 endPos, float radius, int slices
Vector3 capCenter = endPos;

float baseSliceAngle = (2.0f*PI)/slices;
float baseRingAngle = PI * 0.5 / rings;
float baseRingAngle = PI * 0.5f / rings;

rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -4697,7 +4708,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
// Load bone info from GLTF skin data
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));

for (unsigned int i = 0; i < skin.joints_count; i++)
Expand Down Expand Up @@ -5097,7 +5108,7 @@ static Model LoadGLTF(const char *fileName)
model.bones = LoadBoneInfoGLTF(skin, &model.boneCount);
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];
model.bindPose[i].translation.x = node.translation[0];
Expand Down Expand Up @@ -5275,7 +5286,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, unsigned in
if (data->skins_count == 1)
{
cgltf_skin skin = data->skins[0];
*animCount = data->animations_count;
*animCount = (int)data->animations_count;
animations = RL_MALLOC(data->animations_count*sizeof(ModelAnimation));

for (unsigned int i = 0; i < data->animations_count; i++)
Expand Down Expand Up @@ -5349,12 +5360,12 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, unsigned in
animations[i].frameCount = (int)(animDuration*1000.0f/GLTF_ANIMDELAY);
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));
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};
Quaternion rotation = {0, 0, 0, 1};
Expand Down Expand Up @@ -5567,7 +5578,7 @@ static Model LoadM3D(const char *fileName)
// Map no material to index 0 with default shader, everything else materialid + 1
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
if (mi != m3d->face[i].materialid)
Expand All @@ -5584,7 +5595,7 @@ static Model LoadM3D(const char *fileName)
k++;
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].triangleCount = l;
Expand Down Expand Up @@ -5636,11 +5647,11 @@ static Model LoadM3D(const char *fileName)
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 + 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 + 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 + 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)
Expand All @@ -5664,7 +5675,7 @@ static Model LoadM3D(const char *fileName)
int skinid = m3d->vertex[m3d->face[i].vertex[n]].skinid;

// 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++)
{
Expand All @@ -5684,7 +5695,7 @@ static Model LoadM3D(const char *fileName)
}

// Load materials
for (i = 0; i < m3d->nummaterial; i++)
for (i = 0; i < (int)m3d->nummaterial; i++)
{
model.materials[i + 1] = LoadMaterialDefault();

Expand Down Expand Up @@ -5761,7 +5772,7 @@ static Model LoadM3D(const char *fileName)
model.bones = RL_CALLOC(model.boneCount, sizeof(BoneInfo));
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;
strncpy(model.bones[i].name, m3d->bone[i].name, sizeof(model.bones[i].name));
Expand Down Expand Up @@ -5864,7 +5875,7 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int
// 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);

for (i = 0; i < m3d->numbone; i++)
for (i = 0; i < (int)m3d->numbone; i++)
{
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));
Expand All @@ -5884,7 +5895,7 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int

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.y = m3d->vertex[pose[j].pos].y*m3d->scale;
Expand Down
12 changes: 6 additions & 6 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
// Draw a pixel
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)
Expand Down Expand Up @@ -156,8 +156,8 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo
{
rlBegin(RL_LINES);
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();
}

Expand Down Expand Up @@ -209,7 +209,7 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)

float dy = current.y-previous.y;
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)
{
Expand Down Expand Up @@ -254,7 +254,7 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl

float dy = current.y-previous.y;
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)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP

float dy = current.y-previous.y;
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)
{
Expand Down
9 changes: 9 additions & 0 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,17 @@
#define QOI_MALLOC RL_MALLOC
#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
#include "external/qoi.h"

#if defined(_MSC_VER )
#pragma warning( pop )
#endif

#endif

#if defined(SUPPORT_IMAGE_EXPORT)
Expand Down

0 comments on commit edaca16

Please sign in to comment.