Refactor
This commit is contained in:
parent
82c772bfdb
commit
c6d2266026
@ -1,17 +1 @@
|
||||
#include "ContentPack.h"
|
||||
|
||||
using std::string;
|
||||
using std::filesystem::path;
|
||||
|
||||
ContentPack::ContentPack(const string id,
|
||||
const path folder)
|
||||
: id(id), folder(folder) {
|
||||
|
||||
}
|
||||
const string& ContentPack::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
const path& ContentPack::getFolder() const {
|
||||
return folder;
|
||||
}
|
||||
|
||||
@ -4,15 +4,9 @@
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
class ContentPack {
|
||||
const std::string id;
|
||||
const std::filesystem::path folder;
|
||||
public:
|
||||
ContentPack(const std::string id,
|
||||
const std::filesystem::path folder);
|
||||
|
||||
const std::string& getId() const;
|
||||
const std::filesystem::path& getFolder() const;
|
||||
struct ContentPack {
|
||||
std::string id;
|
||||
std::filesystem::path folder;
|
||||
};
|
||||
|
||||
#endif // CONTENT_CONTENT_PACK_H_
|
||||
|
||||
@ -29,9 +29,13 @@
|
||||
#include "files/files.h"
|
||||
#include "files/engine_paths.h"
|
||||
|
||||
#include "content/Content.h"
|
||||
#include "content/ContentPack.h"
|
||||
#include "content/ContentLoader.h"
|
||||
#include "frontend/locale/langs.h"
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::shared_ptr;
|
||||
using std::string;
|
||||
@ -40,12 +44,24 @@ using std::filesystem::path;
|
||||
using glm::vec3;
|
||||
using gui::GUI;
|
||||
|
||||
Engine::Engine(EngineSettings& settings, EnginePaths* paths, Content* content)
|
||||
: settings(settings), content(content), paths(paths) {
|
||||
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
||||
: settings(settings), paths(paths) {
|
||||
if (Window::initialize(settings.display)){
|
||||
throw initialize_error("could not initialize window");
|
||||
}
|
||||
Shader::preprocessor->setLibFolder(paths->getResources()/path("shaders/lib"));
|
||||
|
||||
auto resdir = paths->getResources();
|
||||
contentPacks.push_back({"base", resdir/path("content/base")});
|
||||
{
|
||||
ContentBuilder contentBuilder;
|
||||
setup_definitions(&contentBuilder);
|
||||
for (auto& pack : contentPacks) {
|
||||
ContentLoader loader(pack.folder);
|
||||
loader.load(&contentBuilder);
|
||||
}
|
||||
content.reset(contentBuilder.build());
|
||||
}
|
||||
Shader::preprocessor->setLibFolder(paths->getResources()/path("shaders/lib"));
|
||||
|
||||
assets = new Assets();
|
||||
std::cout << "-- loading assets" << std::endl;
|
||||
@ -61,10 +77,6 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths, Content* content)
|
||||
}
|
||||
Audio::initialize();
|
||||
gui = new GUI();
|
||||
|
||||
auto resdir = paths->getResources();
|
||||
contentPacks.push_back(ContentPack("base", resdir/path("content/base")));
|
||||
|
||||
if (settings.ui.language == "auto") {
|
||||
settings.ui.language = platform::detect_locale();
|
||||
}
|
||||
@ -145,7 +157,7 @@ void Engine::setScreen(shared_ptr<Screen> screen) {
|
||||
}
|
||||
|
||||
const Content* Engine::getContent() const {
|
||||
return content;
|
||||
return content.get();
|
||||
}
|
||||
|
||||
vector<ContentPack>& Engine::getContentPacks() {
|
||||
|
||||
@ -8,12 +8,12 @@
|
||||
#include "typedefs.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "content/Content.h"
|
||||
#include "content/ContentPack.h"
|
||||
|
||||
class Assets;
|
||||
class Level;
|
||||
class Screen;
|
||||
class Content;
|
||||
class EnginePaths;
|
||||
|
||||
namespace gui {
|
||||
@ -30,7 +30,7 @@ class Engine {
|
||||
std::shared_ptr<Screen> screen = nullptr;
|
||||
std::vector<ContentPack> contentPacks;
|
||||
EngineSettings& settings;
|
||||
Content* content;
|
||||
std::unique_ptr<Content> content = nullptr;
|
||||
EnginePaths* paths;
|
||||
|
||||
uint64_t frame = 0;
|
||||
@ -39,7 +39,7 @@ class Engine {
|
||||
|
||||
gui::GUI* gui;
|
||||
public:
|
||||
Engine(EngineSettings& settings, EnginePaths* paths, Content* content);
|
||||
Engine(EngineSettings& settings, EnginePaths* paths);
|
||||
~Engine();
|
||||
|
||||
void updateTimers();
|
||||
|
||||
@ -105,11 +105,11 @@ void langs::load(const path& resdir,
|
||||
reader.read(lang, "");
|
||||
}
|
||||
for (auto pack : packs) {
|
||||
path file = pack.getFolder()/filename;
|
||||
path file = pack.folder/filename;
|
||||
if (fs::is_regular_file(file)) {
|
||||
string text = files::read_string(file);
|
||||
Reader reader(file.string(), text);
|
||||
reader.read(lang, pack.getId()+":");
|
||||
reader.read(lang, pack.id+":");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,13 +12,6 @@
|
||||
#include "files/files.h"
|
||||
#include "files/settings_io.h"
|
||||
#include "files/engine_paths.h"
|
||||
#include "content/Content.h"
|
||||
#include "content/ContentLoader.h"
|
||||
|
||||
#include "coders/png.h"
|
||||
#include "graphics/Atlas.h"
|
||||
#include "graphics/ImageData.h"
|
||||
|
||||
#include "util/command_line.h"
|
||||
|
||||
using std::filesystem::path;
|
||||
@ -29,13 +22,6 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
platform::configure_encoding();
|
||||
ContentBuilder contentBuilder;
|
||||
setup_definitions(&contentBuilder);
|
||||
// TODO: implement worlds indexing
|
||||
ContentLoader loader(paths.getResources()/path("content/base"));
|
||||
loader.load(&contentBuilder);
|
||||
|
||||
std::unique_ptr<Content> content(contentBuilder.build());
|
||||
try {
|
||||
EngineSettings settings;
|
||||
toml::Wrapper wrapper = create_wrapper(settings);
|
||||
@ -44,16 +30,16 @@ int main(int argc, char** argv) {
|
||||
path controls_file = platform::get_controls_file();
|
||||
if (std::filesystem::is_regular_file(settings_file)) {
|
||||
std::cout << "-- loading settings" << std::endl;
|
||||
std::string content = files::read_string(settings_file);
|
||||
toml::Reader reader(&wrapper, settings_file.string(), content);
|
||||
std::string text = files::read_string(settings_file);
|
||||
toml::Reader reader(&wrapper, settings_file.string(), text);
|
||||
reader.read();
|
||||
}
|
||||
Engine engine(settings, &paths, content.get());
|
||||
Engine engine(settings, &paths);
|
||||
setup_bindings();
|
||||
if (std::filesystem::is_regular_file(controls_file)) {
|
||||
std::cout << "-- loading controls" << std::endl;
|
||||
std::string content = files::read_string(controls_file);
|
||||
load_controls(controls_file.string(), content);
|
||||
std::string text = files::read_string(controls_file);
|
||||
load_controls(controls_file.string(), text);
|
||||
}
|
||||
engine.mainloop();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user