refactor: 统一智能指针创建函数命名
将 makePtr 和 makeUnique 分别重命名为 shared 和 unique,以提供更简洁的智能指针创建接口
This commit is contained in:
parent
aec444f2b5
commit
00d709fcc8
|
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
// 创建移动的中心方块
|
||||
centerBox_ =
|
||||
makePtr<CollisionBox>(80.0f, 80.0f, Color(0.2f, 0.6f, 1.0f, 0.8f));
|
||||
shared<CollisionBox>(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<CollisionBox>(70.0f, 70.0f, color);
|
||||
auto box = shared<CollisionBox>(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<CollisionDemoScene>());
|
||||
app.enterScene(shared<CollisionDemoScene>());
|
||||
|
||||
E2D_LOG_INFO("开始主循环...");
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
// 进入 Hello World 场景
|
||||
app.enterScene(makePtr<HelloWorldScene>());
|
||||
app.enterScene(shared<HelloWorldScene>());
|
||||
|
||||
E2D_LOG_INFO("开始主循环...");
|
||||
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ template <typename T> using UniquePtr = std::unique_ptr<T>;
|
|||
template <typename T> using WeakPtr = std::weak_ptr<T>;
|
||||
|
||||
/// 创建 shared_ptr 的便捷函数
|
||||
template <typename T, typename... Args> inline Ptr<T> makePtr(Args &&...args) {
|
||||
template <typename T, typename... Args> inline Ptr<T> shared(Args &&...args) {
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// 创建 unique_ptr 的便捷函数
|
||||
template <typename T, typename... Args>
|
||||
inline UniquePtr<T> makeUnique(Args &&...args) {
|
||||
inline UniquePtr<T> unique(Args &&...args) {
|
||||
return std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,17 +2,18 @@
|
|||
#include <audio/audio_engine.h>
|
||||
#include <event/event_dispatcher.h>
|
||||
#include <event/event_queue.h>
|
||||
#include <renderer/camera.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <graphics/vram_manager.h>
|
||||
#include <platform/input.h>
|
||||
#include <platform/window.h>
|
||||
#include <renderer/camera.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <resource/resource_manager.h>
|
||||
#include <scene/scene_manager.h>
|
||||
#include <utils/logger.h>
|
||||
#include <utils/object_pool.h>
|
||||
#include <utils/timer.h>
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
|
@ -91,7 +92,7 @@ bool Application::init(const AppConfig &config) {
|
|||
// ========================================
|
||||
// 3. 创建窗口(包含 SDL_Init + GLES 3.2 上下文创建)
|
||||
// ========================================
|
||||
window_ = makeUnique<Window>();
|
||||
window_ = unique<Window>();
|
||||
WindowConfig winConfig;
|
||||
winConfig.title = config.title;
|
||||
winConfig.width = config.width;
|
||||
|
|
@ -130,12 +131,12 @@ bool Application::init(const AppConfig &config) {
|
|||
// ========================================
|
||||
// 5. 初始化其他子系统
|
||||
// ========================================
|
||||
sceneManager_ = makeUnique<SceneManager>();
|
||||
resourceManager_ = makeUnique<ResourceManager>();
|
||||
timerManager_ = makeUnique<TimerManager>();
|
||||
eventQueue_ = makeUnique<EventQueue>();
|
||||
eventDispatcher_ = makeUnique<EventDispatcher>();
|
||||
camera_ = makeUnique<Camera>(0, static_cast<float>(window_->width()),
|
||||
sceneManager_ = unique<SceneManager>();
|
||||
resourceManager_ = unique<ResourceManager>();
|
||||
timerManager_ = unique<TimerManager>();
|
||||
eventQueue_ = unique<EventQueue>();
|
||||
eventDispatcher_ = unique<EventDispatcher>();
|
||||
camera_ = unique<Camera>(0, static_cast<float>(window_->width()),
|
||||
static_cast<float>(window_->height()), 0);
|
||||
|
||||
// 窗口大小回调
|
||||
|
|
|
|||
|
|
@ -210,11 +210,11 @@ glm::mat4 GLRenderer::getCurrentTransform() const {
|
|||
|
||||
Ptr<Texture> GLRenderer::createTexture(int width, int height,
|
||||
const uint8_t *pixels, int channels) {
|
||||
return makePtr<GLTexture>(width, height, pixels, channels);
|
||||
return shared<GLTexture>(width, height, pixels, channels);
|
||||
}
|
||||
|
||||
Ptr<Texture> GLRenderer::loadTexture(const std::string &filepath) {
|
||||
return makePtr<GLTexture>(filepath);
|
||||
return shared<GLTexture>(filepath);
|
||||
}
|
||||
|
||||
void GLRenderer::beginSpriteBatch() { spriteBatch_.begin(viewProjection_); }
|
||||
|
|
@ -430,7 +430,7 @@ void GLRenderer::fillPolygon(const std::vector<Vec2> &points,
|
|||
|
||||
Ptr<FontAtlas> GLRenderer::createFontAtlas(const std::string &filepath,
|
||||
int fontSize, bool useSDF) {
|
||||
return makePtr<GLFontAtlas>(filepath, fontSize, useSDF);
|
||||
return shared<GLFontAtlas>(filepath, fontSize, useSDF);
|
||||
}
|
||||
|
||||
void GLRenderer::drawText(const FontAtlas &font, const std::string &text,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
#include <graphics/opengl/gl_texture.h>
|
||||
#include <graphics/gpu_context.h>
|
||||
#include <graphics/opengl/gl_texture.h>
|
||||
#include <graphics/vram_manager.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <cstring>
|
||||
#include <utils/logger.h>
|
||||
#include <fstream>
|
||||
#include <stb/stb_image.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -455,7 +457,7 @@ Ptr<Texture> GLTexture::create(int width, int height, PixelFormat format) {
|
|||
channels = 4;
|
||||
break;
|
||||
}
|
||||
return makePtr<GLTexture>(width, height, nullptr, channels);
|
||||
return shared<GLTexture>(width, height, nullptr, channels);
|
||||
}
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#include <graphics/texture_atlas.h>
|
||||
#include <utils/logger.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <graphics/texture_atlas.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ TextureAtlasPage::TextureAtlasPage(int width, int height)
|
|||
: width_(width), height_(height), isFull_(false), usedArea_(0) {
|
||||
// 创建空白纹理
|
||||
std::vector<uint8_t> emptyData(width * height * 4, 0);
|
||||
texture_ = makePtr<GLTexture>(width, height, emptyData.data(), 4);
|
||||
texture_ = shared<GLTexture>(width, height, emptyData.data(), 4);
|
||||
|
||||
// 初始化矩形打包根节点
|
||||
root_ = std::make_unique<PackNode>(0, 0, width, height);
|
||||
|
|
@ -23,8 +24,9 @@ TextureAtlasPage::TextureAtlasPage(int width, int height)
|
|||
|
||||
TextureAtlasPage::~TextureAtlasPage() = default;
|
||||
|
||||
bool TextureAtlasPage::tryAddTexture(const std::string& name, int texWidth, int texHeight,
|
||||
const uint8_t* pixels, Rect& outUvRect) {
|
||||
bool TextureAtlasPage::tryAddTexture(const std::string &name, int texWidth,
|
||||
int texHeight, const uint8_t *pixels,
|
||||
Rect &outUvRect) {
|
||||
if (isFull_) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -39,7 +41,7 @@ bool TextureAtlasPage::tryAddTexture(const std::string& name, int texWidth, int
|
|||
}
|
||||
|
||||
// 尝试插入
|
||||
PackNode* node = insert(root_.get(), paddedWidth, paddedHeight);
|
||||
PackNode *node = insert(root_.get(), paddedWidth, paddedHeight);
|
||||
if (node == nullptr) {
|
||||
// 无法放入,标记为满
|
||||
isFull_ = true;
|
||||
|
|
@ -47,12 +49,14 @@ bool TextureAtlasPage::tryAddTexture(const std::string& name, int texWidth, int
|
|||
}
|
||||
|
||||
// 写入像素数据(跳过边距区域)
|
||||
writePixels(node->x + PADDING, node->y + PADDING, texWidth, texHeight, pixels);
|
||||
writePixels(node->x + PADDING, node->y + PADDING, texWidth, texHeight,
|
||||
pixels);
|
||||
|
||||
// 创建条目
|
||||
AtlasEntry entry;
|
||||
entry.name = name;
|
||||
entry.originalSize = Vec2(static_cast<float>(texWidth), static_cast<float>(texHeight));
|
||||
entry.originalSize =
|
||||
Vec2(static_cast<float>(texWidth), static_cast<float>(texHeight));
|
||||
entry.padding = PADDING;
|
||||
|
||||
// 计算 UV 坐标(考虑边距)
|
||||
|
|
@ -67,20 +71,21 @@ bool TextureAtlasPage::tryAddTexture(const std::string& name, int texWidth, int
|
|||
entries_[name] = std::move(entry);
|
||||
usedArea_ += paddedWidth * paddedHeight;
|
||||
|
||||
E2D_LOG_DEBUG("Added texture '{}' to atlas: {}x{} at ({}, {})",
|
||||
name, texWidth, texHeight, node->x, node->y);
|
||||
E2D_LOG_DEBUG("Added texture '{}' to atlas: {}x{} at ({}, {})", name,
|
||||
texWidth, texHeight, node->x, node->y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TextureAtlasPage::PackNode* TextureAtlasPage::insert(PackNode* node, int width, int height) {
|
||||
TextureAtlasPage::PackNode *TextureAtlasPage::insert(PackNode *node, int width,
|
||||
int height) {
|
||||
if (node == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 如果节点已被使用,尝试子节点
|
||||
if (node->used) {
|
||||
PackNode* result = insert(node->left.get(), width, height);
|
||||
PackNode *result = insert(node->left.get(), width, height);
|
||||
if (result != nullptr) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -104,19 +109,24 @@ TextureAtlasPage::PackNode* TextureAtlasPage::insert(PackNode* node, int width,
|
|||
|
||||
if (dw > dh) {
|
||||
// 水平分割
|
||||
node->left = std::make_unique<PackNode>(node->x, node->y, width, node->height);
|
||||
node->right = std::make_unique<PackNode>(node->x + width, node->y, dw, node->height);
|
||||
node->left =
|
||||
std::make_unique<PackNode>(node->x, node->y, width, node->height);
|
||||
node->right =
|
||||
std::make_unique<PackNode>(node->x + width, node->y, dw, node->height);
|
||||
} else {
|
||||
// 垂直分割
|
||||
node->left = std::make_unique<PackNode>(node->x, node->y, node->width, height);
|
||||
node->right = std::make_unique<PackNode>(node->x, node->y + height, node->width, dh);
|
||||
node->left =
|
||||
std::make_unique<PackNode>(node->x, node->y, node->width, height);
|
||||
node->right =
|
||||
std::make_unique<PackNode>(node->x, node->y + height, node->width, dh);
|
||||
}
|
||||
|
||||
// 递归插入到左子节点
|
||||
return insert(node->left.get(), width, height);
|
||||
}
|
||||
|
||||
void TextureAtlasPage::writePixels(int x, int y, int w, int h, const uint8_t* pixels) {
|
||||
void TextureAtlasPage::writePixels(int x, int y, int w, int h,
|
||||
const uint8_t *pixels) {
|
||||
if (texture_ == nullptr || pixels == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -126,11 +136,12 @@ void TextureAtlasPage::writePixels(int x, int y, int w, int h, const uint8_t* pi
|
|||
reinterpret_cast<uintptr_t>(texture_->getNativeHandle()));
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
pixels);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
const AtlasEntry* TextureAtlasPage::getEntry(const std::string& name) const {
|
||||
const AtlasEntry *TextureAtlasPage::getEntry(const std::string &name) const {
|
||||
auto it = entries_.find(name);
|
||||
if (it != entries_.end()) {
|
||||
return &it->second;
|
||||
|
|
@ -147,11 +158,8 @@ float TextureAtlasPage::getUsageRatio() const {
|
|||
// ============================================================================
|
||||
|
||||
TextureAtlas::TextureAtlas()
|
||||
: pageSize_(TextureAtlasPage::DEFAULT_SIZE),
|
||||
sizeThreshold_(256),
|
||||
enabled_(true),
|
||||
initialized_(false) {
|
||||
}
|
||||
: pageSize_(TextureAtlasPage::DEFAULT_SIZE), sizeThreshold_(256),
|
||||
enabled_(true), initialized_(false) {}
|
||||
|
||||
TextureAtlas::~TextureAtlas() = default;
|
||||
|
||||
|
|
@ -161,8 +169,8 @@ void TextureAtlas::init(int pageSize) {
|
|||
E2D_LOG_INFO("TextureAtlas initialized with page size: {}", pageSize);
|
||||
}
|
||||
|
||||
bool TextureAtlas::addTexture(const std::string& name, int width, int height,
|
||||
const uint8_t* pixels) {
|
||||
bool TextureAtlas::addTexture(const std::string &name, int width, int height,
|
||||
const uint8_t *pixels) {
|
||||
if (!enabled_ || !initialized_) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -181,7 +189,7 @@ bool TextureAtlas::addTexture(const std::string& name, int width, int height,
|
|||
|
||||
// 尝试添加到现有页面
|
||||
Rect uvRect;
|
||||
for (auto& page : pages_) {
|
||||
for (auto &page : pages_) {
|
||||
if (page->tryAddTexture(name, width, height, pixels, uvRect)) {
|
||||
entryToPage_[name] = page.get();
|
||||
return true;
|
||||
|
|
@ -200,11 +208,11 @@ bool TextureAtlas::addTexture(const std::string& name, int width, int height,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool TextureAtlas::contains(const std::string& name) const {
|
||||
bool TextureAtlas::contains(const std::string &name) const {
|
||||
return entryToPage_.find(name) != entryToPage_.end();
|
||||
}
|
||||
|
||||
const Texture* TextureAtlas::getAtlasTexture(const std::string& name) const {
|
||||
const Texture *TextureAtlas::getAtlasTexture(const std::string &name) const {
|
||||
auto it = entryToPage_.find(name);
|
||||
if (it != entryToPage_.end()) {
|
||||
return it->second->getTexture().get();
|
||||
|
|
@ -212,10 +220,10 @@ const Texture* TextureAtlas::getAtlasTexture(const std::string& name) const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Rect TextureAtlas::getUVRect(const std::string& name) const {
|
||||
Rect TextureAtlas::getUVRect(const std::string &name) const {
|
||||
auto it = entryToPage_.find(name);
|
||||
if (it != entryToPage_.end()) {
|
||||
const AtlasEntry* entry = it->second->getEntry(name);
|
||||
const AtlasEntry *entry = it->second->getEntry(name);
|
||||
if (entry != nullptr) {
|
||||
return entry->uvRect;
|
||||
}
|
||||
|
|
@ -223,10 +231,10 @@ Rect TextureAtlas::getUVRect(const std::string& name) const {
|
|||
return Rect(0, 0, 1, 1); // 默认 UV
|
||||
}
|
||||
|
||||
Vec2 TextureAtlas::getOriginalSize(const std::string& name) const {
|
||||
Vec2 TextureAtlas::getOriginalSize(const std::string &name) const {
|
||||
auto it = entryToPage_.find(name);
|
||||
if (it != entryToPage_.end()) {
|
||||
const AtlasEntry* entry = it->second->getEntry(name);
|
||||
const AtlasEntry *entry = it->second->getEntry(name);
|
||||
if (entry != nullptr) {
|
||||
return entry->originalSize;
|
||||
}
|
||||
|
|
@ -240,7 +248,7 @@ float TextureAtlas::getTotalUsageRatio() const {
|
|||
}
|
||||
|
||||
float total = 0.0f;
|
||||
for (const auto& page : pages_) {
|
||||
for (const auto &page : pages_) {
|
||||
total += page->getUsageRatio();
|
||||
}
|
||||
return total / pages_.size();
|
||||
|
|
@ -256,7 +264,7 @@ void TextureAtlas::clear() {
|
|||
// TextureAtlasManager 单例实现
|
||||
// ============================================================================
|
||||
|
||||
TextureAtlasManager& TextureAtlasManager::getInstance() {
|
||||
TextureAtlasManager &TextureAtlasManager::getInstance() {
|
||||
static TextureAtlasManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ bool Window::create(const WindowConfig &config) {
|
|||
}
|
||||
|
||||
// 创建输入管理器
|
||||
input_ = makeUnique<Input>();
|
||||
input_ = unique<Input>();
|
||||
input_->init();
|
||||
|
||||
// 初始化光标
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace extra2d {
|
|||
UniquePtr<Renderer> Renderer::create(BackendType type) {
|
||||
switch (type) {
|
||||
case BackendType::OpenGL:
|
||||
return makeUnique<GLRenderer>();
|
||||
return unique<GLRenderer>();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ Ptr<Texture> ResourceManager::loadTextureInternal(const std::string &filepath,
|
|||
|
||||
// 创建新纹理
|
||||
try {
|
||||
auto texture = makePtr<GLTexture>(fullPath);
|
||||
auto texture = shared<GLTexture>(fullPath);
|
||||
if (!texture->isValid()) {
|
||||
E2D_LOG_ERROR("ResourceManager: failed to load texture: {}", filepath);
|
||||
return nullptr;
|
||||
|
|
@ -465,7 +465,7 @@ Ptr<FontAtlas> ResourceManager::loadFont(const std::string &filepath,
|
|||
|
||||
// 创建新字体图集
|
||||
try {
|
||||
auto font = makePtr<GLFontAtlas>(fullPath, fontSize, useSDF);
|
||||
auto font = shared<GLFontAtlas>(fullPath, fontSize, useSDF);
|
||||
if (!font->getTexture() || !font->getTexture()->isValid()) {
|
||||
E2D_LOG_ERROR("ResourceManager: failed to load font: {}", filepath);
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@
|
|||
#include <scene/scene.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
Scene::Scene() { defaultCamera_ = makePtr<Camera>(); }
|
||||
Scene::Scene() { defaultCamera_ = shared<Camera>(); }
|
||||
|
||||
void Scene::setCamera(Ptr<Camera> camera) { camera_ = camera; }
|
||||
|
||||
|
|
@ -56,13 +55,9 @@ void Scene::updateScene(float dt) {
|
|||
}
|
||||
}
|
||||
|
||||
void Scene::onEnter() {
|
||||
Node::onEnter();
|
||||
}
|
||||
void Scene::onEnter() { Node::onEnter(); }
|
||||
|
||||
void Scene::onExit() {
|
||||
Node::onExit();
|
||||
}
|
||||
void Scene::onExit() { Node::onExit(); }
|
||||
|
||||
void Scene::collectRenderCommands(std::vector<RenderCommand> &commands,
|
||||
int parentZOrder) {
|
||||
|
|
@ -73,6 +68,6 @@ void Scene::collectRenderCommands(std::vector<RenderCommand> &commands,
|
|||
Node::collectRenderCommands(commands, parentZOrder);
|
||||
}
|
||||
|
||||
Ptr<Scene> Scene::create() { return makePtr<Scene>(); }
|
||||
Ptr<Scene> Scene::create() { return shared<Scene>(); }
|
||||
|
||||
} // namespace extra2d
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ namespace extra2d {
|
|||
|
||||
ShapeNode::ShapeNode() = default;
|
||||
|
||||
Ptr<ShapeNode> ShapeNode::create() { return makePtr<ShapeNode>(); }
|
||||
Ptr<ShapeNode> ShapeNode::create() { return shared<ShapeNode>(); }
|
||||
|
||||
Ptr<ShapeNode> ShapeNode::createPoint(const Vec2 &pos, const Color &color) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Point;
|
||||
node->color_ = color;
|
||||
node->points_ = {pos};
|
||||
|
|
@ -21,7 +21,7 @@ Ptr<ShapeNode> ShapeNode::createPoint(const Vec2 &pos, const Color &color) {
|
|||
|
||||
Ptr<ShapeNode> ShapeNode::createLine(const Vec2 &start, const Vec2 &end,
|
||||
const Color &color, float width) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Line;
|
||||
node->color_ = color;
|
||||
node->lineWidth_ = width;
|
||||
|
|
@ -31,7 +31,7 @@ Ptr<ShapeNode> ShapeNode::createLine(const Vec2 &start, const Vec2 &end,
|
|||
|
||||
Ptr<ShapeNode> ShapeNode::createRect(const Rect &rect, const Color &color,
|
||||
float width) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Rect;
|
||||
node->color_ = color;
|
||||
node->lineWidth_ = width;
|
||||
|
|
@ -52,7 +52,7 @@ Ptr<ShapeNode> ShapeNode::createFilledRect(const Rect &rect,
|
|||
Ptr<ShapeNode> ShapeNode::createCircle(const Vec2 ¢er, float radius,
|
||||
const Color &color, int segments,
|
||||
float width) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Circle;
|
||||
node->color_ = color;
|
||||
node->lineWidth_ = width;
|
||||
|
|
@ -74,7 +74,7 @@ Ptr<ShapeNode> ShapeNode::createFilledCircle(const Vec2 ¢er, float radius,
|
|||
Ptr<ShapeNode> ShapeNode::createTriangle(const Vec2 &p1, const Vec2 &p2,
|
||||
const Vec2 &p3, const Color &color,
|
||||
float width) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Triangle;
|
||||
node->color_ = color;
|
||||
node->lineWidth_ = width;
|
||||
|
|
@ -93,7 +93,7 @@ Ptr<ShapeNode> ShapeNode::createFilledTriangle(const Vec2 &p1, const Vec2 &p2,
|
|||
|
||||
Ptr<ShapeNode> ShapeNode::createPolygon(const std::vector<Vec2> &points,
|
||||
const Color &color, float width) {
|
||||
auto node = makePtr<ShapeNode>();
|
||||
auto node = shared<ShapeNode>();
|
||||
node->shapeType_ = ShapeType::Polygon;
|
||||
node->color_ = color;
|
||||
node->lineWidth_ = width;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <graphics/texture.h>
|
||||
#include <renderer/render_command.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <graphics/texture.h>
|
||||
#include <scene/sprite.h>
|
||||
|
||||
|
||||
namespace extra2d {
|
||||
|
||||
Sprite::Sprite() = default;
|
||||
|
|
@ -20,9 +19,7 @@ void Sprite::setTexture(Ptr<Texture> texture) {
|
|||
}
|
||||
}
|
||||
|
||||
void Sprite::setTextureRect(const Rect &rect) {
|
||||
textureRect_ = rect;
|
||||
}
|
||||
void Sprite::setTextureRect(const Rect &rect) { textureRect_ = rect; }
|
||||
|
||||
void Sprite::setColor(const Color &color) { color_ = color; }
|
||||
|
||||
|
|
@ -30,14 +27,14 @@ void Sprite::setFlipX(bool flip) { flipX_ = flip; }
|
|||
|
||||
void Sprite::setFlipY(bool flip) { flipY_ = flip; }
|
||||
|
||||
Ptr<Sprite> Sprite::create() { return makePtr<Sprite>(); }
|
||||
Ptr<Sprite> Sprite::create() { return shared<Sprite>(); }
|
||||
|
||||
Ptr<Sprite> Sprite::create(Ptr<Texture> texture) {
|
||||
return makePtr<Sprite>(texture);
|
||||
return shared<Sprite>(texture);
|
||||
}
|
||||
|
||||
Ptr<Sprite> Sprite::create(Ptr<Texture> texture, const Rect &rect) {
|
||||
auto sprite = makePtr<Sprite>(texture);
|
||||
auto sprite = shared<Sprite>(texture);
|
||||
sprite->setTextureRect(rect);
|
||||
return sprite;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ Button::Button(const std::string &text) : Button() { text_ = text; }
|
|||
* @brief 创建空按钮对象
|
||||
* @return 按钮对象指针
|
||||
*/
|
||||
Ptr<Button> Button::create() { return makePtr<Button>(); }
|
||||
Ptr<Button> Button::create() { return shared<Button>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带文本的按钮对象
|
||||
|
|
@ -68,7 +68,7 @@ Ptr<Button> Button::create() { return makePtr<Button>(); }
|
|||
* @return 按钮对象指针
|
||||
*/
|
||||
Ptr<Button> Button::create(const std::string &text) {
|
||||
return makePtr<Button>(text);
|
||||
return shared<Button>(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,7 +78,7 @@ Ptr<Button> Button::create(const std::string &text) {
|
|||
* @return 按钮对象指针
|
||||
*/
|
||||
Ptr<Button> Button::create(const std::string &text, Ptr<FontAtlas> font) {
|
||||
auto btn = makePtr<Button>(text);
|
||||
auto btn = shared<Button>(text);
|
||||
btn->setFont(font);
|
||||
return btn;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ CheckBox::CheckBox() {
|
|||
* @brief 创建复选框对象
|
||||
* @return 复选框对象指针
|
||||
*/
|
||||
Ptr<CheckBox> CheckBox::create() { return makePtr<CheckBox>(); }
|
||||
Ptr<CheckBox> CheckBox::create() { return shared<CheckBox>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带标签的复选框对象
|
||||
|
|
@ -24,7 +24,7 @@ Ptr<CheckBox> CheckBox::create() { return makePtr<CheckBox>(); }
|
|||
* @return 复选框对象指针
|
||||
*/
|
||||
Ptr<CheckBox> CheckBox::create(const std::string &label) {
|
||||
auto cb = makePtr<CheckBox>();
|
||||
auto cb = shared<CheckBox>();
|
||||
cb->setLabel(label);
|
||||
return cb;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Label::Label(const std::string &text) : text_(text) {
|
|||
* @brief 创建空标签对象
|
||||
* @return 标签对象指针
|
||||
*/
|
||||
Ptr<Label> Label::create() { return makePtr<Label>(); }
|
||||
Ptr<Label> Label::create() { return shared<Label>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带文本的标签对象
|
||||
|
|
@ -30,7 +30,7 @@ Ptr<Label> Label::create() { return makePtr<Label>(); }
|
|||
* @return 标签对象指针
|
||||
*/
|
||||
Ptr<Label> Label::create(const std::string &text) {
|
||||
return makePtr<Label>(text);
|
||||
return shared<Label>(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +40,7 @@ Ptr<Label> Label::create(const std::string &text) {
|
|||
* @return 标签对象指针
|
||||
*/
|
||||
Ptr<Label> Label::create(const std::string &text, Ptr<FontAtlas> font) {
|
||||
auto label = makePtr<Label>(text);
|
||||
auto label = shared<Label>(text);
|
||||
label->setFont(font);
|
||||
return label;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ ProgressBar::ProgressBar() {
|
|||
* @brief 创建进度条对象
|
||||
* @return 进度条对象指针
|
||||
*/
|
||||
Ptr<ProgressBar> ProgressBar::create() { return makePtr<ProgressBar>(); }
|
||||
Ptr<ProgressBar> ProgressBar::create() { return shared<ProgressBar>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带范围的进度条对象
|
||||
|
|
@ -27,7 +27,7 @@ Ptr<ProgressBar> ProgressBar::create() { return makePtr<ProgressBar>(); }
|
|||
* @return 进度条对象指针
|
||||
*/
|
||||
Ptr<ProgressBar> ProgressBar::create(float min, float max, float value) {
|
||||
auto bar = makePtr<ProgressBar>();
|
||||
auto bar = shared<ProgressBar>();
|
||||
bar->setRange(min, max);
|
||||
bar->setValue(value);
|
||||
return bar;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ RadioButton::RadioButton() {
|
|||
* @brief 创建单选按钮对象
|
||||
* @return 单选按钮对象指针
|
||||
*/
|
||||
Ptr<RadioButton> RadioButton::create() { return makePtr<RadioButton>(); }
|
||||
Ptr<RadioButton> RadioButton::create() { return shared<RadioButton>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带标签的单选按钮对象
|
||||
|
|
@ -24,7 +24,7 @@ Ptr<RadioButton> RadioButton::create() { return makePtr<RadioButton>(); }
|
|||
* @return 单选按钮对象指针
|
||||
*/
|
||||
Ptr<RadioButton> RadioButton::create(const std::string &label) {
|
||||
auto rb = makePtr<RadioButton>();
|
||||
auto rb = shared<RadioButton>();
|
||||
rb->setLabel(label);
|
||||
return rb;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Slider::Slider() {
|
|||
* @brief 创建滑动条对象
|
||||
* @return 滑动条对象指针
|
||||
*/
|
||||
Ptr<Slider> Slider::create() { return makePtr<Slider>(); }
|
||||
Ptr<Slider> Slider::create() { return shared<Slider>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带范围的滑动条对象
|
||||
|
|
@ -27,7 +27,7 @@ Ptr<Slider> Slider::create() { return makePtr<Slider>(); }
|
|||
* @return 滑动条对象指针
|
||||
*/
|
||||
Ptr<Slider> Slider::create(float min, float max, float value) {
|
||||
auto slider = makePtr<Slider>();
|
||||
auto slider = shared<Slider>();
|
||||
slider->setRange(min, max);
|
||||
slider->setValue(value);
|
||||
return slider;
|
||||
|
|
|
|||
|
|
@ -57,9 +57,7 @@ void Text::setFontSize(int size) {
|
|||
* @brief 设置水平对齐方式
|
||||
* @param align 对齐方式
|
||||
*/
|
||||
void Text::setAlignment(Alignment align) {
|
||||
alignment_ = align;
|
||||
}
|
||||
void Text::setAlignment(Alignment align) { alignment_ = align; }
|
||||
|
||||
/**
|
||||
* @brief 设置垂直对齐方式
|
||||
|
|
@ -152,14 +150,14 @@ Vec2 Text::calculateDrawPosition() const {
|
|||
* @brief 创建空文本对象
|
||||
* @return 文本对象指针
|
||||
*/
|
||||
Ptr<Text> Text::create() { return makePtr<Text>(); }
|
||||
Ptr<Text> Text::create() { return shared<Text>(); }
|
||||
|
||||
/**
|
||||
* @brief 创建带文本的对象
|
||||
* @param text 文本内容
|
||||
* @return 文本对象指针
|
||||
*/
|
||||
Ptr<Text> Text::create(const std::string &text) { return makePtr<Text>(text); }
|
||||
Ptr<Text> Text::create(const std::string &text) { return shared<Text>(text); }
|
||||
|
||||
/**
|
||||
* @brief 创建带文本和字体的对象
|
||||
|
|
@ -168,7 +166,7 @@ Ptr<Text> Text::create(const std::string &text) { return makePtr<Text>(text); }
|
|||
* @return 文本对象指针
|
||||
*/
|
||||
Ptr<Text> Text::create(const std::string &text, Ptr<FontAtlas> font) {
|
||||
auto t = makePtr<Text>(text);
|
||||
auto t = shared<Text>(text);
|
||||
t->setFont(font);
|
||||
return t;
|
||||
}
|
||||
|
|
@ -185,7 +183,7 @@ Ptr<Text> Text::createFormat(const char *fmt, ...) {
|
|||
char buffer[256];
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
va_end(args);
|
||||
return makePtr<Text>(buffer);
|
||||
return shared<Text>(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -201,7 +199,7 @@ Ptr<Text> Text::createFormat(Ptr<FontAtlas> font, const char *fmt, ...) {
|
|||
char buffer[256];
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
va_end(args);
|
||||
auto t = makePtr<Text>(buffer);
|
||||
auto t = shared<Text>(buffer);
|
||||
t->setFont(font);
|
||||
return t;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <simpleini/SimpleIni.h>
|
||||
#include <utils/data.h>
|
||||
#include <utils/logger.h>
|
||||
#include <simpleini/SimpleIni.h>
|
||||
|
||||
|
||||
// Switch 平台特定头文件
|
||||
#ifdef __SWITCH__
|
||||
|
|
@ -15,7 +16,7 @@ public:
|
|||
CSimpleIniA ini;
|
||||
};
|
||||
|
||||
DataStore::DataStore() : impl_(makeUnique<Impl>()) {}
|
||||
DataStore::DataStore() : impl_(unique<Impl>()) {}
|
||||
|
||||
DataStore::~DataStore() {
|
||||
// 如果在事务中,尝试提交
|
||||
|
|
@ -203,9 +204,7 @@ std::string DataStore::getSaveDataPath(const std::string &path) const {
|
|||
return path;
|
||||
}
|
||||
|
||||
UserId DataStore::getCurrentUserId() {
|
||||
return UserId();
|
||||
}
|
||||
UserId DataStore::getCurrentUserId() { return UserId(); }
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -402,7 +401,8 @@ std::vector<std::string> DataStore::getAllSections() const {
|
|||
return sections;
|
||||
}
|
||||
|
||||
std::vector<std::string> DataStore::getAllKeys(const std::string §ion) const {
|
||||
std::vector<std::string>
|
||||
DataStore::getAllKeys(const std::string §ion) const {
|
||||
std::vector<std::string> keys;
|
||||
CSimpleIniA::TNamesDepend keyList;
|
||||
impl_->ini.GetAllKeys(section.c_str(), keyList);
|
||||
|
|
|
|||
Loading…
Reference in New Issue