Extra2D/include/module/imodule.h

70 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <types/base/types.h>
namespace extra2d {
/**
* @brief 模块类型枚举
*/
enum class ModuleType : uint8 {
Core, // 核心模块(必须)
System, // 系统模块(平台相关)
Feature, // 功能模块
Extension // 扩展模块
};
/**
* @brief 模块接口 - 基于事件总线
*
* 模块不再通过虚函数被调用,而是通过监听事件响应
* 模块可以发送事件,但不应直接调用其他模块
*
* 设计理念:
* - 模块是引擎的内置组件,在编译时确定
* - 模块之间通过事件总线通信,零直接依赖
* - 模块的生命周期由 ModuleRegistry 管理
*/
class IModule {
public:
virtual ~IModule() = default;
/**
* @brief 获取模块名称
* @return 模块唯一标识名
*/
virtual const char* name() const = 0;
/**
* @brief 获取模块类型
* @return 模块类型,用于分类和优先级管理
*/
virtual ModuleType type() const { return ModuleType::Feature; }
/**
* @brief 获取模块优先级
* @return 优先级数值,越小优先级越高
*/
virtual int priority() const { return 0; }
/**
* @brief 初始化模块
*
* 在此注册事件监听器
* 返回 false 表示初始化失败,引擎将停止
*
* @return 初始化是否成功
*/
virtual bool init() { return true; }
/**
* @brief 关闭模块
*
* 在此执行清理工作
* 事件监听器会自动注销RAII
*/
virtual void shutdown() {}
};
} // namespace extra2d