Extra2D/examples/hello_module/hello_module.h

66 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include <extra2d/extra2d.h>
#include <functional>
#include <string>
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