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