Extra2D/examples/hello_module/hello_module.cpp

83 lines
1.5 KiB
C++
Raw Normal View History

#include "hello_module.h"
#include <extra2d/core/module_macros.h>
#include <extra2d/utils/logger.h>
namespace extra2d {
HelloModule::HelloModule()
: Module()
, config_()
, time_(0.0f) {
}
HelloModule::~HelloModule() {
if (isInitialized()) {
destroyModule();
}
}
void HelloModule::setupModule() {
if (isInitialized()) {
return;
}
if (config_.greeting.empty()) {
config_.greeting = "Hello, Extra2D!";
}
if (config_.repeatCount <= 0) {
config_.repeatCount = 1;
}
setInitialized(true);
E2D_LOG_INFO("HelloModule initialized");
E2D_LOG_INFO(" Greeting: {}", config_.greeting);
E2D_LOG_INFO(" Repeat Count: {}", config_.repeatCount);
E2D_LOG_INFO(" Logging Enabled: {}", config_.enableLogging);
sayHello();
}
void HelloModule::destroyModule() {
if (!isInitialized()) {
return;
}
if (config_.enableLogging) {
E2D_LOG_INFO("HelloModule shutdown - Goodbye!");
}
setInitialized(false);
}
void HelloModule::onUpdate(UpdateContext& ctx) {
if (!isInitialized()) {
ctx.next();
return;
}
time_ += ctx.getDeltaTime();
if (time_ >= 5.0f) {
sayHello();
time_ = 0.0f;
}
ctx.next();
}
void HelloModule::sayHello() const {
if (!config_.enableLogging) {
return;
}
for (int i = 0; i < config_.repeatCount; ++i) {
E2D_LOG_INFO("[HelloModule] {}", config_.greeting);
}
}
} // namespace extra2d
E2D_MODULE(HelloModule, 1000)