refactor(core): 重命名智能指针类型别名
将 UniquePtr 重命名为 Unique,WeakPtr 重命名为 Weak 更新相关文件和文档中的引用
This commit is contained in:
parent
c61edbb9dd
commit
ec136e42e4
|
|
@ -60,10 +60,10 @@ private:
|
|||
|
||||
AppConfig config_;
|
||||
|
||||
UniquePtr<Window> window_;
|
||||
UniquePtr<Renderer> renderer_;
|
||||
UniquePtr<EventQueue> eventQueue_;
|
||||
UniquePtr<EventDispatcher> eventDispatcher_;
|
||||
Unique<Window> window_;
|
||||
Unique<Renderer> renderer_;
|
||||
Unique<EventQueue> eventQueue_;
|
||||
Unique<EventDispatcher> eventDispatcher_;
|
||||
|
||||
bool initialized_ = false;
|
||||
bool running_ = false;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -12,9 +11,9 @@ namespace extra2d {
|
|||
// ---------------------------------------------------------------------------
|
||||
template <typename T> using Ptr = std::shared_ptr<T>;
|
||||
|
||||
template <typename T> using UniquePtr = std::unique_ptr<T>;
|
||||
template <typename T> using Unique = std::unique_ptr<T>;
|
||||
|
||||
template <typename T> using WeakPtr = std::weak_ptr<T>;
|
||||
template <typename T> using Weak = std::weak_ptr<T>;
|
||||
|
||||
/// 创建 shared_ptr 的便捷函数
|
||||
template <typename T, typename... Args> inline Ptr<T> shared(Args &&...args) {
|
||||
|
|
@ -23,7 +22,7 @@ template <typename T, typename... Args> inline Ptr<T> shared(Args &&...args) {
|
|||
|
||||
/// 创建 unique_ptr 的便捷函数
|
||||
template <typename T, typename... Args>
|
||||
inline UniquePtr<T> unique(Args &&...args) {
|
||||
inline Unique<T> unique(Args &&...args) {
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <extra2d/audio/sound.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/graphics/alpha_mask.h>
|
||||
|
|
@ -7,15 +8,15 @@
|
|||
#include <extra2d/graphics/texture.h>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
// ============================================================================
|
||||
|
|
@ -66,13 +67,16 @@ public:
|
|||
Ptr<Texture> loadTexture(const std::string &filepath, bool async);
|
||||
|
||||
/// 加载纹理(完整参数:异步 + 压缩格式)
|
||||
Ptr<Texture> loadTexture(const std::string &filepath, bool async, TextureFormat format);
|
||||
Ptr<Texture> loadTexture(const std::string &filepath, bool async,
|
||||
TextureFormat format);
|
||||
|
||||
/// 异步加载纹理(带回调)
|
||||
void loadTextureAsync(const std::string &filepath, TextureLoadCallback callback);
|
||||
void loadTextureAsync(const std::string &filepath,
|
||||
TextureLoadCallback callback);
|
||||
|
||||
/// 异步加载纹理(指定格式 + 回调)
|
||||
void loadTextureAsync(const std::string &filepath, TextureFormat format, TextureLoadCallback callback);
|
||||
void loadTextureAsync(const std::string &filepath, TextureFormat format,
|
||||
TextureLoadCallback callback);
|
||||
|
||||
/// 加载纹理并生成Alpha遮罩(用于不规则形状图片)
|
||||
Ptr<Texture> loadTextureWithAlphaMask(const std::string &filepath);
|
||||
|
|
@ -146,7 +150,8 @@ public:
|
|||
/// @param filepath 文件路径
|
||||
/// @param encoding 文件编码(默认 UTF-8)
|
||||
/// @return 文件内容字符串
|
||||
std::string loadTextFile(const std::string &filepath, const std::string &encoding);
|
||||
std::string loadTextFile(const std::string &filepath,
|
||||
const std::string &encoding);
|
||||
|
||||
/// 通过key获取已缓存的文本内容
|
||||
std::string getTextFile(const std::string &key) const;
|
||||
|
|
@ -251,14 +256,16 @@ private:
|
|||
bool useSDF) const;
|
||||
|
||||
// 内部加载实现
|
||||
Ptr<Texture> loadTextureInternal(const std::string &filepath, TextureFormat format);
|
||||
Ptr<Texture> loadTextureInternal(const std::string &filepath,
|
||||
TextureFormat format);
|
||||
|
||||
// 选择最佳纹理格式
|
||||
TextureFormat selectBestFormat(TextureFormat requested) const;
|
||||
|
||||
// 压缩纹理数据
|
||||
std::vector<uint8_t> compressTexture(const uint8_t* data, int width, int height,
|
||||
int channels, TextureFormat format);
|
||||
std::vector<uint8_t> compressTexture(const uint8_t *data, int width,
|
||||
int height, int channels,
|
||||
TextureFormat format);
|
||||
|
||||
// 互斥锁保护缓存
|
||||
mutable std::mutex textureMutex_;
|
||||
|
|
@ -268,8 +275,8 @@ private:
|
|||
mutable std::mutex jsonFileMutex_;
|
||||
|
||||
// 资源缓存 - 使用弱指针实现自动清理
|
||||
std::unordered_map<std::string, WeakPtr<FontAtlas>> fontCache_;
|
||||
std::unordered_map<std::string, WeakPtr<Sound>> soundCache_;
|
||||
std::unordered_map<std::string, Weak<FontAtlas>> fontCache_;
|
||||
std::unordered_map<std::string, Weak<Sound>> soundCache_;
|
||||
|
||||
// 文本文件缓存 - 使用强引用(字符串值类型)
|
||||
std::unordered_map<std::string, std::string> textFileCache_;
|
||||
|
|
|
|||
|
|
@ -256,14 +256,14 @@ private:
|
|||
std::vector<Ptr<Node>> children_; // 24 bytes
|
||||
|
||||
// 3. 子节点索引(加速查找)
|
||||
std::unordered_map<std::string, WeakPtr<Node>> nameIndex_; // 56 bytes
|
||||
std::unordered_map<int, WeakPtr<Node>> tagIndex_; // 56 bytes
|
||||
std::unordered_map<std::string, Weak<Node>> nameIndex_; // 56 bytes
|
||||
std::unordered_map<int, Weak<Node>> tagIndex_; // 56 bytes
|
||||
|
||||
// 4. 事件分发器
|
||||
EventDispatcher eventDispatcher_; // 大小取决于实现
|
||||
|
||||
// 5. 父节点引用
|
||||
WeakPtr<Node> parent_; // 16 bytes
|
||||
Weak<Node> parent_; // 16 bytes
|
||||
|
||||
// 7. 变换属性(按访问频率分组)
|
||||
Vec2 position_ = Vec2::Zero(); // 8 bytes
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ public:
|
|||
|
||||
private:
|
||||
class Impl;
|
||||
UniquePtr<Impl> impl_;
|
||||
Unique<Impl> impl_;
|
||||
std::string filename_;
|
||||
std::string mountName_;
|
||||
UserId defaultUserId_;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <extra2d/core/types.h>
|
||||
#include <extra2d/core/string.h>
|
||||
#include <extra2d/core/math_types.h>
|
||||
#include <extra2d/core/string.h>
|
||||
#include <extra2d/core/types.h>
|
||||
#include <functional>
|
||||
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
namespace extra2d {
|
||||
|
|
@ -59,7 +60,7 @@ private:
|
|||
bool vsync_;
|
||||
bool shouldClose_;
|
||||
bool fullscreen_;
|
||||
UniquePtr<Input> input_;
|
||||
Unique<Input> input_;
|
||||
|
||||
bool initSDL(const WindowConfig &config);
|
||||
void deinitSDL();
|
||||
|
|
|
|||
Loading…
Reference in New Issue