Browse Source

Review formatting

pull/3849/head
Ray 10 months ago
parent
commit
fea3395fc1
5 changed files with 62 additions and 58 deletions
  1. +14
    -11
      src/platforms/rcore_desktop_sdl.c
  2. +22
    -21
      src/rmodels.c
  3. +7
    -7
      src/rshapes.c
  4. +11
    -11
      src/rtext.c
  5. +8
    -8
      src/rtextures.c

+ 14
- 11
src/platforms/rcore_desktop_sdl.c View File

@ -971,21 +971,20 @@ void SetMouseCursor(int cursor)
CORE.Input.Mouse.cursor = cursor;
}
static void UpdateSDLTouchPoints(SDL_TouchFingerEvent event)
static void UpdateTouchPointsSDL(SDL_TouchFingerEvent event)
{
CORE.Input.Touch.pointCount = SDL_GetNumTouchFingers(event.touchId);
for (int i=0; i<CORE.Input.Touch.pointCount; i++)
for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
{
SDL_Finger *finger = SDL_GetTouchFinger(event.touchId, i);
CORE.Input.Touch.pointId[i] = finger->id;
CORE.Input.Touch.position[i].x = finger->x * CORE.Window.screen.width;
CORE.Input.Touch.position[i].y = finger->y * CORE.Window.screen.height;
CORE.Input.Touch.position[i].x = finger->x*CORE.Window.screen.width;
CORE.Input.Touch.position[i].y = finger->y*CORE.Window.screen.height;
CORE.Input.Touch.currentTouchState[i] = 1;
}
for (int i=CORE.Input.Touch.pointCount; i<MAX_TOUCH_POINTS; i++)
CORE.Input.Touch.currentTouchState[i] = 0;
for (int i = CORE.Input.Touch.pointCount; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.currentTouchState[i] = 0;
}
// Register all input events
@ -1218,19 +1217,19 @@ void PollInputEvents(void)
case SDL_FINGERDOWN:
{
UpdateSDLTouchPoints(event.tfinger);
UpdateTouchPointsSDL(event.tfinger);
touchAction = 1;
realTouch = true;
} break;
case SDL_FINGERUP:
{
UpdateSDLTouchPoints(event.tfinger);
UpdateTouchPointsSDL(event.tfinger);
touchAction = 0;
realTouch = true;
} break;
case SDL_FINGERMOTION:
{
UpdateSDLTouchPoints(event.tfinger);
UpdateTouchPointsSDL(event.tfinger);
touchAction = 2;
realTouch = true;
} break;
@ -1239,7 +1238,9 @@ void PollInputEvents(void)
case SDL_JOYDEVICEADDED:
{
int jid = event.jdevice.which;
if (!CORE.Input.Gamepad.ready[jid] && (jid < MAX_GAMEPADS)) {
if (!CORE.Input.Gamepad.ready[jid] && (jid < MAX_GAMEPADS))
{
platform.gamepad[jid] = SDL_JoystickOpen(jid);
if (platform.gamepad[jid])
@ -1260,7 +1261,9 @@ void PollInputEvents(void)
case SDL_JOYDEVICEREMOVED:
{
int jid = event.jdevice.which;
if (jid == SDL_JoystickInstanceID(platform.gamepad[jid])) {
if (jid == SDL_JoystickInstanceID(platform.gamepad[jid]))
{
SDL_JoystickClose(platform.gamepad[jid]);
platform.gamepad[jid] = SDL_JoystickOpen(0);
CORE.Input.Gamepad.ready[jid] = false;

+ 22
- 21
src/rmodels.c View File

@ -54,8 +54,8 @@
#include "raymath.h" // Required for: Vector3, Quaternion and Matrix functionality
#include <stdio.h> // Required for: sprintf()
#include <stdlib.h> // Required for: malloc(), free()
#include <string.h> // Required for: memcmp(), strlen()
#include <stdlib.h> // Required for: malloc(), calloc(), free()
#include <string.h> // Required for: memcmp(), strlen(), strncpy()
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), fabsf()
#if defined(SUPPORT_FILEFORMAT_OBJ) || defined(SUPPORT_FILEFORMAT_MTL)
@ -1883,7 +1883,7 @@ bool ExportMeshAsCode(Mesh mesh, const char *fileName)
byteCount += sprintf(txtData + byteCount, "// Mesh basic information\n");
byteCount += sprintf(txtData + byteCount, "#define %s_VERTEX_COUNT %i\n", varFileName, mesh.vertexCount);
byteCount += sprintf(txtData + byteCount, "#define %s_TRIANGLE_COUNT %i\n\n", varFileName, mesh.triangleCount);
// Define vertex attributes data as separate arrays
//-----------------------------------------------------------------------------------------
if (mesh.vertices != NULL) // Vertex position (XYZ - 3 components per vertex - float)
@ -1892,28 +1892,28 @@ bool ExportMeshAsCode(Mesh mesh, const char *fileName)
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.vertices[i]);
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.vertices[mesh.vertexCount*3 - 1]);
}
if (mesh.texcoords != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
if (mesh.texcoords != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
{
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords[i]);
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords[mesh.vertexCount*2 - 1]);
}
if (mesh.texcoords2 != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
if (mesh.texcoords2 != NULL) // Vertex texture coordinates (UV - 2 components per vertex - float)
{
byteCount += sprintf(txtData + byteCount, "static float %s_TEXCOORD2_DATA[%i] = { ", varFileName, mesh.vertexCount*2);
for (int i = 0; i < mesh.vertexCount*2 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.texcoords2[i]);
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.texcoords2[mesh.vertexCount*2 - 1]);
}
if (mesh.normals != NULL) // Vertex normals (XYZ - 3 components per vertex - float)
{
byteCount += sprintf(txtData + byteCount, "static float %s_NORMAL_DATA[%i] = { ", varFileName, mesh.vertexCount*3);
for (int i = 0; i < mesh.vertexCount*3 - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "%.3ff,\n" : "%.3ff, "), mesh.normals[i]);
byteCount += sprintf(txtData + byteCount, "%.3ff };\n\n", mesh.normals[mesh.vertexCount*3 - 1]);
}
if (mesh.tangents != NULL) // Vertex tangents (XYZW - 4 components per vertex - float)
{
byteCount += sprintf(txtData + byteCount, "static float %s_TANGENT_DATA[%i] = { ", varFileName, mesh.vertexCount*4);
@ -4050,7 +4050,7 @@ static Model LoadOBJ(const char *fileName)
model.meshCount = meshCount;
// Set number of materials available
// NOTE: There could be more materials available than meshes but it will be resolved at
// NOTE: There could be more materials available than meshes but it will be resolved at
// model.meshMaterial, just assigning the right material to corresponding mesh
model.materialCount = materialCount;
if (model.materialCount == 0)
@ -4068,7 +4068,7 @@ static Model LoadOBJ(const char *fileName)
for (int i = 0; i < model.meshCount; i++)
{
// WARNING: We need to calculate the mesh triangles manually using meshes[i].face_offset
// because in case of triangulated quads, meshes[i].length actually report quads,
// because in case of triangulated quads, meshes[i].length actually report quads,
// despite the triangulation that is efectively considered on attrib.num_faces
unsigned int tris = 0;
if (i == model.meshCount - 1) tris = attrib.num_faces - meshes[i].face_offset;
@ -5283,7 +5283,7 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->component_type == cgltf_component_type_r_16u) && (attribute->type == cgltf_type_vec2))
{
// TODO: WARNING: model.meshes[].boneIds is an (unsigned char *) --> Conversion required!
// Handle 16-bit unsigned short, vec2 format
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(unsigned short));
unsigned short *ptr = (unsigned short *)model.meshes[meshIndex].boneIds;
@ -5292,7 +5292,7 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->component_type == cgltf_component_type_r_16u) && (attribute->type == cgltf_type_vec4))
{
// TODO: WARNING: model.meshes[].boneIds is an (unsigned char *) --> Conversion required!
// Handle 16-bit unsigned short, vec4 format
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned short));
unsigned short *ptr = (unsigned short *)model.meshes[meshIndex].boneIds;
@ -5301,7 +5301,7 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->component_type == cgltf_component_type_r_32u) && (attribute->type == cgltf_type_vec4))
{
// TODO: WARNING: model.meshes[].boneIds is an (unsigned char *) --> Conversion required!
// Handle 32-bit unsigned int, vec4 format
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*4, sizeof(unsigned int));
unsigned int *ptr = (unsigned int *)model.meshes[meshIndex].boneIds;
@ -5310,7 +5310,7 @@ static Model LoadGLTF(const char *fileName)
else if ((attribute->component_type == cgltf_component_type_r_32f) && (attribute->type == cgltf_type_vec2))
{
// TODO: WARNING: model.meshes[].boneIds is an (unsigned char *) --> Conversion required!
// Handle 32-bit float, vec2 format
model.meshes[meshIndex].boneIds = RL_CALLOC(model.meshes[meshIndex].vertexCount*2, sizeof(float));
float *ptr = (float *)model.meshes[meshIndex].boneIds;
@ -5641,7 +5641,7 @@ static Model LoadVOX(const char *fileName)
// 6*4 = 12 vertices per voxel
Vector3 *pvertices = (Vector3 *)voxarray.vertices.array;
Vector3* pnormals = (Vector3*)voxarray.normals.array;
Vector3 *pnormals = (Vector3 *)voxarray.normals.array;
Color *pcolors = (Color *)voxarray.colors.array;
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
@ -5657,16 +5657,16 @@ static Model LoadVOX(const char *fileName)
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
size = pmesh->vertexCount*sizeof(float)*3;
pmesh->vertices = RL_MALLOC(size);
pmesh->vertices = p">(float *)RL_MALLOC(size);
memcpy(pmesh->vertices, pvertices, size);
// Copy normals
pmesh->normals = RL_MALLOC(size); //Rk. size as vertices
pmesh->normals = p">(float *)RL_MALLOC(size);
memcpy(pmesh->normals, pnormals, size);
// Copy indices
size = voxarray.indices.used*sizeof(unsigned short);
pmesh->indices = RL_MALLOC(size);
pmesh->indices = p">(float *)RL_MALLOC(size);
memcpy(pmesh->indices, pindices, size);
pmesh->triangleCount = (pmesh->vertexCount/4)*2;
@ -6074,8 +6074,9 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, int *animCou
animations[a].boneCount = m3d->numbone + 1;
animations[a].bones = RL_MALLOC((m3d->numbone + 1)*sizeof(BoneInfo));
animations[a].framePoses = RL_MALLOC(animations[a].frameCount*sizeof(Transform *));
strncpy(animations[a].name, m3d->action[a].name, sizeof(animations[a].name));
animations[a].name[sizeof(animations[a].name) - 1] = '\0';
strncpy(animations[a].name, m3d->action[a].name, sizeof(animations[a].name));
animations[a].name[sizeof(animations[a].name) - 1] = '\0';
TRACELOG(LOG_INFO, "MODEL: [%s] animation #%i: %i msec, %i frames", fileName, a, m3d->action[a].durationmsec, animations[a].frameCount);
for (i = 0; i < (int)m3d->numbone; i++)

+ 7
- 7
src/rshapes.c View File

@ -338,7 +338,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA
}
// NOTE: In case number of segments is odd, we add one last piece to the cake
if ((segments%2) == 1)
if ((p">(unsigned int)segments%2) == 1)
{
rlColor4ub(color.r, color.g, color.b, color.a);
@ -1574,7 +1574,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
#if defined(SUPPORT_SPLINE_MITERS)
Vector2 prevNormal = (Vector2){-(points[1].y - points[0].y), (points[1].x - points[0].x)};
float prevLength = sqrtf(prevNormal.x*prevNormal.x + prevNormal.y*prevNormal.y);
if (prevLength > 0.0f)
{
prevNormal.x /= prevLength;
@ -1587,7 +1587,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
}
Vector2 prevRadius = { 0.5f*thick*prevNormal.x, 0.5f*thick*prevNormal.y };
for (int i = 0; i < pointCount - 1; i++)
{
Vector2 normal = { 0 };
@ -1596,7 +1596,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
{
normal = (Vector2){-(points[i + 2].y - points[i + 1].y), (points[i + 2].x - points[i + 1].x)};
float normalLength = sqrtf(normal.x*normal.x + normal.y*normal.y);
if (normalLength > 0.0f)
{
normal.x /= normalLength;
@ -1615,7 +1615,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
Vector2 radius = { prevNormal.x + normal.x, prevNormal.y + normal.y };
float radiusLength = sqrtf(radius.x*radius.x + radius.y*radius.y);
if (radiusLength > 0.0f)
{
radius.x /= radiusLength;
@ -1639,7 +1639,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
radius.x = 0.0f;
radius.y = 0.0f;
}
Vector2 strip[4] = {
{ points[i].x - prevRadius.x, points[i].y - prevRadius.y },
{ points[i].x + prevRadius.x, points[i].y + prevRadius.y },
@ -1677,7 +1677,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color)
DrawTriangleStrip(strip, 4, color);
}
#endif
#if defined(SUPPORT_SPLINE_SEGMENT_CAPS)
// TODO: Add spline segment rounded caps at the begin/end of the spline
#endif

+ 11
- 11
src/rtext.c View File

@ -536,7 +536,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
font.glyphCount = (codepointCount > 0)? codepointCount : 95;
font.glyphPadding = 0;
#if defined(SUPPORT_FILEFORMAT_TTF)
#if defined(SUPPORT_FILEFORMAT_TTF)
if (TextIsEqual(fileExtLower, ".ttf") ||
TextIsEqual(fileExtLower, ".otf"))
{
@ -1468,10 +1468,10 @@ float TextToFloat(const char *text)
if (text[0] == '-') sign = -1.0f;
text++;
}
int i = 0;
for (; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10.0f + (float)(text[i] - '0');
if (text[i++] != '.') value *= sign;
else
{
@ -1482,7 +1482,7 @@ float TextToFloat(const char *text)
divisor = divisor*10.0f;
}
}
return value;
}
@ -2275,7 +2275,7 @@ static unsigned char HexToInt(char hex)
static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, int *codepoints, int codepointCount, int *outFontSize)
{
#define MAX_BUFFER_SIZE 256
char buffer[MAX_BUFFER_SIZE] = { 0 };
GlyphInfo *glyphs = NULL;
@ -2289,7 +2289,7 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, i
const char *fileTextPtr = fileText;
bool fontMalformed = false; // Is the font malformed
bool fontStarted = false; // Has font started (STARTFONT)
bool fontStarted = false; // Has font started (STARTFONT)
int fontBBw = 0; // Font base character bounding box width
int fontBBh = 0; // Font base character bounding box height
int fontBBxoff0 = 0; // Font base character bounding box X0 offset
@ -2300,7 +2300,7 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, i
bool charBitmapStarted = false; // Has bitmap data started (BITMAP)
int charBitmapNextRow = 0; // Y position for the next row of bitmap data
int charEncoding = -1; // The unicode value of the character (-1 if not set)
int charBBw = 0; // Character bounding box width
int charBBw = 0; // Character bounding box width
int charBBh = 0; // Character bounding box height
int charBBxoff0 = 0; // Character bounding box X0 offset
int charBByoff0 = 0; // Character bounding box Y0 offset
@ -2347,17 +2347,17 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, i
if (charGlyphInfo != NULL)
{
int pixelY = charBitmapNextRow++;
if (pixelY >= charGlyphInfo->image.height) break;
for (int x = 0; x < readBytes; x++)
{
unsigned char byte = HexToInt(buffer[x]);
for (int bitX = 0; bitX < 4; bitX++)
{
int pixelX = ((x*4) + bitX);
if (pixelX >= charGlyphInfo->image.width) break;
if ((byte & (8 >> bitX)) > 0) ((unsigned char *)charGlyphInfo->image.data)[(pixelY*charGlyphInfo->image.width) + pixelX] = 255;
@ -2393,7 +2393,7 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, i
{
// Search for glyph index in codepoints
charGlyphInfo = NULL;
for (int codepointIndex = 0; codepointIndex < codepointCount; codepointIndex++)
{
if (codepoints[codepointIndex] == charEncoding)

+ 8
- 8
src/rtextures.c View File

@ -2139,7 +2139,7 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize)
if ((image->data == NULL) || (image->width == 0) || (image->height == 0) || kernel == NULL) return;
int kernelWidth = (int)sqrtf((float)kernelSize);
if (kernelWidth*kernelWidth != kernelSize)
{
TRACELOG(LOG_WARNING, "IMAGE: Convolution kernel must be square to be applied");
@ -2165,7 +2165,7 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize)
float aRes = 0.0f;
int startRange = 0, endRange = 0;
if (kernelWidth%2 == 0)
{
startRange = -kernelWidth/2;
@ -2176,7 +2176,7 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize)
startRange = -kernelWidth/2;
endRange = kernelWidth/2 + 1;
}
for(int x = 0; x < image->height; x++)
{
for (int y = 0; y < image->width; y++)
@ -2188,14 +2188,14 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize)
int xkabs = xk + kernelWidth/2;
int ykabs = yk + kernelWidth/2;
unsigned int imgindex = image->width*(x + xk) + (y + yk);
if (imgindex >= (unsigned int)(image->width*image->height))
{
temp[kernelWidth * xkabs + ykabs].x = 0.0f;
temp[kernelWidth * xkabs + ykabs].y = 0.0f;
temp[kernelWidth * xkabs + ykabs].z = 0.0f;
temp[kernelWidth * xkabs + ykabs].w = 0.0f;
}
}
else
{
temp[kernelWidth * xkabs + ykabs].x = ((float)pixels[imgindex].r)/255.0f*kernel[kernelWidth*xkabs + ykabs];
@ -2245,7 +2245,7 @@ void ImageKernelConvolution(Image *image, float* kernel, int kernelSize)
for (int i = 0; i < (image->width*image->height); i++)
{
float alpha = (float)imageCopy2[i].w;
pixels[i].r = (unsigned char)((imageCopy2[i].x)*255.0f);
pixels[i].g = (unsigned char)((imageCopy2[i].y)*255.0f);
pixels[i].b = (unsigned char)((imageCopy2[i].z)*255.0f);
@ -3875,8 +3875,8 @@ TextureCubemap LoadTextureCubemap(Image image, int layout)
// NOTE: Cubemap data is expected to be provided as 6 images in a single data array,
// one after the other (that's a vertical image), following convention: +X, -X, +Y, -Y, +Z, -Z
cubemap.id = rlLoadTextureCubemap(faces.data, size, faces.format);
if (cubemap.id != 0)
if (cubemap.id != 0)
{
cubemap.format = faces.format;
cubemap.mipmaps = 1;

Loading…
Cancel
Save