From cc55e53afd6040403439b5a19589f3e77f84ecd9 Mon Sep 17 00:00:00 2001 From: stickm4n Date: Tue, 31 Jan 2023 03:41:39 -0500 Subject: [PATCH] Code cleanup. Grammar and typos fixed. --- src/config.h | 26 ++++---- src/external/jar_mod.h | 2 +- src/raudio.c | 22 +++---- src/raylib.h | 28 ++++---- src/raymath.h | 14 ++-- src/rcamera.h | 73 ++++++++++----------- src/rcore.c | 68 +++++++++---------- src/rgestures.h | 14 ++-- src/rlgl.h | 2 +- src/rmodels.c | 74 ++++++++++----------- src/rshapes.c | 10 +-- src/rtext.c | 24 +++---- src/rtextures.c | 146 ++++++++++++++++++++--------------------- src/utils.c | 10 +-- 14 files changed, 257 insertions(+), 256 deletions(-) diff --git a/src/config.h b/src/config.h index f67ea3cb0..880f26b1e 100644 --- a/src/config.h +++ b/src/config.h @@ -50,7 +50,7 @@ // Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. // However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. #define SUPPORT_WINMM_HIGHRES_TIMER 1 -// Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used +// Use busy wait loop for timing sync, if not defined, a high-resolution timer is set up and used //#define SUPPORT_BUSY_WAIT_LOOP 1 // Use a partial-busy wait loop, in this case frame sleeps for most of the time, but then runs a busy loop at the end for accuracy #define SUPPORT_PARTIALBUSY_WAIT_LOOP @@ -65,14 +65,14 @@ // Support automatic generated events, loading and recording of those events when required //#define SUPPORT_EVENTS_AUTOMATION 1 // Support custom frame control, only for advance users -// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timming + PollInputEvents() +// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents() // Enabling this flag allows manual control of the frame processes, use at your own risk //#define SUPPORT_CUSTOM_FRAME_CONTROL 1 // rcore: Configuration values //------------------------------------------------------------------------------------ #define MAX_FILEPATH_CAPACITY 8192 // Maximum file paths capacity -#define MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value) +#define MAX_FILEPATH_LENGTH 4096 // Maximum length for file paths (Linux PATH_MAX default value) #define MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported #define MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported @@ -110,12 +110,12 @@ // Default shader vertex attribute names to set location points // NOTE: When a new shader is loaded, the following locations are tried to be set for convenience -#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0 -#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1 -#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2 -#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3 -#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4 -#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4 +#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5 #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix @@ -139,7 +139,7 @@ //------------------------------------------------------------------------------------ // Module: rtextures - Configuration Flags //------------------------------------------------------------------------------------ -// Selecte desired fileformats to be supported for image data loading +// Select desired file formats to be supported for image data loading #define SUPPORT_FILEFORMAT_PNG 1 //#define SUPPORT_FILEFORMAT_BMP 1 //#define SUPPORT_FILEFORMAT_TGA 1 @@ -171,7 +171,7 @@ // Default font is loaded on window initialization to be available for the user to render simple text // NOTE: If enabled, uses external module functions to load default raylib font #define SUPPORT_DEFAULT_FONT 1 -// Selected desired font fileformats to be supported for loading +// Selected desired font file formats to be supported for loading #define SUPPORT_FILEFORMAT_FNT 1 #define SUPPORT_FILEFORMAT_TTF 1 @@ -189,7 +189,7 @@ //------------------------------------------------------------------------------------ // Module: rmodels - Configuration Flags //------------------------------------------------------------------------------------ -// Selected desired model fileformats to be supported for loading +// Selected desired model file formats to be supported for loading #define SUPPORT_FILEFORMAT_OBJ 1 #define SUPPORT_FILEFORMAT_MTL 1 #define SUPPORT_FILEFORMAT_IQM 1 @@ -208,7 +208,7 @@ //------------------------------------------------------------------------------------ // Module: raudio - Configuration Flags //------------------------------------------------------------------------------------ -// Desired audio fileformats to be supported for loading +// Desired audio file formats to be supported for loading #define SUPPORT_FILEFORMAT_WAV 1 #define SUPPORT_FILEFORMAT_OGG 1 #define SUPPORT_FILEFORMAT_XM 1 diff --git a/src/external/jar_mod.h b/src/external/jar_mod.h index eacd3b7d6..54316f196 100644 --- a/src/external/jar_mod.h +++ b/src/external/jar_mod.h @@ -1130,7 +1130,7 @@ static bool jar_mod_load( jar_mod_context_t * modctx, void * mod_data, int mod_d { if( modctx ) { - memcopy(&(modctx->song.title),modmemory,1084); + memcopy(&(modctx->song.title),modmemory,20); i = 0; modctx->number_of_channels = 0; diff --git a/src/raudio.c b/src/raudio.c index 46d8223d9..260f0417c 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -306,7 +306,7 @@ typedef enum { #endif // NOTE: Different logic is used when feeding data to the playback device -// depending on whether or not data is streamed (Music vs Sound) +// depending on whether data is streamed or not (Music vs Sound) typedef enum { AUDIO_BUFFER_USAGE_STATIC = 0, AUDIO_BUFFER_USAGE_STREAM @@ -466,7 +466,7 @@ void InitAudioDevice(void) return; } - // Mixing happens on a seperate thread which means we need to synchronize. I'm using a mutex here to make things simple, but may + // Mixing happens on a seperated thread which means we need to synchronize. I'm using a mutex here to make things simple, but may // want to look at something a bit smarter later on to keep everything real-time, if that's necessary. if (ma_mutex_init(&AUDIO.System.lock) != MA_SUCCESS) { @@ -707,7 +707,7 @@ void TrackAudioBuffer(AudioBuffer *buffer) ma_mutex_unlock(&AUDIO.System.lock); } -// Untrack audio buffer from linked list +// Un-track audio buffer from linked list void UntrackAudioBuffer(AudioBuffer *buffer) { ma_mutex_lock(&AUDIO.System.lock); @@ -882,7 +882,7 @@ Sound LoadSoundFromWave(Wave wave) if (audioBuffer == NULL) { TRACELOG(LOG_WARNING, "SOUND: Failed to create buffer"); - return sound; // early return to avoid dereferencing the audioBuffer null pointer + return sound; // early return to avoid de-referencing the audioBuffer null pointer } frameCount = (ma_uint32)ma_convert_frames(audioBuffer->data, frameCount, AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, wave.data, frameCountIn, formatIn, wave.channels, wave.sampleRate); @@ -1050,7 +1050,7 @@ void PlaySoundMulti(Sound sound) unsigned int oldAge = 0; int oldIndex = -1; - // find the first non playing pool entry + // find the first non-playing pool entry for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) { if (AUDIO.MultiChannel.channels[i] > oldAge) @@ -1066,7 +1066,7 @@ void PlaySoundMulti(Sound sound) } } - // If no none playing pool members can be index choose the oldest + // If no non-playing pool members can be indexed, choose the oldest if (index == -1) { TRACELOG(LOG_WARNING, "SOUND: Buffer pool is already full, count: %i", AUDIO.MultiChannel.poolCounter); @@ -2000,8 +2000,8 @@ void UnloadAudioStream(AudioStream stream) } // Update audio stream buffers with data -// NOTE 1: Only updates one buffer of the stream source: unqueue -> update -> queue -// NOTE 2: To unqueue a buffer it needs to be processed: IsAudioStreamProcessed() +// NOTE 1: Only updates one buffer of the stream source: un-queue -> update -> queue +// NOTE 2: To un-queue a buffer it needs to be processed: IsAudioStreamProcessed() void UpdateAudioStream(AudioStream stream, const void *data, int frameCount) { if (stream.buffer != NULL) @@ -2198,7 +2198,7 @@ static ma_uint32 ReadAudioBufferFramesInInternalFormat(AudioBuffer *audioBuffer, if (currentSubBufferIndex > 1) return 0; - // Another thread can update the processed state of buffers so + // Another thread can update the processed state of buffers so if // we just take a copy here to try and avoid potential synchronization problems bool isSubBufferProcessed[2] = { 0 }; isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0]; @@ -2212,7 +2212,7 @@ static ma_uint32 ReadAudioBufferFramesInInternalFormat(AudioBuffer *audioBuffer, { // We break from this loop differently depending on the buffer's usage // - For static buffers, we simply fill as much data as we can - // - For streaming buffers we only fill the halves of the buffer that are processed + // - For streaming buffers we only fill halves of the buffer that are processed // Unprocessed halves must keep their audio data in-tact if (audioBuffer->usage == AUDIO_BUFFER_USAGE_STATIC) { @@ -2269,7 +2269,7 @@ static ma_uint32 ReadAudioBufferFramesInInternalFormat(AudioBuffer *audioBuffer, // For static buffers we can fill the remaining frames with silence for safety, but we don't want // to report those frames as "read". The reason for this is that the caller uses the return value - // to know whether or not a non-looping sound has finished playback. + // to know whether a non-looping sound has finished playback or not. if (audioBuffer->usage != AUDIO_BUFFER_USAGE_STATIC) framesRead += totalFramesRemaining; } diff --git a/src/raylib.h b/src/raylib.h index e0b7a3159..b83cb9c69 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -216,7 +216,7 @@ typedef struct Vector4 { // Quaternion, 4 components (Vector4 alias) typedef Vector4 Quaternion; -// Matrix, 4x4 components, column major, OpenGL style, right handed +// Matrix, 4x4 components, column major, OpenGL style, right-handed typedef struct Matrix { float m0, m4, m8, m12; // Matrix first row (4 components) float m1, m5, m9, m13; // Matrix second row (4 components) @@ -413,8 +413,8 @@ typedef struct Ray { // RayCollision, ray hit information typedef struct RayCollision { bool hit; // Did the ray hit something? - float distance; // Distance to nearest hit - Vector3 point; // Point of nearest hit + float distance; // Distance to the nearest hit + Vector3 point; // Point of the nearest hit Vector3 normal; // Surface normal of hit } RayCollision; @@ -428,7 +428,7 @@ typedef struct BoundingBox { typedef struct Wave { unsigned int frameCount; // Total number of frames (considering channels) unsigned int sampleRate; // Frequency (samples per second) - unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int sampleSize; // The bit depth (bits per sample): 8, 16, 32 (24 not supported) unsigned int channels; // Number of channels (1-mono, 2-stereo, ...) void *data; // Buffer data pointer } Wave; @@ -444,7 +444,7 @@ typedef struct AudioStream { rAudioProcessor *processor; // Pointer to internal data processor, useful for audio effects unsigned int sampleRate; // Frequency (samples per second) - unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + unsigned int sampleSize; // The bit depth (bits per sample): 8, 16, 32 (24 not supported) unsigned int channels; // Number of channels (1-mono, 2-stereo, ...) } AudioStream; @@ -492,9 +492,9 @@ typedef struct VrStereoConfig { // File path list typedef struct FilePathList { - unsigned int capacity; // Filepaths max entries - unsigned int count; // Filepaths entries count - char **paths; // Filepaths entries + unsigned int capacity; // Filepath max entries + unsigned int count; // Filepath entries count + char **paths; // Filepath entries } FilePathList; //---------------------------------------------------------------------------------- @@ -681,7 +681,7 @@ typedef enum { MOUSE_CURSOR_RESIZE_NS = 6, // Vertical resize/move arrow shape MOUSE_CURSOR_RESIZE_NWSE = 7, // Top-left to bottom-right diagonal resize/move arrow shape MOUSE_CURSOR_RESIZE_NESW = 8, // The top-right to bottom-left diagonal resize/move arrow shape - MOUSE_CURSOR_RESIZE_ALL = 9, // The omni-directional resize/move cursor shape + MOUSE_CURSOR_RESIZE_ALL = 9, // The omnidirectional resize/move cursor shape MOUSE_CURSOR_NOT_ALLOWED = 10 // The operation-not-allowed shape } MouseCursor; @@ -839,7 +839,7 @@ typedef enum { typedef enum { CUBEMAP_LAYOUT_AUTO_DETECT = 0, // Automatically detect layout type CUBEMAP_LAYOUT_LINE_VERTICAL, // Layout is defined by a vertical line with faces - CUBEMAP_LAYOUT_LINE_HORIZONTAL, // Layout is defined by an horizontal line with faces + CUBEMAP_LAYOUT_LINE_HORIZONTAL, // Layout is defined by a horizontal line with faces CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR, // Layout is defined by a 3x4 cross with cubemap faces CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE, // Layout is defined by a 4x3 cross with cubemap faces CUBEMAP_LAYOUT_PANORAMA // Layout is defined by a panorama image (equirectangular map) @@ -903,7 +903,7 @@ typedef enum { } NPatchLayout; // Callbacks to hook some internal functions -// WARNING: This callbacks are intended for advance users +// WARNING: These callbacks are intended for advance users typedef void (*TraceLogCallback)(int logLevel, const char *text, va_list args); // Logging: Redirect trace log messages typedef unsigned char *(*LoadFileDataCallback)(const char *fileName, unsigned int *bytesRead); // FileIO: Load binary data typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); // FileIO: Save binary data @@ -1179,8 +1179,8 @@ RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Colo RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out -RLAPI void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); // Draw line using quadratic bezier curves with a control point -RLAPI void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color); // Draw line using cubic bezier curves with 2 control points +RLAPI void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); // Draw line using quadratic Bézier curves with a control point +RLAPI void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color); // Draw line using cubic Bézier curves with 2 control points RLAPI void DrawLineStrip(Vector2 *points, int pointCount, Color color); // Draw lines sequence RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle @@ -1228,7 +1228,7 @@ RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); //------------------------------------------------------------------------------------ // Image loading functions -// NOTE: This functions do not require GPU access +// NOTE: These functions do not require GPU access RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM) RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data RLAPI Image LoadImageAnim(const char *fileName, int *frames); // Load image sequence from file (frames appended to image.data) diff --git a/src/raymath.h b/src/raymath.h index eb244ad44..08afe313c 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -312,14 +312,14 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2) RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { float result = 0.0f; - + float dot = v1.x*v2.x + v1.y*v2.y; // Dot product float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp if (dotClamp > 1.0f) dotClamp = 1.0f; result = acosf(dotClamp); - + // Alternative implementation, more costly //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); @@ -585,12 +585,12 @@ RMAPI Vector3 Vector3Perpendicular(Vector3 v) { Vector3 result = { 0 }; - float min = (float) fabs(v.x); + float min = fabsf(v.x); Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f}; if (fabsf(v.y) < min) { - min = (float) fabs(v.y); + min = fabsf(v.y); Vector3 tmp = {0.0f, 1.0f, 0.0f}; cardinalAxis = tmp; } @@ -903,7 +903,7 @@ RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view) { Vector3 result = { 0 }; - // Calculate unproject matrix (multiply view matrix by projection matrix) and invert it + // Calculate un-project matrix (multiply view matrix by projection matrix) and invert it Matrix matViewProj = { // MatrixMultiply(view, projection); view.m0*projection.m0 + view.m1*projection.m4 + view.m2*projection.m8 + view.m3*projection.m12, view.m0*projection.m1 + view.m1*projection.m5 + view.m2*projection.m9 + view.m3*projection.m13, @@ -966,7 +966,7 @@ RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view) // Create quaternion from source point Quaternion quat = { source.x, source.y, source.z, 1.0f }; - // Multiply quat point by unproject matrix + // Multiply quat point by un-project matrix Quaternion qtransformed = { // QuaternionTransform(quat, matViewProjInv) matViewProjInv.m0*quat.x + matViewProjInv.m4*quat.y + matViewProjInv.m8*quat.z + matViewProjInv.m12*quat.w, matViewProjInv.m1*quat.x + matViewProjInv.m5*quat.y + matViewProjInv.m9*quat.z + matViewProjInv.m13*quat.w, @@ -1927,6 +1927,8 @@ RMAPI Quaternion QuaternionFromMatrix(Matrix mat) result.x = (mat.m8 + mat.m2) * mult; result.y = (mat.m6 + mat.m9) * mult; break; + default: /* Suppress warnings */ + break; } return result; diff --git a/src/rcamera.h b/src/rcamera.h index 1b77e19a9..89ab56d0e 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -150,7 +150,7 @@ void SetCameraMoveControls(int keyFront, int keyBack, #endif // Camera mouse movement sensitivity -#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.5f // TODO: it should be independant of framerate +#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.5f // TODO: it should be independent of framerate #define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f // FREE_CAMERA @@ -158,7 +158,7 @@ void SetCameraMoveControls(int keyFront, int keyBack, #define CAMERA_FREE_DISTANCE_MIN_CLAMP 0.3f #define CAMERA_FREE_DISTANCE_MAX_CLAMP 120.0f #define CAMERA_FREE_MIN_CLAMP 85.0f -#define CAMERA_FREE_MAX_CLAMP -85.0f +#define CAMERA_FREE_MAX_CLAMP (-85.0f) #define CAMERA_FREE_SMOOTH_ZOOM_SENSITIVITY 0.05f #define CAMERA_FREE_PANNING_DIVIDER 5.1f @@ -169,7 +169,7 @@ void SetCameraMoveControls(int keyFront, int keyBack, //#define CAMERA_FIRST_PERSON_MOUSE_SENSITIVITY 0.003f #define CAMERA_FIRST_PERSON_FOCUS_DISTANCE 25.0f #define CAMERA_FIRST_PERSON_MIN_CLAMP 89.0f -#define CAMERA_FIRST_PERSON_MAX_CLAMP -89.0f +#define CAMERA_FIRST_PERSON_MAX_CLAMP (-89.0f) // When walking, y-position of the player moves up-down at step frequency (swinging) but // also the body slightly tilts left-right on every step, when all the body weight is left over one foot (tilting) @@ -181,7 +181,7 @@ void SetCameraMoveControls(int keyFront, int keyBack, //#define CAMERA_THIRD_PERSON_MOUSE_SENSITIVITY 0.003f #define CAMERA_THIRD_PERSON_DISTANCE_CLAMP 1.2f #define CAMERA_THIRD_PERSON_MIN_CLAMP 5.0f -#define CAMERA_THIRD_PERSON_MAX_CLAMP -85.0f +#define CAMERA_THIRD_PERSON_MAX_CLAMP (-85.0f) #define CAMERA_THIRD_PERSON_OFFSET (Vector3){ 0.4f, 0.0f, 0.0f } // PLAYER (used by camera) @@ -313,45 +313,44 @@ void UpdateCamera(Camera *camera) } // Camera looking down - else if ((camera->position.y > camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0)) + else if ((camera->position.y > camera->target.y)) { - camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + if (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP && mouseWheelMove < 0 || camera->target.y >= 0) + { + camera->target.x += + mouseWheelMove * (camera->target.x - camera->position.x) * CAMERA_MOUSE_SCROLL_SENSITIVITY / + CAMERA.targetDistance; + camera->target.y += + mouseWheelMove * (camera->target.y - camera->position.y) * CAMERA_MOUSE_SCROLL_SENSITIVITY / + CAMERA.targetDistance; + camera->target.z += + mouseWheelMove * (camera->target.z - camera->position.z) * CAMERA_MOUSE_SCROLL_SENSITIVITY / + CAMERA.targetDistance; + // if (camera->target.y < 0) camera->target.y = -0.001; + } + else if ((camera->target.y < 0) && (mouseWheelMove > 0)) { + CAMERA.targetDistance -= (mouseWheelMove * CAMERA_MOUSE_SCROLL_SENSITIVITY); + if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) + CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; + } } - else if ((camera->position.y > camera->target.y) && (camera->target.y >= 0)) - { - camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - // if (camera->target.y < 0) camera->target.y = -0.001; - } - else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (mouseWheelMove > 0)) - { - CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); - if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; - } // Camera looking up - else if ((camera->position.y < camera->target.y) && (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0)) + else if (camera->position.y < camera->target.y) { - camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + if (CAMERA.targetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP && mouseWheelMove < 0 || camera->target.y <= 0) + { + camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; + } + else if (camera->target.y > 0 && mouseWheelMove > 0) + { + CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); + if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; + } } - else if ((camera->position.y < camera->target.y) && (camera->target.y <= 0)) - { - camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_MOUSE_SCROLL_SENSITIVITY/CAMERA.targetDistance; - // if (camera->target.y > 0) camera->target.y = 0.001; - } - else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0)) - { - CAMERA.targetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); - if (CAMERA.targetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) CAMERA.targetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP; - } // Input keys checks if (keyPan) @@ -530,7 +529,7 @@ void UpdateCamera(Camera *camera) camera->position.z = cosf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.z; } break; - case CAMERA_CUSTOM: break; + case CAMERA_CUSTOM: default: break; } } diff --git a/src/rcore.c b/src/rcore.c index f2f0cbbe0..b4f38aaa3 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -626,8 +626,8 @@ static bool InitGraphicsDevice(int width, int height); // Initialize graphics d static void SetupFramebuffer(int width, int height); // Setup main framebuffer static void SetupViewport(int width, int height); // Set viewport for a provided width and height -static void ScanDirectoryFiles(const char *basePath, FilePathList *list, const char *filter); // Scan all files and directories in a base path -static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *list, const char *filter); // Scan all files and directories recursively from a base path +static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const char *filter); // Scan all files and directories in a base path +static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *files, const char *filter); // Scan all files and directories recursively from a base path #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error @@ -864,7 +864,7 @@ void InitWindow(int width, int height, const char *title) LoadFontDefault(); #if defined(SUPPORT_MODULE_RSHAPES) Rectangle rec = GetFontDefault().recs[95]; - // NOTE: We setup a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering + // NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); // WARNING: Module required: rshapes #endif #else @@ -1317,7 +1317,7 @@ void MaximizeWindow(void) void MinimizeWindow(void) { #if defined(PLATFORM_DESKTOP) - // NOTE: Following function launches callback that sets appropiate flag! + // NOTE: Following function launches callback that sets appropriate flag! glfwIconifyWindow(CORE.Window.handle); #endif } @@ -2193,7 +2193,7 @@ void BeginMode3D(Camera3D camera) rlDrawRenderBatchActive(); // Update and draw internal render batch rlMatrixMode(RL_PROJECTION); // Switch to projection matrix - rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection + rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d orthogonal projection rlLoadIdentity(); // Reset current matrix (projection) float aspect = (float)CORE.Window.currentFbo.width/(float)CORE.Window.currentFbo.height; @@ -2469,7 +2469,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode) // After shader loading, we TRY to set default location names if (shader.id > 0) { - // Default shader attribute locations have been binded before linking: + // Default shader attribute locations have been bound before linking: // vertex position location = 0 // vertex texcoord location = 1 // vertex normal location = 2 @@ -2484,7 +2484,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode) // All locations reseted to -1 (no location) for (int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1; - // Get handles to GLSL input attibute locations + // Get handles to GLSL input attribute locations shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION); shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD); shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2); @@ -2552,7 +2552,7 @@ void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniform { rlEnableShader(shader.id); rlSetUniform(locIndex, value, uniformType, count); - //rlDisableShader(); // Avoid reseting current shader program, in case other uniforms are set + //rlDisableShader(); // Avoid resetting current shader program, in case other uniforms are set } } @@ -2617,7 +2617,7 @@ Ray GetMouseRay(Vector2 mouse, Camera camera) Vector3 farPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView); // Unproject the mouse cursor in the near plane. - // We need this as the source position because orthographic projects, compared to perspect doesn't have a + // We need this as the source position because orthographic projects, compared to perspective doesn't have a // convergence point, meaning that the "eye" of the camera is more like a plane than a point. Vector3 cameraPlanePointerPos = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView); @@ -2754,7 +2754,7 @@ int GetFPS(void) #if !defined(SUPPORT_CUSTOM_FRAME_CONTROL) #define FPS_CAPTURE_FRAMES_COUNT 30 // 30 captures - #define FPS_AVERAGE_TIME_SECONDS 0.5f // 500 millisecondes + #define FPS_AVERAGE_TIME_SECONDS 0.5f // 500 milliseconds #define FPS_STEP (FPS_AVERAGE_TIME_SECONDS/FPS_CAPTURE_FRAMES_COUNT) static int index = 0; @@ -2807,7 +2807,7 @@ double GetTime(void) // Setup window configuration flags (view FLAGS) // NOTE: This function is expected to be called before window creation, -// because it setups some flags for the window creation process. +// because it sets up some flags for the window creation process. // To configure window states after creation, just use SetWindowState() void SetConfigFlags(unsigned int flags) { @@ -3032,7 +3032,7 @@ const char *GetDirectoryPath(const char *filePath) if (filePath[1] != ':' && filePath[0] != '\\' && filePath[0] != '/') { // For security, we set starting path to current directory, - // obtained path will be concated to this + // obtained path will be concat to this dirPath[0] = '.'; dirPath[1] = '/'; } @@ -3168,8 +3168,8 @@ const char *GetApplicationDirectory(void) return appDir; } -// Load directory filepaths -// NOTE: Base path is prepended to the scanned filepaths +// Load directory file paths +// NOTE: Base path is prepended to the scanned file paths // WARNING: Directory is scanned twice, first time to get files count // No recursive scanning is done! FilePathList LoadDirectoryFiles(const char *dirPath) @@ -3185,7 +3185,7 @@ FilePathList LoadDirectoryFiles(const char *dirPath) // SCAN 1: Count files while ((entity = readdir(dir)) != NULL) { - // NOTE: We skip '.' (current dir) and '..' (parent dir) filepaths + // NOTE: We skip '.' (current dir) and '..' (parent dir) file paths if ((strcmp(entity->d_name, ".") != 0) && (strcmp(entity->d_name, "..") != 0)) fileCounter++; } @@ -3196,7 +3196,7 @@ FilePathList LoadDirectoryFiles(const char *dirPath) closedir(dir); - // SCAN 2: Read filepaths + // SCAN 2: Read file paths // NOTE: Directory paths are also registered ScanDirectoryFiles(dirPath, &files, NULL); @@ -3208,7 +3208,7 @@ FilePathList LoadDirectoryFiles(const char *dirPath) return files; } -// Load directory filepaths with extension filtering and recursive directory scan +// Load directory file paths with extension filtering and recursive directory scan // NOTE: On recursive loading we do not pre-scan for file count, we use MAX_FILEPATH_CAPACITY FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs) { @@ -3225,8 +3225,8 @@ FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool return files; } -// Unload directory filepaths -// WARNING: files.count is not reseted to 0 after unloading +// Unload directory file paths +// WARNING: files.count is not reset to 0 after unloading void UnloadDirectoryFiles(FilePathList files) { for (unsigned int i = 0; i < files.capacity; i++) RL_FREE(files.paths[i]); @@ -3260,7 +3260,7 @@ bool IsFileDropped(void) else return false; } -// Load dropped filepaths +// Load dropped file paths FilePathList LoadDroppedFiles(void) { FilePathList files = { 0 }; @@ -3271,7 +3271,7 @@ FilePathList LoadDroppedFiles(void) return files; } -// Unload dropped filepaths +// Unload dropped file paths void UnloadDroppedFiles(FilePathList files) { // WARNING: files pointers are the same as internal ones @@ -4096,11 +4096,11 @@ static bool InitGraphicsDevice(int width, int height) if (CORE.Window.fullscreen) { - // remember center for switchinging from fullscreen to window + // remember center for switching from fullscreen to window if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) { - // If screen width/height equal to the dislpay, we can't calclulate the window pos for toggling fullscreened/windowed. - // Toggling fullscreened/windowed with pos(0, 0) can cause problems in some platforms, such as X11. + // If screen width/height equal to the display, we can't calculate the window pos for toggling full-screened/windowed. + // Toggling full-screened/windowed with pos(0, 0) can cause problems in some platforms, such as X11. CORE.Window.position.x = CORE.Window.display.width/4; CORE.Window.position.y = CORE.Window.display.height/4; } @@ -4137,7 +4137,7 @@ static bool InitGraphicsDevice(int width, int height) // framebuffer is rendered correctly but once displayed on a 16:9 monitor, it gets stretched // by the sides to fit all monitor space... - // Try to setup the most appropiate fullscreen framebuffer for the requested screenWidth/screenHeight + // Try to setup the most appropriate fullscreen framebuffer for the requested screenWidth/screenHeight // It considers device display resolution mode and setups a framebuffer with black bars if required (render size/offset) // Modified global variables: CORE.Window.screen.width/CORE.Window.screen.height - CORE.Window.render.width/CORE.Window.render.height - CORE.Window.renderOffset.x/CORE.Window.renderOffset.y - CORE.Window.screenScale // TODO: It is a quite cumbersome solution to display size vs requested size, it should be reviewed or removed... @@ -4204,7 +4204,7 @@ static bool InitGraphicsDevice(int width, int height) // NOTE: V-Sync can be enabled by graphic driver configuration if (CORE.Window.flags & FLAG_VSYNC_HINT) { - // WARNING: It seems to hits a critical render path in Intel HD Graphics + // WARNING: It seems to hit a critical render path in Intel HD Graphics glfwSwapInterval(1); TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC"); } @@ -4216,11 +4216,11 @@ static bool InitGraphicsDevice(int width, int height) if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) { // NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling - // Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); + // Frame buffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); #if !defined(__APPLE__) glfwGetFramebufferSize(CORE.Window.handle, &fbWidth, &fbHeight); - // Screen scaling matrix is required in case desired screen area is different than display area + // Screen scaling matrix is required in case desired screen area is different from display area CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f); // Mouse input scaling for the new screen size @@ -4818,7 +4818,7 @@ static void InitTimer(void) // NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could // take longer than expected... for that reason we use the busy wait loop // Ref: http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected -// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32! +// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timing on Win32! void WaitTime(double seconds) { #if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP) @@ -4989,7 +4989,7 @@ void PollInputEvents(void) // NOTE: There is no callback available, so we get it manually // Get remapped buttons GLFWgamepadstate state = { 0 }; - glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller + glfwGetGamepadState(i, &state); // This remaps all gamepads, so they have their buttons mapped like an xbox controller const unsigned char *buttons = state.buttons; @@ -5413,7 +5413,7 @@ static void CharCallback(GLFWwindow *window, unsigned int key) //TRACELOG(LOG_DEBUG, "Char Callback: KEY:%i(%c)", key, key); // NOTE: Registers any key down considering OS keyboard layout but - // do not detects action events, those should be managed by user... + // do not detect action events, those should be managed by user... // Ref: https://github.com/glfw/glfw/issues/668#issuecomment-166794907 // Ref: https://www.glfw.org/docs/latest/input_guide.html#input_char @@ -5456,7 +5456,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].y /= (float)GetScreenHeight(); - // Gesture data is sent to gestures system for processing + // Gesture data is sent to gesture system for processing ProcessGestureEvent(gestureEvent); #endif } @@ -5487,7 +5487,7 @@ static void MouseCursorPosCallback(GLFWwindow *window, double x, double y) gestureEvent.position[0].x /= (float)GetScreenWidth(); gestureEvent.position[0].y /= (float)GetScreenHeight(); - // Gesture data is sent to gestures system for processing + // Gesture data is sent to gesture system for processing ProcessGestureEvent(gestureEvent); #endif } @@ -5508,7 +5508,7 @@ static void CursorEnterCallback(GLFWwindow *window, int enter) // GLFW3 Window Drop Callback, runs when drop files into window static void WindowDropCallback(GLFWwindow *window, int count, const char **paths) { - // In case previous dropped filepaths have not been freed, we free them + // In case previous dropped file paths have not been freed, we free them if (CORE.Window.dropFileCount > 0) { for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]); diff --git a/src/rgestures.h b/src/rgestures.h index b63ac9678..8cd4181c9 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -241,7 +241,7 @@ static GesturesData GESTURES = { //---------------------------------------------------------------------------------- // Module specific Functions Declaration //---------------------------------------------------------------------------------- -static float rgVector2Angle(Vector2 initialPosition, Vector2 finalPosition); +static float rgVector2Angle(Vector2 v1, Vector2 v2); static float rgVector2Distance(Vector2 v1, Vector2 v2); static double rgGetCurrentTime(void); @@ -249,7 +249,7 @@ static double rgGetCurrentTime(void); // Module Functions Definition //---------------------------------------------------------------------------------- -// Enable only desired getures to be detected +// Enable only desired gestures to be detected void SetGesturesEnabled(unsigned int flags) { GESTURES.enabledFlags = flags; @@ -300,7 +300,7 @@ void ProcessGestureEvent(GestureEvent event) { if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0]; - // NOTE: GESTURES.Drag.intensity dependend on the resolution of the screen + // NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition); GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.timeDuration)); @@ -472,7 +472,7 @@ Vector2 GetGestureDragVector(void) } // Get drag angle -// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise +// NOTE: Angle in degrees, horizontal-right is 0, counter clock-wise float GetGestureDragAngle(void) { // NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP @@ -488,8 +488,8 @@ Vector2 GetGesturePinchVector(void) return GESTURES.Pinch.vector; } -// Get angle beween two pinch points -// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise +// Get angle between two pinch points +// NOTE: Angle in degrees, horizontal-right is 0, counter clock-wise float GetGesturePinchAngle(void) { // NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE @@ -518,7 +518,7 @@ static float rgVector2Distance(Vector2 v1, Vector2 v2) float dx = v2.x - v1.x; float dy = v2.y - v1.y; - result = (float)sqrt(dx*dx + dy*dy); + result = sqrtf(dx*dx + dy*dy); return result; } diff --git a/src/rlgl.h b/src/rlgl.h index 2b982a9a1..b0718fbe1 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -502,7 +502,7 @@ typedef enum { } rlShaderAttributeDataType; // Framebuffer attachment type -// NOTE: By default up to 8 color channels defined but it can be more +// NOTE: By default up to 8 color channels defined, but it can be more typedef enum { RL_ATTACHMENT_COLOR_CHANNEL0 = 0, // Framebuffer attachment type: color 0 RL_ATTACHMENT_COLOR_CHANNEL1, // Framebuffer attachment type: color 1 diff --git a/src/rmodels.c b/src/rmodels.c index 15de05c09..63765bd85 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -1125,7 +1125,7 @@ void UnloadModel(Model model) // Unload materials maps // NOTE: As the user could be sharing shaders and textures between models, - // we don't unload the material but just free it's maps, + // we don't unload the material but just free its maps, // the user is responsible for freeing models shaders and textures for (int i = 0; i < model.materialCount; i++) RL_FREE(model.materials[i].maps); @@ -1146,7 +1146,7 @@ void UnloadModelKeepMeshes(Model model) { // Unload materials maps // NOTE: As the user could be sharing shaders and textures between models, - // we don't unload the material but just free it's maps, + // we don't unload the material but just free its maps, // the user is responsible for freeing models shaders and textures for (int i = 0; i < model.materialCount; i++) RL_FREE(model.materials[i].maps); @@ -1230,7 +1230,7 @@ void UploadMesh(Mesh *mesh, bool dynamic) rlEnableVertexAttribute(1); // WARNING: When setting default vertex attribute values, the values for each generic vertex attribute - // is part of current state and it is maintained even if a different program object is used + // is part of current state, and it is maintained even if a different program object is used if (mesh->normals != NULL) { @@ -1383,7 +1383,7 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform) } // Get a copy of current matrices to work with, - // just in case stereo render is required and we need to modify them + // just in case stereo render is required, and we need to modify them // NOTE: At this point the modelview matrix just contains the view matrix (camera) // That's because BeginMode3D() sets it and there is no model-drawing function // that modifies it, all use rlPushMatrix() and rlPopMatrix() @@ -1396,7 +1396,7 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform) if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], matView); if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], matProjection); - // Model transformation matrix is send to shader uniform location: SHADER_LOC_MATRIX_MODEL + // Model transformation matrix is sent to shader uniform location: SHADER_LOC_MATRIX_MODEL if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MODEL], transform); // Accumulate several model transformations: @@ -1587,7 +1587,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i } // Get a copy of current matrices to work with, - // just in case stereo render is required and we need to modify them + // just in case stereo render is required, and we need to modify them // NOTE: At this point the modelview matrix just contains the view matrix (camera) // That's because BeginMode3D() sets it and there is no model-drawing function // that modifies it, all use rlPushMatrix() and rlPopMatrix() @@ -1738,7 +1738,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i else rlDrawVertexArrayInstanced(0, mesh.vertexCount, instances); } - // Unbind all binded texture maps + // Unbind all bound texture maps for (int i = 0; i < MAX_MATERIAL_MAPS; i++) { if (material.maps[i].texture.id > 0) @@ -2045,7 +2045,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame) int boneId = 0; int boneCounter = 0; - float boneWeight = 0.0; + float boneWeight = 0.0f; const int vValues = mesh.vertexCount*3; for (int vCounter = 0; vCounter < vValues; vCounter += 3) @@ -2559,7 +2559,7 @@ Mesh GenMeshSphere(float radius, int rings, int slices) return mesh; } -// Generate hemi-sphere mesh (half sphere, no bottom cap) +// Generate hemisphere mesh (half sphere, no bottom cap) Mesh GenMeshHemiSphere(float radius, int rings, int slices) { Mesh mesh = { 0 }; @@ -3242,7 +3242,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) } } - // Move data from mapVertices temp arays to vertices float array + // Move data from mapVertices temp arrays to vertices float array mesh.vertexCount = vCounter; mesh.triangleCount = vCounter/3; @@ -3325,7 +3325,7 @@ BoundingBox GetMeshBoundingBox(Mesh mesh) } // Compute mesh tangents -// NOTE: To calculate mesh tangents and binormals we need mesh vertex positions and texture coordinates +// NOTE: To calculate mesh tangents and binomials we need mesh vertex positions and texture coordinates // Implementation base don: https://answers.unity.com/questions/7789/calculating-tangents-vector4.html void GenMeshTangents(Mesh *mesh) { @@ -3727,8 +3727,8 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box) t[3] = (box.max.y - ray.position.y)*t[9]; t[4] = (box.min.z - ray.position.z)*t[10]; t[5] = (box.max.z - ray.position.z)*t[10]; - t[6] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5])); - t[7] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5])); + t[6] = fmax(fmax(fminf(t[0], t[1]), fminf(t[2], t[3])), fminf(t[4], t[5])); + t[7] = fmin(fmin(fmaxf(t[0], t[1]), fmaxf(t[2], t[3])), fmaxf(t[4], t[5])); collision.hit = !((t[7] < 0) || (t[6] > t[7])); collision.distance = t[6]; @@ -3742,7 +3742,7 @@ RayCollision GetRayCollisionBox(Ray ray, BoundingBox box) // NOTE: We use an additional .01 to fix numerical errors collision.normal = Vector3Scale(collision.normal, 2.01f); collision.normal = Vector3Divide(collision.normal, Vector3Subtract(box.max, box.min)); - // The relevant elemets of the vector are now slightly larger than 1.0f (or smaller than -1.0f) + // The relevant elements of the vector are now slightly larger than 1.0f (or smaller than -1.0f) // and the others are somewhere between -1.0 and 1.0 casting to int is exactly our wanted normal! collision.normal.x = (float)((int)collision.normal.x); collision.normal.y = (float)((int)collision.normal.y); @@ -3842,7 +3842,7 @@ RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3 // Calculate u parameter and test bound u = Vector3DotProduct(tv, p)*invDet; - // The intersection lies outside of the triangle + // The intersection lies outside the triangle if ((u < 0.0f) || (u > 1.0f)) return collision; // Prepare to test v parameter @@ -3851,7 +3851,7 @@ RayCollision GetRayCollisionTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3 // Calculate V parameter and test bound v = Vector3DotProduct(ray.direction, q)*invDet; - // The intersection lies outside of the triangle + // The intersection lies outside the triangle if ((v < 0.0f) || ((u + v) > 1.0f)) return collision; t = Vector3DotProduct(edge2, q)*invDet; @@ -4287,10 +4287,10 @@ static Model LoadIQM(const char *fileName) for (unsigned int m = 0; m < iqmHeader->num_meshes; m++) { int vCounter = 0; - for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) + for (unsigned int j = imesh[m].first_vertex * 3; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 3; j++) { - model.meshes[m].vertices[vCounter] = vertex[i]; - model.meshes[m].animVertices[vCounter] = vertex[i]; + model.meshes[m].vertices[vCounter] = vertex[j]; + model.meshes[m].animVertices[vCounter] = vertex[j]; vCounter++; } } @@ -4305,10 +4305,10 @@ static Model LoadIQM(const char *fileName) for (unsigned int m = 0; m < iqmHeader->num_meshes; m++) { int vCounter = 0; - for (unsigned int i = imesh[m].first_vertex*3; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*3; i++) + for (unsigned int j = imesh[m].first_vertex * 3; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 3; j++) { - model.meshes[m].normals[vCounter] = normal[i]; - model.meshes[m].animNormals[vCounter] = normal[i]; + model.meshes[m].normals[vCounter] = normal[j]; + model.meshes[m].animNormals[vCounter] = normal[j]; vCounter++; } } @@ -4323,9 +4323,9 @@ static Model LoadIQM(const char *fileName) for (unsigned int m = 0; m < iqmHeader->num_meshes; m++) { int vCounter = 0; - for (unsigned int i = imesh[m].first_vertex*2; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*2; i++) + for (unsigned int j = imesh[m].first_vertex * 2; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 2; j++) { - model.meshes[m].texcoords[vCounter] = text[i]; + model.meshes[m].texcoords[vCounter] = text[j]; vCounter++; } } @@ -4340,9 +4340,9 @@ static Model LoadIQM(const char *fileName) for (unsigned int m = 0; m < iqmHeader->num_meshes; m++) { int boneCounter = 0; - for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) + for (unsigned int j = imesh[m].first_vertex * 4; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 4; j++) { - model.meshes[m].boneIds[boneCounter] = blendi[i]; + model.meshes[m].boneIds[boneCounter] = blendi[j]; boneCounter++; } } @@ -4357,9 +4357,9 @@ static Model LoadIQM(const char *fileName) for (unsigned int m = 0; m < iqmHeader->num_meshes; m++) { int boneCounter = 0; - for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) + for (unsigned int j = imesh[m].first_vertex * 4; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 4; j++) { - model.meshes[m].boneWeights[boneCounter] = blendw[i]/255.0f; + model.meshes[m].boneWeights[boneCounter] = blendw[j] / 255.0f; boneCounter++; } } @@ -4376,9 +4376,9 @@ static Model LoadIQM(const char *fileName) model.meshes[m].colors = RL_CALLOC(model.meshes[m].vertexCount*4, sizeof(unsigned char)); int vCounter = 0; - for (unsigned int i = imesh[m].first_vertex*4; i < (imesh[m].first_vertex + imesh[m].num_vertexes)*4; i++) + for (unsigned int j = imesh[m].first_vertex * 4; j < (imesh[m].first_vertex + imesh[m].num_vertexes) * 4; j++) { - model.meshes[m].colors[vCounter] = color[i]; + model.meshes[m].colors[vCounter] = color[j]; vCounter++; } } @@ -4671,7 +4671,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat { Image image = { 0 }; - if (cgltfImage->uri != NULL) // Check if image data is provided as a uri (base64 or path) + if (cgltfImage->uri != NULL) // Check if image data is provided as an uri (base64 or path) { if ((strlen(cgltfImage->uri) > 5) && (cgltfImage->uri[0] == 'd') && @@ -5042,7 +5042,7 @@ static Model LoadGLTF(const char *fileName) // Load data into a temp buffer to be converted to raylib data type unsigned short *temp = RL_MALLOC(attribute->count*4*sizeof(unsigned short)); - LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp); + LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp) // Convert data to raylib color data type (4 bytes) for (unsigned int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(((float)temp[c]/65535.0f)*255.0f); @@ -5056,7 +5056,7 @@ static Model LoadGLTF(const char *fileName) // Load data into a temp buffer to be converted to raylib data type float *temp = RL_MALLOC(attribute->count*4*sizeof(float)); - LOAD_ATTRIBUTE(attribute, 4, float, temp); + LOAD_ATTRIBUTE(attribute, 4, float, temp) // Convert data to raylib color data type (4 bytes), we expect the color data normalized for (unsigned int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(temp[c]*255.0f); @@ -5091,7 +5091,7 @@ static Model LoadGLTF(const char *fileName) // Load data into a temp buffer to be converted to raylib data type unsigned int *temp = RL_MALLOC(attribute->count*sizeof(unsigned int)); - LOAD_ATTRIBUTE(attribute, 1, unsigned int, temp); + LOAD_ATTRIBUTE(attribute, 1, unsigned int, temp) // Convert data to raylib indices data type (unsigned short) for (unsigned int d = 0; d < attribute->count; d++) model.meshes[meshIndex].indices[d] = (unsigned short)temp[d]; @@ -5110,7 +5110,7 @@ static Model LoadGLTF(const char *fileName) { // The primitive actually keeps the pointer to the corresponding material, // raylib instead assigns to the mesh the by its index, as loaded in model.materials array - // To get the index, we check if material pointers match and we assign the corresponding index, + // To get the index, we check if material pointers match, and we assign the corresponding index, // skipping index 0, the default material if (&data->materials[m] == data->meshes[i].primitives[p].material) { @@ -5613,7 +5613,7 @@ static Model LoadM3D(const char *fileName) // Materials are grouped together if (mi != m3d->face[i].materialid) { - // there should be only one material switch per material kind, but be bulletproof for unoptimal model files + // there should be only one material switch per material kind, but be bulletproof for non-optimal model files if (k + 1 >= model.meshCount) { model.meshCount++; @@ -5842,7 +5842,7 @@ static Model LoadM3D(const char *fileName) } // Load bone-pose default mesh into animation vertices. These will be updated when UpdateModelAnimation gets - // called, but not before, however DrawMesh uses these if they exists (so not good if they are left empty). + // called, but not before, however DrawMesh uses these if they exist (so not good if they are left empty). if (m3d->numbone && m3d->numskin) { for(i = 0; i < model.meshCount; i++) diff --git a/src/rshapes.c b/src/rshapes.c index 86e014e2a..9da79bdc0 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -230,7 +230,7 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color) DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color); } -// Draw line using quadratic bezier curves with a control point +// Draw line using quadratic Bézier curves with a control point void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color) { const float step = 1.0f/BEZIER_LINE_DIVISIONS; @@ -275,7 +275,7 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color); } -// Draw line using cubic bezier curves with 2 control points +// Draw line using cubic Bézier curves with 2 control points void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color) { const float step = 1.0f/BEZIER_LINE_DIVISIONS; @@ -978,7 +978,7 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co rlSetTexture(texShapes.id); rlBegin(RL_QUADS); - // Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner + // Draw all the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; @@ -1207,7 +1207,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo rlBegin(RL_QUADS); - // Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner + // Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; @@ -1342,7 +1342,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo // Use LINES to draw the outline rlBegin(RL_LINES); - // Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner + // Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; diff --git a/src/rtext.c b/src/rtext.c index 9908b44df..665b53d56 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -65,7 +65,7 @@ #include // Required for: vsprintf() #include // Required for: strcmp(), strstr(), strcpy(), strncpy() [Used in TextReplace()], sscanf() [Used in LoadBMFont()] #include // Required for: va_list, va_start(), vsprintf(), va_end() [Used in TextFormat()] -#include // Requried for: toupper(), tolower() [Used in TextToUpper(), TextToLower()] +#include // Required for: toupper(), tolower() [Used in TextToUpper(), TextToLower()] #if defined(SUPPORT_FILEFORMAT_TTF) #define STB_RECT_PACK_IMPLEMENTATION @@ -336,7 +336,7 @@ Font LoadFont(const char *fileName) } else { - SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); // By default we set point filter (best performance) + SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); // By default, we set point filter (the best performance) TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", FONT_TTF_DEFAULT_SIZE, FONT_TTF_DEFAULT_NUMCHARS); } @@ -584,7 +584,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz glyphCount = (glyphCount > 0)? glyphCount : 95; // Fill fontChars in case not provided externally - // NOTE: By default we fill glyphCount consecutevely, starting at 32 (Space) + // NOTE: By default we fill glyphCount consecutively, starting at 32 (Space) if (fontChars == NULL) { @@ -647,7 +647,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz } } - // Get bounding box for character (may be offset to account for chars that dip above or below the line) + // Get bounding box for character (maybe offset to account for chars that dip above or below the line) /* int chX1, chY1, chX2, chY2; stbtt_GetCodepointBitmapBox(&fontInfo, ch, scaleFactor, scaleFactor, &chX1, &chY1, &chX2, &chY2); @@ -777,7 +777,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC for (int i = 0; i < glyphCount; i++) { - // It return char rectangles in atlas + // It returns char rectangles in atlas recs[i].x = rects[i].x + (float)padding; recs[i].y = rects[i].y + (float)padding; recs[i].width = (float)chars[i].image.width; @@ -855,7 +855,7 @@ bool ExportFontAsCode(Font font, const char *fileName) #define TEXT_BYTES_PER_LINE 20 #endif - #define MAX_FONT_DATA_SIZE 1024*1024 // 1 MB + #define MAX_FONT_DATA_SIZE (1024*1024) // 1 MB // Get file name from path char fileNamePascal[256] = { 0 }; @@ -1040,7 +1040,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f int size = TextLength(text); // Total size in bytes of the text, scanned by codepoints in loop - int textOffsetY = 0; // Offset between lines (on line break '\n') + int textOffsetY = 0; // Offset between lines (on linebreak '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor @@ -1053,7 +1053,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f int index = GetGlyphIndex(font, codepoint); // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all of the bad bytes using the '?' symbol moving one byte + // but we need to draw all the bad bytes using the '?' symbol moving one byte if (codepoint == 0x3f) codepointByteCount = 1; if (codepoint == '\n') @@ -1119,7 +1119,7 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz // Draw multiple character (codepoints) void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint) { - int textOffsetY = 0; // Offset between lines (on line break '\n') + int textOffsetY = 0; // Offset between lines (on linebreak '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor @@ -1195,7 +1195,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing index = GetGlyphIndex(font, letter); // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1 + // but we need to draw all the bad bytes using the '?' symbol so to not skip any we set next = 1 if (letter == 0x3f) next = 1; i += next - 1; @@ -1410,7 +1410,7 @@ char *TextReplace(char *text, const char *replace, const char *by) char *insertPoint = NULL; // Next insert point char *temp = NULL; // Temp pointer int replaceLen = 0; // Replace string length of (the string to remove) - int byLen = 0; // Replacement length (the string to replace replace by) + int byLen = 0; // Replacement length (the string to replace by) int lastReplacePos = 0; // Distance between replace and end of last replace int count = 0; // Number of replacements @@ -1756,7 +1756,7 @@ const char *CodepointToUTF8(int codepoint, int *utf8Size) #endif // SUPPORT_TEXT_MANIPULATION // Get next codepoint in a UTF-8 encoded text, scanning until '\0' is found -// When a invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned +// When an invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned // Total number of bytes processed are returned as a parameter // NOTE: The standard says U+FFFD should be returned in case of errors // but that character is not supported by the default font in raylib diff --git a/src/rtextures.c b/src/rtextures.c index 89a91b051..4a1d17bdc 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -124,7 +124,7 @@ #define RL_GPUTEX_SUPPORT_ASTC #endif -// Image fileformats not supported by default +// Image file formats not supported by default #if defined(__TINYC__) #define STBI_NO_SIMD #endif @@ -750,8 +750,8 @@ Image GenImageGradientRadial(int width, int height, float density, Color inner, float dist = hypotf((float)x - centerX, (float)y - centerY); float factor = (dist - radius*density)/(radius*(1.0f - density)); - factor = (float)fmax(factor, 0.0f); - factor = (float)fmin(factor, 1.f); // dist can be bigger than radius so we have to check + factor = fmaxf(factor, 0.0f); + factor = fminf(factor, 1.f); // dist can be bigger than radius, so we have to check pixels[y*width + x].r = (int)((float)outer.r*factor + (float)inner.r*(1.0f - factor)); pixels[y*width + x].g = (int)((float)outer.g*factor + (float)inner.g*(1.0f - factor)); @@ -893,12 +893,12 @@ Image GenImageCellular(int width, int height, int tileSize) Vector2 neighborSeed = seeds[(tileY + j)*seedsPerRow + tileX + i]; - float dist = (float)hypot(x - (int)neighborSeed.x, y - (int)neighborSeed.y); - minDistance = (float)fmin(minDistance, dist); + float dist = hypotf(x - (int)neighborSeed.x, y - (int)neighborSeed.y); + minDistance = fminf(minDistance, dist); } } - // I made this up but it seems to give good results at all tile sizes + // I made this up, but it seems to give good results at all tile sizes int intensity = (int)(minDistance*256.0f/tileSize); if (intensity > 255) intensity = 255; @@ -1103,9 +1103,9 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round(pixels[i].x*31.0f)); - g = (unsigned char)(round(pixels[i].y*63.0f)); - b = (unsigned char)(round(pixels[i].z*31.0f)); + r = (unsigned char)(roundf(pixels[i].x*31.0f)); + g = (unsigned char)(roundf(pixels[i].y*63.0f)); + b = (unsigned char)(roundf(pixels[i].z*31.0f)); ((unsigned short *)image->data)[i] = (unsigned short)r << 11 | (unsigned short)g << 5 | (unsigned short)b; } @@ -1115,11 +1115,11 @@ void ImageFormat(Image *image, int newFormat) { image->data = (unsigned char *)RL_MALLOC(image->width*image->height*3*sizeof(unsigned char)); - for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) + for (int i = 0, j = 0; i < image->width * image->height * 3; i += 3, j++) { - ((unsigned char *)image->data)[i] = (unsigned char)(pixels[k].x*255.0f); - ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].y*255.0f); - ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[k].z*255.0f); + ((unsigned char *)image->data)[i] = (unsigned char)(pixels[j].x * 255.0f); + ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[j].y * 255.0f); + ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[j].z * 255.0f); } } break; case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: @@ -1133,9 +1133,9 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round(pixels[i].x*31.0f)); - g = (unsigned char)(round(pixels[i].y*31.0f)); - b = (unsigned char)(round(pixels[i].z*31.0f)); + r = (unsigned char)(roundf(pixels[i].x*31.0f)); + g = (unsigned char)(roundf(pixels[i].y*31.0f)); + b = (unsigned char)(roundf(pixels[i].z*31.0f)); a = (pixels[i].w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0; ((unsigned short *)image->data)[i] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; @@ -1153,10 +1153,10 @@ void ImageFormat(Image *image, int newFormat) for (int i = 0; i < image->width*image->height; i++) { - r = (unsigned char)(round(pixels[i].x*15.0f)); - g = (unsigned char)(round(pixels[i].y*15.0f)); - b = (unsigned char)(round(pixels[i].z*15.0f)); - a = (unsigned char)(round(pixels[i].w*15.0f)); + r = (unsigned char)(roundf(pixels[i].x*15.0f)); + g = (unsigned char)(roundf(pixels[i].y*15.0f)); + b = (unsigned char)(roundf(pixels[i].z*15.0f)); + a = (unsigned char)(roundf(pixels[i].w*15.0f)); ((unsigned short *)image->data)[i] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a; } @@ -1166,17 +1166,17 @@ void ImageFormat(Image *image, int newFormat) { image->data = (unsigned char *)RL_MALLOC(image->width*image->height*4*sizeof(unsigned char)); - for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) + for (int i = 0, j = 0; i < image->width * image->height * 4; i += 4, j++) { - ((unsigned char *)image->data)[i] = (unsigned char)(pixels[k].x*255.0f); - ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[k].y*255.0f); - ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[k].z*255.0f); - ((unsigned char *)image->data)[i + 3] = (unsigned char)(pixels[k].w*255.0f); + ((unsigned char *)image->data)[i] = (unsigned char)(pixels[j].x * 255.0f); + ((unsigned char *)image->data)[i + 1] = (unsigned char)(pixels[j].y * 255.0f); + ((unsigned char *)image->data)[i + 2] = (unsigned char)(pixels[j].z * 255.0f); + ((unsigned char *)image->data)[i + 3] = (unsigned char)(pixels[j].w * 255.0f); } } break; case PIXELFORMAT_UNCOMPRESSED_R32: { - // WARNING: Image is converted to GRAYSCALE eqeuivalent 32bit + // WARNING: Image is converted to GRAYSCALE equivalent 32bit image->data = (float *)RL_MALLOC(image->width*image->height*sizeof(float)); @@ -1189,23 +1189,23 @@ void ImageFormat(Image *image, int newFormat) { image->data = (float *)RL_MALLOC(image->width*image->height*3*sizeof(float)); - for (int i = 0, k = 0; i < image->width*image->height*3; i += 3, k++) + for (int i = 0, j = 0; i < image->width * image->height * 3; i += 3, j++) { - ((float *)image->data)[i] = pixels[k].x; - ((float *)image->data)[i + 1] = pixels[k].y; - ((float *)image->data)[i + 2] = pixels[k].z; + ((float *)image->data)[i] = pixels[j].x; + ((float *)image->data)[i + 1] = pixels[j].y; + ((float *)image->data)[i + 2] = pixels[j].z; } } break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: { image->data = (float *)RL_MALLOC(image->width*image->height*4*sizeof(float)); - for (int i = 0, k = 0; i < image->width*image->height*4; i += 4, k++) + for (int i = 0, j = 0; i < image->width * image->height * 4; i += 4, j++) { - ((float *)image->data)[i] = pixels[k].x; - ((float *)image->data)[i + 1] = pixels[k].y; - ((float *)image->data)[i + 2] = pixels[k].z; - ((float *)image->data)[i + 3] = pixels[k].w; + ((float *)image->data)[i] = pixels[j].x; + ((float *)image->data)[i + 1] = pixels[j].y; + ((float *)image->data)[i + 2] = pixels[j].z; + ((float *)image->data)[i + 3] = pixels[j].w; } } break; default: break; @@ -1214,7 +1214,7 @@ void ImageFormat(Image *image, int newFormat) RL_FREE(pixels); pixels = NULL; - // In case original image had mipmaps, generate mipmaps for formated image + // In case original image had mipmaps, generate mipmaps for formatted image // NOTE: Original mipmaps are replaced by new ones, if custom mipmaps were used, they are lost if (image->mipmaps > 1) { @@ -1269,7 +1269,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co int size = (int)strlen(text); // Get size in bytes of text int textOffsetX = 0; // Image drawing position X - int textOffsetY = 0; // Offset between lines (on line break '\n') + int textOffsetY = 0; // Offset between lines (on linebreak '\n') // NOTE: Text image is generated at font base size, later scaled to desired font size Vector2 imSize = MeasureTextEx(font, text, (float)font.baseSize, spacing); // WARNING: Module required: rtext @@ -1286,7 +1286,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co int index = GetGlyphIndex(font, codepoint); // WARNING: Module required: rtext // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all of the bad bytes using the '?' symbol moving one byte + // but we need to draw all the bad bytes using the '?' symbol moving one byte if (codepoint == 0x3f) codepointByteCount = 1; if (codepoint == '\n') @@ -1331,7 +1331,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co } // Crop image depending on alpha value -// NOTE: Threshold is defined as a percentatge: 0.0f -> 1.0f +// NOTE: Threshold is defined as a percentage: 0.0f -> 1.0f void ImageAlphaCrop(Image *image, float threshold) { // Security check to avoid program crash @@ -1372,9 +1372,9 @@ void ImageAlphaClear(Image *image, Color color, float threshold) { unsigned char thresholdValue = ((threshold < 0.5f)? 0 : 1); - unsigned char r = (unsigned char)(round((float)color.r*31.0f)); - unsigned char g = (unsigned char)(round((float)color.g*31.0f)); - unsigned char b = (unsigned char)(round((float)color.b*31.0f)); + unsigned char r = (unsigned char)(roundf((float)color.r*31.0f)); + unsigned char g = (unsigned char)(roundf((float)color.g*31.0f)); + unsigned char b = (unsigned char)(roundf((float)color.b*31.0f)); unsigned char a = (color.a < 128)? 0 : 1; for (int i = 0; i < image->width*image->height; i++) @@ -1389,10 +1389,10 @@ void ImageAlphaClear(Image *image, Color color, float threshold) { unsigned char thresholdValue = (unsigned char)(threshold*15.0f); - unsigned char r = (unsigned char)(round((float)color.r*15.0f)); - unsigned char g = (unsigned char)(round((float)color.g*15.0f)); - unsigned char b = (unsigned char)(round((float)color.b*15.0f)); - unsigned char a = (unsigned char)(round((float)color.a*15.0f)); + unsigned char r = (unsigned char)(roundf((float)color.r*15.0f)); + unsigned char g = (unsigned char)(roundf((float)color.g*15.0f)); + unsigned char b = (unsigned char)(roundf((float)color.b*15.0f)); + unsigned char a = (unsigned char)(roundf((float)color.a*15.0f)); for (int i = 0; i < image->width*image->height; i++) { @@ -1711,7 +1711,7 @@ void ImageResize(Image *image, int newWidth, int newHeight) Color *pixels = LoadImageColors(*image); Color *output = (Color *)RL_MALLOC(newWidth*newHeight*sizeof(Color)); - // NOTE: Color data is casted to (unsigned char *), there shouldn't been any problem... + // NOTE: Color data is cast to (unsigned char *), there shouldn't been any problem... stbir_resize_uint8((unsigned char *)pixels, image->width, image->height, 0, (unsigned char *)output, newWidth, newHeight, 0, 4); int format = image->format; @@ -1891,7 +1891,7 @@ void ImageMipmaps(Image *image) } // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -// NOTE: In case selected bpp do not represent an known 16bit format, +// NOTE: In case selected bpp do not represent a known 16bit format, // dithered data is stored in the LSB part of the unsigned short void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp) { @@ -2531,7 +2531,7 @@ void UnloadImagePalette(Color *colors) } // Get image alpha border rectangle -// NOTE: Threshold is defined as a percentatge: 0.0f -> 1.0f +// NOTE: Threshold is defined as a percentage: 0.0f -> 1.0f Rectangle GetImageAlphaBorder(Image image, float threshold) { Rectangle crop = { 0 }; @@ -2729,9 +2729,9 @@ void ImageDrawPixel(Image *dst, int x, int y, Color color) // NOTE: Calculate R5G6B5 equivalent color Vector3 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*31.0f)); - unsigned char g = (unsigned char)(round(coln.y*63.0f)); - unsigned char b = (unsigned char)(round(coln.z*31.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*31.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*63.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*31.0f)); ((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 11 | (unsigned short)g << 5 | (unsigned short)b; @@ -2741,9 +2741,9 @@ void ImageDrawPixel(Image *dst, int x, int y, Color color) // NOTE: Calculate R5G5B5A1 equivalent color Vector4 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f, (float)color.a/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*31.0f)); - unsigned char g = (unsigned char)(round(coln.y*31.0f)); - unsigned char b = (unsigned char)(round(coln.z*31.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*31.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*31.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*31.0f)); unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0; ((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; @@ -2754,10 +2754,10 @@ void ImageDrawPixel(Image *dst, int x, int y, Color color) // NOTE: Calculate R5G5B5A1 equivalent color Vector4 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f, (float)color.a/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*15.0f)); - unsigned char g = (unsigned char)(round(coln.y*15.0f)); - unsigned char b = (unsigned char)(round(coln.z*15.0f)); - unsigned char a = (unsigned char)(round(coln.w*15.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*15.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*15.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*15.0f)); + unsigned char a = (unsigned char)(roundf(coln.w*15.0f)); ((unsigned short *)dst->data)[y*dst->width + x] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a; @@ -3049,7 +3049,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color if ((srcRec.y + srcRec.height) > src.height) srcRec.height = src.height - srcRec.y; // Check if source rectangle needs to be resized to destination rectangle - // In that case, we make a copy of source and we apply all required transform + // In that case, we make a copy of source, and we apply all required transform if (((int)srcRec.width != (int)dstRec.width) || ((int)srcRec.height != (int)dstRec.height)) { srcMod = ImageFromImage(src, srcRec); // Create image from another image @@ -3080,7 +3080,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color if (dst->width < srcRec.width) srcRec.width = (float)dst->width; if (dst->height < srcRec.height) srcRec.height = (float)dst->height; - // This blitting method is quite fast! The process followed is: + // This blotting method is quite fast! The process followed is: // for every pixel -> [get_src_format/get_dst_format -> blend -> format_to_dst] // Some optimization ideas: // [x] Avoid creating source copy if not required (no resize required) @@ -3273,7 +3273,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layout) faces = GenImageColor(size, size*6, MAGENTA); ImageFormat(&faces, image.format); - // NOTE: Image formating does not work with compressed textures + // NOTE: Image formatting does not work with compressed textures for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); } @@ -3606,7 +3606,7 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 // NOTE: Vertex position can be transformed using matrices // but the process is way more costly than just calculating // the vertex positions manually, like done above. - // I leave here the old implementation for educational pourposes, + // I leave here the old implementation for educational purposes, // just in case someone wants to do some performance test /* rlSetTexture(texture.id); @@ -4244,9 +4244,9 @@ void SetPixelColor(void *dstPtr, Color color, int format) // NOTE: Calculate R5G6B5 equivalent color Vector3 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*31.0f)); - unsigned char g = (unsigned char)(round(coln.y*63.0f)); - unsigned char b = (unsigned char)(round(coln.z*31.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*31.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*63.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*31.0f)); ((unsigned short *)dstPtr)[0] = (unsigned short)r << 11 | (unsigned short)g << 5 | (unsigned short)b; @@ -4256,9 +4256,9 @@ void SetPixelColor(void *dstPtr, Color color, int format) // NOTE: Calculate R5G5B5A1 equivalent color Vector4 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f, (float)color.a/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*31.0f)); - unsigned char g = (unsigned char)(round(coln.y*31.0f)); - unsigned char b = (unsigned char)(round(coln.z*31.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*31.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*31.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*31.0f)); unsigned char a = (coln.w > ((float)PIXELFORMAT_UNCOMPRESSED_R5G5B5A1_ALPHA_THRESHOLD/255.0f))? 1 : 0; ((unsigned short *)dstPtr)[0] = (unsigned short)r << 11 | (unsigned short)g << 6 | (unsigned short)b << 1 | (unsigned short)a; @@ -4269,10 +4269,10 @@ void SetPixelColor(void *dstPtr, Color color, int format) // NOTE: Calculate R5G5B5A1 equivalent color Vector4 coln = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f, (float)color.a/255.0f }; - unsigned char r = (unsigned char)(round(coln.x*15.0f)); - unsigned char g = (unsigned char)(round(coln.y*15.0f)); - unsigned char b = (unsigned char)(round(coln.z*15.0f)); - unsigned char a = (unsigned char)(round(coln.w*15.0f)); + unsigned char r = (unsigned char)(roundf(coln.x*15.0f)); + unsigned char g = (unsigned char)(roundf(coln.y*15.0f)); + unsigned char b = (unsigned char)(roundf(coln.z*15.0f)); + unsigned char a = (unsigned char)(roundf(coln.w*15.0f)); ((unsigned short *)dstPtr)[0] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a; diff --git a/src/utils.c b/src/utils.c index 030e59734..97c36b5bc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -63,10 +63,10 @@ static int logTypeLevel = LOG_INFO; // Minimum log type level static TraceLogCallback traceLog = NULL; // TraceLog callback function pointer -static LoadFileDataCallback loadFileData = NULL; // LoadFileData callback funtion pointer -static SaveFileDataCallback saveFileData = NULL; // SaveFileText callback funtion pointer -static LoadFileTextCallback loadFileText = NULL; // LoadFileText callback funtion pointer -static SaveFileTextCallback saveFileText = NULL; // SaveFileText callback funtion pointer +static LoadFileDataCallback loadFileData = NULL; // LoadFileData callback function pointer +static SaveFileDataCallback saveFileData = NULL; // SaveFileText callback function pointer +static LoadFileTextCallback loadFileText = NULL; // LoadFileText callback function pointer +static SaveFileTextCallback saveFileText = NULL; // SaveFileText callback function pointer //---------------------------------------------------------------------------------- // Functions to set internal callbacks @@ -166,7 +166,7 @@ void *MemAlloc(unsigned int size) return ptr; } -// Internal memory reallocator +// Internal memory re-allocator void *MemRealloc(void *ptr, unsigned int size) { void *ret = RL_REALLOC(ptr, size);