diff --git a/src/camera.h b/src/camera.h index d6c15298d..6d24c4b4f 100644 --- a/src/camera.h +++ b/src/camera.h @@ -212,7 +212,7 @@ typedef struct { //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -static CameraData CAMERA = { +static CameraData CAMERA = { .mode = 0, .targetDistance = 0, .playerEyesPosition = 1.85f, @@ -444,7 +444,7 @@ void UpdateCamera(Camera *camera) Matrix translation = MatrixTranslate(0, 0, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER)); Matrix rotation = MatrixRotateXYZ((Vector3){ PI*2 - CAMERA.angle.y, PI*2 - CAMERA.angle.x, 0 }); Matrix transform = MatrixMultiply(translation, rotation); - + camera->target.x = camera->position.x - transform.m12; camera->target.y = camera->position.y - transform.m13; camera->target.z = camera->position.z - transform.m14; diff --git a/src/core.c b/src/core.c index 8a920cdfc..252b7e0eb 100644 --- a/src/core.c +++ b/src/core.c @@ -356,7 +356,7 @@ typedef struct CoreData { Size render; // Framebuffer width and height (render area, including black bars if required) Point renderOffset; // Offset from render area (must be divided by 2) Matrix screenScale; // Matrix to scale screen (framebuffer rendering) - + char **dropFilesPath; // Store dropped files paths as strings int dropFilesCount; // Count dropped files strings @@ -608,12 +608,12 @@ void InitWindow(int width, int height, const char *title) TRACELOG(LOG_INFO, "Initializing raylib %s", RAYLIB_VERSION); CORE.Window.title = title; - + // Initialize required global values different than 0 CORE.Input.Keyboard.exitKey = KEY_ESCAPE; CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f }; CORE.Input.Gamepad.lastButtonPressed = -1; - + #if defined(PLATFORM_ANDROID) CORE.Window.screen.width = width; CORE.Window.screen.height = height; @@ -824,7 +824,7 @@ bool WindowShouldClose(void) while (!CORE.Window.alwaysRun && CORE.Window.minimized) glfwWaitEvents(); CORE.Window.shouldClose = glfwWindowShouldClose(CORE.Window.handle); - + return CORE.Window.shouldClose; } else return true; @@ -872,7 +872,7 @@ void ToggleFullscreen(void) CORE.Window.fullscreen = !CORE.Window.fullscreen; // Toggle fullscreen flag // NOTE: glfwSetWindowMonitor() doesn't work properly (bugs) - if (CORE.Window.fullscreen) + if (CORE.Window.fullscreen) { // Store previous window position (in case we exit fullscreen) glfwGetWindowPos(CORE.Window.handle, &CORE.Window.position.x, &CORE.Window.position.y); @@ -887,7 +887,7 @@ void ToggleFullscreen(void) const GLFWvidmode *mode = glfwGetVideoMode(monitor); glfwSetWindowMonitor(CORE.Window.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate); - + // Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS) // NOTE: V-Sync can be enabled by graphic driver configuration if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1); @@ -1281,14 +1281,14 @@ void EndDrawing(void) SwapBuffers(); // Copy back buffer to front buffer PollInputEvents(); // Poll user events - + // Frame time control system CORE.Time.current = GetTime(); CORE.Time.draw = CORE.Time.current - CORE.Time.previous; CORE.Time.previous = CORE.Time.current; CORE.Time.frame = CORE.Time.update + CORE.Time.draw; - + // Wait for some milliseconds... if (CORE.Time.frame < CORE.Time.target) { @@ -1299,9 +1299,9 @@ void EndDrawing(void) CORE.Time.previous = CORE.Time.current; CORE.Time.frame += waitTime; // Total frame time: update + draw + wait - - //SetWindowTitle(FormatText("Update: %f, Draw: %f, Req.Wait: %f, Real.Wait: %f, Total: %f, Target: %f\n", - // (float)CORE.Time.update, (float)CORE.Time.draw, (float)(CORE.Time.target - (CORE.Time.update + CORE.Time.draw)), + + //SetWindowTitle(FormatText("Update: %f, Draw: %f, Req.Wait: %f, Real.Wait: %f, Total: %f, Target: %f\n", + // (float)CORE.Time.update, (float)CORE.Time.draw, (float)(CORE.Time.target - (CORE.Time.update + CORE.Time.draw)), // (float)waitTime, (float)CORE.Time.frame, (float)CORE.Time.target)); } } @@ -1315,7 +1315,7 @@ void BeginMode2D(Camera2D camera) // Apply 2d camera transformation to modelview rlMultMatrixf(MatrixToFloat(GetCameraMatrix2D(camera))); - + // Apply screen scaling if required rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); } @@ -1551,7 +1551,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh if (camera.type == CAMERA_PERSPECTIVE) { // Calculate projection matrix from perspective - matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)width/(double)height), DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE); + matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)width/(double)height), DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE); } else if (camera.type == CAMERA_ORTHOGRAPHIC) { @@ -1560,7 +1560,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh double right = top*aspect; // Calculate projection matrix from orthographic - matProj = MatrixOrtho(-right, right, -top, top, DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE); + matProj = MatrixOrtho(-right, right, -top, top, DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE); } // Calculate view matrix from camera look at (and transpose it) @@ -1579,7 +1579,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w }; // Calculate 2d screen position vector - Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)width, (ndcPos.y + 1.0f)/2.0f*(float)height }; + Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)width, (ndcPos.y + 1.0f)/2.0f*(float)height }; return screenPosition; } @@ -1865,7 +1865,7 @@ bool IsFileExtension(const char *fileName, const char *ext) { int extCount = 0; const char **checkExts = TextSplit(ext, ';', &extCount); - + char fileExtLower[16] = { 0 }; strcpy(fileExtLower, TextToLower(fileExt)); @@ -1966,8 +1966,8 @@ const char *GetDirectoryPath(const char *filePath) const char *lastSlash = NULL; static char dirPath[MAX_FILEPATH_LENGTH]; memset(dirPath, 0, MAX_FILEPATH_LENGTH); - - // For security, we set starting path to current directory, + + // For security, we set starting path to current directory, // obtained path will be concated to this //dirPath[0] = '.'; //dirPath[1] = '/'; @@ -2063,7 +2063,7 @@ void ClearDirectoryFiles(void) RL_FREE(dirFilesPath); } - + dirFilesCount = 0; } @@ -2454,8 +2454,8 @@ bool IsMouseButtonPressed(int button) if (IsGestureDetected(GESTURE_TAP)) pressed = true; #else // NOTE: On PLATFORM_DESKTOP and PLATFORM_WEB IsMouseButtonPressed() is equivalent to GESTURE_TAP - if (((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) && - (CORE.Input.Mouse.currentButtonState[button] == 1)) || IsGestureDetected(GESTURE_TAP)) pressed = true; + if (((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) && + (CORE.Input.Mouse.currentButtonState[button] == 1)) || IsGestureDetected(GESTURE_TAP)) pressed = true; #endif return pressed; @@ -2482,7 +2482,7 @@ bool IsMouseButtonReleased(int button) bool released = false; #if !defined(PLATFORM_ANDROID) - if ((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) && + if ((CORE.Input.Mouse.currentButtonState[button] != CORE.Input.Mouse.previousButtonState[button]) && (CORE.Input.Mouse.currentButtonState[button] == 0)) released = true; #endif @@ -2701,7 +2701,7 @@ static bool InitGraphicsDevice(int width, int height) //glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers #if defined(PLATFORM_DESKTOP) && defined(SUPPORT_HIGH_DPI) // Resize window content area based on the monitor content scale. - // NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11. + // NOTE: This hint only has an effect on platforms where screen coordinates and pixels always map 1:1 such as Windows and X11. // On platforms like macOS the resolution of the framebuffer is changed independently of the window size. glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); // Scale content area based on the monitor content scale where window is placed on #endif @@ -3224,7 +3224,7 @@ static bool InitGraphicsDevice(int width, int height) CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f); #if !defined(__APPLE__) SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight); -#endif +#endif #endif // PLATFORM_DESKTOP && SUPPORT_HIGH_DPI // Setup default viewport @@ -3391,7 +3391,7 @@ static void Wait(float ms) #elif defined(__APPLE__) usleep(ms*1000.0f); #endif - + #if defined(SUPPORT_HALFBUSY_WAIT_LOOP) while (GetTime() < destTime) { } #endif @@ -3548,7 +3548,7 @@ static void PollInputEvents(void) { CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = CORE.Input.Keyboard.lastKeyPressed.Contents[CORE.Input.Keyboard.lastKeyPressed.Tail]; // Read the key from the buffer CORE.Input.Keyboard.keyPressedQueueCount++; - + CORE.Input.Keyboard.lastKeyPressed.Tail = (CORE.Input.Keyboard.lastKeyPressed.Tail + 1) & 0x07; // Increment the tail pointer forwards and binary wraparound after 7 (fifo is 8 elements long) } @@ -3852,7 +3852,7 @@ static void PollInputEvents(void) // Android ALooper_pollAll() variables int pollResult = 0; int pollEvents = 0; - + // Poll Events (registered events) // NOTE: Activity is paused if not enabled (CORE.Android.appEnabled) while ((pollResult = ALooper_pollAll(CORE.Android.appEnabled? 0 : -1, NULL, &pollEvents, (void**)&CORE.Android.source)) >= 0) @@ -4223,7 +4223,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN) { CORE.Input.Keyboard.currentKeyState[keycode] = 1; // Key down - + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; CORE.Input.Keyboard.keyPressedQueueCount++; } @@ -4240,7 +4240,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN) { CORE.Input.Keyboard.currentKeyState[keycode] = 1; // Key down - + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; CORE.Input.Keyboard.keyPressedQueueCount++; } @@ -4589,15 +4589,15 @@ static void ProcessKeyboard(void) } else if (keysBuffer[i] == 0x0a) // raylib KEY_ENTER (don't mix with <linux/input.h> KEY_*) { - CORE.Input.Keyboard.currentKeyState[257] = 1; - + CORE.Input.Keyboard.currentKeyState[257] = 1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = 257; // Add keys pressed into queue CORE.Input.Keyboard.keyPressedQueueCount++; } else if (keysBuffer[i] == 0x7f) // raylib KEY_BACKSPACE - { - CORE.Input.Keyboard.currentKeyState[259] = 1; - + { + CORE.Input.Keyboard.currentKeyState[259] = 1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = 257; // Add keys pressed into queue CORE.Input.Keyboard.keyPressedQueueCount++; } @@ -5026,7 +5026,7 @@ static void *EventThread(void *arg) */ CORE.Input.Keyboard.currentKeyState[keycode] = event.value; - if (event.value == 1) + if (event.value == 1) { CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = keycode; // Register last key pressed CORE.Input.Keyboard.keyPressedQueueCount++; diff --git a/src/models.c b/src/models.c index 953e1f623..825368964 100644 --- a/src/models.c +++ b/src/models.c @@ -114,7 +114,7 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) void DrawPoint3D(Vector3 position, Color color) { if (rlCheckBufferLimit(8)) rlglDraw(); - + rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); @@ -955,7 +955,7 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount) { TRACELOG(LOG_ERROR, "IQM version %i is incorrect.", iqm.version); fclose(iqmFile); - + return NULL; } @@ -2376,7 +2376,7 @@ void MeshBinormals(Mesh *mesh) //Vector3 normal = { mesh->normals[i*3 + 0], mesh->normals[i*3 + 1], mesh->normals[i*3 + 2] }; //Vector3 tangent = { mesh->tangents[i*4 + 0], mesh->tangents[i*4 + 1], mesh->tangents[i*4 + 2] }; //Vector3 binormal = Vector3Scale(Vector3CrossProduct(normal, tangent), mesh->tangents[i*4 + 3]); - + // TODO: Register computed binormal in mesh->binormal? } } @@ -2408,13 +2408,13 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota { // TODO: Review color + tint premultiplication mechanism Color color = model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color; - + Color colorTint = WHITE; colorTint.r = (((float)color.r/255.0)*((float)tint.r/255.0))*255; colorTint.g = (((float)color.g/255.0)*((float)tint.g/255.0))*255; colorTint.b = (((float)color.b/255.0)*((float)tint.b/255.0))*255; colorTint.a = (((float)color.a/255.0)*((float)tint.a/255.0))*255; - + model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color = colorTint; rlDrawMesh(model.meshes[i], model.materials[model.meshMaterial[i]], model.transform); model.materials[model.meshMaterial[i]].maps[MAP_DIFFUSE].color = color; @@ -3406,7 +3406,7 @@ static Texture LoadTextureFromCgltfImage(cgltf_image *image, const char *texPath unsigned char *raw = stbi_load_from_memory(data, size, &w, &h, NULL, 4); Image rimage = LoadImagePro(raw, w, h, UNCOMPRESSED_R8G8B8A8); - + // TODO: Tint shouldn't be applied here! ImageColorTint(&rimage, tint); texture = LoadTextureFromImage(rimage); @@ -3416,7 +3416,7 @@ static Texture LoadTextureFromCgltfImage(cgltf_image *image, const char *texPath else { Image rimage = LoadImage(TextFormat("%s/%s", texPath, image->uri)); - + // TODO: Tint shouldn't be applied here! ImageColorTint(&rimage, tint); texture = LoadTextureFromImage(rimage); @@ -3544,7 +3544,7 @@ static Model LoadGLTF(const char *fileName) const char *texPath = GetDirectoryPath(fileName); //Ensure material follows raylib support for PBR (metallic/roughness flow) - if (data->materials[i].has_pbr_metallic_roughness) + if (data->materials[i].has_pbr_metallic_roughness) { float roughness = data->materials[i].pbr_metallic_roughness.roughness_factor; float metallic = data->materials[i].pbr_metallic_roughness.metallic_factor; @@ -3560,12 +3560,12 @@ static Model LoadGLTF(const char *fileName) model.materials[i].maps[MAP_ROUGHNESS].color = tint; - if (data->materials[i].pbr_metallic_roughness.base_color_texture.texture) + if (data->materials[i].pbr_metallic_roughness.base_color_texture.texture) { model.materials[i].maps[MAP_ALBEDO].texture = LoadTextureFromCgltfImage(data->materials[i].pbr_metallic_roughness.base_color_texture.texture->image, texPath, tint); } - // NOTE: Tint isn't need for other textures.. pass null or clear? + // NOTE: Tint isn't need for other textures.. pass null or clear? // Just set as white, multiplying by white has no effect tint = WHITE; @@ -3576,12 +3576,12 @@ static Model LoadGLTF(const char *fileName) model.materials[i].maps[MAP_ROUGHNESS].value = roughness; model.materials[i].maps[MAP_METALNESS].value = metallic; - if (data->materials[i].normal_texture.texture) + if (data->materials[i].normal_texture.texture) { model.materials[i].maps[MAP_NORMAL].texture = LoadTextureFromCgltfImage(data->materials[i].normal_texture.texture->image, texPath, tint); } - - if (data->materials[i].occlusion_texture.texture) + + if (data->materials[i].occlusion_texture.texture) { model.materials[i].maps[MAP_OCCLUSION].texture = LoadTextureFromCgltfImage(data->materials[i].occlusion_texture.texture->image, texPath, tint); } diff --git a/src/physac.h b/src/physac.h index 3fb832b67..977c3c55b 100644 --- a/src/physac.h +++ b/src/physac.h @@ -112,7 +112,7 @@ #elif !defined(__cplusplus) && !defined(bool) typedef enum { false, true } bool; #endif - + // Vector2 type typedef struct Vector2 { float x; @@ -1257,7 +1257,7 @@ static void DestroyPhysicsManifold(PhysicsManifold manifold) printf("[PHYSAC] Not possible to manifold id %i in pointers array\n", id); #endif return; // Prevent access to index -1 - } + } // Free manifold allocated memory PHYSAC_FREE(manifold); diff --git a/src/raudio.c b/src/raudio.c index 4e184b8ea..5e55a36b9 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -163,10 +163,10 @@ typedef enum { } TraceLogType; #endif -// NOTE: Different logic is used when feeding data to the playback device +// NOTE: Different logic is used when feeding data to the playback device // depending on whether or not data is streamed (Music vs Sound) -typedef enum { - AUDIO_BUFFER_USAGE_STATIC = 0, +typedef enum { + AUDIO_BUFFER_USAGE_STATIC = 0, AUDIO_BUFFER_USAGE_STREAM } AudioBufferUsage; @@ -274,7 +274,7 @@ void InitAudioDevice(void) { // TODO: Load AUDIO context memory dynamically? AUDIO.System.masterVolume = 1.0f; - + // Init audio context ma_context_config ctxConfig = ma_context_config_init(); ctxConfig.logCallback = OnLog; @@ -386,7 +386,7 @@ AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam TRACELOG(LOG_ERROR, "InitAudioBuffer() : Failed to allocate memory for audio buffer"); return NULL; } - + audioBuffer->data = RL_CALLOC(sizeInFrames*channels*ma_get_bytes_per_sample(format), 1); // Audio data runs through a format converter @@ -1541,7 +1541,7 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const framesToRead -= framesJustRead; framesRead += framesJustRead; } - + if (!audioBuffer->playing) { framesRead = frameCount; @@ -1697,7 +1697,7 @@ static void InitAudioBufferPool(void) // Close the audio buffers pool static void CloseAudioBufferPool(void) { - for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) + for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) { RL_FREE(AUDIO.MultiChannel.pool[i]->data); RL_FREE(AUDIO.MultiChannel.pool[i]); diff --git a/src/rlgl.h b/src/rlgl.h index bb59d4439..4d86737c9 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -64,7 +64,7 @@ #if defined(RLGL_STANDALONE) #define RAYMATH_STANDALONE #define RAYMATH_HEADER_ONLY - + #define RLAPI // We are building or using rlgl as a static library (or Linux shared library) #if defined(_WIN32) @@ -74,11 +74,11 @@ #define RLAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll) #endif #endif - + // Support TRACELOG macros #if defined(SUPPORT_TRACELOG) #define TRACELOG(level, ...) TraceLog(level, __VA_ARGS__) - + #if defined(SUPPORT_TRACELOG_DEBUG) #define TRACELOGD(...) TraceLog(LOG_DEBUG, __VA_ARGS__) #else @@ -212,7 +212,7 @@ typedef unsigned char byte; unsigned char b; unsigned char a; } Color; - + // Rectangle type typedef struct Rectangle { float x; @@ -816,7 +816,7 @@ typedef struct rlglData { int currentBuffer; // Current buffer tracking, multi-buffering system is supported DrawCall *draws; // Draw calls array int drawsCounter; // Draw calls counter - + Texture2D shapesTexture; // Texture used on shapes drawing (usually a white) Rectangle shapesTextureRec; // Texture source rectangle used on shapes drawing unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader) diff --git a/src/rmem.h b/src/rmem.h index 9c7d0a70e..6ea6ffaa0 100644 --- a/src/rmem.h +++ b/src/rmem.h @@ -694,7 +694,7 @@ BiStack CreateBiStack(const size_t len) { BiStack destack = { 0 }; if (len == 0UL) return destack; - + destack.size = len; destack.mem = malloc(len*sizeof *destack.mem); if (destack.mem==NULL) destack.size = 0UL; @@ -726,11 +726,11 @@ void DestroyBiStack(BiStack *const destack) void *BiStackAllocFront(BiStack *const destack, const size_t len) { if ((destack == NULL) || (destack->mem == NULL)) return NULL; - + const size_t ALIGNED_LEN = __AlignSize(len, sizeof(uintptr_t)); // front end stack is too high! if (destack->front + ALIGNED_LEN >= destack->back) return NULL; - + uint8_t *ptr = destack->front; destack->front += ALIGNED_LEN; return ptr; @@ -739,11 +739,11 @@ void *BiStackAllocFront(BiStack *const destack, const size_t len) void *BiStackAllocBack(BiStack *const destack, const size_t len) { if ((destack == NULL) || (destack->mem == NULL)) return NULL; - + const size_t ALIGNED_LEN = __AlignSize(len, sizeof(uintptr_t)); // back end stack is too low if (destack->back - ALIGNED_LEN <= destack->front) return NULL; - + destack->back -= ALIGNED_LEN; return destack->back; } diff --git a/src/shapes.c b/src/shapes.c index ca68d9517..4cae2784b 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -1386,7 +1386,7 @@ void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Colo rlPushMatrix(); rlTranslatef(center.x, center.y, 0.0f); rlRotatef(rotation, 0.0f, 0.0f, 1.0f); - + rlBegin(RL_LINES); for (int i = 0; i < sides; i++) { diff --git a/src/text.c b/src/text.c index c23a90318..345d2b10a 100644 --- a/src/text.c +++ b/src/text.c @@ -555,7 +555,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c if (type != FONT_SDF) chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, SDF_CHAR_PADDING, SDF_ON_EDGE_VALUE, SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); else chars[i].image.data = NULL; - + stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL); chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor); @@ -816,7 +816,7 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float scale, // Character rectangle on screen // NOTE: Quad is scaled proportionally to base character width-height Rectangle rec = { position.x, position.y, font.recs[index].width*scale, font.recs[index].height*scale }; - + DrawTexturePro(font.texture, font.recs[index], rec, (Vector2){ 0, 0 }, 0.0f, tint); } @@ -828,7 +828,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f int textOffsetY = 0; // Offset between lines (on line break '\n') float textOffsetX = 0.0f; // Offset X to next character to draw - + float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor for (int i = 0; i < length; i++) @@ -851,20 +851,20 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f } else { - if ((codepoint != ' ') && (codepoint != '\t')) + if ((codepoint != ' ') && (codepoint != '\t')) { Rectangle rec = { position.x + textOffsetX + font.chars[index].offsetX*scaleFactor, - position.y + textOffsetY + font.chars[index].offsetY*scaleFactor, - font.recs[index].width*scaleFactor, + position.y + textOffsetY + font.chars[index].offsetY*scaleFactor, + font.recs[index].width*scaleFactor, font.recs[index].height*scaleFactor }; - + DrawTexturePro(font.texture, font.recs[index], rec, (Vector2){ 0, 0 }, 0.0f, tint); } if (font.chars[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing); else textOffsetX += ((float)font.chars[index].advanceX*scaleFactor + spacing); } - + i += (codepointByteCount - 1); // Move text bytes counter to next codepoint } } @@ -888,7 +888,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f // Word/character wrapping mechanism variables enum { MEASURE_STATE = 0, DRAW_STATE = 1 }; int state = wordWrap? MEASURE_STATE : DRAW_STATE; - + int startLine = -1; // Index where to begin drawing (where a line begins) int endLine = -1; // Index where to stop drawing (where a line ends) int lastk = -1; // Holds last value of the character position @@ -929,13 +929,13 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f endLine = (endLine < 1)? i : endLine; if (i == endLine) endLine -= codepointByteCount; if ((startLine + codepointByteCount) == endLine) endLine = (i - codepointByteCount); - + state = !state; } else if ((i + 1) == length) { endLine = i; - + state = !state; } else if (codepoint == '\n') state = !state; @@ -987,7 +987,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f DrawTexturePro(font.texture, font.recs[index], (Rectangle){ rec.x + textOffsetX + font.chars[index].offsetX*scaleFactor, rec.y + textOffsetY + font.chars[index].offsetY*scaleFactor, - font.recs[index].width*scaleFactor, font.recs[index].height*scaleFactor }, + font.recs[index].width*scaleFactor, font.recs[index].height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, (!isGlyphSelected)? tint : selectTint); } } @@ -1000,7 +1000,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f endLine = -1; glyphWidth = 0; k = lastk; - + state = !state; } } @@ -1085,7 +1085,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing int GetGlyphIndex(Font font, int codepoint) { #define TEXT_CHARACTER_NOTFOUND 63 // Character: '?' - + #define UNORDERED_CHARSET #if defined(UNORDERED_CHARSET) int index = TEXT_CHARACTER_NOTFOUND; @@ -1113,7 +1113,7 @@ int GetGlyphIndex(Font font, int codepoint) int TextCopy(char *dst, const char *src) { int bytes = 0; - + if (dst != NULL) { while (*src != '\0') @@ -1121,7 +1121,7 @@ int TextCopy(char *dst, const char *src) *dst = *src; dst++; src++; - + bytes++; } @@ -1161,14 +1161,14 @@ const char *TextFormat(const char *text, ...) // We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 }; static int index = 0; - + char *currentBuffer = buffers[index]; va_list args; va_start(args, text); vsprintf(currentBuffer, text, args); va_end(args); - + index += 1; // Move to next buffer for next function call if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0; @@ -1431,10 +1431,10 @@ int TextToInteger(const char *text) if (text[0] == '-') sign = -1; text++; } - + for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10 + (int)(text[i] - '0'); - return value*sign; + return value*sign; } // Encode text codepoint into utf8 text (memory must be freed!) @@ -1445,17 +1445,17 @@ char *TextToUtf8(int *codepoints, int length) char *text = (char *)calloc(length*5, 1); const char *utf8 = NULL; int size = 0; - + for (int i = 0, bytes = 0; i < length; i++) { utf8 = CodepointToUtf8(codepoints[i], &bytes); strncpy(text + size, utf8, bytes); size += bytes; } - + // Resize memory to text length + string NULL terminator text = RL_REALLOC(text, size + 1); - + return text; } diff --git a/src/textures.c b/src/textures.c index 899554b0a..10016a28d 100644 --- a/src/textures.c +++ b/src/textures.c @@ -458,9 +458,9 @@ void UnloadRenderTexture(RenderTexture2D target) Color *GetImageData(Image image) { if ((image.width == 0) || (image.height == 0)) return NULL; - + Color *pixels = (Color *)RL_MALLOC(image.width*image.height*sizeof(Color)); - + if (image.format >= COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats"); else { @@ -686,9 +686,9 @@ Vector4 *GetImageDataNormalized(Image image) Rectangle GetImageAlphaBorder(Image image, float threshold) { Rectangle crop = { 0 }; - + Color *pixels = GetImageData(image); - + if (pixels != NULL) { int xMin = 65536; // Define a big enough number @@ -2992,9 +2992,9 @@ static Image LoadAnimatedGIF(const char *fileName, int *frames, int **delays) { fseek(gifFile, 0L, SEEK_END); int size = ftell(gifFile); - fseek(gifFile, 0L, SEEK_SET); + fseek(gifFile, 0L, SEEK_SET); - unsigned char *buffer = (unsigned char *)RL_CALLOC(size, sizeof(char)); + unsigned char *buffer = (unsigned char *)RL_CALLOC(size, sizeof(char)); fread(buffer, sizeof(char), size, gifFile); fclose(gifFile); // Close file pointer diff --git a/src/utils.h b/src/utils.h index 756b6553f..1c399b68b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -34,7 +34,7 @@ #if defined(SUPPORT_TRACELOG) #define TRACELOG(level, ...) TraceLog(level, __VA_ARGS__) - + #if defined(SUPPORT_TRACELOG_DEBUG) #define TRACELOGD(...) TraceLog(LOG_DEBUG, __VA_ARGS__) #else