Skip to content

Commit

Permalink
Review formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Feb 29, 2024
1 parent 1e84506 commit fea3395
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 58 deletions.
25 changes: 14 additions & 11 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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])
Expand All @@ -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;
Expand Down
43 changes: 22 additions & 21 deletions src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 = (float *)RL_MALLOC(size);
memcpy(pmesh->vertices, pvertices, size);

// Copy normals
pmesh->normals = RL_MALLOC(size); //Rk. size as vertices
pmesh->normals = (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 = (float *)RL_MALLOC(size);
memcpy(pmesh->indices, pindices, size);

pmesh->triangleCount = (pmesh->vertexCount/4)*2;
Expand Down Expand Up @@ -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++)
Expand Down
14 changes: 7 additions & 7 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (((unsigned int)segments%2) == 1)
{
rlColor4ub(color.r, color.g, color.b, color.a);

Expand Down Expand Up @@ -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;
Expand All @@ -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 };
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 },
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down Expand Up @@ -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
{
Expand All @@ -1482,7 +1482,7 @@ float TextToFloat(const char *text)
divisor = divisor*10.0f;
}
}

return value;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit fea3395

Please sign in to comment.