minor refactor & fixes
This commit is contained in:
@@ -13,6 +13,11 @@
|
|||||||
|
|
||||||
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
||||||
: assets(assets), paths(paths) {
|
: assets(assets), paths(paths) {
|
||||||
|
addLoader(ASSET_SHADER, assetload::shader);
|
||||||
|
addLoader(ASSET_TEXTURE, assetload::texture);
|
||||||
|
addLoader(ASSET_FONT, assetload::font);
|
||||||
|
addLoader(ASSET_ATLAS, assetload::atlas);
|
||||||
|
addLoader(ASSET_LAYOUT, assetload::layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addLoader(int tag, aloader_func func) {
|
void AssetsLoader::addLoader(int tag, aloader_func func) {
|
||||||
@@ -42,14 +47,6 @@ bool AssetsLoader::loadNext() {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::createDefaults(AssetsLoader& loader) {
|
|
||||||
loader.addLoader(ASSET_SHADER, assetload::shader);
|
|
||||||
loader.addLoader(ASSET_TEXTURE, assetload::texture);
|
|
||||||
loader.addLoader(ASSET_FONT, assetload::font);
|
|
||||||
loader.addLoader(ASSET_ATLAS, assetload::atlas);
|
|
||||||
loader.addLoader(ASSET_LAYOUT, assetload::layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addLayouts(int env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
void addLayouts(int env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
||||||
if (!fs::is_directory(folder)) {
|
if (!fs::is_directory(folder)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public:
|
|||||||
bool hasNext() const;
|
bool hasNext() const;
|
||||||
bool loadNext();
|
bool loadNext();
|
||||||
|
|
||||||
static void createDefaults(AssetsLoader& loader);
|
|
||||||
static void addDefaults(AssetsLoader& loader, const Content* content);
|
static void addDefaults(AssetsLoader& loader, const Content* content);
|
||||||
|
|
||||||
const ResPaths* getPaths() const;
|
const ResPaths* getPaths() const;
|
||||||
|
|||||||
+12
-12
@@ -42,7 +42,8 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
||||||
: settings(settings), paths(paths) {
|
: settings(settings), paths(paths)
|
||||||
|
{
|
||||||
if (Window::initialize(settings.display)){
|
if (Window::initialize(settings.display)){
|
||||||
throw initialize_error("could not initialize window");
|
throw initialize_error("could not initialize window");
|
||||||
}
|
}
|
||||||
@@ -52,18 +53,21 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
|||||||
|
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
std::vector<fs::path> roots {resdir};
|
std::vector<fs::path> roots {resdir};
|
||||||
resPaths.reset(new ResPaths(resdir, roots));
|
|
||||||
assets.reset(new Assets());
|
resPaths = std::make_unique<ResPaths>(resdir, roots);
|
||||||
|
assets = std::make_unique<Assets>();
|
||||||
|
|
||||||
|
|
||||||
AssetsLoader loader(assets.get(), resPaths.get());
|
AssetsLoader loader(assets.get(), resPaths.get());
|
||||||
AssetsLoader::createDefaults(loader);
|
|
||||||
AssetsLoader::addDefaults(loader, nullptr);
|
AssetsLoader::addDefaults(loader, nullptr);
|
||||||
|
|
||||||
Shader::preprocessor->setPaths(resPaths.get());
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
while (loader.hasNext()) {
|
while (loader.hasNext()) {
|
||||||
if (!loader.loadNext()) {
|
if (!loader.loadNext()) {
|
||||||
assets.reset();
|
assets.reset();
|
||||||
|
scripting::close();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
throw initialize_error("could not to initialize assets");
|
throw initialize_error("could not to load assets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +77,6 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
|||||||
settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources());
|
settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources());
|
||||||
}
|
}
|
||||||
setLanguage(settings.ui.language);
|
setLanguage(settings.ui.language);
|
||||||
std::cout << "-- initializing finished" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::updateTimers() {
|
void Engine::updateTimers() {
|
||||||
@@ -99,11 +102,10 @@ void Engine::updateHotkeys() {
|
|||||||
void Engine::mainloop() {
|
void Engine::mainloop() {
|
||||||
setScreen(std::make_shared<MenuScreen>(this));
|
setScreen(std::make_shared<MenuScreen>(this));
|
||||||
|
|
||||||
std::cout << "-- preparing systems" << std::endl;
|
|
||||||
|
|
||||||
Batch2D batch(1024);
|
Batch2D batch(1024);
|
||||||
lastTime = Window::time();
|
lastTime = Window::time();
|
||||||
|
|
||||||
|
std::cout << "-- initialized" << std::endl;
|
||||||
while (!Window::isShouldClose()){
|
while (!Window::isShouldClose()){
|
||||||
assert(screen != nullptr);
|
assert(screen != nullptr);
|
||||||
updateTimers();
|
updateTimers();
|
||||||
@@ -129,12 +131,11 @@ void Engine::mainloop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Engine::~Engine() {
|
Engine::~Engine() {
|
||||||
screen = nullptr;
|
std::cout << "-- shutting down" << std::endl;
|
||||||
|
screen.reset();
|
||||||
content.reset();
|
content.reset();
|
||||||
|
|
||||||
Audio::finalize();
|
Audio::finalize();
|
||||||
|
|
||||||
std::cout << "-- shutting down" << std::endl;
|
|
||||||
assets.reset();
|
assets.reset();
|
||||||
scripting::close();
|
scripting::close();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
@@ -184,7 +185,6 @@ void Engine::loadContent() {
|
|||||||
std::unique_ptr<Assets> new_assets(new Assets());
|
std::unique_ptr<Assets> new_assets(new Assets());
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||||
AssetsLoader::createDefaults(loader);
|
|
||||||
AssetsLoader::addDefaults(loader, content.get());
|
AssetsLoader::addDefaults(loader, content.get());
|
||||||
while (loader.hasNext()) {
|
while (loader.hasNext()) {
|
||||||
if (!loader.loadNext()) {
|
if (!loader.loadNext()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user