refactor: 移除未使用的类型定义并简化监听器链表操作

- 删除 EventTrait 和 TupleExtractor 中未使用的 FuncType 类型别名
- 删除 AssetsModule 中未使用的缓存、默认资源、互斥锁及相关数据结构
- 提取监听器链表追加操作为独立函数以消除重复代码
This commit is contained in:
ChestnutYueyue 2026-03-16 17:57:13 +08:00
parent b672b16b83
commit 690854698f
3 changed files with 18 additions and 68 deletions

View File

@ -4,20 +4,16 @@
#include <assets/core/asset_system.h>
#include <assets/asset_loader.h>
#include <assets/handle.h>
#include <atomic>
#include <event/events.h>
#include <functional>
#include <memory>
#include <module/module.h>
#include <module/module_registry.h>
#include <mutex>
#include <renderer/material.h>
#include <renderer/mesh.h>
#include <renderer/shader.h>
#include <renderer/texture.h>
#include <shared_mutex>
#include <string>
#include <unordered_map>
#include <vector>
namespace extra2d {
@ -261,19 +257,6 @@ private:
std::unique_ptr<AssetLoader<Texture>> textureLoader_;
std::unique_ptr<AssetLoader<Shader>> shaderLoader_;
// 路径缓存(避免重复加载)
std::unordered_map<std::string, Handle<Texture>> texturePathCache_;
std::unordered_map<std::string, Handle<Shader>> shaderPathCache_;
// 默认资源
Handle<Texture> defaultTexture_;
Handle<Shader> defaultShader_;
Handle<Material> defaultMaterial_;
Handle<Mesh> defaultQuad_;
// 线程安全
mutable std::shared_mutex mutex_;
// 事件监听器
std::unique_ptr<events::OnShow::Listener> onShowListener_;
@ -286,12 +269,9 @@ private:
public:
struct LoadTask {
enum class Type { Texture, Shader };
enum class Priority { Low = 0, Normal = 1, High = 2 };
Type type;
Priority priority;
std::string path;
std::string secondaryPath; // 用于着色器的片段着色器路径
std::function<void(Handle<Texture>)> textureCallback;
std::function<void(Handle<Shader>)> shaderCallback;
};
@ -321,15 +301,6 @@ public:
// 资源依赖跟踪
//===========================================================================
public:
/**
* @brief
*/
struct DependencyInfo {
Handle<Texture> texture;
Handle<Shader> shader;
std::vector<Handle<Material>> dependentMaterials;
};
/**
* @brief
*/

View File

@ -79,13 +79,11 @@ struct EventTrait {
*/
template<typename T>
struct TupleExtractor {
using FuncType = void();
using StdFuncType = std::function<void()>;
};
template<typename... Args>
struct TupleExtractor<std::tuple<Args...>> {
using FuncType = void(Args...);
using StdFuncType = std::function<void(Args...)>;
};
@ -120,9 +118,6 @@ public:
}
}
const char* busName() const { return EHandler::BUS_NAME; }
const char* eventName() const { return EHandler::NAME; }
private:
bool enabled_ = true;
StdFuncType callback_;

View File

@ -2,6 +2,21 @@
namespace extra2d::event {
static void appendListenerEntry(ListenerEntry *&head, ListenerEntry *entry) {
entry->next = nullptr;
entry->prev = nullptr;
if (!head) {
head = entry;
return;
}
ListenerEntry *tail = head;
while (tail->next) {
tail = tail->next;
}
tail->next = entry;
entry->prev = tail;
}
ListenerContainer::~ListenerContainer() {
ListenerEntry *curr = listenerList_;
while (curr) {
@ -27,34 +42,9 @@ void ListenerContainer::addListener(ListenerBase *listener) {
return;
if (broadcasting_ > 0) {
// 广播期间,添加到待添加列表(保持顺序,使用尾插)
listener->entry_->next = nullptr;
if (!listenersToAdd_) {
listenersToAdd_ = listener->entry_;
} else {
// 找到尾部
ListenerEntry* tail = listenersToAdd_;
while (tail->next) {
tail = tail->next;
}
tail->next = listener->entry_;
}
appendListenerEntry(listenersToAdd_, listener->entry_);
} else {
// 非广播期间,添加到主列表尾部(保持顺序)
listener->entry_->next = nullptr;
listener->entry_->prev = nullptr;
if (!listenerList_) {
listenerList_ = listener->entry_;
} else {
// 找到尾部
ListenerEntry* tail = listenerList_;
while (tail->next) {
tail = tail->next;
}
tail->next = listener->entry_;
listener->entry_->prev = tail;
}
appendListenerEntry(listenerList_, listener->entry_);
}
}
@ -85,13 +75,7 @@ void ListenerContainer::processPendingListeners() {
while (listenersToAdd_) {
ListenerEntry *entry = listenersToAdd_;
listenersToAdd_ = entry->next;
entry->next = listenerList_;
entry->prev = nullptr;
if (listenerList_) {
listenerList_->prev = entry;
}
listenerList_ = entry;
appendListenerEntry(listenerList_, entry);
}
for (auto *entry : listenersToRemove_) {