变更初始
This commit is contained in:
66
Fostbite2D/src/fostbite2D/core/application.cpp
Normal file
66
Fostbite2D/src/fostbite2D/core/application.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <fostbite2D/core/application.h>
|
||||
namespace frostbite2D {
|
||||
|
||||
Application &Application::get() {
|
||||
static Application instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Application::use(Module &m) {
|
||||
for (auto *existing : modules_) {
|
||||
if (existing == &m) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
modules_.push_back(&m);
|
||||
}
|
||||
|
||||
void Application::use(std::initializer_list<Module *> modules) {
|
||||
for (auto *m : modules) {
|
||||
if (m) {
|
||||
use(*m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::init() {
|
||||
AppConfig cfg;
|
||||
return init(cfg);
|
||||
}
|
||||
|
||||
bool Application::init(const AppConfig &config) {
|
||||
if (initialized_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this->window_ = new Window();
|
||||
|
||||
if (!window_->create(config.windowConfig)) {
|
||||
SDL_Log("Failed to create window");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::shutdown() {
|
||||
if (!initialized_)
|
||||
return;
|
||||
|
||||
// VRAMMgr::get().printStats();
|
||||
|
||||
// ServiceLocator::instance().clear();
|
||||
|
||||
// window_ = nullptr;
|
||||
|
||||
initialized_ = false;
|
||||
running_ = false;
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
if (initialized_) {
|
||||
shutdown();
|
||||
}
|
||||
}
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user