Răsfoiți Sursa

Review formatting to follow raylib conventions

Ray 9 luni în urmă
părinte
comite
962f1c26ff
5 a modificat fișierele cu 61 adăugiri și 74 ștergeri
  1. 6 11
      src/raudio.c
  2. 2 1
      src/rcore.c
  3. 49 58
      src/rmodels.c
  4. 3 3
      src/rtext.c
  5. 1 1
      src/rtextures.c

+ 6 - 11
src/raudio.c

@@ -2461,23 +2461,18 @@ static ma_uint32 ReadAudioBufferFramesInMixingFormat(AudioBuffer *audioBuffer, f
 
         float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut);
 
-        /* At this point we can convert the data to our mixing format. */
+        // At this point we can convert the data to our mixing format
         ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration);    /* Safe cast. */
         ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration;
         ma_data_converter_process_pcm_frames(&audioBuffer->converter, inputBuffer, &inputFramesProcessedThisIteration, runningFramesOut, &outputFramesProcessedThisIteration);
 
-        totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; /* Safe cast. */
+        totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; // Safe cast
 
-        if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration)
-        {
-            break;  /* Ran out of input data. */
-        }
+        if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration) break;  // Ran out of input data
 
-        /* This should never be hit, but will add it here for safety. Ensures we get out of the loop when no input nor output frames are processed. */
-        if (inputFramesProcessedThisIteration == 0 && outputFramesProcessedThisIteration == 0)
-        {
-            break;
-        }
+        // This should never be hit, but added here for safety
+        // Ensures we get out of the loop when no input nor output frames are processed
+        if ((inputFramesProcessedThisIteration == 0) && (outputFramesProcessedThisIteration == 0)) break;
     }
 
     return totalOutputFramesProcessed;

+ 2 - 1
src/rcore.c

@@ -3315,7 +3315,8 @@ float GetGamepadAxisMovement(int gamepad, int axis)
 {
     float value = (axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER)? -1.0f : 0.0f;
 
-    if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) {
+    if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS))
+    {
         float movement = value < 0.0f ? CORE.Input.Gamepad.axisState[gamepad][axis] : fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]);
 
         if (movement > value) value = CORE.Input.Gamepad.axisState[gamepad][axis];

+ 49 - 58
src/rmodels.c

@@ -4190,39 +4190,36 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform
 static Model LoadOBJ(const char *fileName)
 {
     tinyobj_attrib_t objAttributes = { 0 };
-    tinyobj_shape_t* objShapes = NULL;
+    tinyobj_shape_t *objShapes = NULL;
     unsigned int objShapeCount = 0;
 
-    tinyobj_material_t* objMaterials = NULL;
+    tinyobj_material_t *objMaterials = NULL;
     unsigned int objMaterialCount = 0;
 
     Model model = { 0 };
     model.transform = MatrixIdentity();
 
-    char* fileText = LoadFileText(fileName);
+    char *fileText = LoadFileText(fileName);
 
     if (fileText == NULL)
     {
-        TRACELOG(LOG_ERROR, "MODEL Unable to read obj file %s", fileName);
+        TRACELOG(LOG_ERROR, "MODEL: [%s] Unable to read obj file", fileName);
         return model;
     }
 
     char currentDir[1024] = { 0 };
     strcpy(currentDir, GetWorkingDirectory()); // Save current working directory
-    const char* workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness
-    if (CHDIR(workingDir) != 0)
-    {
-        TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
-    }
+    const char *workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness
+    if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
 
     unsigned int dataSize = (unsigned int)strlen(fileText);
-
+    
     unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
     int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
 
     if (ret != TINYOBJ_SUCCESS)
     {
-        TRACELOG(LOG_ERROR, "MODEL Unable to read obj data %s", fileName);
+        TRACELOG(LOG_ERROR, "MODEL: Unable to read obj data %s", fileName);
         return model;
     }
 
@@ -4233,52 +4230,51 @@ static Model LoadOBJ(const char *fileName)
     int lastMaterial = -1;
     unsigned int meshIndex = 0;
 
-    // count meshes
+    // Count meshes
     unsigned int nextShapeEnd = objAttributes.num_face_num_verts;
 
-    // see how many verts till the next shape
-
+    // See how many verts till the next shape
     if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
 
-    // walk all the faces
+    // Walk all the faces
     for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
     {
         if (faceId >= nextShapeEnd)
         {
-            // try to find the last vert in the next shape
+            // Try to find the last vert in the next shape
             nextShape++;
             if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
-            else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
+            else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces
             meshIndex++;
         }
-        else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
+        else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial))
         {
-            meshIndex++;// if this is a new material, we need to allocate a new mesh
+            meshIndex++; // If this is a new material, we need to allocate a new mesh
         }
 
         lastMaterial = objAttributes.material_ids[faceId];
         faceVertIndex += objAttributes.face_num_verts[faceId];
     }
 
-    // allocate the base meshes and materials
+    // Allocate the base meshes and materials
     model.meshCount = meshIndex + 1;
-    model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount);
+    model.meshes = (Mesh *)MemAlloc(sizeof(Mesh)*model.meshCount);
 
     if (objMaterialCount > 0)
     {
         model.materialCount = objMaterialCount;
-        model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount);
+        model.materials = (Material *)MemAlloc(sizeof(Material)*objMaterialCount);
     }
-    else // we must allocate at least one material
+    else // We must allocate at least one material
     {
         model.materialCount = 1;
-        model.materials = (Material*)MemAlloc(sizeof(Material) * 1);
+        model.materials = (Material *)MemAlloc(sizeof(Material)*1);
     }
 
-    model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount);
+    model.meshMaterial = (int *)MemAlloc(sizeof(int)*model.meshCount);
 
-    // see how many verts are in each mesh
-    unsigned int* localMeshVertexCounts = (unsigned int*)MemAlloc(sizeof(unsigned int) * model.meshCount);
+    // See how many verts are in each mesh
+    unsigned int *localMeshVertexCounts = (unsigned int *)MemAlloc(sizeof(unsigned int)*model.meshCount);
 
     faceVertIndex = 0;
     nextShapeEnd = objAttributes.num_face_num_verts;
@@ -4287,23 +4283,22 @@ static Model LoadOBJ(const char *fileName)
     unsigned int localMeshVertexCount = 0;
 
     nextShape = 1;
-    if (objShapeCount > 1)
-        nextShapeEnd = objShapes[nextShape].face_offset;
+    if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
 
-    // walk all the faces
+    // Walk all the faces
     for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
     {
-        bool newMesh = false; // do we need a new mesh?
+        bool newMesh = false; // Do we need a new mesh?
         if (faceId >= nextShapeEnd)
         {
-            // try to find the last vert in the next shape
+            // Try to find the last vert in the next shape
             nextShape++;
             if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
             else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
 
             newMesh = true;
         }
-        else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
+        else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial))
         {
             newMesh = true;
         }
@@ -4321,50 +4316,52 @@ static Model LoadOBJ(const char *fileName)
         faceVertIndex += objAttributes.face_num_verts[faceId];
         localMeshVertexCount += objAttributes.face_num_verts[faceId];
     }
+    
     localMeshVertexCounts[meshIndex] = localMeshVertexCount;
 
     for (int i = 0; i < model.meshCount; i++)
     {
-        // allocate the buffers for each mesh
+        // Allocate the buffers for each mesh
         unsigned int vertexCount = localMeshVertexCounts[i];
 
         model.meshes[i].vertexCount = vertexCount;
         model.meshes[i].triangleCount = vertexCount / 3;
 
-        model.meshes[i].vertices = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
-        model.meshes[i].normals = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
-        model.meshes[i].texcoords = (float*)MemAlloc(sizeof(float) * vertexCount * 2);
-        model.meshes[i].colors = (unsigned char*)MemAlloc(sizeof(unsigned char) * vertexCount * 4);
+        model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
+        model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
+        model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
+        model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
     }
 
     MemFree(localMeshVertexCounts);
     localMeshVertexCounts = NULL;
 
-    // fill meshes
+    // Fill meshes
     faceVertIndex = 0;
 
     nextShapeEnd = objAttributes.num_face_num_verts;
 
-    // see how many verts till the next shape
+    // See how many verts till the next shape
     nextShape = 1;
     if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
     lastMaterial = -1;
     meshIndex = 0;
     localMeshVertexCount = 0;
 
-    // walk all the faces
+    // Walk all the faces
     for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
     {
-        bool newMesh = false; // do we need a new mesh?
+        bool newMesh = false; // Do we need a new mesh?
         if (faceId >= nextShapeEnd)
         {
-            // try to find the last vert in the next shape
+            // Try to find the last vert in the next shape
             nextShape++;
             if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
-            else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
+            else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces
             newMesh = true;
         }
-        // if this is a new material, we need to allocate a new mesh
+        
+        // If this is a new material, we need to allocate a new mesh
         if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) newMesh = true;
         lastMaterial = objAttributes.material_ids[faceId];
 
@@ -4375,8 +4372,7 @@ static Model LoadOBJ(const char *fileName)
         }
 
         int matId = 0;
-        if (lastMaterial >= 0 && lastMaterial < (int)objMaterialCount)
-            matId = lastMaterial;
+        if ((lastMaterial >= 0) && (lastMaterial < (int)objMaterialCount)) matId = lastMaterial;
 
         model.meshMaterial[meshIndex] = matId;
 
@@ -4386,19 +4382,15 @@ static Model LoadOBJ(const char *fileName)
             int normalIndex = objAttributes.faces[faceVertIndex].vn_idx;
             int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx;
 
-            for (int i = 0; i < 3; i++)
-                model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i];
+            for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
 
-            for (int i = 0; i < 3; i++)
-                model.meshes[meshIndex].normals[localMeshVertexCount * 3 + i] = objAttributes.normals[normalIndex * 3 + i];
+            for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i];
 
-            for (int i = 0; i < 2; i++)
-                model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + i] = objAttributes.texcoords[texcordIndex * 2 + i];
+            for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
 
-            model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1];
+            model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
 
-            for (int i = 0; i < 4; i++)
-                model.meshes[meshIndex].colors[localMeshVertexCount * 4 + i] = 255;
+            for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;
 
             faceVertIndex++;
             localMeshVertexCount++;
@@ -4412,8 +4404,7 @@ static Model LoadOBJ(const char *fileName)
     tinyobj_shapes_free(objShapes, objShapeCount);
     tinyobj_materials_free(objMaterials, objMaterialCount);
 
-    for (int i = 0; i < model.meshCount; i++)
-        UploadMesh(model.meshes + i, true);
+    for (int i = 0; i < model.meshCount; i++) UploadMesh(model.meshes + i, true);
 
     // Restore current working directory
     if (CHDIR(currentDir) != 0)

+ 3 - 3
src/rtext.c

@@ -2325,9 +2325,9 @@ static Font LoadBMFont(const char *fileName)
 // Convert hexadecimal to decimal (single digit)
 static unsigned char HexToInt(char hex)
 {
-    if (hex >= '0' && hex <= '9') return hex - '0';
-    else if (hex >= 'a' && hex <= 'f') return hex - 'a' + 10;
-    else if (hex >= 'A' && hex <= 'F') return hex - 'A' + 10;
+    if ((hex >= '0') && (hex <= '9')) return hex - '0';
+    else if ((hex >= 'a') && (hex <= 'f')) return hex - 'a' + 10;
+    else if ((hex >= 'A') && (hex <= 'F')) return hex - 'A' + 10;
     else return 0;
 }
 

+ 1 - 1
src/rtextures.c

@@ -3567,7 +3567,7 @@ void ImageDrawLineEx(Image *dst, Vector2 start, Vector2 end, int thick, Color co
     ImageDrawLine(dst, x1, y1, x2, y2, color);
 
     // Determine if the line is more horizontal or vertical
-    if (dx != 0 && abs(dy/dx) < 1)
+    if ((dx != 0) && (abs(dy/dx) < 1))
     {
         // Line is more horizontal
         // Calculate half the width of the line