audio listener configuration fix

This commit is contained in:
MihailRis 2024-05-05 19:51:14 +03:00
parent 2a77c24414
commit 75e56ebd83
6 changed files with 47 additions and 24 deletions

View File

@ -8,6 +8,7 @@
#include "coders/GLSLExtension.h"
#include "coders/imageio.hpp"
#include "coders/json.h"
#include "coders/toml.h"
#include "content/ContentLoader.h"
#include "core_defs.h"
#include "files/files.h"
@ -41,6 +42,8 @@
static debug::Logger logger("engine");
namespace fs = std::filesystem;
void addWorldGenerators() {
@ -60,6 +63,10 @@ inline void create_channel(Engine* engine, std::string name, NumberSetting& sett
Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, EnginePaths* paths)
: settings(settings), settingsHandler(settingsHandler), paths(paths)
{
corecontent::setup_bindings();
loadSettings();
controller = std::make_unique<EngineController>(this);
if (Window::initialize(&this->settings.display)){
throw initialize_error("could not initialize window");
@ -89,6 +96,21 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
scripting::initialize(this);
}
void Engine::loadSettings() {
fs::path settings_file = paths->getSettingsFile();
if (fs::is_regular_file(settings_file)) {
logger.info() << "loading settings";
std::string text = files::read_string(settings_file);
toml::parse(settingsHandler, settings_file.string(), text);
}
fs::path controls_file = paths->getControlsFile();
if (fs::is_regular_file(controls_file)) {
logger.info() << "loading controls";
std::string text = files::read_string(controls_file);
Events::loadBindings(controls_file.u8string(), text);
}
}
void Engine::onAssetsLoaded() {
gui->onAssetsLoad(assets.get());
}
@ -163,7 +185,14 @@ void Engine::processPostRunnables() {
scripting::process_post_runnables();
}
void Engine::saveSettings() {
logger.info() << "saving settings";
files::write_string(paths->getSettingsFile(), toml::stringify(settingsHandler));
files::write_string(paths->getControlsFile(), Events::writeBindings());
}
Engine::~Engine() {
saveSettings();
logger.info() << "shutting down";
if (screen) {
screen->onEngineShutdown();

View File

@ -60,6 +60,8 @@ class Engine : public util::ObjectsKeeper {
std::unique_ptr<gui::GUI> gui;
void loadSettings();
void saveSettings();
void updateTimers();
void updateHotkeys();
void renderFrame(Batch2D& batch);

View File

@ -10,6 +10,8 @@
#include "WorldFiles.h"
const fs::path SCREENSHOTS_FOLDER {"screenshots"};
const fs::path CONTROLS_FILE {"controls.json"};
const fs::path SETTINGS_FILE {"settings.toml"};
fs::path EnginePaths::getUserfiles() const {
return userfiles;
@ -54,6 +56,14 @@ fs::path EnginePaths::getWorldFolder(const std::string& name) {
return getWorldsFolder()/fs::path(name);
}
fs::path EnginePaths::getControlsFile() {
return userfiles/fs::path(CONTROLS_FILE);
}
fs::path EnginePaths::getSettingsFile() {
return userfiles/fs::path(SETTINGS_FILE);
}
std::vector<fs::path> EnginePaths::scanForWorlds() {
std::vector<fs::path> folders;

View File

@ -28,6 +28,8 @@ public:
fs::path getWorldsFolder();
fs::path getWorldFolder();
fs::path getWorldFolder(const std::string& name);
fs::path getControlsFile();
fs::path getSettingsFile();
bool isWorldNameUsed(std::string name);
void setUserfiles(fs::path folder);

View File

@ -126,7 +126,7 @@ void LevelScreen::update(float delta) {
camera->position-camera->dir,
player->hitbox->velocity,
camera->dir,
camera->up
glm::vec3(0, 1, 0)
);
if (!hud->isPause()) {

View File

@ -7,7 +7,6 @@
#include "core_defs.h"
#include "engine.h"
#include "coders/toml.h"
#include "files/files.h"
#include "files/settings_io.hpp"
#include "files/engine_paths.h"
@ -16,9 +15,6 @@
#include "window/Events.h"
#include "debug/Logger.hpp"
inline std::string SETTINGS_FILE = "settings.toml";
inline std::string CONTROLS_FILE = "controls.json";
static debug::Logger logger("main");
namespace fs = std::filesystem;
@ -35,26 +31,10 @@ int main(int argc, char** argv) {
try {
EngineSettings settings;
SettingsHandler handler(settings);
fs::path settings_file = userfiles/fs::path(SETTINGS_FILE);
fs::path controls_file = userfiles/fs::path(CONTROLS_FILE);
if (fs::is_regular_file(settings_file)) {
logger.info() << "loading settings";
std::string text = files::read_string(settings_file);
toml::parse(handler, settings_file.string(), text);
}
corecontent::setup_bindings();
Engine engine(settings, handler, &paths);
if (fs::is_regular_file(controls_file)) {
logger.info() << "loading controls";
std::string text = files::read_string(controls_file);
Events::loadBindings(controls_file.string(), text);
}
engine.mainloop();
logger.info() << "saving settings";
files::write_string(settings_file, toml::stringify(handler));
files::write_string(controls_file, Events::writeBindings());
Engine engine(settings, handler, &paths);
engine.mainloop();
}
catch (const initialize_error& err) {
logger.error() << "could not to initialize engine\n" << err.what();