From 00d709fcc841758c6fbd9efa714eab3208a09769 Mon Sep 17 00:00:00 2001 From: ChestnutYueyue <952134128@qq.com> Date: Thu, 26 Feb 2026 20:08:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E6=8C=87=E9=92=88=E5=88=9B=E5=BB=BA=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 makePtr 和 makeUnique 分别重命名为 shared 和 unique,以提供更简洁的智能指针创建接口 --- examples/collision_demo/main.cpp | 6 +- examples/hello_world/main.cpp | 2 +- include/core/types.h | 4 +- src/app/application.cpp | 21 ++--- src/graphics/opengl/gl_renderer.cpp | 6 +- src/graphics/opengl/gl_texture.cpp | 8 +- src/graphics/texture_atlas.cpp | 132 +++++++++++++++------------- src/platform/window.cpp | 2 +- src/renderer/render_backend.cpp | 2 +- src/resource/resource_manager.cpp | 4 +- src/scene/scene.cpp | 13 +-- src/scene/shape_node.cpp | 14 +-- src/scene/sprite.cpp | 13 ++- src/ui/button.cpp | 6 +- src/ui/check_box.cpp | 4 +- src/ui/label.cpp | 6 +- src/ui/progress_bar.cpp | 4 +- src/ui/radio_button.cpp | 4 +- src/ui/slider.cpp | 4 +- src/ui/text.cpp | 14 ++- src/utils/data.cpp | 12 +-- 21 files changed, 141 insertions(+), 140 deletions(-) diff --git a/examples/collision_demo/main.cpp b/examples/collision_demo/main.cpp index 3d382a4..2c1b0b4 100644 --- a/examples/collision_demo/main.cpp +++ b/examples/collision_demo/main.cpp @@ -68,7 +68,7 @@ public: // 创建移动的中心方块 centerBox_ = - makePtr(80.0f, 80.0f, Color(0.2f, 0.6f, 1.0f, 0.8f)); + shared(80.0f, 80.0f, Color(0.2f, 0.6f, 1.0f, 0.8f)); centerBox_->setPosition(Vec2(centerX, centerY)); addChild(centerBox_); @@ -184,7 +184,7 @@ private: }; for (const auto &[pos, color] : positions) { - auto box = makePtr(70.0f, 70.0f, color); + auto box = shared(70.0f, 70.0f, color); box->setPosition(pos); addChild(box); boxes_.push_back(box); @@ -267,7 +267,7 @@ int main(int argc, char **argv) { } // 进入场景 - app.enterScene(makePtr()); + app.enterScene(shared()); E2D_LOG_INFO("开始主循环..."); diff --git a/examples/hello_world/main.cpp b/examples/hello_world/main.cpp index 1d72b17..c8fd8a7 100644 --- a/examples/hello_world/main.cpp +++ b/examples/hello_world/main.cpp @@ -111,7 +111,7 @@ int main(int argc, char **argv) { } // 进入 Hello World 场景 - app.enterScene(makePtr()); + app.enterScene(shared()); E2D_LOG_INFO("开始主循环..."); diff --git a/include/core/types.h b/include/core/types.h index fb75de7..ee93b7d 100644 --- a/include/core/types.h +++ b/include/core/types.h @@ -17,13 +17,13 @@ template using UniquePtr = std::unique_ptr; template using WeakPtr = std::weak_ptr; /// 创建 shared_ptr 的便捷函数 -template inline Ptr makePtr(Args &&...args) { +template inline Ptr shared(Args &&...args) { return std::make_shared(std::forward(args)...); } /// 创建 unique_ptr 的便捷函数 template -inline UniquePtr makeUnique(Args &&...args) { +inline UniquePtr unique(Args &&...args) { return std::make_unique(std::forward(args)...); } diff --git a/src/app/application.cpp b/src/app/application.cpp index 5924d0f..1bad306 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -2,17 +2,18 @@ #include