From 1cea142562dc23024325187006c57fdd91a13024 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:29:58 +0200 Subject: [PATCH 1/3] Update to C++20 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8b9c0bc..bb3cb6ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14) project(libscratchcpp VERSION 0.15.0 LANGUAGES C CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) option(LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON) From 5ffff8d74be0fea79be06a805c2d023ae08321bf Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:30:11 +0200 Subject: [PATCH 2/3] Use std::numbers::pi --- src/blocks/motionblocks.cpp | 12 +++++------- src/scratch/sprite_p.cpp | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/blocks/motionblocks.cpp b/src/blocks/motionblocks.cpp index 6acaf7eb..9d23cc42 100644 --- a/src/blocks/motionblocks.cpp +++ b/src/blocks/motionblocks.cpp @@ -20,8 +20,6 @@ using namespace libscratchcpp; -static const double pi = std::acos(-1); // TODO: Use std::numbers::pi in C++20 - std::string MotionBlocks::name() const { return "Motion"; @@ -357,7 +355,7 @@ CompilerValue *MotionBlocks::compileDirection(Compiler *compiler) BLOCK_EXPORT void motion_movesteps(Sprite *sprite, double steps) { double dir = sprite->direction(); - sprite->setPosition(sprite->x() + std::sin(dir * pi / 180) * steps, sprite->y() + std::cos(dir * pi / 180) * steps); + sprite->setPosition(sprite->x() + std::sin(dir * std::numbers::pi / 180) * steps, sprite->y() + std::cos(dir * std::numbers::pi / 180) * steps); } BLOCK_EXPORT void motion_turnright(Sprite *sprite, double degrees) @@ -387,9 +385,9 @@ inline void motion_point_towards_pos(Sprite *sprite, double x, double y) else sprite->setDirection(90); } else if (deltaY < 0) - sprite->setDirection(180 + (180 / pi) * std::atan(deltaX / deltaY)); + sprite->setDirection(180 + (180 / std::numbers::pi) * std::atan(deltaX / deltaY)); else - sprite->setDirection((180 / pi) * std::atan(deltaX / deltaY)); + sprite->setDirection((180 / std::numbers::pi) * std::atan(deltaX / deltaY)); } BLOCK_EXPORT void motion_point_towards_mouse(Sprite *sprite) @@ -678,7 +676,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite) assert(nearestEdge != 0); // Point away from the nearest edge - double radians = (90 - sprite->direction()) * pi / 180; + double radians = (90 - sprite->direction()) * std::numbers::pi / 180; double dx = std::cos(radians); double dy = -std::sin(radians); @@ -704,7 +702,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite) break; } - double newDirection = (180 / pi) * (std::atan2(dy, dx)) + 90; + double newDirection = (180 / std::numbers::pi) * (std::atan2(dy, dx)) + 90; sprite->setDirection(newDirection); // Keep within the stage diff --git a/src/scratch/sprite_p.cpp b/src/scratch/sprite_p.cpp index 37dfc591..282c3ab9 100644 --- a/src/scratch/sprite_p.cpp +++ b/src/scratch/sprite_p.cpp @@ -10,7 +10,6 @@ using namespace libscratchcpp; -static const double pi = std::acos(-1); // TODO: Use std::numbers::pi in C++20 static const double FENCE_WIDTH = 15; SpritePrivate::SpritePrivate(Sprite *sprite) : From d884851667a1bf1bb8c3596abad7649145e15c09 Mon Sep 17 00:00:00 2001 From: adazem009 <68537469+adazem009@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:30:31 +0200 Subject: [PATCH 3/3] Use std::bit_ceil() to calculate new string size --- src/scratch/string_functions.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scratch/string_functions.cpp b/src/scratch/string_functions.cpp index 6d4b9375..c9767179 100644 --- a/src/scratch/string_functions.cpp +++ b/src/scratch/string_functions.cpp @@ -21,8 +21,7 @@ extern "C" size++; // null terminator if (str->allocatedSize < size) { - // TODO: Use std::bit_ceil() in C++20 - const size_t newSize = std::pow(2, std::ceil(std::log2(size))); + const size_t newSize = std::bit_ceil(size); assert((str->data && str->allocatedSize > 0) || (!str->data && str->allocatedSize == 0)); if (str->data)