diff --git a/res/layouts/pages/settings.xml.lua b/res/layouts/pages/settings.xml.lua index 65c107a5..322b6b51 100644 --- a/res/layouts/pages/settings.xml.lua +++ b/res/layouts/pages/settings.xml.lua @@ -1,8 +1,5 @@ function create_setting(id, name, step, postfix) local info = core.get_setting_info(id) - if postfix == nil then - postfix = "" - end document.settings_panel:add(gui.template("track_setting", { id=id, name=gui.str(name, "settings"), @@ -10,7 +7,7 @@ function create_setting(id, name, step, postfix) min=info.min, max=info.max, step=step, - postfix=postfix + postfix=postfix or "" })) end @@ -41,6 +38,6 @@ function on_open() create_checkbox("camera.shaking", "Camera Shaking") document.langs_btn.text = string.format( "%s: %s", gui.str("Language", "settings"), - gui.get_locales_info()[gui.get_locale()].name + gui.get_locales_info()[core.get_setting("ui.language")].name ) end diff --git a/src/audio/audio.h b/src/audio/audio.h index 64fb99e2..cb0d5358 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -352,52 +352,52 @@ namespace audio { /// @brief Initialize audio system or use no audio mode /// @param enabled try to initialize actual audio - extern void initialize(bool enabled); + void initialize(bool enabled); /// @brief Load audio file info and PCM data /// @param file audio file /// @param headerOnly read header only /// @throws std::runtime_error if I/O error ocurred or format is unknown /// @return PCM audio data - extern PCM* load_PCM(const fs::path& file, bool headerOnly); + PCM* load_PCM(const fs::path& file, bool headerOnly); /// @brief Load sound from file /// @param file audio file path /// @param keepPCM store PCM data in sound to make it accessible with Sound::getPCM /// @throws std::runtime_error if I/O error ocurred or format is unknown /// @return new Sound instance - extern Sound* load_sound(const fs::path& file, bool keepPCM); + Sound* load_sound(const fs::path& file, bool keepPCM); /// @brief Create new sound from PCM data /// @param pcm PCM data /// @param keepPCM store PCM data in sound to make it accessible with Sound::getPCM /// @return new Sound instance - extern Sound* create_sound(std::shared_ptr pcm, bool keepPCM); + Sound* create_sound(std::shared_ptr pcm, bool keepPCM); /// @brief Open new PCM stream from file /// @param file audio file path /// @throws std::runtime_error if I/O error ocurred or format is unknown /// @return new PCMStream instance - extern PCMStream* open_PCM_stream(const fs::path& file); + PCMStream* open_PCM_stream(const fs::path& file); /// @brief Open new audio stream from file /// @param file audio file path /// @param keepSource store PCMStream in stream to make it accessible with Stream::getSource /// @return new Stream instance - extern Stream* open_stream(const fs::path& file, bool keepSource); + Stream* open_stream(const fs::path& file, bool keepSource); /// @brief Open new audio stream from source /// @param stream PCM data source /// @param keepSource store PCMStream in stream to make it accessible with Stream::getSource /// @return new Stream instance - extern Stream* open_stream(std::shared_ptr stream, bool keepSource); + Stream* open_stream(std::shared_ptr stream, bool keepSource); /// @brief Configure 3D listener /// @param position listener position /// @param velocity listener velocity (used for Doppler effect) /// @param lookAt point the listener look at /// @param up camera up vector - extern void set_listener( + void set_listener( glm::vec3 position, glm::vec3 velocity, glm::vec3 lookAt, @@ -415,7 +415,7 @@ namespace audio { /// (PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH) /// @param channel channel index /// @return speaker id or 0 - extern speakerid_t play( + speakerid_t play( Sound* sound, glm::vec3 position, bool relative, @@ -435,7 +435,7 @@ namespace audio { /// @param loop loop stream /// @param channel channel index /// @return speaker id or 0 - extern speakerid_t play( + speakerid_t play( std::shared_ptr stream, glm::vec3 position, bool relative, @@ -454,7 +454,7 @@ namespace audio { /// @param loop loop stream /// @param channel channel index /// @return speaker id or 0 - extern speakerid_t play_stream( + speakerid_t play_stream( const fs::path& file, glm::vec3 position, bool relative, @@ -467,49 +467,49 @@ namespace audio { /// @brief Get speaker by id /// @param id speaker id /// @return speaker or nullptr - extern Speaker* get_speaker(speakerid_t id); + Speaker* get_speaker(speakerid_t id); /// @brief Create new channel. /// All non-builtin channels will be destroyed on audio::reset() call /// @param name channel name /// @return new channel index - extern int create_channel(const std::string& name); + int create_channel(const std::string& name); /// @brief Get channel index by name /// @param name channel name /// @return channel index or -1 - extern int get_channel_index(const std::string& name); + int get_channel_index(const std::string& name); /// @brief Get channel by index. 0 - is master channel /// @param index channel index /// @return channel or nullptr - extern Channel* get_channel(int index); + Channel* get_channel(int index); /// @brief Get channel by name. /// @param name channel name /// @return channel or nullptr - extern Channel* get_channel(const std::string& name); + Channel* get_channel(const std::string& name); /// @brief Get stream associated with speaker /// @param id speaker id /// @return stream or nullptr - extern std::shared_ptr get_associated_stream(speakerid_t id); + std::shared_ptr get_associated_stream(speakerid_t id); /// @brief Get alive speakers number (including paused) - extern size_t count_speakers(); + size_t count_speakers(); /// @brief Get playing streams number (including paused) - extern size_t count_streams(); + size_t count_streams(); /// @brief Update audio streams and sound instanced /// @param delta time elapsed since the last update (seconds) - extern void update(double delta); + void update(double delta); /// @brief Stop all playing audio in channel, reset channel state - extern void reset_channel(int channel); + void reset_channel(int channel); /// @brief Finalize audio system - extern void close(); + void close(); }; #endif // AUDIO_AUDIO_H_ diff --git a/src/core_defs.h b/src/core_defs.h index f9ff9d9a..789d2100 100644 --- a/src/core_defs.h +++ b/src/core_defs.h @@ -29,8 +29,8 @@ inline const std::string BIND_HUD_INVENTORY = "hud.inventory"; class ContentBuilder; namespace corecontent { - extern void setup_bindings(); - extern void setup(ContentBuilder* builder); + void setup_bindings(); + void setup(ContentBuilder* builder); } #endif // CORE_DEFS_H_ diff --git a/src/files/files.cpp b/src/files/files.cpp index 59fa44b1..2ea31a44 100644 --- a/src/files/files.cpp +++ b/src/files/files.cpp @@ -34,64 +34,64 @@ void files::rafile::read(char* buffer, std::streamsize size) { } bool files::write_bytes(fs::path filename, const ubyte* data, size_t size) { - std::ofstream output(filename, std::ios::binary); - if (!output.is_open()) - return false; - output.write((const char*)data, size); - output.close(); - return true; + std::ofstream output(filename, std::ios::binary); + if (!output.is_open()) + return false; + output.write((const char*)data, size); + output.close(); + return true; } uint files::append_bytes(fs::path filename, const ubyte* data, size_t size) { - std::ofstream output(filename, std::ios::binary | std::ios::app); - if (!output.is_open()) - return 0; - uint position = output.tellp(); - output.write((const char*)data, size); - output.close(); - return position; + std::ofstream output(filename, std::ios::binary | std::ios::app); + if (!output.is_open()) + return 0; + uint position = output.tellp(); + output.write((const char*)data, size); + output.close(); + return position; } bool files::read(fs::path filename, char* data, size_t size) { - std::ifstream output(filename, std::ios::binary); - if (!output.is_open()) - return false; - output.read(data, size); - output.close(); - return true; + std::ifstream output(filename, std::ios::binary); + if (!output.is_open()) + return false; + output.read(data, size); + output.close(); + return true; } -ubyte* files::read_bytes(fs::path filename, size_t& length) { - std::ifstream input(filename, std::ios::binary); - if (!input.is_open()) - return nullptr; - input.seekg(0, std::ios_base::end); - length = input.tellg(); - input.seekg(0, std::ios_base::beg); +std::unique_ptr files::read_bytes(fs::path filename, size_t& length) { + std::ifstream input(filename, std::ios::binary); + if (!input.is_open()) + return nullptr; + input.seekg(0, std::ios_base::end); + length = input.tellg(); + input.seekg(0, std::ios_base::beg); - std::unique_ptr data(new char[length]); - input.read(data.get(), length); - input.close(); - return (ubyte*)data.release(); + auto data = std::make_unique(length); + input.read((char*)data.get(), length); + input.close(); + return data; } std::string files::read_string(fs::path filename) { - size_t size; - std::unique_ptr bytes (read_bytes(filename, size)); - if (bytes == nullptr) { - throw std::runtime_error("could not to load file '"+ - filename.string()+"'"); - } - return std::string((const char*)bytes.get(), size); + size_t size; + std::unique_ptr bytes (read_bytes(filename, size)); + if (bytes == nullptr) { + throw std::runtime_error("could not to load file '"+ + filename.string()+"'"); + } + return std::string((const char*)bytes.get(), size); } bool files::write_string(fs::path filename, const std::string content) { - std::ofstream file(filename); - if (!file) { - return false; - } - file << content; - return true; + std::ofstream file(filename); + if (!file) { + return false; + } + file << content; + return true; } bool files::write_json(fs::path filename, const dynamic::Map* obj, bool nice) { @@ -104,11 +104,11 @@ bool files::write_binary_json(fs::path filename, const dynamic::Map* obj, bool c } std::unique_ptr files::read_json(fs::path filename) { - std::string text = files::read_string(filename); - try { - auto obj = json::parse(filename.string(), text); + std::string text = files::read_string(filename); + try { + auto obj = json::parse(filename.string(), text); return obj; - } catch (const parsing_error& error) { + } catch (const parsing_error& error) { std::cerr << error.errorLog() << std::endl; throw std::runtime_error("could not to parse "+filename.string()); } @@ -123,19 +123,19 @@ std::unique_ptr files::read_binary_json(fs::path file) { } std::vector files::read_list(fs::path filename) { - std::ifstream file(filename); - if (!file) { - throw std::runtime_error("could not to open file "+filename.u8string()); - } - std::vector lines; - std::string line; - while (std::getline(file, line)) { + std::ifstream file(filename); + if (!file) { + throw std::runtime_error("could not to open file "+filename.u8string()); + } + std::vector lines; + std::string line; + while (std::getline(file, line)) { util::trim(line); - if (line.length() == 0) - continue; - if (line[0] == '#') - continue; - lines.push_back(line); - } - return lines; + if (line.length() == 0) + continue; + if (line[0] == '#') + continue; + lines.push_back(line); + } + return lines; } diff --git a/src/files/files.h b/src/files/files.h index eba79a07..5bf79a0a 100644 --- a/src/files/files.h +++ b/src/files/files.h @@ -31,20 +31,20 @@ namespace files { /// @param file target file /// @param data data bytes array /// @param size size of data bytes array - extern bool write_bytes(fs::path file, const ubyte* data, size_t size); + bool write_bytes(fs::path file, const ubyte* data, size_t size); /// @brief Append bytes array to the file without any extra data /// @param file target file /// @param data data bytes array /// @param size size of data bytes array - extern uint append_bytes(fs::path file, const ubyte* data, size_t size); + uint append_bytes(fs::path file, const ubyte* data, size_t size); /// @brief Write string to the file - extern bool write_string(fs::path filename, const std::string content); + bool write_string(fs::path filename, const std::string content); /// @brief Write dynamic data to the JSON file /// @param nice if true, human readable format will be used, otherwise minimal - extern bool write_json( + bool write_json( fs::path filename, const dynamic::Map* obj, bool nice=true); @@ -52,21 +52,21 @@ namespace files { /// @brief Write dynamic data to the binary JSON file /// (see src/coders/binary_json_spec.md) /// @param compressed use gzip compression - extern bool write_binary_json( + bool write_binary_json( fs::path filename, const dynamic::Map* obj, bool compressed=false ); - extern bool read(fs::path, char* data, size_t size); - extern ubyte* read_bytes(fs::path, size_t& length); - extern std::string read_string(fs::path filename); + bool read(fs::path, char* data, size_t size); + std::unique_ptr read_bytes(fs::path, size_t& length); + std::string read_string(fs::path filename); /// @brief Read JSON or BJSON file /// @param file *.json or *.bjson file - extern std::unique_ptr read_json(fs::path file); - extern std::unique_ptr read_binary_json(fs::path file); - extern std::vector read_list(fs::path file); + std::unique_ptr read_json(fs::path file); + std::unique_ptr read_binary_json(fs::path file); + std::vector read_list(fs::path file); } -#endif /* FILES_FILES_H_ */ \ No newline at end of file +#endif /* FILES_FILES_H_ */ diff --git a/src/frontend/menu.cpp b/src/frontend/menu.cpp index 82eff74f..2263bc23 100644 --- a/src/frontend/menu.cpp +++ b/src/frontend/menu.cpp @@ -25,7 +25,7 @@ void menus::create_version_label(Engine* engine) { auto gui = engine->getGUI(); auto text = ENGINE_VERSION_STRING+" development build"; gui->add(guiutil::create( - "