From 016b7d0a3a6d67e5d78a19d8c0adaa555712e67d Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Sat, 19 Aug 2023 08:43:00 -0300 Subject: [PATCH 1/7] Fix text_unicode.c example crashing (#3250) * Fix text_unicode.c example crashing * Adjust the text_unicode.c example crashing fix --- examples/text/text_unicode.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c index eb2a7843c..b25e3273b 100644 --- a/examples/text/text_unicode.c +++ b/examples/text/text_unicode.c @@ -187,12 +187,11 @@ int main(void) // Add a new set of emojis when SPACE is pressed if (IsKeyPressed(KEY_SPACE)) RandomizeEmoji(); - // Set the selected emoji and copy its text to clipboard + // Set the selected emoji if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && (hovered != -1) && (hovered != selected)) { selected = hovered; selectedPos = hoveredPos; - SetClipboardText(messages[emoji[selected].message].text); } Vector2 mouse = GetMousePosition(); @@ -267,7 +266,7 @@ int main(void) a = b; b = tmp; } - + if (msgRect.x + msgRect.width > screenWidth) msgRect.x -= (msgRect.x + msgRect.width) - screenWidth + 10; // Draw chat bubble @@ -287,11 +286,11 @@ int main(void) DrawText(info, (int)pos.x, (int)pos.y, 10, RAYWHITE); } //------------------------------------------------------------------------------ - + // Draw the info text DrawText("These emojis have something to tell you, click each to find out!", (screenWidth - 650)/2, screenHeight - 40, 20, GRAY); DrawText("Each emoji is a unicode character from a font, not a texture... Press [SPACEBAR] to refresh", (screenWidth - 484)/2, screenHeight - 16, 10, GRAY); - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -342,7 +341,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec, { int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop - float textOffsetY = 0; // Offset between lines (on line break '\n') + float textOffsetY = 0.0f; // Offset between lines (on line break '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/(float)font.baseSize; // Character rectangle scaling factor @@ -465,4 +464,4 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec, textOffsetX += glyphWidth; } -} \ No newline at end of file +} From 5a33f19964c845fd891342a6291f082e82ed2bf4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 19 Aug 2023 20:09:43 +0200 Subject: [PATCH 2/7] Revert "Fix #3246" This reverts commit e4dcbd518091a5854a517ea4cfc3f7e2d29de1a7. --- src/rlgl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index 9ca099acf..3756e5ac7 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -2945,7 +2945,6 @@ bool rlCheckRenderBatchLimit(int vCount) unsigned int rlLoadTexture(const void *data, int width, int height, int format, int mipmapCount) { unsigned int id = 0; - if (data == NULL) return id; glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding From 820343e7ac56546af93066f89425a828156ea82b Mon Sep 17 00:00:00 2001 From: "actondev (Christos)" Date: Sun, 20 Aug 2023 21:27:39 +0200 Subject: [PATCH 3/7] add build.zig options for individual modules (#3254) --- src/build.zig | 58 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/build.zig b/src/build.zig index 9aab4812a..27250f5ff 100644 --- a/src/build.zig +++ b/src/build.zig @@ -6,7 +6,6 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built "-std=gnu99", "-D_GNU_SOURCE", "-DGL_SILENCE_DEPRECATION=199309L", - "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 }; const raylib = b.addStaticLibrary(.{ @@ -22,15 +21,38 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built } raylib.addCSourceFiles(&.{ - srcdir ++ "/raudio.c", srcdir ++ "/rcore.c", - srcdir ++ "/rmodels.c", - srcdir ++ "/rshapes.c", - srcdir ++ "/rtext.c", - srcdir ++ "/rtextures.c", srcdir ++ "/utils.c", }, raylib_flags); + if (options.raudio) { + raylib.addCSourceFiles(&.{ + srcdir ++ "/raudio.c", + }, raylib_flags); + } + if (options.rmodels) { + raylib.addCSourceFiles(&.{ + srcdir ++ "/rmodels.c", + }, &[_][]const u8{ + "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 + } ++ raylib_flags); + } + if (options.rshapes) { + raylib.addCSourceFiles(&.{ + srcdir ++ "/rshapes.c", + }, raylib_flags); + } + if (options.rtext) { + raylib.addCSourceFiles(&.{ + srcdir ++ "/rtext.c", + }, raylib_flags); + } + if (options.rtextures) { + raylib.addCSourceFiles(&.{ + srcdir ++ "/rtextures.c", + }, raylib_flags); + } + var gen_step = std.build.Step.WriteFile.create(b); raylib.step.dependOn(&gen_step.step); @@ -137,6 +159,11 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built } pub const Options = struct { + raudio: bool = true, + rmodels: bool = true, + rshapes: bool = true, + rtext: bool = true, + rtextures: bool = true, raygui: bool = false, platform_drm: bool = false, }; @@ -152,19 +179,24 @@ pub fn build(b: *std.Build) void { // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - const raygui = b.option(bool, "raygui", "Compile with raygui support"); - const platform_drm = b.option(bool, "platform_drm", "Compile raylib in native mode (no X11)"); + const defaults = Options{}; + const options = Options{ + .platform_drm = b.option(bool, "platform_drm", "Compile raylib in native mode (no X11)") orelse defaults.platform_drm, + .raudio = b.option(bool, "raudio", "Compile with audio support") orelse defaults.raudio, + .rmodels = b.option(bool, "rmodels", "Compile with models support") orelse defaults.rmodels, + .rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext, + .rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures, + .rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes, + .raygui = b.option(bool, "raygui", "Compile with raygui support") orelse defaults.raygui, + }; - const lib = addRaylib(b, target, optimize, .{ - .raygui = raygui orelse false, - .platform_drm = platform_drm orelse false, - }); + const lib = addRaylib(b, target, optimize, options); lib.installHeader("src/raylib.h", "raylib.h"); lib.installHeader("src/raymath.h", "raymath.h"); lib.installHeader("src/rlgl.h", "rlgl.h"); - if (raygui orelse false) { + if (options.raygui) { lib.installHeader("../raygui/src/raygui.h", "raygui.h"); } From 8189bddefbb91525386dfdd60e268cc33e956a1f Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 20 Aug 2023 21:36:36 +0200 Subject: [PATCH 4/7] tweaks --- src/rshapes.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/rshapes.c b/src/rshapes.c index ea45aefc4..f3061f8b3 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -498,6 +498,13 @@ void DrawCircle(int centerX, int centerY, float radius, Color color) DrawCircleV((Vector2){ (float)centerX, (float)centerY }, radius, color); } +// Draw a color-filled circle (Vector version) +// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues +void DrawCircleV(Vector2 center, float radius, Color color) +{ + DrawCircleSector(center, radius, 0, 360, 36, color); +} + // Draw a piece of a circle void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color) { @@ -530,6 +537,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlSetTexture(texShapes.id); rlBegin(RL_QUADS); + // NOTE: Every QUAD actually represents two segments for (int i = 0; i < segments/2; i++) { @@ -539,7 +547,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlVertex2f(center.x, center.y); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength*2))*radius, center.y + sinf(DEG2RAD*(angle + stepLength*2))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength*2.0f))*radius, center.y + sinf(DEG2RAD*(angle + stepLength*2.0f))*radius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); @@ -547,11 +555,11 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); - angle += (stepLength*2); + angle += (stepLength*2.0f); } // NOTE: In case number of segments is odd, we add one last piece to the cake - if (segments%2) + if ((segments%2) == 1) { rlColor4ub(color.r, color.g, color.b, color.a); @@ -567,6 +575,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); } + rlEnd(); rlSetTexture(0); @@ -659,13 +668,6 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co rlEnd(); } -// Draw a color-filled circle (Vector version) -// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues -void DrawCircleV(Vector2 center, float radius, Color color) -{ - DrawCircleSector(center, radius, 0, 360, 36, color); -} - // Draw circle outline void DrawCircleLines(int centerX, int centerY, float radius, Color color) { From b3f82a148ac59ae0615597e553fb64b836616d63 Mon Sep 17 00:00:00 2001 From: "actondev (Christos)" Date: Sun, 20 Aug 2023 23:53:20 +0200 Subject: [PATCH 5/7] Add `IsKeyPressedRepeat` (desktop only) (#3245) Since the key pressed are handle by comparing current vs previous state (ie frame), a special way is needed to handle key repeats. --- src/raylib.h | 1 + src/rcore.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index abc8371bc..d932e3a34 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1115,6 +1115,7 @@ RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize // Input-related functions: keyboard RLAPI bool IsKeyPressed(int key); // Check if a key has been pressed once +RLAPI bool IsKeyPressedRepeat(int key); // Check if a key has been pressed again (Only PLATFORM_DESKTOP) RLAPI bool IsKeyDown(int key); // Check if a key is being pressed RLAPI bool IsKeyReleased(int key); // Check if a key has been released once RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed diff --git a/src/rcore.c b/src/rcore.c index 7d8811b05..52a58d6d6 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -438,6 +438,8 @@ typedef struct CoreData { int exitKey; // Default exit key char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state + // NOTE: Since key press logic involves comparing prev vs cur key state, we need to handle key repeats specially + char keyRepeatInFrame[MAX_KEYBOARD_KEYS]; // Registers key repeats for current frame. int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue int keyPressedQueueCount; // Input keys queue count @@ -3755,6 +3757,13 @@ bool IsKeyPressed(int key) return pressed; } +// Check if a key has been pressed again (only PLATFORM_DESKTOP) +bool IsKeyPressedRepeat(int key) +{ + if (CORE.Input.Keyboard.keyRepeatInFrame[key] == 1) return true; + else return true; +} + // Check if a key is being pressed (key held down) bool IsKeyDown(int key) { @@ -5170,6 +5179,8 @@ void PollInputEvents(void) // Reset keys/chars pressed registered CORE.Input.Keyboard.keyPressedQueueCount = 0; CORE.Input.Keyboard.charPressedQueueCount = 0; + // Reset key repeats + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; #if !(defined(PLATFORM_RPI) || defined(PLATFORM_DRM)) // Reset last gamepad button/axis registered state @@ -5179,7 +5190,11 @@ void PollInputEvents(void) #if defined(PLATFORM_RPI) || defined(PLATFORM_DRM) // Register previous keys states - for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i]; + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) + { + CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i]; + CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; + } PollKeyboardEvents(); @@ -5586,7 +5601,8 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i // WARNING: GLFW could return GLFW_REPEAT, we need to consider it as 1 // to work properly with our implementation (IsKeyDown/IsKeyUp checks) if (action == GLFW_RELEASE) CORE.Input.Keyboard.currentKeyState[key] = 0; - else CORE.Input.Keyboard.currentKeyState[key] = 1; + else if(action == GLFW_PRESS) CORE.Input.Keyboard.currentKeyState[key] = 1; + else if(action == GLFW_REPEAT) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1; #if !defined(PLATFORM_WEB) // WARNING: Check if CAPS/NUM key modifiers are enabled and force down state for those keys @@ -6357,7 +6373,11 @@ static void ProcessKeyboard(void) bufferByteCount = read(STDIN_FILENO, keysBuffer, MAX_KEYBUFFER_SIZE); // POSIX system call // Reset pressed keys array (it will be filled below) - for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) CORE.Input.Keyboard.currentKeyState[i] = 0; + for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) + { + CORE.Input.Keyboard.currentKeyState[i] = 0; + CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; + } // Fill all read bytes (looking for keys) for (int i = 0; i < bufferByteCount; i++) From dfd0436428f95c31885646183d64678f05a80494 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 21 Aug 2023 00:34:35 +0200 Subject: [PATCH 6/7] Reviewed `IsKeyPressedRepeat()` #3248 --- src/rcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index 52a58d6d6..1cae7f582 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -3761,7 +3761,7 @@ bool IsKeyPressed(int key) bool IsKeyPressedRepeat(int key) { if (CORE.Input.Keyboard.keyRepeatInFrame[key] == 1) return true; - else return true; + else return false; } // Check if a key is being pressed (key held down) From 5ed83dfa2928bae7e7f53076a6edca789e513173 Mon Sep 17 00:00:00 2001 From: vitopigno <103512727+VitusVeit@users.noreply.github.com> Date: Mon, 21 Aug 2023 00:36:00 +0200 Subject: [PATCH 7/7] Update rcore.c (#3255) --- src/rcore.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index 1cae7f582..10303fe94 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -4470,13 +4470,16 @@ static bool InitGraphicsDevice(int width, int height) #endif // 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 + // NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need + // to be activated on web platforms since VSync is enforced there. +#if !defined(PLATFORM_WEB) if (CORE.Window.flags & FLAG_VSYNC_HINT) { // WARNING: It seems to hit a critical render path in Intel HD Graphics glfwSwapInterval(1); TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC"); } +#endif int fbWidth = CORE.Window.screen.width; int fbHeight = CORE.Window.screen.height;