Extra2D/examples/hello_module/hello_module.h

68 lines
1.3 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 <extra2d/core/module.h>
#include <string>
#include <functional>
namespace extra2d {
/**
* @brief Hello模块配置结构
*/
struct HelloCfg {
std::string greeting;
int repeatCount;
int priority;
HelloCfg()
: greeting("Hello, Extra2D!")
, repeatCount(1)
, priority(100) {}
};
/**
* @brief Hello模块示例
* 展示如何创建自定义模块
*/
class HelloModule : public Module {
public:
/**
* @brief 配置类型别名(向后兼容)
*/
using Cfg = HelloCfg;
/**
* @brief 构造函数
* @param cfg 配置
*/
explicit HelloModule(const HelloCfg& cfg = HelloCfg{});
/**
* @brief 构造函数Lambda 配置)
* @param configFn 配置函数
*/
explicit HelloModule(std::function<void(HelloCfg&)> configFn);
/**
* @brief 析构函数
*/
~HelloModule() override;
bool init() override;
void shutdown() override;
bool ok() const override { return initialized_; }
const char* name() const override { return "hello"; }
int priority() const override { return cfg_.priority; }
/**
* @brief 执行问候操作
*/
void sayHello() const;
private:
HelloCfg cfg_;
bool initialized_ = false;
};
} // namespace extra2d