57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#include <iostream>
|
|
#include <cmath>
|
|
#include <stdint.h>
|
|
#include <memory>
|
|
#include <filesystem>
|
|
#include <stdexcept>
|
|
|
|
#include "definitions.h"
|
|
#include "engine.h"
|
|
#include "util/platform.h"
|
|
#include "coders/toml.h"
|
|
#include "files/files.h"
|
|
#include "files/settings_io.h"
|
|
#include "files/engine_paths.h"
|
|
#include "util/command_line.h"
|
|
|
|
using std::filesystem::path;
|
|
|
|
int main(int argc, char** argv) {
|
|
EnginePaths paths;
|
|
if (!parse_cmdline(argc, argv, paths))
|
|
return EXIT_SUCCESS;
|
|
|
|
platform::configure_encoding();
|
|
std::filesystem::path userfiles = paths.getUserfiles();
|
|
try {
|
|
EngineSettings settings;
|
|
std::unique_ptr<toml::Wrapper> wrapper (create_wrapper(settings));
|
|
|
|
path settings_file = userfiles/platform::get_settings_file();
|
|
path controls_file = userfiles/platform::get_controls_file();
|
|
if (std::filesystem::is_regular_file(settings_file)) {
|
|
std::cout << "-- loading settings" << std::endl;
|
|
std::string text = files::read_string(settings_file);
|
|
toml::Reader reader(wrapper.get(), settings_file.string(), text);
|
|
reader.read();
|
|
}
|
|
setup_bindings();
|
|
Engine engine(settings, &paths);
|
|
if (std::filesystem::is_regular_file(controls_file)) {
|
|
std::cout << "-- loading controls" << std::endl;
|
|
std::string text = files::read_string(controls_file);
|
|
load_controls(controls_file.string(), text);
|
|
}
|
|
engine.mainloop();
|
|
|
|
std::cout << "-- saving settings" << std::endl;
|
|
files::write_string(settings_file, wrapper->write());
|
|
files::write_string(controls_file, write_controls());
|
|
}
|
|
catch (const initialize_error& err) {
|
|
std::cerr << "could not to initialize engine" << std::endl;
|
|
std::cerr << err.what() << std::endl;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|