diff --git a/CMakeLists.txt b/CMakeLists.txt index dc082b81..db417f05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.0) +cmake_minimum_required (VERSION 3.14) cmake_policy(SET CMP0028 NEW) project (ericw-tools) @@ -14,6 +14,11 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") + add_compile_options(/EHsc) + message(STATUS "working around exceptions not being enabled by default on clang-cl") +endif() + include_directories( "${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/3rdparty/glm") @@ -75,10 +80,6 @@ if (ERICWTOOLS_ASAN) add_link_options(-fsanitize=address) endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") - add_compile_options(/EHsc) -endif() - # 10.9: minimum version that supports unordered_map # 10.14: required by tbb 2021.3.0 (due to use of alignas) # 10.15: required by std::filesytstem diff --git a/include/common/cmdlib.hh b/include/common/cmdlib.hh index 874ba7db..80729ae9 100644 --- a/include/common/cmdlib.hh +++ b/include/common/cmdlib.hh @@ -19,6 +19,7 @@ #pragma once +#include // for std::min #include #include #include @@ -765,7 +766,7 @@ protected: return traits_type::eof(); } - ptrdiff_t free_space = epptr() - pptr(); + std::streamsize free_space = epptr() - pptr(); std::streamsize num_write = std::min(free_space, n); memcpy(pptr(), s, n); @@ -783,7 +784,7 @@ protected: return traits_type::eof(); } - ptrdiff_t free_space = egptr() - gptr(); + std::streamsize free_space = egptr() - gptr(); std::streamsize num_read = std::min(free_space, n); memcpy(s, gptr(), n); diff --git a/include/common/log.hh b/include/common/log.hh index 010ece5d..42d78db9 100644 --- a/include/common/log.hh +++ b/include/common/log.hh @@ -86,7 +86,7 @@ inline void print(const char *fmt, const Args &...args) // TODO: C++20 source_location #ifdef _MSC_VER -#define funcprint(fmt, ...) print(__FUNCTION__ ": " fmt, ##__VA_ARGS__) +#define funcprint(fmt, ...) print("{}: " fmt, __FUNCTION__, ##__VA_ARGS__) #else #define funcprint(fmt, ...) print("{}: " fmt, __func__, ##__VA_ARGS__) #endif diff --git a/include/common/settings.hh b/include/common/settings.hh index e3795295..a08a9eaf 100644 --- a/include/common/settings.hh +++ b/include/common/settings.hh @@ -393,29 +393,28 @@ protected: virtual void setValueInternal(T f, source newsource) override { if (f < _min) { - logging::print("WARNING: '{}': {} is less than minimum value {}.\n", primaryName(), f, _min); + logging::print("WARNING: '{}': {} is less than minimum value {}.\n", this->primaryName(), f, _min); f = _min; } if (f > _max) { - logging::print("WARNING: '{}': {} is greater than maximum value {}.\n", primaryName(), f, _max); + logging::print("WARNING: '{}': {} is greater than maximum value {}.\n", this->primaryName(), f, _max); f = _max; } - setting_value::setValueInternal(f, newsource); + this->setting_value::setValueInternal(f, newsource); } public: inline setting_numeric(setting_container *dictionary, const nameset &names, T v, T minval, T maxval, const setting_group *group = nullptr, const char *description = "") - : setting_value(dictionary, names, v, group, description), _min(minval), _max(maxval) + : setting_value(dictionary, names, v, group, description), _min(minval), _max(maxval) { // check the default value is valid Q_assert(_min < _max); - Q_assert(_value >= _min); - Q_assert(_value <= _max); + Q_assert(this->_value >= _min); + Q_assert(this->_value <= _max); } - template>> inline setting_numeric(setting_container *dictionary, const nameset &names, T v, const setting_group *group = nullptr, const char *description = "") : setting_numeric( @@ -423,10 +422,9 @@ public: { } - template>> inline bool boolValue() const { - return _value > 0; + return this->_value > 0; } virtual bool parse(const std::string &settingName, parser_base_t &parser, bool locked = false) override @@ -444,7 +442,7 @@ public: f = static_cast(std::stoull(parser.token)); } - setValueFromParse(f, locked); + this->setValueFromParse(f, locked); return true; } @@ -453,7 +451,7 @@ public: } } - virtual std::string stringValue() const override { return std::to_string(_value); } + virtual std::string stringValue() const override { return std::to_string(this->_value); } virtual std::string format() const override { return "n"; } }; @@ -471,7 +469,7 @@ public: inline setting_enum(setting_container *dictionary, const nameset &names, T v, const std::initializer_list> &enumValues, const setting_group *group = nullptr, const char *description = "") - : setting_value(dictionary, names, v, group, description), _values(enumValues.begin(), enumValues.end()) + : setting_value(dictionary, names, v, group, description), _values(enumValues.begin(), enumValues.end()) { } @@ -690,7 +688,8 @@ public: return; } - setting->parse(name, parser_t{value}, locked); + parser_t p{value}; + setting->parse(name, p, locked); } inline void setSettings(const entdict_t &epairs, bool locked) @@ -747,7 +746,10 @@ public: // before the parsing routine; set up options, members, etc virtual void preinitialize(int argc, const char **argv) { setParameters(argc, argv); } // do the actual parsing - virtual void initialize(int argc, const char **argv) { parse(token_parser_t(argc, argv)); } + virtual void initialize(int argc, const char **argv) { + token_parser_t p(argc, argv); + parse(p); + } // after parsing has concluded, handle the side effects virtual void postinitialize(int argc, const char **argv); diff --git a/include/light/entities.hh b/include/light/entities.hh index fc08e0cc..02d05541 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -73,7 +73,7 @@ public: settings::setting_numeric formula{this, "delay", LF_LINEAR, LF_LINEAR, LF_INVERSE2A}; settings::setting_scalar spotangle{this, "angle", 40.0}; settings::setting_scalar spotangle2{this, "softangle", 0.0}; - settings::setting_numeric style{this, "style", 0.0, 0, 254}; + settings::setting_numeric style{this, "style", 0, 0, 254}; settings::setting_scalar anglescale{this, {"anglesense", "anglescale"}, -1.0}; // fallback to worldspawn settings::setting_scalar dirtscale{this, "dirtscale", 0.0}; settings::setting_scalar dirtgain{this, "dirtgain", 0}; diff --git a/include/vis/leafbits.hh b/include/vis/leafbits.hh index a93bdf0a..9d33ec25 100644 --- a/include/vis/leafbits.hh +++ b/include/vis/leafbits.hh @@ -119,5 +119,5 @@ public: } }; - constexpr reference operator[](const size_t &index) { return {bits, index >> shift, 1ULL << (index & mask)}; } + constexpr reference operator[](const size_t &index) { return {bits, index >> shift, 1u << (index & mask)}; } }; diff --git a/light/light.cc b/light/light.cc index 3a809342..b7dd7435 100644 --- a/light/light.cc +++ b/light/light.cc @@ -103,7 +103,8 @@ setting_group experimental_group{"Experimental options", 60}; void light_settings::initialize(int argc, const char **argv) { - auto remainder = parse(token_parser_t(argc - 1, argv + 1)); + token_parser_t p(argc - 1, argv + 1); + auto remainder = parse(p); if (remainder.size() <= 0 || remainder.size() > 1) { printHelp(); diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 0502a7bd..16ecc6c6 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -56,12 +56,14 @@ void qbsp_settings::initialize(int argc, const char **argv) { if (auto file = fs::load("qbsp.ini")) { logging::print("Loading options from qbsp.ini\n"); - parse(parser_t(file->data(), file->size())); + parser_t p(file->data(), file->size()); + parse(p); } try { - auto remainder = parse(token_parser_t(argc - 1, argv + 1)); + token_parser_t p(argc - 1, argv + 1); + auto remainder = parse(p); if (remainder.size() <= 0 || remainder.size() > 2) { printHelp(); diff --git a/vis/vis.cc b/vis/vis.cc index fb1ead41..cb5bcee2 100644 --- a/vis/vis.cc +++ b/vis/vis.cc @@ -50,7 +50,8 @@ setting_group advanced_group{"Advanced", 300}; void vis_settings::initialize(int argc, const char **argv) { - auto remainder = parse(token_parser_t(argc - 1, argv + 1)); + token_parser_t p(argc - 1, argv + 1); + auto remainder = parse(p); if (remainder.size() <= 0 || remainder.size() > 1) { printHelp();