refactor: 移除未使用的类型定义并简化监听器链表操作
- 删除 EventTrait 和 TupleExtractor 中未使用的 FuncType 类型别名 - 删除 AssetsModule 中未使用的缓存、默认资源、互斥锁及相关数据结构 - 提取监听器链表追加操作为独立函数以消除重复代码
This commit is contained in:
parent
b672b16b83
commit
690854698f
|
|
@ -4,20 +4,16 @@
|
||||||
#include <assets/core/asset_system.h>
|
#include <assets/core/asset_system.h>
|
||||||
#include <assets/asset_loader.h>
|
#include <assets/asset_loader.h>
|
||||||
#include <assets/handle.h>
|
#include <assets/handle.h>
|
||||||
#include <atomic>
|
|
||||||
#include <event/events.h>
|
#include <event/events.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <module/module.h>
|
#include <module/module.h>
|
||||||
#include <module/module_registry.h>
|
#include <module/module_registry.h>
|
||||||
#include <mutex>
|
|
||||||
#include <renderer/material.h>
|
#include <renderer/material.h>
|
||||||
#include <renderer/mesh.h>
|
#include <renderer/mesh.h>
|
||||||
#include <renderer/shader.h>
|
#include <renderer/shader.h>
|
||||||
#include <renderer/texture.h>
|
#include <renderer/texture.h>
|
||||||
#include <shared_mutex>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace extra2d {
|
namespace extra2d {
|
||||||
|
|
@ -261,19 +257,6 @@ private:
|
||||||
std::unique_ptr<AssetLoader<Texture>> textureLoader_;
|
std::unique_ptr<AssetLoader<Texture>> textureLoader_;
|
||||||
std::unique_ptr<AssetLoader<Shader>> shaderLoader_;
|
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_;
|
std::unique_ptr<events::OnShow::Listener> onShowListener_;
|
||||||
|
|
||||||
|
|
@ -286,12 +269,9 @@ private:
|
||||||
public:
|
public:
|
||||||
struct LoadTask {
|
struct LoadTask {
|
||||||
enum class Type { Texture, Shader };
|
enum class Type { Texture, Shader };
|
||||||
enum class Priority { Low = 0, Normal = 1, High = 2 };
|
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
Priority priority;
|
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string secondaryPath; // 用于着色器的片段着色器路径
|
|
||||||
std::function<void(Handle<Texture>)> textureCallback;
|
std::function<void(Handle<Texture>)> textureCallback;
|
||||||
std::function<void(Handle<Shader>)> shaderCallback;
|
std::function<void(Handle<Shader>)> shaderCallback;
|
||||||
};
|
};
|
||||||
|
|
@ -321,15 +301,6 @@ public:
|
||||||
// 资源依赖跟踪
|
// 资源依赖跟踪
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief 资源依赖关系
|
|
||||||
*/
|
|
||||||
struct DependencyInfo {
|
|
||||||
Handle<Texture> texture;
|
|
||||||
Handle<Shader> shader;
|
|
||||||
std::vector<Handle<Material>> dependentMaterials;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 注册材质对纹理的依赖
|
* @brief 注册材质对纹理的依赖
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -79,13 +79,11 @@ struct EventTrait {
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct TupleExtractor {
|
struct TupleExtractor {
|
||||||
using FuncType = void();
|
|
||||||
using StdFuncType = std::function<void()>;
|
using StdFuncType = std::function<void()>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
struct TupleExtractor<std::tuple<Args...>> {
|
struct TupleExtractor<std::tuple<Args...>> {
|
||||||
using FuncType = void(Args...);
|
|
||||||
using StdFuncType = std::function<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:
|
private:
|
||||||
bool enabled_ = true;
|
bool enabled_ = true;
|
||||||
StdFuncType callback_;
|
StdFuncType callback_;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,21 @@
|
||||||
|
|
||||||
namespace extra2d::event {
|
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() {
|
ListenerContainer::~ListenerContainer() {
|
||||||
ListenerEntry *curr = listenerList_;
|
ListenerEntry *curr = listenerList_;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
|
|
@ -27,34 +42,9 @@ void ListenerContainer::addListener(ListenerBase *listener) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (broadcasting_ > 0) {
|
if (broadcasting_ > 0) {
|
||||||
// 广播期间,添加到待添加列表(保持顺序,使用尾插)
|
appendListenerEntry(listenersToAdd_, listener->entry_);
|
||||||
listener->entry_->next = nullptr;
|
|
||||||
if (!listenersToAdd_) {
|
|
||||||
listenersToAdd_ = listener->entry_;
|
|
||||||
} else {
|
|
||||||
// 找到尾部
|
|
||||||
ListenerEntry* tail = listenersToAdd_;
|
|
||||||
while (tail->next) {
|
|
||||||
tail = tail->next;
|
|
||||||
}
|
|
||||||
tail->next = listener->entry_;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 非广播期间,添加到主列表尾部(保持顺序)
|
appendListenerEntry(listenerList_, listener->entry_);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,13 +75,7 @@ void ListenerContainer::processPendingListeners() {
|
||||||
while (listenersToAdd_) {
|
while (listenersToAdd_) {
|
||||||
ListenerEntry *entry = listenersToAdd_;
|
ListenerEntry *entry = listenersToAdd_;
|
||||||
listenersToAdd_ = entry->next;
|
listenersToAdd_ = entry->next;
|
||||||
|
appendListenerEntry(listenerList_, entry);
|
||||||
entry->next = listenerList_;
|
|
||||||
entry->prev = nullptr;
|
|
||||||
if (listenerList_) {
|
|
||||||
listenerList_->prev = entry;
|
|
||||||
}
|
|
||||||
listenerList_ = entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto *entry : listenersToRemove_) {
|
for (auto *entry : listenersToRemove_) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue