From 3c90a218033f81c229cd2d8555e24abc04bcf967 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Sun, 21 Jan 2024 10:49:46 +0100 Subject: [PATCH] chore(*): general code improvements --- include/phoenix/model_script.hh | 21 ++-- include/zenkit/Archive.hh | 5 +- include/zenkit/CutsceneLibrary.hh | 5 +- include/zenkit/DaedalusScript.hh | 158 +++++++++++--------------- include/zenkit/DaedalusVm.hh | 123 ++++++++++---------- include/zenkit/Error.hh | 2 - include/zenkit/Font.hh | 1 - include/zenkit/Material.hh | 1 - include/zenkit/Mmap.hh | 4 +- include/zenkit/Model.hh | 1 - include/zenkit/ModelAnimation.hh | 7 +- include/zenkit/ModelHierarchy.hh | 5 +- include/zenkit/ModelMesh.hh | 1 - include/zenkit/MorphMesh.hh | 1 - include/zenkit/MultiResolutionMesh.hh | 5 +- include/zenkit/SaveGame.hh | 17 ++- include/zenkit/SoftSkinMesh.hh | 5 +- include/zenkit/Stream.hh | 13 +-- include/zenkit/Texture.hh | 50 +++----- include/zenkit/Vfs.hh | 7 +- include/zenkit/World.hh | 4 +- include/zenkit/addon/daedalus.hh | 40 +++---- include/zenkit/addon/texcvt.hh | 2 +- include/zenkit/vobs/Camera.hh | 6 +- include/zenkit/vobs/Light.hh | 1 - include/zenkit/vobs/Misc.hh | 25 ++-- include/zenkit/vobs/Sound.hh | 2 - include/zenkit/vobs/Trigger.hh | 7 -- include/zenkit/vobs/VirtualObject.hh | 11 +- include/zenkit/vobs/Zone.hh | 3 - include/zenkit/world/BspTree.hh | 1 - include/zenkit/world/WayNet.hh | 2 - src/Archive.cc | 38 +++---- src/Boxes.cc | 2 +- src/CutsceneLibrary.cc | 20 ++-- src/DaedalusScript.cc | 35 +++--- src/DaedalusVm.cc | 112 +++++++++--------- src/Error.cc | 2 +- src/Font.cc | 7 +- src/Logger.cc | 6 +- src/Mesh.cc | 6 +- src/MmapPosix.cc | 7 +- src/ModelAnimation.cc | 24 ++-- src/ModelHierarchy.cc | 7 +- src/ModelMesh.cc | 6 +- src/ModelScript.cc | 18 +-- src/ModelScriptDsl.cc | 10 +- src/ModelScriptDsl.hh | 2 - src/MorphMesh.cc | 6 +- src/MultiResolutionMesh.cc | 44 +++---- src/SaveGame.cc | 7 +- src/SoftSkinMesh.cc | 16 +-- src/Stream.cc | 64 +++++------ src/Texture.cc | 18 ++- src/Vfs.cc | 37 +++--- src/World.cc | 8 +- src/addon/daedalus.cc | 44 +++---- src/addon/texcvt.cc | 8 +- src/archive/ArchiveAscii.cc | 47 ++++---- src/archive/ArchiveAscii.hh | 9 +- src/archive/ArchiveBinary.cc | 4 +- src/archive/ArchiveBinary.hh | 8 +- src/archive/ArchiveBinsafe.cc | 22 ++-- src/archive/ArchiveBinsafe.hh | 11 +- src/vobs/Misc.cc | 2 +- src/vobs/MovableObject.cc | 2 - src/vobs/Trigger.cc | 3 +- src/world/BspTree.cc | 24 ++-- src/world/WayNet.cc | 4 +- tests/TestDaedalusScript.cc | 3 +- tests/TestFont.cc | 12 +- tests/TestModelAnimation.cc | 28 ++--- tests/TestModelScript.cc | 2 +- tests/TestMultiResolutionMesh.cc | 2 +- tests/TestVobsG1.cc | 2 +- tests/TestWorld.cc | 4 +- 76 files changed, 581 insertions(+), 698 deletions(-) diff --git a/include/phoenix/model_script.hh b/include/phoenix/model_script.hh index 882f695f..e2110a11 100644 --- a/include/phoenix/model_script.hh +++ b/include/phoenix/model_script.hh @@ -6,15 +6,13 @@ namespace phoenix { namespace mds { - ZKREM("use zenkit::AnimationFlags::NONE") static constexpr auto const af_none = zenkit::AnimationFlags::NONE; - ZKREM("use zenkit::AnimationFlags::MOVE") static constexpr auto const af_move = zenkit::AnimationFlags::MOVE; - ZKREM("use zenkit::AnimationFlags::ROTATE") - static constexpr auto const af_rotate = zenkit::AnimationFlags::ROTATE; - ZKREM("use zenkit::AnimationFlags::QUEUE") static constexpr auto const af_queue = zenkit::AnimationFlags::QUEUE; - ZKREM("use zenkit::AnimationFlags::FLY") static constexpr auto const af_fly = zenkit::AnimationFlags::FLY; - ZKREM("use zenkit::AnimationFlags::IDLE") static constexpr auto const af_idle = zenkit::AnimationFlags::IDLE; - ZKREM("use zenkit::AnimationFlags::INPLACE") - static constexpr auto const af_inplace = zenkit::AnimationFlags::INPLACE; + ZKREM("use zenkit::AnimationFlags::NONE") static constexpr auto af_none = zenkit::AnimationFlags::NONE; + ZKREM("use zenkit::AnimationFlags::MOVE") static constexpr auto af_move = zenkit::AnimationFlags::MOVE; + ZKREM("use zenkit::AnimationFlags::ROTATE") static constexpr auto af_rotate = zenkit::AnimationFlags::ROTATE; + ZKREM("use zenkit::AnimationFlags::QUEUE") static constexpr auto af_queue = zenkit::AnimationFlags::QUEUE; + ZKREM("use zenkit::AnimationFlags::FLY") static constexpr auto af_fly = zenkit::AnimationFlags::FLY; + ZKREM("use zenkit::AnimationFlags::IDLE") static constexpr auto af_idle = zenkit::AnimationFlags::IDLE; + ZKREM("use zenkit::AnimationFlags::INPLACE") static constexpr auto af_inplace = zenkit::AnimationFlags::INPLACE; using animation_direction ZKREM("renamed to zenkit::AnimationDirection") = zenkit::AnimationDirection; using animation_flags ZKREM("use zenkit::AnimationFlags instead") = zenkit::AnimationFlags; @@ -35,9 +33,8 @@ namespace phoenix { using animation_combination ZKREM("renamed to zenkit::MdsAnimationCombine") = zenkit::MdsAnimationCombine; } // namespace mds - struct script_sytax_error : public zenkit::ParserError { - public: - ZKINT inline script_sytax_error(std::string&&, std::string&&) : zenkit::ParserError("") {} + struct script_sytax_error final : zenkit::ParserError { + ZKINT script_sytax_error(std::string&&, std::string&&) : ParserError("") {} }; using model_script ZKREM("renamed to zenkit::ModelScript") = zenkit::ModelScript; diff --git a/include/zenkit/Archive.hh b/include/zenkit/Archive.hh index 4128a7e3..6b54a4fe 100644 --- a/include/zenkit/Archive.hh +++ b/include/zenkit/Archive.hh @@ -273,7 +273,6 @@ namespace zenkit { /// \brief Skips the next entry in the reader. virtual void skip_entry() = 0; - protected: ArchiveHeader header; Read* read; @@ -289,8 +288,8 @@ namespace zenkit { static std::unique_ptr to(Write* w, ArchiveFormat format); static std::unique_ptr to_save(Write* w, ArchiveFormat format); - void write_object(std::shared_ptr obj, GameVersion version); - void write_object(std::string_view name, std::shared_ptr obj, GameVersion version); + void write_object(std::shared_ptr const& obj, GameVersion version); + void write_object(std::string_view name, std::shared_ptr const& obj, GameVersion version); void write_object(std::string_view name, Object const* obj, GameVersion version); virtual std::uint32_t write_object_begin(std::string_view object_name, std::string_view class_name, std::uint16_t version) = 0; diff --git a/include/zenkit/CutsceneLibrary.hh b/include/zenkit/CutsceneLibrary.hh index a278c5cd..72013c39 100644 --- a/include/zenkit/CutsceneLibrary.hh +++ b/include/zenkit/CutsceneLibrary.hh @@ -61,14 +61,14 @@ namespace zenkit { /// using buffer::duplicate. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static CutsceneLibrary parse(phoenix::buffer& path); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static CutsceneLibrary parse(phoenix::buffer& buf); /// \brief Parses a message database from the data in the given buffer. /// \param[in] buf The buffer to read from (by rvalue-reference). /// \return The parsed message database object. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static CutsceneLibrary parse(phoenix::buffer&& path); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static CutsceneLibrary parse(phoenix::buffer&& buf); /// \brief Retrieves a message block by it's name. /// \param name The name of the block to get @@ -78,7 +78,6 @@ namespace zenkit { ZKAPI void load(Read* r); ZKAPI void save(Write* r, ArchiveFormat fmt) const; - public: /// \brief A list of all message blocks in the database. std::vector blocks {}; }; diff --git a/include/zenkit/DaedalusScript.hh b/include/zenkit/DaedalusScript.hh index f536557c..16a9eec7 100644 --- a/include/zenkit/DaedalusScript.hh +++ b/include/zenkit/DaedalusScript.hh @@ -315,7 +315,7 @@ namespace zenkit { class DaedalusOpaqueInstance final : public DaedalusInstance { public: ZKAPI DaedalusOpaqueInstance(DaedalusSymbol const& sym, std::vector const& members); - ZKAPI ~DaedalusOpaqueInstance(); + ZKAPI ~DaedalusOpaqueInstance() override; protected: friend class symbol; @@ -342,65 +342,56 @@ namespace zenkit { class ZKAPI DaedalusTransientInstance : public DaedalusInstance { public: DaedalusTransientInstance(); - ~DaedalusTransientInstance(); protected: friend class DaedalusSymbol; virtual void set_int(DaedalusSymbol const& sym, uint16_t index, std::int32_t value) = 0; - virtual std::int32_t get_int(DaedalusSymbol const& sym, uint16_t index) const = 0; + [[nodiscard]] virtual std::int32_t get_int(DaedalusSymbol const& sym, uint16_t index) const = 0; virtual void set_float(DaedalusSymbol const& sym, uint16_t index, float value) = 0; - virtual float get_float(DaedalusSymbol const& sym, uint16_t index) const = 0; + [[nodiscard]] virtual float get_float(DaedalusSymbol const& sym, uint16_t index) const = 0; virtual void set_string(DaedalusSymbol const& sym, uint16_t index, std::string_view value) = 0; - virtual std::string const& get_string(DaedalusSymbol const& sym, uint16_t index) const = 0; + [[nodiscard]] virtual std::string const& get_string(DaedalusSymbol const& sym, uint16_t index) const = 0; }; /// \brief The base class for all exceptions thrown by interacting with a script. - struct DaedalusScriptError : public Error { + struct DaedalusScriptError : Error { using Error::Error; }; /// \brief An exception thrown if the symbol with a given name could not be found. - struct DaedalusSymbolNotFound : public DaedalusScriptError { - public: + struct DaedalusSymbolNotFound : DaedalusScriptError { ZKAPI explicit DaedalusSymbolNotFound(std::string&& name); - public: std::string name; }; /// \brief An exception thrown if registering a class member was unsuccessful. - struct DaedalusMemberRegistrationError : public DaedalusScriptError { - public: + struct DaedalusMemberRegistrationError : DaedalusScriptError { ZKAPI explicit DaedalusMemberRegistrationError(DaedalusSymbol const* sym, std::string&& message); - public: /// \brief The symbol being registered. DaedalusSymbol const* sym; }; /// \brief An exception thrown if the type of the member being registered does not match the type provided. - struct DaedalusInvalidRegistrationDataType final : public DaedalusMemberRegistrationError { - public: + struct DaedalusInvalidRegistrationDataType final : DaedalusMemberRegistrationError { ZKAPI explicit DaedalusInvalidRegistrationDataType(DaedalusSymbol const* sym, std::string&& given); - public: std::string given; }; /// \brief An exception thrown when the value of a symbol accessed in a way which is not permissible. - struct DaedalusIllegalAccess : public DaedalusScriptError { + struct DaedalusIllegalAccess : DaedalusScriptError { using DaedalusScriptError::DaedalusScriptError; }; /// \brief An exception thrown when the type of a symbol does not match the type expected. - struct DaedalusIllegalTypeAccess final : public DaedalusIllegalAccess { - public: + struct DaedalusIllegalTypeAccess final : DaedalusIllegalAccess { ZKINT DaedalusIllegalTypeAccess(DaedalusSymbol const* sym, DaedalusDataType expected); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; @@ -409,11 +400,9 @@ namespace zenkit { }; /// \brief An exception thrown when an out-of-bounds index is accessed. - struct DaedalusIllegalIndexAccess final : public DaedalusIllegalAccess { - public: + struct DaedalusIllegalIndexAccess final : DaedalusIllegalAccess { ZKINT DaedalusIllegalIndexAccess(DaedalusSymbol const* sym, std::size_t index); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; @@ -422,21 +411,17 @@ namespace zenkit { }; /// \brief An exception thrown when a constant symbol is accessed as mutable - struct DaedalusIllegalConstAccess final : public DaedalusIllegalAccess { - public: + struct DaedalusIllegalConstAccess final : DaedalusIllegalAccess { ZKINT explicit DaedalusIllegalConstAccess(DaedalusSymbol const* sym); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; }; /// \brief An exception thrown when the parent class of a member does not match the class of an instance. - struct DaedalusIllegalInstanceAccess final : public DaedalusIllegalAccess { - public: + struct DaedalusIllegalInstanceAccess final : DaedalusIllegalAccess { ZKINT DaedalusIllegalInstanceAccess(DaedalusSymbol const* sym, std::uint32_t expected_parent); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; @@ -445,31 +430,25 @@ namespace zenkit { }; /// \brief An exception thrown when the parent class of a member does not match the class of an instance. - struct DaedalusUnboundMemberAccess final : public DaedalusIllegalAccess { - public: + struct DaedalusUnboundMemberAccess final : DaedalusIllegalAccess { ZKAPI explicit DaedalusUnboundMemberAccess(DaedalusSymbol const* sym); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; }; /// \brief An exception thrown if a member symbol is being access without a context set. - struct DaedalusNoContextError final : public DaedalusIllegalAccess { - public: + struct DaedalusNoContextError final : DaedalusIllegalAccess { ZKINT explicit DaedalusNoContextError(DaedalusSymbol const* sym); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; }; /// \brief An exception thrown if a member symbol is being accessed with a context instance it is not bound to. - struct DaedalusIllegalContextType final : public DaedalusIllegalAccess { - public: + struct DaedalusIllegalContextType final : DaedalusIllegalAccess { ZKAPI DaedalusIllegalContextType(DaedalusSymbol const* sym, std::type_info const& context_type); - public: /// \brief The symbol being accessed. DaedalusSymbol const* sym; @@ -578,8 +557,7 @@ namespace zenkit { /// \tparam T The type of instance to check for. /// \return true if the symbol contains an instance of the given type, false if not. template - ZKAPI typename std::enable_if, - bool>::type inline is_instance_of() { // clang-format on + ZKAPI std::enable_if_t, bool> is_instance_of() { return this->type() == DaedalusDataType::INSTANCE && this->get_instance() != nullptr && this->get_instance()->_m_type == &typeid(T); } @@ -590,118 +568,118 @@ namespace zenkit { /// \brief Tests whether the symbol is a constant. /// \return `true` if the symbol is a constant, `false` if not. - [[nodiscard]] ZKAPI inline bool is_const() const noexcept { + [[nodiscard]] ZKAPI bool is_const() const noexcept { return (_m_flags & DaedalusSymbolFlag::CONST) != 0; } /// \brief Tests whether the symbol is a member variable. /// \return `true` if the symbol is a member, `false` if not. - [[nodiscard]] ZKAPI inline bool is_member() const noexcept { + [[nodiscard]] ZKAPI bool is_member() const noexcept { return (_m_flags & DaedalusSymbolFlag::MEMBER) != 0; } /// \brief Tests whether the symbol is an extern symbol. /// \return `true` if the symbol is an extern symbol, `false` if not. - [[nodiscard]] ZKAPI inline bool is_external() const noexcept { + [[nodiscard]] ZKAPI bool is_external() const noexcept { return (_m_flags & DaedalusSymbolFlag::EXTERNAL) != 0; } /// \brief Tests whether the symbol is merged. /// \return `true` if the symbol is merged, `false` if not. /// \note It is currently not known what 'merged' means. - [[nodiscard]] ZKAPI inline bool is_merged() const noexcept { + [[nodiscard]] ZKAPI bool is_merged() const noexcept { return (_m_flags & DaedalusSymbolFlag::MERGED) != 0; } /// \brief Tests whether the symbol has access trap. /// \return `true` if the symbol has trap enabled, `false` if not. - [[nodiscard]] ZKAPI inline bool has_access_trap() const noexcept { + [[nodiscard]] ZKAPI bool has_access_trap() const noexcept { return (_m_flags & DaedalusSymbolFlag::TRAP_ACCESS) != 0; } /// \brief brief Tests whether the symbol is a compiler-generated symbol /// \return return `true` if the symbol is generated, `false` if not. - [[nodiscard]] ZKAPI inline bool is_generated() const noexcept { + [[nodiscard]] ZKAPI bool is_generated() const noexcept { return _m_generated; } /// \brief brief Tests whether the symbol has a return value. /// \return return `true` if the symbol has a return value, `false` if not. - [[nodiscard]] ZKAPI inline bool has_return() const noexcept { + [[nodiscard]] ZKAPI bool has_return() const noexcept { return (_m_flags & DaedalusSymbolFlag::RETURN) != 0; } /// \return The name of the symbol. - [[nodiscard]] ZKAPI inline std::string const& name() const noexcept { + [[nodiscard]] ZKAPI std::string const& name() const noexcept { return _m_name; } /// \return The address of the symbol. - [[nodiscard]] ZKAPI inline std::uint32_t address() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t address() const noexcept { return static_cast(_m_address); } /// \return The index of the parent symbol or unset if the symbol does not have a parent. - [[nodiscard]] ZKAPI inline std::uint32_t parent() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t parent() const noexcept { return static_cast(_m_parent); } /// \return The count of values stored in the symbol. - [[nodiscard]] ZKAPI inline std::uint32_t count() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t count() const noexcept { return _m_count; } /// \return The type of the symbol. - [[nodiscard]] ZKAPI inline DaedalusDataType type() const noexcept { + [[nodiscard]] ZKAPI DaedalusDataType type() const noexcept { return _m_type; } /// \return The index of the symbol. - [[nodiscard]] ZKAPI inline std::uint32_t index() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t index() const noexcept { return _m_index; } /// \return The return type of the symbol. - [[nodiscard]] ZKAPI inline DaedalusDataType rtype() const noexcept { + [[nodiscard]] ZKAPI DaedalusDataType rtype() const noexcept { return _m_return_type; } /// \return The index of the file the symbol was in. - [[nodiscard]] ZKAPI inline std::uint32_t file_index() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t file_index() const noexcept { return _m_file_index; } /// \return The offset in bytes of a member from the start of the instance. - [[nodiscard]] ZKAPI inline std::uint32_t offset_as_member() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t offset_as_member() const noexcept { return _m_member_offset; } - [[nodiscard]] ZKAPI inline std::uint32_t line_start() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t line_start() const noexcept { return _m_line_start; } - [[nodiscard]] ZKAPI inline std::uint32_t line_count() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t line_count() const noexcept { return _m_line_count; } - [[nodiscard]] ZKAPI inline std::uint32_t char_start() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t char_start() const noexcept { return _m_char_start; } - [[nodiscard]] ZKAPI inline std::uint32_t char_count() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t char_count() const noexcept { return _m_char_count; } - [[nodiscard]] ZKAPI inline std::uint32_t class_size() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t class_size() const noexcept { return _m_class_size; } - [[nodiscard]] ZKAPI inline std::type_info const& registered_to() const noexcept { + [[nodiscard]] ZKAPI std::type_info const& registered_to() const noexcept { return *_m_registered_to; - }; + } protected: template - inline T const* get_member_ptr(std::uint16_t index, DaedalusInstance const* context) const { + T const* get_member_ptr(std::uint16_t index, DaedalusInstance const* context) const { if (!_m_registered_to) throw DaedalusUnboundMemberAccess(this); if (*_m_registered_to != *context->_m_type) throw DaedalusIllegalContextType {this, *context->_m_type}; @@ -711,7 +689,7 @@ namespace zenkit { } template - inline T* get_member_ptr(std::uint16_t index, DaedalusInstance* context) { + T* get_member_ptr(std::uint16_t index, DaedalusInstance* context) { if (!_m_registered_to) throw DaedalusUnboundMemberAccess(this); if (*_m_registered_to != *context->_m_type) throw DaedalusIllegalContextType {this, *context->_m_type}; @@ -760,7 +738,7 @@ namespace zenkit { std::uint8_t size {1}; /// \brief Reads an instruction from a reader. - /// \param[in,out] in The reader to read from + /// \param[in,out] r The reader to read from /// \return The instruction read. ZKINT static DaedalusInstruction decode(Read* r); }; @@ -792,17 +770,16 @@ namespace zenkit { /// \throws DaedalusInvalidRegistrationDataType If the datatype of \p _member is different than that of the /// symbol. template - typename std::enable_if || std::is_same_v<_member, float> || - std::is_same_v<_member, std::int32_t> || - (std::is_enum_v<_member> && sizeof(_member) == 4), - void>::type - register_member(std::string_view name, _member (_class::*field)[N]) { // clang-format on + std::enable_if_t || std::is_same_v<_member, float> || + std::is_same_v<_member, std::int32_t> || (std::is_enum_v<_member> && sizeof(_member) == 4), + void> + register_member(std::string_view name, _member (_class::*field)[N]) { auto* type = &typeid(_class); - auto* sym = _check_member<_class, _member, N>(name, type); + auto* sym = _check_member<_member, N>(name, type); - _class* base = 0; + _class* base = nullptr; auto member = &(base->*field); - sym->_m_member_offset = std::uint64_t(member) & 0xFFFFFFFF; + sym->_m_member_offset = reinterpret_cast(member) & 0xFFFFFFFF; sym->_m_registered_to = type; } @@ -814,22 +791,21 @@ namespace zenkit { /// \throws DaedalusInvalidRegistrationDataType If the datatype of \p _member is different than that of the /// symbol. template - typename std::enable_if || std::is_same_v<_member, float> || - std::is_same_v<_member, std::int32_t> || - (std::is_enum_v<_member> && sizeof(_member) == 4), - void>::type + std::enable_if_t || std::is_same_v<_member, float> || + std::is_same_v<_member, std::int32_t> || (std::is_enum_v<_member> && sizeof(_member) == 4), + void> register_member(std::string_view name, _member _class::*field) { auto* type = &typeid(_class); - auto* sym = _check_member<_class, _member, 1>(name, type); + auto* sym = _check_member<_member, 1>(name, type); - _class* base = 0; + _class* base = nullptr; auto member = &(base->*field); - sym->_m_member_offset = std::uint64_t(member) & 0xFFFFFFFF; + sym->_m_member_offset = reinterpret_cast(member) & 0xFFFFFFFF; sym->_m_registered_to = type; } /// \return All symbols in the script - [[nodiscard]] ZKAPI inline std::vector const& symbols() const noexcept { + [[nodiscard]] ZKAPI std::vector const& symbols() const noexcept { return _m_symbols; } @@ -845,7 +821,7 @@ namespace zenkit { find_parameters_for_function(DaedalusSymbol const* parent) const; /// \brief Retrieves the symbol with the given \p address set - /// \param index The address of the symbol to get + /// \param address The address of the symbol to get /// \return The symbol or `nullptr` if no symbol with that address was found. [[nodiscard]] ZKAPI DaedalusSymbol const* find_symbol_by_address(std::uint32_t address) const; @@ -860,7 +836,7 @@ namespace zenkit { [[nodiscard]] ZKAPI DaedalusSymbol* find_symbol_by_index(std::uint32_t index); /// \brief Retrieves the symbol with the given \p address set - /// \param index The address of the symbol to get + /// \param address The address of the symbol to get /// \return The symbol or `nullptr` if no symbol with that address was found. [[nodiscard]] ZKAPI DaedalusSymbol* find_symbol_by_address(std::uint32_t address); @@ -893,7 +869,7 @@ namespace zenkit { /// \param inst The instance to get the symbol for. /// \return The symbol associated with that instance or nullptr if the symbol is not associated /// with any instance. - ZKAPI inline DaedalusSymbol const* find_symbol_by_instance(DaedalusInstance const& inst) const { + ZKAPI DaedalusSymbol const* find_symbol_by_instance(DaedalusInstance const& inst) const { return find_symbol_by_index(inst._m_symbol_index); } @@ -901,7 +877,7 @@ namespace zenkit { /// \param inst The instance to get the symbol for. /// \return The symbol associated with that instance or nullptr if the symbol is not associated /// with any instance. - ZKAPI inline DaedalusSymbol* find_symbol_by_instance(DaedalusInstance const& inst) { + ZKAPI DaedalusSymbol* find_symbol_by_instance(DaedalusInstance const& inst) { return find_symbol_by_index(inst._m_symbol_index); } @@ -910,8 +886,8 @@ namespace zenkit { /// \return The symbol associated with that instance or nullptr if the symbol is not associated /// with any instance. template - ZKAPI typename std::enable_if, DaedalusSymbol const*>:: - type inline find_symbol_by_instance(std::shared_ptr const& inst) const { // clang-format on + ZKAPI std::enable_if_t, DaedalusSymbol const*> + find_symbol_by_instance(std::shared_ptr const& inst) const { return find_symbol_by_index(inst->_m_symbol_index); } @@ -920,8 +896,8 @@ namespace zenkit { /// \return The symbol associated with that instance or nullptr if the symbol is not associated /// with any instance. template - ZKAPI typename std::enable_if, DaedalusSymbol*>:: - type inline find_symbol_by_instance(std::shared_ptr const& inst) { + ZKAPI std::enable_if_t, DaedalusSymbol*> + find_symbol_by_instance(std::shared_ptr const& inst) { return find_symbol_by_index(inst->_m_symbol_index); } @@ -934,7 +910,7 @@ namespace zenkit { void register_as_opaque(DaedalusSymbol* sym); protected: - template + template DaedalusSymbol* _check_member(std::string_view name, std::type_info const* type) { auto* sym = find_symbol_by_name(name); @@ -946,7 +922,7 @@ namespace zenkit { " expected " + std::to_string(sym->count())}; // check class registration - auto* parent = find_symbol_by_index(static_cast(sym->parent())); + auto* parent = find_symbol_by_index(sym->parent()); if (parent == nullptr) throw DaedalusMemberRegistrationError {sym, "no parent found"}; if (parent->_m_registered_to == nullptr) { diff --git a/include/zenkit/DaedalusVm.hh b/include/zenkit/DaedalusVm.hh index b376f1ea..663f75a0 100644 --- a/include/zenkit/DaedalusVm.hh +++ b/include/zenkit/DaedalusVm.hh @@ -36,26 +36,25 @@ namespace zenkit { public: ZKAPI DaedalusIllegalExternalDefinition(DaedalusSymbol const* sym, std::string&& message); - public: /// \brief The symbol the external is being registered for. DaedalusSymbol const* sym; }; /// \brief An exception thrown if the return type of a new external registration does not match /// the return type defined in the script. - class DaedalusIllegalExternalReturnType : public DaedalusIllegalExternalDefinition { + class DaedalusIllegalExternalReturnType final : public DaedalusIllegalExternalDefinition { public: ZKAPI DaedalusIllegalExternalReturnType(DaedalusSymbol const* sym, std::string&& provided); }; /// \brief An exception thrown if one of the parameter types of a new external registration does not match /// the type defined in the script. - class DaedalusIllegalExternalParameter : public DaedalusIllegalExternalDefinition { + class DaedalusIllegalExternalParameter final : public DaedalusIllegalExternalDefinition { public: ZKAPI DaedalusIllegalExternalParameter(DaedalusSymbol const* sym, std::string&& provided, std::uint8_t i); }; - class DaedalusVmException : public DaedalusScriptError { + class DaedalusVmException final : public DaedalusScriptError { using DaedalusScriptError::DaedalusScriptError; }; @@ -114,8 +113,8 @@ namespace zenkit { /// \param sym The name of the function to call. /// \param args The arguments for the function call. template - R call_function(std::string_view name, P... args) { - return call_function(find_symbol_by_name(name), args...); + R call_function(std::string_view sym, P... args) { + return call_function(find_symbol_by_name(sym), args...); } /// \brief Calls a function by it's symbol. @@ -153,22 +152,17 @@ namespace zenkit { unsafe_call(sym); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v || std::is_same_v) { // clear the stack _m_stack_ptr = 0; - return {}; - } else if constexpr (!std::is_same_v) { - auto ret = pop_call_return_value(); + } - // clear the stack - _m_stack_ptr = 0; + auto ret = pop_call_return_value(); - return ret; - } else { - // clear the stack - _m_stack_ptr = 0; - } + // clear the stack + _m_stack_ptr = 0; + return ret; } /// \brief Initializes an instance with the given type and name and returns it. @@ -180,8 +174,7 @@ namespace zenkit { /// \param name The name of the instance to initialize (ie. 'STT_309_WHISTLER') /// \return The initialized instance. template - - typename std::enable_if, std::shared_ptr<_instance_t>>::type + std::enable_if_t, std::shared_ptr<_instance_t>> init_instance(std::string_view name) { return init_instance<_instance_t>(find_symbol_by_name(name)); } @@ -191,7 +184,7 @@ namespace zenkit { /// \param instance The instance to initialize. /// \param name The name of the instance to initialize (ie. 'STT_309_WHISTLER') template - typename std::enable_if, void>::type + std::enable_if_t, void> init_instance(std::shared_ptr<_instance_t> const& instance, std::string_view name) { init_instance<_instance_t>(instance, find_symbol_by_name(name)); } @@ -205,8 +198,7 @@ namespace zenkit { /// \param sym The symbol to initialize. /// \return The initialized instance. template - - typename std::enable_if, std::shared_ptr<_instance_t>>::type + std::enable_if_t, std::shared_ptr<_instance_t>> init_instance(DaedalusSymbol* sym) { // create the instance auto inst = std::make_shared<_instance_t>(); @@ -219,7 +211,7 @@ namespace zenkit { /// \param instance The instance to initialize. /// \param sym The symbol to initialize. template - typename std::enable_if, void>::type + std::enable_if_t, void> init_instance(std::shared_ptr<_instance_t> const& instance, DaedalusSymbol* sym) { // Perform initial instance setup this->allocate_instance(instance, sym); @@ -249,7 +241,7 @@ namespace zenkit { /// \param name The name of the instance to initialize (ie. 'STT_309_WHISTLER') /// \return The initialized instance. template - typename std::enable_if, std::shared_ptr<_instance_t>>::type + std::enable_if_t, std::shared_ptr<_instance_t>> allocate_instance(std::string_view name) { return allocate_instance<_instance_t>(find_symbol_by_name(name)); } @@ -263,7 +255,7 @@ namespace zenkit { /// \param instance The instance to initialize. /// \param name The name of the instance to initialize (ie. 'STT_309_WHISTLER') template - typename std::enable_if, void>::type + std::enable_if_t, void> allocate_instance(std::shared_ptr<_instance_t> const& instance, std::string_view name) { allocate_instance<_instance_t>(instance, find_symbol_by_name(name)); } @@ -277,8 +269,7 @@ namespace zenkit { /// \param sym The symbol to initialize. /// \return The initialized instance. template - - typename std::enable_if, std::shared_ptr<_instance_t>>::type + std::enable_if_t, std::shared_ptr<_instance_t>> allocate_instance(DaedalusSymbol* sym) { // create the instance auto inst = std::make_shared<_instance_t>(); @@ -295,7 +286,7 @@ namespace zenkit { /// \param instance The instance to initialize. /// \param sym The symbol to initialize. template - typename std::enable_if, void>::type + std::enable_if_t, void> allocate_instance(std::shared_ptr<_instance_t> const& instance, DaedalusSymbol* sym) { if (sym == nullptr) { throw DaedalusVmException {"Cannot init instance: not found"}; @@ -642,27 +633,27 @@ namespace zenkit { ZKAPI void unsafe_set_gi(std::shared_ptr i); /// \return the symbol referring to the global var C_NPC self. - ZKAPI inline DaedalusSymbol* global_self() { + [[nodiscard]] ZKAPI DaedalusSymbol* global_self() { return _m_self_sym; } /// \return the symbol referring to the global var C_NPC other. - ZKAPI inline DaedalusSymbol* global_other() { + [[nodiscard]] ZKAPI DaedalusSymbol* global_other() { return _m_other_sym; } /// \return the symbol referring to the global var C_NPC victim. - ZKAPI inline DaedalusSymbol* global_victim() { + [[nodiscard]] ZKAPI DaedalusSymbol* global_victim() { return _m_victim_sym; } /// \return the symbol referring to the global var C_NPC hero. - ZKAPI inline DaedalusSymbol* global_hero() { + [[nodiscard]] ZKAPI DaedalusSymbol* global_hero() { return _m_hero_sym; } /// \return the symbol referring to the global var C_NPC item. - ZKAPI inline DaedalusSymbol* global_item() { + [[nodiscard]] ZKAPI DaedalusSymbol* global_item() { return _m_item_sym; } @@ -670,24 +661,26 @@ namespace zenkit { ZKAPI void print_stack_trace() const; /// \return The current program counter (or instruction index) the VM is at. - [[nodiscard]] ZKAPI inline uint32_t pc() const noexcept { + [[nodiscard]] ZKAPI uint32_t pc() const noexcept { return _m_pc; } [[nodiscard]] ZKAPI std::int32_t - get_int(std::shared_ptr& context, - std::variant>& value, - uint16_t index); + get_int(std::shared_ptr const& context, + std::variant> const& value, + uint16_t index) const; [[nodiscard]] ZKAPI float - get_float(std::shared_ptr& context, - std::variant>& value, - uint16_t index); - - ZKAPI void - set_int(std::shared_ptr& context, DaedalusSymbol* ref, uint16_t index, std::int32_t value); + get_float(std::shared_ptr const& context, + std::variant> const& value, + uint16_t index) const; + + ZKAPI void set_int(std::shared_ptr const& context, + DaedalusSymbol* ref, + uint16_t index, + std::int32_t value); ZKAPI void - set_float(std::shared_ptr& context, DaedalusSymbol* ref, uint16_t index, float value); - ZKAPI void set_string(std::shared_ptr& context, + set_float(std::shared_ptr const& context, DaedalusSymbol* ref, uint16_t index, float value); + ZKAPI void set_string(std::shared_ptr const& context, DaedalusSymbol* ref, uint16_t index, std::string_view value); @@ -759,11 +752,11 @@ namespace zenkit { /// DaedalusSymbol*, std::string_view) /// \return The value popped. template - typename std::enable_if || std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || is_raw_instance_ptr_v || - std::is_same_v, - T>::type + std::enable_if_t || std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v || + std::is_same_v || is_raw_instance_ptr_v || + std::is_same_v, + T> pop_value_for_external() { if constexpr (is_instance_ptr_v) { auto r = pop_instance(); @@ -787,7 +780,7 @@ namespace zenkit { auto r = pop_instance(); if (r != nullptr && !std::is_same_v) { - auto& expected = typeid(typename std::remove_pointer_t); + auto& expected = typeid(std::remove_pointer_t); if (!r->_m_type) { throw DaedalusVmException {"Popping instance of unregistered type: " + @@ -838,10 +831,10 @@ namespace zenkit { /// \tparam T The type of value to push. /// \param v The value to push. template - typename std::enable_if || std::is_convertible_v || - std::is_convertible_v || std::is_same_v || - std::is_same_v || std::is_same_v, - void>::type + std::enable_if_t || std::is_convertible_v || + std::is_convertible_v || std::is_same_v || + std::is_same_v || std::is_same_v, + void> push_value_from_external(T v) { // clang-format on if constexpr (is_instance_ptr_v) { push_instance(std::static_pointer_cast(v)); @@ -881,10 +874,10 @@ namespace zenkit { } template - typename std::enable_if || std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v, - void>::type + std::enable_if_t || std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v || + std::is_same_v, + void> check_call_return_type(DaedalusSymbol const* sym) { if constexpr (is_instance_ptr_v) { if (sym->rtype() != DaedalusDataType::INSTANCE) @@ -905,12 +898,12 @@ namespace zenkit { } template - typename std::enable_if || std::is_same_v, float> || - std::is_same_v, std::int32_t> || - std::is_same_v, bool> || - std::is_same_v, std::string_view> || - std::is_same_v, DaedalusSymbol*>, - void>::type + std::enable_if_t || std::is_same_v, float> || + std::is_same_v, std::int32_t> || + std::is_same_v, bool> || + std::is_same_v, std::string_view> || + std::is_same_v, DaedalusSymbol*>, + void> push_call_parameters(std::vector const& defined, P value, Px... more) { // clang-format on if constexpr (is_instance_ptr_v

|| std::is_same_v) { if (defined[i]->type() != DaedalusDataType::INSTANCE) diff --git a/include/zenkit/Error.hh b/include/zenkit/Error.hh index f3d781a3..1bf15b4b 100644 --- a/include/zenkit/Error.hh +++ b/include/zenkit/Error.hh @@ -17,7 +17,6 @@ namespace zenkit { return message.c_str(); } - public: std::string const message; }; @@ -29,7 +28,6 @@ namespace zenkit { ZKINT explicit ParserError(std::string&& resource_type, std::exception const& cause); ZKINT explicit ParserError(std::string&& resource_type, std::exception const& cause, std::string&& context); - public: std::string const resource_type; std::optional const context {std::nullopt}; std::optional const cause {std::nullopt}; diff --git a/include/zenkit/Font.hh b/include/zenkit/Font.hh index 9f32c897..ac3f8a5d 100644 --- a/include/zenkit/Font.hh +++ b/include/zenkit/Font.hh @@ -59,7 +59,6 @@ namespace zenkit { ZKAPI void load(Read* r); ZKAPI void save(Write* w) const; - public: /// \brief The name of this font. std::string name; diff --git a/include/zenkit/Material.hh b/include/zenkit/Material.hh index 35d869ac..14401f33 100644 --- a/include/zenkit/Material.hh +++ b/include/zenkit/Material.hh @@ -128,7 +128,6 @@ namespace zenkit { class Material : public Object { ZK_OBJECT(ObjectType::zCMaterial); - public: /// \brief Parses a material from the given *ZenGin* archive. /// ///

This implementation is heavily based on the implementation found in diff --git a/include/zenkit/Mmap.hh b/include/zenkit/Mmap.hh index 2b409029..db8ce1dc 100644 --- a/include/zenkit/Mmap.hh +++ b/include/zenkit/Mmap.hh @@ -14,11 +14,11 @@ namespace zenkit { ~Mmap() noexcept; - [[nodiscard]] inline std::byte const* data() const noexcept { + [[nodiscard]] std::byte const* data() const noexcept { return _m_data; } - [[nodiscard]] inline std::size_t size() const noexcept { + [[nodiscard]] std::size_t size() const noexcept { return _m_size; } diff --git a/include/zenkit/Model.hh b/include/zenkit/Model.hh index b4dea768..3b2a477f 100644 --- a/include/zenkit/Model.hh +++ b/include/zenkit/Model.hh @@ -38,7 +38,6 @@ namespace zenkit { ZKAPI void load(Read* r); ZKAPI void save(Write* w, GameVersion version) const; - public: /// \brief The zenkit::ModelHierarchy associated with this model. ModelHierarchy hierarchy {}; diff --git a/include/zenkit/ModelAnimation.hh b/include/zenkit/ModelAnimation.hh index 3ab65a5c..fc02428a 100644 --- a/include/zenkit/ModelAnimation.hh +++ b/include/zenkit/ModelAnimation.hh @@ -92,7 +92,7 @@ namespace zenkit { /// \brief Represents an animation event. struct AnimationEvent { - static constexpr auto const VMAX = 4; + static constexpr auto VMAX = 4; AnimationEventType type; @@ -122,18 +122,17 @@ namespace zenkit { /// using buffer::duplicate. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelAnimation parse(phoenix::buffer& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelAnimation parse(phoenix::buffer& buf); /// \brief Parses an animation from the data in the given buffer. /// \param[in] buf The buffer to read from (by rvalue-reference). /// \return The parsed animation. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelAnimation parse(phoenix::buffer&& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelAnimation parse(phoenix::buffer&& buf); ZKAPI void load(Read* r); - public: /// \brief The name of the animation std::string name {}; diff --git a/include/zenkit/ModelHierarchy.hh b/include/zenkit/ModelHierarchy.hh index be237b77..a3e49e3b 100644 --- a/include/zenkit/ModelHierarchy.hh +++ b/include/zenkit/ModelHierarchy.hh @@ -47,7 +47,7 @@ namespace zenkit { /// using buffer::duplicate. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelHierarchy parse(phoenix::buffer& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelHierarchy parse(phoenix::buffer& buf); /// \brief Parses a model hierarchy from the data in the given buffer. /// @@ -58,12 +58,11 @@ namespace zenkit { /// \return The parsed model hierarchy object. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelHierarchy parse(phoenix::buffer&& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static ModelHierarchy parse(phoenix::buffer&& buf); ZKAPI void load(Read* r); ZKAPI void save(Write* w) const; - public: /// \brief The list of nodes this hierarchy consists of. std::vector nodes {}; diff --git a/include/zenkit/ModelMesh.hh b/include/zenkit/ModelMesh.hh index dfdf432c..561f3b40 100644 --- a/include/zenkit/ModelMesh.hh +++ b/include/zenkit/ModelMesh.hh @@ -47,7 +47,6 @@ namespace zenkit { ZKAPI void load(Read* r); ZKAPI void save(Write* w, GameVersion version) const; - public: /// \brief A list of soft-skin meshes associated with this model mesh. std::vector meshes {}; diff --git a/include/zenkit/MorphMesh.hh b/include/zenkit/MorphMesh.hh index 8de6f6be..ec51ee3b 100644 --- a/include/zenkit/MorphMesh.hh +++ b/include/zenkit/MorphMesh.hh @@ -77,7 +77,6 @@ namespace zenkit { ZKAPI void load(Read* r); - public: /// \brief The name of the mesh. std::string name {}; diff --git a/include/zenkit/MultiResolutionMesh.hh b/include/zenkit/MultiResolutionMesh.hh index 5fdd6514..e773744b 100644 --- a/include/zenkit/MultiResolutionMesh.hh +++ b/include/zenkit/MultiResolutionMesh.hh @@ -94,21 +94,20 @@ namespace zenkit { /// using buffer::duplicate. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static MultiResolutionMesh parse(phoenix::buffer& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static MultiResolutionMesh parse(phoenix::buffer& buf); /// \brief Parses a proto mesh from the data in the given buffer. /// \param[in] buf The buffer to read from (by rvalue-reference). /// \return The parsed proto mesh. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&) - [[nodiscard]] ZKREM("use ::load()") ZKAPI static MultiResolutionMesh parse(phoenix::buffer&& in); + [[nodiscard]] ZKREM("use ::load()") ZKAPI static MultiResolutionMesh parse(phoenix::buffer&& buf); ZKAPI void load(Read* r); ZKINT void load_from_section(Read* r); ZKAPI void save(Write* w, GameVersion version) const; ZKINT void save_to_section(Write* w, GameVersion version) const; - public: /// \brief The vertex positions associated with the mesh. std::vector positions; diff --git a/include/zenkit/SaveGame.hh b/include/zenkit/SaveGame.hh index 4418224e..e7f26c7b 100644 --- a/include/zenkit/SaveGame.hh +++ b/include/zenkit/SaveGame.hh @@ -131,18 +131,17 @@ namespace zenkit { class SaveGame { public: - explicit SaveGame(GameVersion version); + ZKAPI explicit SaveGame(GameVersion version); - void load(std::filesystem::path const& path); - void save(std::filesystem::path const& path, World& world, std::string world_name); + ZKAPI void load(std::filesystem::path const& path); + ZKAPI void save(std::filesystem::path const& path, World& world, std::string const& world_name); - std::shared_ptr load_world() const; - std::shared_ptr load_world(std::string name) const; + [[nodiscard]] ZKAPI std::shared_ptr load_world() const; + [[nodiscard]] ZKAPI std::shared_ptr load_world(std::string_view name) const; - public: - SaveMetadata metadata; - SaveState state; - std::optional thumbnail; + SaveMetadata metadata {}; + SaveState state {}; + std::optional thumbnail {}; private: GameVersion _m_version; diff --git a/include/zenkit/SoftSkinMesh.hh b/include/zenkit/SoftSkinMesh.hh index 8aa46e14..47f1c077 100644 --- a/include/zenkit/SoftSkinMesh.hh +++ b/include/zenkit/SoftSkinMesh.hh @@ -39,19 +39,18 @@ namespace zenkit { /// using buffer::duplicate. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&&) - [[nodiscard]] ZKREM(":: load()") ZKAPI static SoftSkinMesh parse(phoenix::buffer& in); + [[nodiscard]] ZKREM(":: load()") ZKAPI static SoftSkinMesh parse(phoenix::buffer& buf); /// \brief Parses a soft-skin mesh from the data in the given buffer. /// \param[in] buf The buffer to read from (by rvalue-reference). /// \return The parsed soft-skin mesh. /// \throws zenkit::ParserError if parsing fails. /// \see #parse(buffer&) - [[nodiscard]] ZKREM(":: load()") ZKAPI static SoftSkinMesh parse(phoenix::buffer&& in); + [[nodiscard]] ZKREM(":: load()") ZKAPI static SoftSkinMesh parse(phoenix::buffer&& buf); ZKAPI void load(Read* r); ZKAPI void save(Write* w, GameVersion version) const; - public: /// \brief The embedded proto-mesh. MultiResolutionMesh mesh; diff --git a/include/zenkit/Stream.hh b/include/zenkit/Stream.hh index a1dec203..ba55cc0c 100644 --- a/include/zenkit/Stream.hh +++ b/include/zenkit/Stream.hh @@ -12,9 +12,7 @@ #include #include #include -#include #include -#include #include namespace phoenix { @@ -110,7 +108,7 @@ namespace zenkit { [[nodiscard]] virtual size_t tell() const noexcept = 0; [[nodiscard]] virtual bool eof() const noexcept = 0; - [[nodiscard]] static std::unique_ptr from(::FILE* stream); + [[nodiscard]] static std::unique_ptr from(FILE* stream); [[nodiscard]] static std::unique_ptr from(std::istream* stream); [[nodiscard]] static std::unique_ptr from(std::byte const* bytes, size_t len); [[nodiscard]] static std::unique_ptr from(std::vector const* vector); @@ -144,7 +142,7 @@ namespace zenkit { [[nodiscard]] virtual size_t tell() const noexcept = 0; [[nodiscard]] static std::unique_ptr to(std::filesystem::path const& path); - [[nodiscard]] static std::unique_ptr to(::FILE* stream); + [[nodiscard]] static std::unique_ptr to(FILE* stream); [[nodiscard]] static std::unique_ptr to(std::ostream* stream); [[nodiscard]] static std::unique_ptr to(std::byte* bytes, size_t len); [[nodiscard]] static std::unique_ptr to(std::vector* vector); @@ -152,7 +150,7 @@ namespace zenkit { namespace proto { template - inline std::enable_if_t, void> + std::enable_if_t, void> read_chunked(Read* r, char const* name, std::function const& cb) { do { auto type = static_cast(r->read_ushort()); @@ -186,7 +184,7 @@ namespace zenkit { } template - inline std::enable_if_t, void> + std::enable_if_t, void> read_chunked(Read* r, char const* name, std::function const& cb) { do { auto type = static_cast(r->read_ushort()); @@ -220,8 +218,7 @@ namespace zenkit { } template - inline std::enable_if_t, void> - write_chunk(Write* w, T v, std::function const& cb) { + std::enable_if_t, void> write_chunk(Write* w, T v, std::function const& cb) { w->write_ushort(static_cast(v)); auto size_off = static_cast(w->tell()); diff --git a/include/zenkit/Texture.hh b/include/zenkit/Texture.hh index bff3002e..2969d6b7 100644 --- a/include/zenkit/Texture.hh +++ b/include/zenkit/Texture.hh @@ -3,9 +3,8 @@ #pragma once #include "zenkit/Library.hh" +#include #include -#include -#include #include namespace phoenix { @@ -16,7 +15,7 @@ namespace zenkit { class Read; class Write; - constexpr std::uint16_t const ZTEX_PALETTE_ENTRIES = 0x100; + constexpr std::uint16_t ZTEX_PALETTE_ENTRIES = 0x100; /// \brief Texture formats used by the ZenGin. enum class TextureFormat { @@ -53,86 +52,67 @@ namespace zenkit { Texture& operator=(Texture&&) = default; Texture& operator=(Texture const&) = default; - /// \brief Parses a texture from the data in the given buffer. - /// - ///

This implementation is heavily based on the implementation found in - /// [ZenLib](https://github.com/Try/ZenLib). - /// - /// \param[in,out] buf The buffer to read from. - /// \return The parsed texture. - /// \note After this function returns the position of \p buf will be at the end of the parsed object. - /// If you would like to keep your buffer immutable, consider passing a copy of it to #parse(buffer&&) - /// using buffer::duplicate. - /// \throws zenkit::ParserError if parsing fails. - /// \see #parse(buffer&&) [[nodiscard]] ZKREM("use ::load") ZKAPI static Texture parse(phoenix::buffer& in); - - /// \brief Parses a texture from the data in the given buffer. - /// \param[in,out] buf The buffer to read from (by rvalue-reference). - /// \return The parsed texture. - /// \throws zenkit::ParserError if parsing fails. - /// \see #parse(buffer&) [[nodiscard]] ZKREM("use ::load") ZKAPI static Texture parse(phoenix::buffer&& in); ZKAPI void load(Read* r); ZKAPI void save(Write* r) const; /// \return The format of the texture. - [[nodiscard]] ZKAPI inline TextureFormat format() const noexcept { + [[nodiscard]] ZKAPI TextureFormat format() const noexcept { return _m_format; } /// \return The width in pixels of the first mipmap level. - [[nodiscard]] ZKAPI inline std::uint32_t width() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t width() const noexcept { return _m_width; } /// \return The height in pixels of the first mipmap level. - [[nodiscard]] ZKAPI inline std::uint32_t height() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t height() const noexcept { return _m_height; } /// \param level The mipmap level to use (beginning from 0). /// \return The width in pixels of the given mipmap level. - [[nodiscard]] ZKAPI inline std::uint32_t mipmap_width(std::uint32_t level) const noexcept { + [[nodiscard]] ZKAPI std::uint32_t mipmap_width(std::uint32_t level) const noexcept { return _m_width >> level; } /// \param level The mipmap level to use (beginning from 0). /// \return The height in pixels of the given mipmap level. - [[nodiscard]] ZKAPI inline std::uint32_t mipmap_height(std::uint32_t level) const noexcept { + [[nodiscard]] ZKAPI std::uint32_t mipmap_height(std::uint32_t level) const noexcept { return _m_height >> level; } /// \return The width of the texture in-engine. - [[nodiscard]] ZKAPI inline std::uint32_t ref_width() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t ref_width() const noexcept { return _m_reference_width; } /// \return The height of the texture in-engine. - [[nodiscard]] ZKAPI inline std::uint32_t ref_height() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t ref_height() const noexcept { return _m_reference_height; } /// \return The number of mipmaps of the texture. - [[nodiscard]] ZKAPI inline std::uint32_t mipmaps() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t mipmaps() const noexcept { return _m_mipmap_count; } /// \return The average color of the texture. - [[nodiscard]] ZKAPI inline std::uint32_t average_color() const noexcept { + [[nodiscard]] ZKAPI std::uint32_t average_color() const noexcept { return _m_average_color; } /// \return The palette of the texture. - [[nodiscard]] ZKAPI inline ColorARGB* palette() const noexcept { - return (ColorARGB*) _m_palette; + [[nodiscard]] ZKAPI ColorARGB const* palette() const noexcept { + return _m_palette.data(); } /// \param mipmap_level The mipmap level to get. /// \return The texture data at the given mipmap level. - [[nodiscard]] ZKAPI inline std::vector const& - data(std::uint32_t mipmap_level = 0) const noexcept { + [[nodiscard]] ZKAPI std::vector const& data(std::uint32_t mipmap_level = 0) const noexcept { return _m_textures.at(_m_mipmap_count - 1 - mipmap_level); } @@ -144,7 +124,7 @@ namespace zenkit { private: TextureFormat _m_format {}; - ColorARGB _m_palette[ZTEX_PALETTE_ENTRIES] {}; + std::array _m_palette {}; std::uint32_t _m_width {}; std::uint32_t _m_height {}; std::uint32_t _m_reference_width {}; diff --git a/include/zenkit/Vfs.hh b/include/zenkit/Vfs.hh index 30587122..ba5d53d7 100644 --- a/include/zenkit/Vfs.hh +++ b/include/zenkit/Vfs.hh @@ -16,17 +16,17 @@ #include namespace zenkit { - class VfsBrokenDiskError : public Error { + class VfsBrokenDiskError final : public Error { public: ZKINT explicit VfsBrokenDiskError(std::string const& signature); }; - class VfsFileExistsError : public Error { + class VfsFileExistsError final : public Error { public: ZKINT explicit VfsFileExistsError(std::string const& name); }; - class VfsNotFoundError : public Error { + class VfsNotFoundError final : public Error { public: ZKINT explicit VfsNotFoundError(std::string const& name); }; @@ -191,7 +191,6 @@ namespace zenkit { private: ZKINT void mount_disk(std::byte const* buf, std::size_t size, VfsOverwriteBehavior overwrite); - private: VfsNode _m_root; std::vector> _m_data; diff --git a/include/zenkit/World.hh b/include/zenkit/World.hh index f853ffa6..d0621e50 100644 --- a/include/zenkit/World.hh +++ b/include/zenkit/World.hh @@ -69,7 +69,6 @@ namespace zenkit { class World : public Object { ZK_OBJECT(ObjectType::oCWorld); - public: [[nodiscard]] ZKREM("use ::load()") ZKAPI static World parse(phoenix::buffer& buf, GameVersion version); [[nodiscard]] ZKREM("use ::load()") ZKAPI static World parse(phoenix::buffer& buf); [[nodiscard]] ZKREM("use ::load()") ZKAPI static World parse(phoenix::buffer&& buf, GameVersion version); @@ -80,9 +79,8 @@ namespace zenkit { ZKAPI void load(ReadArchive& r, GameVersion version) override; ZKAPI void save(WriteArchive& w, GameVersion version) const override; - uint16_t get_version_identifier(GameVersion game) const override; + [[nodiscard]] ZKAPI uint16_t get_version_identifier(GameVersion game) const override; - public: /// \brief The list of VObs defined in this world. std::vector> world_vobs; diff --git a/include/zenkit/addon/daedalus.hh b/include/zenkit/addon/daedalus.hh index 860ba932..fd9551a7 100644 --- a/include/zenkit/addon/daedalus.hh +++ b/include/zenkit/addon/daedalus.hh @@ -19,7 +19,7 @@ // clang-format on namespace zenkit { - struct IGuildValues : public DaedalusInstance { + struct IGuildValues : DaedalusInstance { static constexpr std::uint32_t count = 66; var int32_t water_depth_knee[count]; @@ -175,7 +175,7 @@ namespace zenkit { }; FLAG(NpcFlag) - struct INpc : public DaedalusInstance { + struct INpc : DaedalusInstance { static constexpr std::uint32_t hitchance_count = 5; // -> TODO: one of "unknown", "one-handed", "two-handed", "bow", "crossbow" static constexpr std::uint32_t name_count = 5; @@ -218,7 +218,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IMission : public DaedalusInstance { + struct IMission : DaedalusInstance { var string name; var string description; var int32_t duration; @@ -263,7 +263,7 @@ namespace zenkit { }; FLAG(ItemFlag) - struct IItem : public DaedalusInstance { + struct IItem : DaedalusInstance { static constexpr std::uint32_t condition_count = 3; static constexpr std::uint32_t state_count = 4; static constexpr std::uint32_t text_count = 6; @@ -316,7 +316,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IFocus : public DaedalusInstance { + struct IFocus : DaedalusInstance { var float npc_longrange; var float npc_range1; var float npc_range2; @@ -345,7 +345,7 @@ namespace zenkit { var int32_t function = 0; }; - struct IInfo : public DaedalusInstance { + struct IInfo : DaedalusInstance { var int32_t npc; var int32_t nr; var int32_t important; @@ -363,7 +363,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IItemReact : public DaedalusInstance { + struct IItemReact : DaedalusInstance { var int32_t npc; var int32_t trade_item; var int32_t trade_amount; @@ -375,7 +375,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct ISpell : public DaedalusInstance { + struct ISpell : DaedalusInstance { var float time_per_mana; var int32_t damage_per_level; var int32_t damage_type; @@ -729,7 +729,7 @@ namespace zenkit { }; FLAG(MenuFlag) - struct IMenu : public DaedalusInstance { + struct IMenu : DaedalusInstance { static constexpr std::uint8_t item_count = 150; var string back_pic; @@ -846,7 +846,7 @@ namespace zenkit { execute_commands ZKREM("renamed to MenuItemSelectAction::EXECUTE_COMMANDS") = EXECUTE_COMMANDS, }; - struct IMenuItem : public DaedalusInstance { + struct IMenuItem : DaedalusInstance { static constexpr std::uint32_t text_count = 10; static constexpr std::uint32_t select_action_count = 5; static constexpr std::uint32_t event_action_count = 10; @@ -884,7 +884,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct ICamera : public DaedalusInstance { + struct ICamera : DaedalusInstance { var float best_range; var float min_range; var float max_range; @@ -944,7 +944,7 @@ namespace zenkit { measure ZKREM("renamed to MusicTransitionType::MEASURE") = MEASURE, }; - struct IMusicSystem : public DaedalusInstance { + struct IMusicSystem : DaedalusInstance { var float volume; var int32_t bit_resolution; var int32_t global_reverb_enabled; @@ -955,7 +955,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IMusicTheme : public DaedalusInstance { + struct IMusicTheme : DaedalusInstance { var string file; var float vol; var int32_t loop; @@ -967,7 +967,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IMusicJingle : public DaedalusInstance { + struct IMusicJingle : DaedalusInstance { var string name; var int32_t loop; var float vol; @@ -976,7 +976,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IParticleEffect : public DaedalusInstance { + struct IParticleEffect : DaedalusInstance { var float pps_value; var string pps_scale_keys_s; var int32_t pps_is_looping; @@ -1038,7 +1038,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IEffectBase : public DaedalusInstance { + struct IEffectBase : DaedalusInstance { static constexpr std::uint8_t user_string_count = 5; var string vis_name_s; @@ -1091,7 +1091,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct IParticleEffectEmitKey : public DaedalusInstance { + struct IParticleEffectEmitKey : DaedalusInstance { var string vis_name_s; var float vis_size_scale; var float scale_duration; @@ -1168,7 +1168,7 @@ namespace zenkit { wait_ext ZKREM("renamed to zenkit::WAIT_EXT") = WAIT_EXT, }; - struct IFightAi : public DaedalusInstance { + struct IFightAi : DaedalusInstance { static constexpr std::uint32_t move_count = 6; var FightAiMove move[move_count]; @@ -1176,7 +1176,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct ISoundEffect : public DaedalusInstance { + struct ISoundEffect : DaedalusInstance { var string file; var int32_t pitch_off; var int32_t pitch_var; @@ -1190,7 +1190,7 @@ namespace zenkit { ZKAPI static void register_(DaedalusScript& s); }; - struct ISoundSystem : public DaedalusInstance { + struct ISoundSystem : DaedalusInstance { var float volume; var int32_t bit_resolution; var int32_t sample_rate; diff --git a/include/zenkit/addon/texcvt.hh b/include/zenkit/addon/texcvt.hh index 0ae727d4..7eccbc6f 100644 --- a/include/zenkit/addon/texcvt.hh +++ b/include/zenkit/addon/texcvt.hh @@ -10,5 +10,5 @@ namespace zenkit { /// \brief Converts a texture to the DDS format. /// \param tex The texture to convert. /// \return A buffer containing the DDS file. - [[nodiscard]] ZKAPI std::vector to_dds(zenkit::Texture const& tex); + [[nodiscard]] ZKAPI std::vector to_dds(Texture const& tex); } // namespace zenkit diff --git a/include/zenkit/vobs/Camera.hh b/include/zenkit/vobs/Camera.hh index f679affa..3999e693 100644 --- a/include/zenkit/vobs/Camera.hh +++ b/include/zenkit/vobs/Camera.hh @@ -89,7 +89,6 @@ namespace zenkit { struct VCameraTrajectoryFrame : VirtualObject { ZK_OBJECT(ObjectType::zCCamTrj_KeyFrame); - public: float time; float roll_angle; float fov_scale; @@ -105,7 +104,7 @@ namespace zenkit { glm::mat4 original_pose; ZKREM("use ::load()") - ZKAPI static std::unique_ptr parse(ReadArchive& ctx, GameVersion version); + ZKAPI static std::unique_ptr parse(ReadArchive& r, GameVersion version); /// \brief Load this object from the given archive. /// \param r The archive to read from; @@ -122,7 +121,6 @@ namespace zenkit { struct VCutsceneCamera : VirtualObject { ZK_OBJECT(ObjectType::zCCSCamera); - public: /// \brief The reference coordinate system of camera trajectory keyframes. /// \note FOR stands for "frame of reference". CameraCoordinateReference trajectory_for; @@ -156,7 +154,7 @@ namespace zenkit { bool goto_time_mode {false}; float cs_time {0}; - ZKREM("use ::load()") ZKAPI static void parse(VCutsceneCamera& obj, ReadArchive& ctx, GameVersion version); + ZKREM("use ::load()") ZKAPI static void parse(VCutsceneCamera& obj, ReadArchive& r, GameVersion version); /// \brief Load this object from the given archive. /// \param r The archive to read from; diff --git a/include/zenkit/vobs/Light.hh b/include/zenkit/vobs/Light.hh index ae14c705..767c72d0 100644 --- a/include/zenkit/vobs/Light.hh +++ b/include/zenkit/vobs/Light.hh @@ -163,7 +163,6 @@ namespace zenkit { struct VLight : VirtualObject, LightPreset { ZK_OBJECT(ObjectType::zCVobLight); - public: ZKREM("use ::load()") ZKAPI static void parse(VLight& obj, ReadArchive& ctx, GameVersion version); /// \brief Load this object from the given archive. diff --git a/include/zenkit/vobs/Misc.hh b/include/zenkit/vobs/Misc.hh index 3b4eeeec..9602b81d 100644 --- a/include/zenkit/vobs/Misc.hh +++ b/include/zenkit/vobs/Misc.hh @@ -80,7 +80,6 @@ namespace zenkit { struct VAnimate : VirtualObject { ZK_OBJECT(ObjectType::zCVobAnimate); - public: /// \brief Whether to start this animation when loading the level. /// \see https://zk.gothickit.dev/engine/objects/zCVobAnimate/#startOn bool start_on {false}; @@ -110,7 +109,6 @@ namespace zenkit { struct VItem : VirtualObject { ZK_OBJECT(ObjectType::oCItem); - public: /// \brief The name of the script instance representing the item. /// \see https://zk.gothickit.dev/engine/objects/oCItem/#itemInstance std::string instance; @@ -139,7 +137,6 @@ namespace zenkit { struct VLensFlare : VirtualObject { ZK_OBJECT(ObjectType::zCVobLensFlare); - public: /// \brief The name of the lens flare effect. /// /// Must be one of the effects listed in `/_work/data/Presets/Lensflare.zen`. @@ -170,7 +167,6 @@ namespace zenkit { struct VParticleEffectController : VirtualObject { ZK_OBJECT(ObjectType::zCPFXController); - public: /// \brief The name of the particle effect. /// /// Corresponds to a `.ZEN` file containing the particle system definition. @@ -206,7 +202,6 @@ namespace zenkit { struct VMessageFilter : VirtualObject { ZK_OBJECT(ObjectType::zCMessageFilter); - public: /// \brief The name of the target VObject. /// /// All `OnTrigger` and `OnUntrigger` messages received by this `zCMessageFilter` VObject are transformed @@ -249,7 +244,6 @@ namespace zenkit { struct VCodeMaster : VirtualObject { ZK_OBJECT(ObjectType::zCCodeMaster); - public: /// \brief The name of the VObject to send an `OnTrigger` event to after all slaves have /// fired in the correct order. /// \see https://zk.gothickit.dev/engine/objects/zCCodeMaster/#triggerTarget @@ -311,7 +305,6 @@ namespace zenkit { struct VMoverController : VirtualObject { ZK_OBJECT(ObjectType::zCMoverController); - public: /// \brief The name of the VMover VOject that is controlled by this VMoverController. /// \see https://zk.gothickit.dev/engine/objects/zCMoverController/#triggerTarget std::string target; @@ -345,7 +338,6 @@ namespace zenkit { struct VTouchDamage : VirtualObject { ZK_OBJECT(ObjectType::oCTouchDamage); - public: /// \brief The amount of damage being dealt. /// \see https://zk.gothickit.dev/engine/objects/zCTouchDamage/#damage float damage; @@ -421,7 +413,6 @@ namespace zenkit { struct VEarthquake : VirtualObject { ZK_OBJECT(ObjectType::zCEarthquake); - public: /// \brief The radius of the earthquake effect /// \see https://zk.gothickit.dev/engine/objects/zCEarthquake/#radius float radius; @@ -452,13 +443,12 @@ namespace zenkit { struct VNpc : VirtualObject { ZK_OBJECT(ObjectType::oCNpc); - public: - static std::uint32_t const attribute_count = 8; - static std::uint32_t const hcs_count = 4; - static std::uint32_t const missions_count = 5; - static std::uint32_t const aivar_count = 100; - static std::uint32_t const packed_count = 9; - static std::uint32_t const protection_count = 8; + static constexpr std::uint32_t attribute_count = 8; + static constexpr std::uint32_t hcs_count = 4; + static constexpr std::uint32_t missions_count = 5; + static constexpr std::uint32_t aivar_count = 100; + static constexpr std::uint32_t packed_count = 9; + static constexpr std::uint32_t protection_count = 8; struct Talent : Object { static constexpr ObjectType TYPE = ObjectType::oCNpcTalent; @@ -576,7 +566,7 @@ namespace zenkit { /// \param version The version of the game to save for. ZKAPI void save(WriteArchive& w, GameVersion version) const override; - uint16_t get_version_identifier(GameVersion game) const override; + [[nodiscard]] ZKAPI uint16_t get_version_identifier(GameVersion game) const override; }; /// \brief Screen effect VObjects are used to create special effects. @@ -588,7 +578,6 @@ namespace zenkit { struct VScreenEffect : VirtualObject { ZK_OBJECT(ObjectType::zCVobScreenFX) - public: /// \brief Load this object from the given archive. /// \param r The archive to read from; /// \param version The version of the game the object was made for. diff --git a/include/zenkit/vobs/Sound.hh b/include/zenkit/vobs/Sound.hh index 6aba2bf0..72729e40 100644 --- a/include/zenkit/vobs/Sound.hh +++ b/include/zenkit/vobs/Sound.hh @@ -45,7 +45,6 @@ namespace zenkit { struct VSound : VirtualObject { ZK_OBJECT(ObjectType::zCVobSound); - public: /// \brief The volume of the sound effect in percent (0-100). /// \see https://zk.gothickit.dev/engine/objects/zCVobSound/#sndVolume float volume {0}; @@ -127,7 +126,6 @@ namespace zenkit { struct VSoundDaytime : VSound { ZK_OBJECT(ObjectType::zCVobSoundDaytime); - public: /// \brief The time of day after which the sound can be heard (`13.5` corresponds to `13:30`). /// /// Must be less than #start_time. diff --git a/include/zenkit/vobs/Trigger.hh b/include/zenkit/vobs/Trigger.hh index e929fbf4..90e4c68c 100644 --- a/include/zenkit/vobs/Trigger.hh +++ b/include/zenkit/vobs/Trigger.hh @@ -95,7 +95,6 @@ namespace zenkit { struct VTrigger : VirtualObject { ZK_OBJECT(ObjectType::zCTrigger); - public: /// \brief The name of VObject to send `OnTrigger` and `OnUntrigger` events to after processing. /// \see https://zk.gothickit.dev/engine/objects/zCTrigger/#triggerTarget std::string target; @@ -231,7 +230,6 @@ namespace zenkit { struct VMover : VTrigger { ZK_OBJECT(ObjectType::zCMover); - public: /// \brief Controls how the mover behaves in response to events ("activation") /// \see https://zk.gothickit.dev/engine/objects/zCMover/#moverBehavior MoverBehavior behavior {MoverBehavior::TOGGLE}; @@ -342,7 +340,6 @@ namespace zenkit { struct VTriggerList : VTrigger { ZK_OBJECT(ObjectType::zCTriggerList); - public: struct Target { /// \brief The name of the VObject to send events to. Behaves like VTrigger#target`. /// \see https://zk.gothickit.dev/engine/objects/zCTriggerList/#triggerTarget @@ -390,7 +387,6 @@ namespace zenkit { struct VTriggerScript : VTrigger { ZK_OBJECT(ObjectType::oCTriggerScript); - public: /// \brief The name script function to call when the trigger successfully processes a message. /// \see https://zk.gothickit.dev/engine/objects/oCTriggerScript/#scriptFunc std::string function {}; @@ -416,7 +412,6 @@ namespace zenkit { struct VTriggerChangeLevel : VTrigger { ZK_OBJECT(ObjectType::oCTriggerChangeLevel); - public: /// \brief The name of the level to load including the file extension. /// \see https://zk.gothickit.dev/engine/objects/oCTriggerChangeLevel/#levelName std::string level_name {}; @@ -446,7 +441,6 @@ namespace zenkit { struct VTriggerWorldStart : VirtualObject { ZK_OBJECT(ObjectType::zCTriggerWorldStart); - public: /// \brief The name of VObject to send an `OnTrigger` event to when the world is loaded and started. /// \see https://zk.gothickit.dev/engine/objects/zCTriggerChangeLevel/#triggerTarget std::string target; @@ -479,7 +473,6 @@ namespace zenkit { struct VTriggerUntouch : VirtualObject { ZK_OBJECT(ObjectType::zCTriggerUntouch); - public: /// \brief The name of VObject to send the `OnTrigger` events to. /// \see https://zk.gothickit.dev/engine/objects/zCTriggerUntouch/#triggerTarget std::string target; diff --git a/include/zenkit/vobs/VirtualObject.hh b/include/zenkit/vobs/VirtualObject.hh index 4fc31134..b86bc7ae 100644 --- a/include/zenkit/vobs/VirtualObject.hh +++ b/include/zenkit/vobs/VirtualObject.hh @@ -130,7 +130,6 @@ namespace zenkit { struct VisualDecal final : Visual { ZK_OBJECT(ObjectType::zCDecal); - public: /// \brief The size of the decal texture as a 2-dimensional vector. /// /// The `x`-coordinate is the width, and the `y`-coordinate is the height. @@ -201,7 +200,6 @@ namespace zenkit { struct EventManager final : Object { ZK_OBJECT(ObjectType::zCEventManager); - public: bool cleared = false; bool active = false; @@ -216,7 +214,6 @@ namespace zenkit { struct AiHuman final : Ai { ZK_OBJECT(ObjectType::oCAIHuman); - public: int water_level; float floor_y; float water_y; @@ -240,7 +237,6 @@ namespace zenkit { struct AiMove final : Ai { ZK_OBJECT(ObjectType::oCAIVobMove); - public: std::weak_ptr vob; std::weak_ptr owner; @@ -314,13 +310,12 @@ namespace zenkit { struct VirtualObject : Object { ZK_OBJECT(ObjectType::zCVob); - public: VirtualObject() = default; - /// \brief Implicit copy-constructor. Disabled for performance reasons. - explicit VirtualObject(VirtualObject const&) = default; + /// \brief Implicit copy-constructor. + VirtualObject(VirtualObject const&) = default; - /// \brief Move-constructor. Disabled for memory safety with shared references. + /// \brief Move-constructor. VirtualObject(VirtualObject&&) = default; /// \brief Default virtual destructor. diff --git a/include/zenkit/vobs/Zone.hh b/include/zenkit/vobs/Zone.hh index d57500ec..d2747175 100644 --- a/include/zenkit/vobs/Zone.hh +++ b/include/zenkit/vobs/Zone.hh @@ -22,7 +22,6 @@ namespace zenkit { struct VZoneMusic : VirtualObject { ZK_OBJECT(ObjectType::oCZoneMusic); - public: /// \brief Whether the music zone is enabled when loading the level. /// \see https://zk.gothickit.dev/engine/objects/oCZoneMusic/#enabled bool enabled {false}; @@ -81,7 +80,6 @@ namespace zenkit { struct VZoneFarPlane : VirtualObject { ZK_OBJECT(ObjectType::zCZoneVobFarPlane); - public: float vob_far_plane_z; float inner_range_percentage; @@ -104,7 +102,6 @@ namespace zenkit { struct VZoneFog : VirtualObject { ZK_OBJECT(ObjectType::zCZoneZFog); - public: float range_center {0}; float inner_range_percentage {0}; glm::u8vec4 color {}; diff --git a/include/zenkit/world/BspTree.hh b/include/zenkit/world/BspTree.hh index ce6e3bcb..b6351885 100644 --- a/include/zenkit/world/BspTree.hh +++ b/include/zenkit/world/BspTree.hh @@ -56,7 +56,6 @@ namespace zenkit { ZKINT void load(Read* r, std::uint32_t version); ZKINT void save(Write* w, GameVersion version) const; - public: /// \brief The mode of the tree (either indoor or outdoor). BspTreeType mode; diff --git a/include/zenkit/world/WayNet.hh b/include/zenkit/world/WayNet.hh index e99c1b6a..2e5a1253 100644 --- a/include/zenkit/world/WayNet.hh +++ b/include/zenkit/world/WayNet.hh @@ -73,11 +73,9 @@ namespace zenkit { class WayNet : public Object { ZK_OBJECT(ObjectType::zCWayNet); - public: ZKINT void load(ReadArchive& r, GameVersion version) override; ZKINT void save(WriteArchive& w, GameVersion version) const override; - public: /// \brief All waypoints of this way-net. std::vector> points; diff --git a/src/Archive.cc b/src/Archive.cc index d40a457c..09456a0f 100644 --- a/src/Archive.cc +++ b/src/Archive.cc @@ -160,32 +160,31 @@ namespace zenkit { {ObjectType::zCCSPoolItem, "zCCSPoolItem"}, }; - ReadArchive::ReadArchive(ArchiveHeader head, Read* r) : header(std::move(head)), read(r) {} + ReadArchive::ReadArchive(ArchiveHeader head, Read* read) : header(std::move(head)), read(read) {} - ReadArchive::ReadArchive(ArchiveHeader head, Read* r, std::unique_ptr owned) - : header(std::move(head)), read(r), _m_owned(std::move(owned)) {} + ReadArchive::ReadArchive(ArchiveHeader head, Read* read, std::unique_ptr owned) + : header(std::move(head)), read(read), _m_owned(std::move(owned)) {} void ArchiveHeader::load(Read* r) { try { if (r->read_line(true) != "ZenGin Archive") { ZKLOGE("ReadArchive", "Invalid Header"); - throw zenkit::ParserError {"ReadArchive", "magic missing"}; + throw ParserError {"ReadArchive", "magic missing"}; } std::string ver = r->read_line(true); if (ver.find("ver ") != 0) { - throw zenkit::ParserError {"ReadArchive", "ver field missing"}; + throw ParserError {"ReadArchive", "ver field missing"}; } this->version = std::stoi(ver.substr(ver.find(' ') + 1)); if (this->version != 1) { - throw zenkit::ParserError {"ReadArchive", "Unsupported format version: " + ver}; + throw ParserError {"ReadArchive", "Unsupported format version: " + ver}; } this->archiver = r->read_line(true); - auto fmt = r->read_line(true); - if (fmt == "ASCII") { + if (auto fmt = r->read_line(true); fmt == "ASCII") { this->format = ArchiveFormat::ASCII; } else if (fmt == "BINARY") { this->format = ArchiveFormat::BINARY; @@ -195,7 +194,7 @@ namespace zenkit { std::string save_game = r->read_line(true); if (save_game.find("saveGame ") != 0) { - throw zenkit::ParserError {"ReadArchive", "saveGame field missing"}; + throw ParserError {"ReadArchive", "saveGame field missing"}; } this->save = std::stoi(save_game.substr(save_game.find(' ') + 1)) != 0; @@ -211,10 +210,10 @@ namespace zenkit { } if (optional != "END") { - throw zenkit::ParserError {"ReadArchive", "first END missing"}; + throw ParserError {"ReadArchive", "first END missing"}; } } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive", e, "reading int"}; + throw ParserError {"ReadArchive", e, "reading int"}; } } @@ -232,9 +231,9 @@ namespace zenkit { } else if (header.format == ArchiveFormat::BINSAFE) { reader = std::make_unique(std::move(header), read.get(), std::move(read)); } else { - throw zenkit::ParserError {"ReadArchive", - "format '" + std::to_string(static_cast(header.format)) + - "' is not supported"}; + throw ParserError {"ReadArchive", + "format '" + std::to_string(static_cast(header.format)) + + "' is not supported"}; } reader->read_header(); @@ -291,7 +290,7 @@ namespace zenkit { } auto it = OBJECTS.find(obj.class_name); - ObjectType type = ObjectType::unknown; + auto type = ObjectType::unknown; if (it != OBJECTS.end()) { type = it->second; } @@ -500,7 +499,7 @@ namespace zenkit { if (syn != nullptr) { // TODO(lmichaelis): The VOb type/id assignment is a hacky workaround! Create separate types! if (is_vobject(type)) { - VirtualObjectType vtype = static_cast(type); + auto vtype = static_cast(type); reinterpret_cast(syn.get())->type = vtype; reinterpret_cast(syn.get())->id = obj.index; } @@ -551,13 +550,12 @@ namespace zenkit { return ar; } - void WriteArchive::write_object(std::shared_ptr obj, GameVersion version) { + void WriteArchive::write_object(std::shared_ptr const& obj, GameVersion version) { this->write_object("%", obj, version); } - void WriteArchive::write_object(std::string_view name, std::shared_ptr obj, GameVersion version) { - auto it = _m_cache.find(obj.get()); - if (it != _m_cache.end()) { + void WriteArchive::write_object(std::string_view name, std::shared_ptr const& obj, GameVersion version) { + if (auto it = _m_cache.find(obj.get()); it != _m_cache.end()) { this->write_ref(name, it->second); return; } diff --git a/src/Boxes.cc b/src/Boxes.cc index 6bbeb492..3966aa09 100644 --- a/src/Boxes.cc +++ b/src/Boxes.cc @@ -36,7 +36,7 @@ namespace zenkit { return bbox; } - void OrientedBoundingBox::load(zenkit::Read* r) { + void OrientedBoundingBox::load(Read* r) { center = r->read_vec3(); axes[0] = r->read_vec3(); axes[1] = r->read_vec3(); diff --git a/src/CutsceneLibrary.cc b/src/CutsceneLibrary.cc index a673c08d..a3672dcf 100644 --- a/src/CutsceneLibrary.cc +++ b/src/CutsceneLibrary.cc @@ -18,8 +18,8 @@ namespace zenkit { return msgs; } - CutsceneLibrary CutsceneLibrary::parse(phoenix::buffer&& path) { - return CutsceneLibrary::parse(path); + CutsceneLibrary CutsceneLibrary::parse(phoenix::buffer&& buf) { + return parse(buf); } CutsceneBlock const* CutsceneLibrary::block_by_name(std::string_view name) const { @@ -39,11 +39,11 @@ namespace zenkit { ArchiveObject obj; if (!archive->read_object_begin(obj)) { - throw zenkit::ParserError {"CutsceneLibrary", "root object missing"}; + throw ParserError {"CutsceneLibrary", "root object missing"}; } if (obj.class_name != "zCCSLib") { - throw zenkit::ParserError {"CutsceneLibrary", "root object is not 'zCCSLib'"}; + throw ParserError {"CutsceneLibrary", "root object is not 'zCCSLib'"}; } auto item_count = archive->read_int(); // NumOfItems @@ -51,7 +51,7 @@ namespace zenkit { for (auto& itm : this->blocks) { if (!archive->read_object_begin(obj) || obj.class_name != "zCCSBlock") { - throw zenkit::ParserError {"CutsceneLibrary", "expected 'zCCSBlock' but didn't find it"}; + throw ParserError {"CutsceneLibrary", "expected 'zCCSBlock' but didn't find it"}; } itm.name = archive->read_string(); // blockName @@ -59,17 +59,17 @@ namespace zenkit { (void) archive->read_float(); // subBlock0 if (block_count != 1) { - throw zenkit::ParserError {"CutsceneLibrary", - "expected only one block but got " + std::to_string(block_count) + " for " + - itm.name}; + throw ParserError {"CutsceneLibrary", + "expected only one block but got " + std::to_string(block_count) + " for " + + itm.name}; } if (!archive->read_object_begin(obj) || obj.class_name != "zCCSAtomicBlock") { - throw zenkit::ParserError {"CutsceneLibrary", "Expected atomic block not found for " + itm.name}; + throw ParserError {"CutsceneLibrary", "Expected atomic block not found for " + itm.name}; } if (!archive->read_object_begin(obj) || obj.class_name != "oCMsgConversation:oCNpcMessage:zCEventMessage") { - throw zenkit::ParserError {"CutsceneLibrary", "Expected oCMsgConversation not found for " + itm.name}; + throw ParserError {"CutsceneLibrary", "Expected oCMsgConversation not found for " + itm.name}; } itm.message.type = archive->read_enum(); // subType diff --git a/src/DaedalusScript.cc b/src/DaedalusScript.cc index 35599315..12cd28a8 100644 --- a/src/DaedalusScript.cc +++ b/src/DaedalusScript.cc @@ -18,7 +18,7 @@ namespace zenkit { std::string&& provided) : DaedalusMemberRegistrationError(s, "wrong datatype: provided '" + provided + "' expected " + - DAEDALUS_DATA_TYPE_NAMES[(std::uint32_t) s->type()]) {} + DAEDALUS_DATA_TYPE_NAMES[static_cast(s->type())]) {} DaedalusIllegalTypeAccess::DaedalusIllegalTypeAccess(DaedalusSymbol const* s, DaedalusDataType expected_dt) : DaedalusIllegalAccess("illegal access of type " + std::to_string(static_cast(expected_dt)) + @@ -130,7 +130,7 @@ namespace zenkit { } std::uint32_t text_size = r->read_uint(); - std::vector code(text_size, std::byte {}); + std::vector code(text_size, std::byte {}); r->read(code.data(), text_size); this->_m_text = Read::from(std::move(code)); @@ -150,7 +150,7 @@ namespace zenkit { DaedalusSymbol const* DaedalusScript::find_symbol_by_name(std::string_view name) const { std::string up {name}; - std::transform(up.begin(), up.end(), up.begin(), ::toupper); + std::transform(up.begin(), up.end(), up.begin(), toupper); if (auto it = _m_symbols_by_name.find(up); it != _m_symbols_by_name.end()) { return find_symbol_by_index(it->second); @@ -176,7 +176,7 @@ namespace zenkit { DaedalusSymbol* DaedalusScript::find_symbol_by_name(std::string_view name) { std::string up {name}; - std::transform(up.begin(), up.end(), up.begin(), ::toupper); + std::transform(up.begin(), up.end(), up.begin(), toupper); if (auto it = _m_symbols_by_name.find(up); it != _m_symbols_by_name.end()) { return find_symbol_by_index(it->second); @@ -323,6 +323,8 @@ namespace zenkit { s[i] = '\t'; s.erase(i + 1, 1); break; + default: + break; } } } @@ -344,7 +346,7 @@ namespace zenkit { this->_m_count = (properties >> 0U) & 0xFFFU; // 12 bits this->_m_type = static_cast((properties >> 12U) & 0xFU); // 4 bits - this->_m_flags = static_cast((properties >> 16U) & 0x3FU); // 6 bits + this->_m_flags = properties >> 16U & 0x3FU; // 6 bits if (this->is_member()) { this->_m_member_offset = vary; @@ -364,13 +366,13 @@ namespace zenkit { switch (this->_m_type) { case DaedalusDataType::FLOAT: { std::unique_ptr value {new float[this->_m_count]}; - r->read((std::uint8_t*) value.get(), this->_m_count * sizeof(float)); + r->read(value.get(), this->_m_count * sizeof(float)); this->_m_value = std::move(value); break; } case DaedalusDataType::INT: { std::unique_ptr value {new std::int32_t[this->_m_count]}; - r->read((std::uint8_t*) value.get(), this->_m_count * sizeof(std::uint32_t)); + r->read(value.get(), this->_m_count * sizeof(std::uint32_t)); this->_m_value = std::move(value); break; } @@ -415,9 +417,8 @@ namespace zenkit { unsigned byte = 4; for (; byte > 0; --byte) { r->seek(-3, Whence::CUR); - auto parent_index = r->read_int(); - if (parent_index == -1) { + if (auto parent_index = r->read_int(); parent_index == -1) { // This parent index is valid. this->_m_parent = parent_index; break; @@ -452,9 +453,9 @@ namespace zenkit { } return *get_member_ptr(index, context); - } else { - return std::get>(_m_value)[index]; } + + return std::get>(_m_value)[index]; } float DaedalusSymbol::get_float(std::uint16_t index, DaedalusInstance const* context) const { @@ -476,9 +477,9 @@ namespace zenkit { } return *get_member_ptr(static_cast(index), context); - } else { - return std::get>(_m_value)[index]; } + + return std::get>(_m_value)[index]; } std::int32_t DaedalusSymbol::get_int(std::uint16_t index, DaedalusInstance const* context) const { @@ -500,9 +501,9 @@ namespace zenkit { } return *get_member_ptr(index, context); - } else { - return std::get>(_m_value)[index]; } + + return std::get>(_m_value)[index]; } void DaedalusSymbol::set_string(std::string_view value, std::uint16_t index, DaedalusInstance* context) { @@ -611,7 +612,7 @@ namespace zenkit { str_count += member->count(); } - _m_storage.reset(new uint8_t[sym.class_size()]()); + _m_storage.reset(new uint8_t[sym.class_size()]); _m_strings.resize(str_count, nullptr); str_count = 0; @@ -665,6 +666,4 @@ namespace zenkit { DaedalusTransientInstance::DaedalusTransientInstance() { _m_type = &typeid(DaedalusTransientInstance); } - - DaedalusTransientInstance::~DaedalusTransientInstance() {} } // namespace zenkit diff --git a/src/DaedalusVm.cc b/src/DaedalusVm.cc index 410288b4..260cd56c 100644 --- a/src/DaedalusVm.cc +++ b/src/DaedalusVm.cc @@ -24,7 +24,6 @@ namespace zenkit { /// guard.inhibit(); /// \endcode struct StackGuard { - public: /// \brief Creates a new stack guard. /// \param machine The VM this instance is guarding. /// \param type The type of value to push if the guard is triggered. @@ -38,8 +37,6 @@ namespace zenkit { if (_m_inhibited) return; switch (_m_type) { - case DaedalusDataType::VOID: - break; case DaedalusDataType::FLOAT: _m_machine->push_float(0); break; @@ -53,8 +50,8 @@ namespace zenkit { case DaedalusDataType::INSTANCE: _m_machine->push_instance(nullptr); break; + case DaedalusDataType::VOID: case DaedalusDataType::CLASS: - break; case DaedalusDataType::PROTOTYPE: break; } @@ -120,16 +117,16 @@ namespace zenkit { } void DaedalusVm::unsafe_set_gi(std::shared_ptr i) { - _m_instance = i; + _m_instance = std::move(i); } bool DaedalusVm::exec() { auto instr = instruction_at(_m_pc); - std::int32_t a {}, b {}; - DaedalusSymbol* sym {}; - try { + std::int32_t a, b; + DaedalusSymbol* sym; + switch (instr.op) { case DaedalusOpcode::ADD: push_int(pop_int() + pop_int()); @@ -230,8 +227,7 @@ namespace zenkit { case DaedalusOpcode::BL: { // Check if the function is overridden and if it is, call the resulting external. sym = find_symbol_by_address(instr.address); - auto cb = _m_function_overrides.find(instr.address); - if (cb != _m_function_overrides.end()) { + if (auto cb = _m_function_overrides.find(instr.address); cb != _m_function_overrides.end()) { // Guard against exceptions during external invocation. StackGuard guard {this, sym->rtype()}; // Call maybe naked. @@ -263,9 +259,9 @@ namespace zenkit { (*_m_default_external)(*this, *sym); guard.inhibit(); break; - } else { - throw DaedalusVmException {"be: no external registered for " + sym->name()}; } + + throw DaedalusVmException {"be: no external registered for " + sym->name()}; } push_call(sym); @@ -423,7 +419,7 @@ namespace zenkit { } _m_pc += instr.size; - } catch (zenkit::DaedalusScriptError& err) { + } catch (DaedalusScriptError& err) { uint32_t prev_pc = _m_pc; if (_m_exception_handler) { @@ -432,14 +428,16 @@ namespace zenkit { if (strategy == DaedalusVmExceptionStrategy::FAIL) { ZKLOGE("DaedalusVm", "+++ Error while executing script: %s +++", err.what()); print_stack_trace(); - throw err; - } else if (strategy == DaedalusVmExceptionStrategy::RETURN) { + throw; + } + + if (strategy == DaedalusVmExceptionStrategy::RETURN) { return false; } } else { ZKLOGE("DaedalusVm", "+++ Error while executing script: %s +++", err.what()); print_stack_trace(); - throw err; + throw; } if (_m_pc == prev_pc) { @@ -462,7 +460,7 @@ namespace zenkit { } void DaedalusVm::push_int(std::int32_t value) { - if (_m_stack_ptr == DaedalusVm::stack_size) { + if (_m_stack_ptr == stack_size) { throw DaedalusVmException {"stack overflow"}; } @@ -470,7 +468,7 @@ namespace zenkit { } void DaedalusVm::push_reference(DaedalusSymbol* value, std::uint8_t index) { - if (_m_stack_ptr == DaedalusVm::stack_size) { + if (_m_stack_ptr == stack_size) { throw DaedalusVmException {"stack overflow"}; } @@ -483,7 +481,7 @@ namespace zenkit { } void DaedalusVm::push_float(float value) { - if (_m_stack_ptr == DaedalusVm::stack_size) { + if (_m_stack_ptr == stack_size) { throw DaedalusVmException {"stack overflow"}; } @@ -491,7 +489,7 @@ namespace zenkit { } void DaedalusVm::push_instance(std::shared_ptr value) { - if (_m_stack_ptr == DaedalusVm::stack_size) { + if (_m_stack_ptr == stack_size) { throw DaedalusVmException {"stack overflow"}; } @@ -507,11 +505,13 @@ namespace zenkit { if (v.reference) { return this->get_int(v.context, v.value, v.index); - } else if (std::holds_alternative(v.value)) { + } + + if (std::holds_alternative(v.value)) { return std::get(v.value); - } else { - throw DaedalusVmException {"tried to pop_int but frame does not contain a int."}; } + + throw DaedalusVmException {"tried to pop_int but frame does not contain a int."}; } float DaedalusVm::pop_float() { @@ -523,18 +523,22 @@ namespace zenkit { if (v.reference) { return this->get_float(v.context, v.value, v.index); - } else if (std::holds_alternative(v.value)) { + } + + if (std::holds_alternative(v.value)) { return std::get(v.value); - } else if (std::holds_alternative(v.value)) { + } + + if (std::holds_alternative(v.value)) { auto k = std::get(v.value); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" - return *(float*) &k; + return *reinterpret_cast(&k); #pragma GCC diagnostic pop - } else { - throw DaedalusVmException {"tried to pop_float but frame does not contain a float."}; } + + throw DaedalusVmException {"tried to pop_float but frame does not contain a float."}; } std::tuple> DaedalusVm::pop_reference() { @@ -560,11 +564,13 @@ namespace zenkit { if (v.reference) { return std::get(v.value)->get_instance(); - } else if (std::holds_alternative>(v.value)) { + } + + if (std::holds_alternative>(v.value)) { return std::get>(v.value); - } else { - throw DaedalusVmException {"tried to pop_instance but frame does not contain am instance."}; } + + throw DaedalusVmException {"tried to pop_instance but frame does not contain am instance."}; } std::string const& DaedalusVm::pop_string() { @@ -594,12 +600,11 @@ namespace zenkit { } void DaedalusVm::register_default_external(std::function const& callback) { - _m_default_external = [this, callback](DaedalusVm& v, DaedalusSymbol& sym) { + _m_default_external = [this, callback](DaedalusVm& v, DaedalusSymbol const& sym) { // pop all parameters from the stack auto params = find_parameters_for_function(&sym); for (int i = static_cast(params.size()) - 1; i >= 0; --i) { auto par = params[static_cast(i)]; - if (par->type() == DaedalusDataType::INT) (void) v.pop_int(); else if (par->type() == DaedalusDataType::FLOAT) @@ -643,7 +648,7 @@ namespace zenkit { auto last_pc = _m_pc; auto tmp_stack_ptr = _m_stack_ptr; - std::stack callstack {_m_call_stack}; + std::stack callstack {_m_call_stack}; ZKLOGE("DaedalusVm", "------- CALL STACK (MOST RECENT CALL FIRST) -------"); @@ -681,8 +686,7 @@ namespace zenkit { break; } case DaedalusDataType::INSTANCE: { - auto& inst = ref->get_instance(); - if (inst != nullptr) { + if (auto& inst = ref->get_instance(); inst != nullptr) { value = "_m_type->name()) + "'>"; } else { value = "NULL"; @@ -705,8 +709,7 @@ namespace zenkit { } else if (std::holds_alternative(v.value)) { ZKLOGE("DaedalusVm", "%d: [IMMEDIATE INT] = %d", tmp_stack_ptr, std::get(v.value)); } else if (std::holds_alternative>(v.value)) { - auto& inst = std::get>(v.value); - if (inst == nullptr) { + if (auto& inst = std::get>(v.value); inst == nullptr) { ZKLOGE("DaedalusVm", "%d: [IMMEDIATE INSTANCE] = NULL", tmp_stack_ptr); } else { ZKLOGE("DaedalusVm", @@ -731,8 +734,7 @@ namespace zenkit { for (auto* sym : symbols) { if (sym == nullptr) continue; - auto instance = sym->get_instance(); - if (instance != nullptr) { + if (auto instance = sym->get_instance(); instance != nullptr) { DaedalusSymbol const* instance_symbol = find_symbol_by_instance(instance); ZKLOGE("DaedalusVm", "%s = %s (%u)", @@ -757,10 +759,10 @@ namespace zenkit { DaedalusIllegalExternalReturnType::DaedalusIllegalExternalReturnType(DaedalusSymbol const* s, std::string&& provided) - : DaedalusIllegalExternalDefinition(s, - "external " + s->name() + " has illegal return type '" + provided + - "', expected '" + DAEDALUS_DATA_TYPE_NAMES[(std::uint32_t) s->rtype()] + - "'") {} + : DaedalusIllegalExternalDefinition( + s, + "external " + s->name() + " has illegal return type '" + provided + "', expected '" + + DAEDALUS_DATA_TYPE_NAMES[static_cast(s->rtype())] + "'") {} DaedalusIllegalExternalParameter::DaedalusIllegalExternalParameter(DaedalusSymbol const* s, std::string&& provided, @@ -768,7 +770,8 @@ namespace zenkit { : DaedalusIllegalExternalDefinition(s, "external " + s->name() + " has illegal parameter type '" + provided + "' (no. " + std::to_string(i) + "), expected '" + - DAEDALUS_DATA_TYPE_NAMES[(std::uint32_t) s->type()] + "'") {} + DAEDALUS_DATA_TYPE_NAMES[static_cast(s->type())] + "'") { + } DaedalusVmExceptionStrategy lenient_vm_exception_handler(DaedalusVm& v, DaedalusScriptError const& exc, DaedalusInstruction const& instr) { @@ -843,9 +846,9 @@ namespace zenkit { } std::int32_t - DaedalusVm::get_int(std::shared_ptr& context, - std::variant>& value, - uint16_t index) { + DaedalusVm::get_int(std::shared_ptr const& context, + std::variant> const& value, + uint16_t index) const { auto* sym = std::get(value); // compatibility: sometimes the context might be zero, but we can't fail so when @@ -862,9 +865,10 @@ namespace zenkit { return sym->get_int(index, context.get()); } - float DaedalusVm::get_float(std::shared_ptr& context, - std::variant>& value, - uint16_t index) { + float + DaedalusVm::get_float(std::shared_ptr const& context, + std::variant> const& value, + uint16_t index) const { auto* sym = std::get(value); // compatibility: sometimes the context might be zero, but we can't fail so when @@ -881,7 +885,7 @@ namespace zenkit { return sym->get_float(index, context.get()); } - void DaedalusVm::set_int(std::shared_ptr& context, + void DaedalusVm::set_int(std::shared_ptr const& context, DaedalusSymbol* ref, uint16_t index, std::int32_t value) { @@ -897,7 +901,7 @@ namespace zenkit { } } - void DaedalusVm::set_float(std::shared_ptr& context, + void DaedalusVm::set_float(std::shared_ptr const& context, DaedalusSymbol* ref, uint16_t index, float value) { @@ -913,7 +917,7 @@ namespace zenkit { } } - void DaedalusVm::set_string(std::shared_ptr& context, + void DaedalusVm::set_string(std::shared_ptr const& context, DaedalusSymbol* ref, uint16_t index, std::string_view value) { diff --git a/src/Error.cc b/src/Error.cc index 0ea5ddba..ce190a21 100644 --- a/src/Error.cc +++ b/src/Error.cc @@ -3,7 +3,7 @@ #include "zenkit/Error.hh" namespace zenkit { - Error::Error(std::string&& msg) : std::exception(), message(std::move(msg)) {} + Error::Error(std::string&& msg) : message(std::move(msg)) {} ParserError::ParserError(std::string&& type) : Error("failed parsing resource of type " + type), resource_type(type) {} diff --git a/src/Font.cc b/src/Font.cc index c315c838..7cf6e306 100644 --- a/src/Font.cc +++ b/src/Font.cc @@ -23,13 +23,12 @@ namespace zenkit { } Font Font::parse(phoenix::buffer&& in) { - return Font::parse(in); + return parse(in); } void Font::load(Read* r) { - auto version = r->read_line(true); - if (version != "1") { - throw zenkit::ParserError {"Font", "version mismatch: expected version 1, got " + version}; + if (auto version = r->read_line(true); version != "1") { + throw ParserError {"Font", "version mismatch: expected version 1, got " + version}; } this->name = r->read_line(false); diff --git a/src/Logger.cc b/src/Logger.cc index 1ed9afdd..f8efbd5b 100644 --- a/src/Logger.cc +++ b/src/Logger.cc @@ -25,7 +25,7 @@ namespace zenkit { ZKINT static void zk_internal_logger_default(LogLevel level, char const* name, char const* message) { time_t now_t = time(nullptr); - struct tm* now = gmtime(&now_t); + tm* now = gmtime(&now_t); fprintf(stderr, ANSI_GRAY "%04d-%02d-%02d %02d:%02d:%02d " ANSI_RESET, @@ -56,13 +56,13 @@ namespace zenkit { } void Logger::use_logger(std::function&& callback) { - Logger::set(LogLevel::INFO, [callback](LogLevel lvl, std::string_view name, std::string_view sv) { + set(LogLevel::INFO, [callback](LogLevel lvl, std::string_view name, std::string_view sv) { callback(lvl, std::string {name} + ": " + std::string {sv}); }); } void Logger::use_default_logger() { - Logger::set_default(LogLevel::INFO); + set_default(LogLevel::INFO); } void Logger::log(LogLevel lvl, char const* name, char const* fmt, ...) { diff --git a/src/Mesh.cc b/src/Mesh.cc index bde5569d..fcef750d 100644 --- a/src/Mesh.cc +++ b/src/Mesh.cc @@ -4,8 +4,6 @@ #include "zenkit/Archive.hh" #include "zenkit/Stream.hh" -#include "Internal.hh" - namespace zenkit { [[maybe_unused]] static constexpr auto MESH_VERSION_G1 = 9; static constexpr auto MESH_VERSION_G2 = 265; @@ -39,7 +37,7 @@ namespace zenkit { } Mesh Mesh::parse(phoenix::buffer&& buf, std::vector const& include_polygons) { - return Mesh::parse(buf, include_polygons); + return parse(buf, include_polygons); } void Mesh::load(Read* r, std::vector const& leaf_polygons, bool force_wide_indices) { @@ -210,11 +208,11 @@ namespace zenkit { continue; } - auto root = 0u; auto a = 1u; // NOTE(lmichaelis): This unpacks triangle fans for (auto b = 2u; b < polygon.vertices.size(); ++b) { + auto root = 0u; this->polygons.vertex_indices.push_back(polygon.vertices[root]); this->polygons.vertex_indices.push_back(polygon.vertices[a]); this->polygons.vertex_indices.push_back(polygon.vertices[b]); diff --git a/src/MmapPosix.cc b/src/MmapPosix.cc index 7589b720..f6d289c8 100644 --- a/src/MmapPosix.cc +++ b/src/MmapPosix.cc @@ -15,12 +15,13 @@ namespace zenkit { throw std::runtime_error {"Failed to open " + path.string()}; } - struct ::stat st {}; + struct stat st {}; if (fstat(handle, &st) != 0) { throw std::runtime_error {"Failed to stat " + path.string()}; } - _m_data = (std::byte*) ::mmap(nullptr, (::size_t) st.st_size, PROT_READ, MAP_SHARED, handle, 0); + _m_data = + static_cast(mmap(nullptr, static_cast(st.st_size), PROT_READ, MAP_SHARED, handle, 0)); if (_m_data == nullptr) { throw std::runtime_error {"Failed to mmap " + path.string()}; } @@ -41,7 +42,7 @@ namespace zenkit { Mmap::~Mmap() noexcept { if (_m_data != nullptr) { - ::munmap((void*) _m_data, _m_size); + munmap((void*) _m_data, _m_size); _m_data = nullptr; _m_platform_handle = nullptr; } diff --git a/src/ModelAnimation.cc b/src/ModelAnimation.cc index a9262e68..ced512a2 100644 --- a/src/ModelAnimation.cc +++ b/src/ModelAnimation.cc @@ -9,13 +9,13 @@ namespace zenkit { /// \brief The highest number representable by a single rotation component. - static float const SAMPLE_ROTATION_RANGE = float(1 << 16) - 1.0f; + constexpr float SAMPLE_ROTATION_RANGE = static_cast(1 << 16) - 1.0f; /// \brief The scaling factor applied to each rotation component. - static float const SAMPLE_ROTATION_SCALE = (1.0f / SAMPLE_ROTATION_RANGE) * 2.1f; + constexpr float SAMPLE_ROTATION_SCALE = (1.0f / SAMPLE_ROTATION_RANGE) * 2.1f; /// \brief The number half way to `SAMPLE_ROTATION_RANGE`. - static std::uint16_t const SAMPLE_ROTATION_MID = (1 << 15) - 1; + constexpr std::uint16_t SAMPLE_ROTATION_MID = (1 << 15) - 1; enum class AnimationChunkType : std::uint16_t { MARKER = 0xa000u, @@ -33,9 +33,9 @@ namespace zenkit { /// \see http://phoenix.gothickit.dev/engine/formats/animation/#sample-positions static glm::vec3 read_sample_position(Read* r, float scale, float minimum) { glm::vec3 v {}; - v.x = (float) r->read_ushort() * scale + minimum; - v.y = (float) r->read_ushort() * scale + minimum; - v.z = (float) r->read_ushort() * scale + minimum; + v.x = static_cast(r->read_ushort()) * scale + minimum; + v.y = static_cast(r->read_ushort()) * scale + minimum; + v.z = static_cast(r->read_ushort()) * scale + minimum; return v; } @@ -45,21 +45,21 @@ namespace zenkit { /// \see http://phoenix.gothickit.dev/engine/formats/animation/#sample-rotations static glm::quat read_sample_quaternion(Read* r) { glm::quat v {}; - v.x = ((float) r->read_ushort() - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; - v.y = ((float) r->read_ushort() - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; - v.z = ((float) r->read_ushort() - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; + v.x = (static_cast(r->read_ushort()) - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; + v.y = (static_cast(r->read_ushort()) - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; + v.z = (static_cast(r->read_ushort()) - SAMPLE_ROTATION_MID) * SAMPLE_ROTATION_SCALE; float len_q = v.x * v.x + v.y * v.y + v.z * v.z; if (len_q > 1.0f) { - float l = 1.0f / ::sqrtf(len_q); + float l = 1.0f / sqrtf(len_q); v.x *= l; v.y *= l; v.z *= l; v.w = 0; } else { // We know the quaternion has to be a unit quaternion, so we can calculate the missing value. - v.w = ::sqrtf(1.0f - len_q); + v.w = sqrtf(1.0f - len_q); } return v; @@ -79,7 +79,7 @@ namespace zenkit { } ModelAnimation ModelAnimation::parse(phoenix::buffer&& in) { - return ModelAnimation::parse(in); + return parse(in); } void ModelAnimation::load(Read* r) { diff --git a/src/ModelHierarchy.cc b/src/ModelHierarchy.cc index ddf6502c..c3ddb512 100644 --- a/src/ModelHierarchy.cc +++ b/src/ModelHierarchy.cc @@ -21,8 +21,8 @@ namespace zenkit { return hierarchy; } - zenkit::ModelHierarchy zenkit::ModelHierarchy::parse(phoenix::buffer&& in) { - return ModelHierarchy::parse(in); + ModelHierarchy ModelHierarchy::parse(phoenix::buffer&& in) { + return parse(in); } void ModelHierarchy::load(Read* r) { @@ -32,8 +32,7 @@ namespace zenkit { [this](Read* c, ModelHierarchyChunkType type) { switch (type) { case ModelHierarchyChunkType::HIERARCHY: { - auto version = c->read_uint(); - if (version != 0x03) { + if (auto version = c->read_uint(); version != 0x03) { ZKLOGW("ModelHierarchy", "Trying to parse ModelHierarchy with unsupported version %d", version); } diff --git a/src/ModelMesh.cc b/src/ModelMesh.cc index c7af6e84..cf1a37b5 100644 --- a/src/ModelMesh.cc +++ b/src/ModelMesh.cc @@ -79,8 +79,8 @@ namespace zenkit { } void ModelMesh::save(Write* w, GameVersion version) const { - proto::write_chunk(w, ModelMeshChunkType::HEADER, [version](Write* w) { - w->write_uint(version == GameVersion::GOTHIC_1 ? VERSION_G1 : VERSION_G2); + proto::write_chunk(w, ModelMeshChunkType::HEADER, [version](Write* wr) { + wr->write_uint(version == GameVersion::GOTHIC_1 ? VERSION_G1 : VERSION_G2); }); /* TODO: Source Chunk @@ -117,6 +117,6 @@ namespace zenkit { } ModelMesh ModelMesh::parse(phoenix::buffer&& buf) { - return ModelMesh::parse(buf); + return parse(buf); } } // namespace zenkit diff --git a/src/ModelScript.cc b/src/ModelScript.cc index 544bad44..664c3d15 100644 --- a/src/ModelScript.cc +++ b/src/ModelScript.cc @@ -81,8 +81,7 @@ namespace zenkit { MdsEventTag evt {}; evt.frame = frame; - auto tp = event_types.find(type); - if (tp == event_types.end()) { + if (auto tp = event_types.find(type); tp == event_types.end()) { evt.type = MdsEventType::UNKNOWN; ZKLOGW("ModelScript", "Unexpected value for MdsEventType: \"%s\"", type.c_str()); } else { @@ -100,9 +99,7 @@ namespace zenkit { evt.slot = a.value_or(""); break; case MdsEventType::SET_FIGHT_MODE: { - auto mode = a.value_or(""); - - if (mode == "FIST") { + if (auto mode = a.value_or(""); mode == "FIST") { evt.fight_mode = MdsFightMode::FIST; } else if (mode == "1H" || mode == "1h") { evt.fight_mode = MdsFightMode::SINGLE_HANDED; @@ -150,7 +147,7 @@ namespace zenkit { } AnimationFlags animation_flags_from_string(std::string_view str) { - AnimationFlags flags = AnimationFlags::NONE; + auto flags = AnimationFlags::NONE; for (char c : str) { switch (c) { @@ -303,8 +300,7 @@ namespace zenkit { event.frame = c->read_int(); auto event_type = c->read_line(false); - auto tp = event_types.find(event_type); - if (tp == event_types.end()) { + if (auto tp = event_types.find(event_type); tp == event_types.end()) { event.type = MdsEventType::UNKNOWN; ZKLOGW("ModelScript", "Unexpected value for MdsEventType: \"%s\"", event_type.c_str()); } else { @@ -322,9 +318,7 @@ namespace zenkit { event.slot = c->read_line(true); break; case MdsEventType::SET_FIGHT_MODE: { - auto mode = c->read_line(true); - - if (mode == "FIST") { + if (auto mode = c->read_line(true); mode == "FIST") { event.fight_mode = MdsFightMode::FIST; } else if (mode == "1H" || mode == "1h") { event.fight_mode = MdsFightMode::SINGLE_HANDED; @@ -448,7 +442,7 @@ namespace zenkit { } ModelScript ModelScript::parse(phoenix::buffer&& buf) { - return ModelScript::parse(buf); + return parse(buf); } void ModelScript::load(Read* r) { diff --git a/src/ModelScriptDsl.cc b/src/ModelScriptDsl.cc index 73ff7fb5..18a51555 100644 --- a/src/ModelScriptDsl.cc +++ b/src/ModelScriptDsl.cc @@ -14,18 +14,17 @@ namespace zenkit { AnimationFlags animation_flags_from_string(std::string_view str); } // namespace mds - struct ScriptSyntaxError : public zenkit::ParserError { - public: + struct ScriptSyntaxError : ParserError { ScriptSyntaxError(std::string&& location, std::string&& msg); }; ScriptSyntaxError::ScriptSyntaxError(std::string&& location, std::string&& msg) - : zenkit::ParserError("ModelScript (source)", "MDS syntax error at " + location + ": " + msg) {} + : ParserError("ModelScript (source)", "MDS syntax error at " + location + ": " + msg) {} constexpr std::string_view token_names[] = {"KEYWORD", "integer", "float", "string", "rparen", "lparen", "rbrace", "lbrace", "colon", "eof", "null"}; - MdsTokenizer::MdsTokenizer(Read* buf) : _m_buffer(buf) {} + MdsTokenizer::MdsTokenizer(Read* buf) : _m_buffer(buf), _m_mark(0) {} MdsToken MdsTokenizer::next() { _m_value.clear(); @@ -163,7 +162,8 @@ namespace zenkit { template void MdsParser::expect() { if (!this->maybe()) { - throw ScriptSyntaxError {_m_stream.format_location(), "expected " + std::string {token_names[int(kind)]}}; + throw ScriptSyntaxError {_m_stream.format_location(), + "expected " + std::string {token_names[static_cast(kind)]}}; } } diff --git a/src/ModelScriptDsl.hh b/src/ModelScriptDsl.hh index 7aa36fe4..4ebd22f7 100644 --- a/src/ModelScriptDsl.hh +++ b/src/ModelScriptDsl.hh @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -95,7 +94,6 @@ namespace zenkit { [[nodiscard]] bool maybe_keyword(std::string_view value); [[nodiscard]] std::optional maybe_named(std::string_view name); - private: MdsTokenizer _m_stream; }; } // namespace zenkit diff --git a/src/MorphMesh.cc b/src/MorphMesh.cc index ca8e440a..495b1b17 100644 --- a/src/MorphMesh.cc +++ b/src/MorphMesh.cc @@ -22,7 +22,7 @@ namespace zenkit { } MorphMesh MorphMesh::parse(phoenix::buffer&& buf) { - return MorphMesh::parse(buf); + return parse(buf); } void MorphMesh::load(Read* r) { @@ -49,8 +49,8 @@ namespace zenkit { break; } case MorphMeshChunkType::MORPH: - for (std::uint32_t i = 0; i < this->morph_positions.size(); ++i) { - this->morph_positions[i] = c->read_vec3(); + for (auto& morph_position : this->morph_positions) { + morph_position = c->read_vec3(); } break; case MorphMeshChunkType::ANIMATIONS: { diff --git a/src/MultiResolutionMesh.cc b/src/MultiResolutionMesh.cc index 22726d02..fabfec2c 100644 --- a/src/MultiResolutionMesh.cc +++ b/src/MultiResolutionMesh.cc @@ -90,14 +90,14 @@ namespace zenkit { // read positions this->positions.resize(vertices_size); - r->seek((ssize_t) vertices_offset, Whence::BEG); + r->seek(static_cast(vertices_offset), Whence::BEG); for (auto& pos : this->positions) { pos = r->read_vec3(); } // read normals this->normals.resize(normals_size); - r->seek((ssize_t) normals_offset, Whence::BEG); + r->seek(static_cast(normals_offset), Whence::BEG); for (auto& normal : this->normals) { normal = r->read_vec3(); } @@ -120,7 +120,7 @@ namespace zenkit { void MultiResolutionMesh::save_to_section(Write* w, GameVersion version) const { w->write_ushort(version == GameVersion::GOTHIC_1 ? VERSION_G1 : VERSION_G2); - auto off_size = w->tell(); + auto off_size = static_cast(w->tell()); w->write_uint(0); auto off_content = w->tell(); @@ -139,7 +139,7 @@ namespace zenkit { sections.push_back(mesh.save(w)); } - auto off_end = w->tell(); + auto off_end = static_cast(w->tell()); w->seek(off_size, Whence::BEG); w->write_uint(off_end - off_size); w->seek(off_end, Whence::BEG); @@ -202,17 +202,17 @@ namespace zenkit { void SubMesh::load(Read* r, SubMeshSection const& map) { // triangles - r->seek((ssize_t) map.triangles.offset, Whence::BEG); + r->seek(static_cast(map.triangles.offset), Whence::BEG); this->triangles.resize(map.triangles.size); - for (std::uint32_t i = 0; i < map.triangles.size; ++i) { + for (auto i = 0u; i < map.triangles.size; ++i) { this->triangles[i] = {{r->read_ushort(), r->read_ushort(), r->read_ushort()}}; } // wedges - r->seek((ssize_t) map.wedges.offset, Whence::BEG); + r->seek(static_cast(map.wedges.offset), Whence::BEG); this->wedges.resize(map.wedges.size); - for (std::uint32_t i = 0; i < map.wedges.size; ++i) { + for (auto i = 0u; i < map.wedges.size; ++i) { this->wedges[i] = {r->read_vec3(), r->read_vec2(), r->read_ushort()}; // and this is why you don't just dump raw binary data @@ -220,58 +220,58 @@ namespace zenkit { } // colors - r->seek((ssize_t) map.colors.offset, Whence::BEG); + r->seek(static_cast(map.colors.offset), Whence::BEG); this->colors.resize(map.colors.size); - for (std::uint32_t i = 0; i < map.colors.size; ++i) { + for (auto i = 0u; i < map.colors.size; ++i) { this->colors[i] = r->read_float(); } // triangle_plane_indices - r->seek((ssize_t) map.triangle_plane_indices.offset, Whence::BEG); + r->seek(static_cast(map.triangle_plane_indices.offset), Whence::BEG); this->triangle_plane_indices.resize(map.triangle_plane_indices.size); - for (std::uint32_t i = 0; i < map.triangle_plane_indices.size; ++i) { + for (auto i = 0u; i < map.triangle_plane_indices.size; ++i) { this->triangle_plane_indices[i] = r->read_ushort(); } // triangle_planes - r->seek((ssize_t) map.triangle_planes.offset, Whence::BEG); + r->seek(static_cast(map.triangle_planes.offset), Whence::BEG); this->triangle_planes.resize(map.triangle_planes.size); - for (std::uint32_t i = 0; i < map.triangle_planes.size; ++i) { + for (auto i = 0u; i < map.triangle_planes.size; ++i) { this->triangle_planes[i] = {r->read_float(), r->read_vec3()}; } // triangle_edges - r->seek((ssize_t) map.triangle_edges.offset, Whence::BEG); + r->seek(static_cast(map.triangle_edges.offset), Whence::BEG); this->triangle_edges.resize(map.triangle_edges.size); - for (std::uint32_t i = 0; i < map.triangle_edges.size; ++i) { + for (auto i = 0u; i < map.triangle_edges.size; ++i) { this->triangle_edges[i] = {{r->read_ushort(), r->read_ushort(), r->read_ushort()}}; } // edges - r->seek((ssize_t) map.edges.offset, Whence::BEG); + r->seek(static_cast(map.edges.offset), Whence::BEG); this->edges.resize(map.edges.size); - for (std::uint32_t i = 0; i < map.edges.size; ++i) { + for (auto i = 0u; i < map.edges.size; ++i) { this->edges[i] = {{r->read_ushort(), r->read_ushort()}}; } // edge_scores - r->seek((ssize_t) map.edge_scores.offset, Whence::BEG); + r->seek(static_cast(map.edge_scores.offset), Whence::BEG); this->edge_scores.resize(map.edge_scores.size); - for (std::uint32_t i = 0; i < map.edge_scores.size; ++i) { + for (auto i = 0u; i < map.edge_scores.size; ++i) { this->edge_scores[i] = r->read_float(); } // wedge_map - r->seek((ssize_t) map.wedge_map.offset, Whence::BEG); + r->seek(static_cast(map.wedge_map.offset), Whence::BEG); this->wedge_map.resize(map.wedge_map.size); - for (std::uint32_t i = 0; i < map.wedge_map.size; ++i) { + for (auto i = 0u; i < map.wedge_map.size; ++i) { this->wedge_map[i] = r->read_ushort(); } } diff --git a/src/SaveGame.cc b/src/SaveGame.cc index 69b44876..4f437913 100644 --- a/src/SaveGame.cc +++ b/src/SaveGame.cc @@ -262,7 +262,7 @@ namespace zenkit { return *result; } - std::shared_ptr SaveGame::load_world(std::string world_name) const { + std::shared_ptr SaveGame::load_world(std::string_view world_name) const { auto path = _m_path / world_name; path.replace_extension("SAV"); @@ -302,8 +302,7 @@ namespace zenkit { // Load THUMB.SAV { ZKLOGI("SaveGame", "Loading THUMB.SAV"); - auto file_thumb = find_file_matching(entries, "THUMB.SAV"); - if (file_thumb) { + if (auto file_thumb = find_file_matching(entries, "THUMB.SAV")) { auto r = Read::from(*file_thumb); this->thumbnail.emplace(); @@ -326,7 +325,7 @@ namespace zenkit { } } - void SaveGame::save(std::filesystem::path const& path, World& world, std::string world_name) { + void SaveGame::save(std::filesystem::path const& path, World& world, std::string const& world_name) { // Copy over the current save if necessary. if (_m_path != path) { if (std::filesystem::exists(path)) { diff --git a/src/SoftSkinMesh.cc b/src/SoftSkinMesh.cc index 994b0bca..2abf0e34 100644 --- a/src/SoftSkinMesh.cc +++ b/src/SoftSkinMesh.cc @@ -89,8 +89,8 @@ namespace zenkit { } void SoftSkinMesh::save(Write* w, GameVersion version) const { - proto::write_chunk(w, SoftSkinMeshChunkType::HEADER, [version](Write* w) { - w->write_uint(version == GameVersion::GOTHIC_1 ? VERSION_G1 : VERSION_G2); + proto::write_chunk(w, SoftSkinMeshChunkType::HEADER, [version](Write* wr) { + wr->write_uint(version == GameVersion::GOTHIC_1 ? VERSION_G1 : VERSION_G2); }); proto::write_chunk(w, SoftSkinMeshChunkType::PROTO, [&, version](Write* wr) { @@ -98,20 +98,20 @@ namespace zenkit { }); proto::write_chunk(w, SoftSkinMeshChunkType::HEADER, [&](Write* wr) { - auto off_size = wr->tell(); + auto off_size = static_cast(wr->tell()); wr->write_uint(0); - for (auto& w : this->weights) { - wr->write_uint(w.size()); + for (auto& we : this->weights) { + wr->write_uint(we.size()); - for (auto& i : w) { + for (auto& i : we) { wr->write_float(i.weight); wr->write_vec3(i.position); wr->write_ubyte(i.node_index); } } - auto off_end = wr->tell(); + auto off_end = static_cast(wr->tell()); wr->seek(off_size, Whence::BEG); wr->write_uint(off_end - off_size); wr->seek(off_end, Whence::BEG); @@ -136,6 +136,6 @@ namespace zenkit { } SoftSkinMesh SoftSkinMesh::parse(phoenix::buffer&& in) { - return SoftSkinMesh::parse(in); + return parse(in); } } // namespace zenkit diff --git a/src/Stream.cc b/src/Stream.cc index 8bc91502..9828dd4c 100644 --- a/src/Stream.cc +++ b/src/Stream.cc @@ -13,14 +13,14 @@ namespace zenkit { template - ZKINT inline T read_any(Read* r) noexcept { + ZKINT T read_any(Read* r) noexcept { T v {}; r->read(&v, sizeof v); return v; } template - ZKINT inline void write_any(Write* r, T const& v) noexcept { + ZKINT void write_any(Write* r, T const& v) noexcept { r->write(&v, sizeof v); } @@ -178,13 +178,13 @@ namespace zenkit { } namespace detail { - static int INTO_C_WHENCE[] = { + constexpr int INTO_C_WHENCE[] = { SEEK_SET, SEEK_CUR, SEEK_END, }; - static std::ios::seekdir INTO_CXX_WHENCE[] = { + constexpr std::ios::seekdir INTO_CXX_WHENCE[] = { std::ios::beg, std::ios::cur, std::ios::end, @@ -208,31 +208,31 @@ namespace zenkit { return static_cast(new_position); } - class ReadFile ZKINT : public Read { + class ReadFile final ZKINT : public Read { public: - explicit ReadFile(::FILE* stream) : _m_stream(stream) {} + explicit ReadFile(FILE* stream) : _m_stream(stream) {} size_t read(void* buf, size_t len) noexcept override { - return ::fread(buf, 1, len, _m_stream); + return fread(buf, 1, len, _m_stream); } void seek(ssize_t off, Whence whence) noexcept override { - ::fseek(_m_stream, off, INTO_C_WHENCE[static_cast(whence)]); + fseek(_m_stream, off, INTO_C_WHENCE[static_cast(whence)]); } [[nodiscard]] size_t tell() const noexcept override { - return static_cast(::ftell(_m_stream)); + return static_cast(ftell(_m_stream)); } [[nodiscard]] bool eof() const noexcept override { - return ::feof(_m_stream); + return feof(_m_stream); } private: - ::FILE* _m_stream; + FILE* _m_stream; }; - class ReadStream ZKINT : public Read { + class ReadStream final ZKINT : public Read { public: explicit ReadStream(std::istream* stream) : _m_stream(stream) {} @@ -246,7 +246,7 @@ namespace zenkit { } [[nodiscard]] size_t tell() const noexcept override { - return static_cast(_m_stream->tellg()); + return _m_stream->tellg(); } [[nodiscard]] bool eof() const noexcept override { @@ -263,7 +263,7 @@ namespace zenkit { size_t read(void* buf, size_t len) noexcept override { len = _m_position + len > _m_length ? _m_length - _m_position : len; - ::memcpy(buf, _m_bytes + _m_position, len); + memcpy(buf, _m_bytes + _m_position, len); _m_position += len; return len; } @@ -273,7 +273,7 @@ namespace zenkit { if (new_position > _m_length) return; - _m_position = static_cast(new_position); + _m_position = new_position; } [[nodiscard]] size_t tell() const noexcept override { @@ -289,7 +289,7 @@ namespace zenkit { size_t _m_length, _m_position {0}; }; - class ZKREM("Deprecated") ReadBuffer ZKINT : public Read { + class ZKREM("Deprecated") ReadBuffer final ZKINT : public Read { public: explicit ReadBuffer(phoenix::buffer* buf) : _m_buffer(buf) {} @@ -330,7 +330,7 @@ namespace zenkit { phoenix::buffer* _m_buffer; }; - class ReadVector ZKINT : public ReadMemory { + class ReadVector final ZKINT : public ReadMemory { public: explicit ReadVector(std::vector vec) : ReadMemory(vec.data(), vec.size()), _m_vector(std::move(vec)) {} @@ -340,7 +340,7 @@ namespace zenkit { }; #ifdef _ZK_WITH_MMAP - class ReadMmap ZKINT : public ReadMemory { + class ReadMmap final ZKINT : public ReadMemory { public: explicit ReadMmap(std::filesystem::path const& path) : ReadMmap(Mmap {path}) {} @@ -351,27 +351,27 @@ namespace zenkit { }; #endif - class WriteFile ZKINT : public Write { + class WriteFile final ZKINT : public Write { public: - explicit WriteFile(::FILE* stream) : _m_stream(stream) {} + explicit WriteFile(FILE* stream) : _m_stream(stream) {} size_t write(void const* buf, size_t len) noexcept override { - return ::fwrite(buf, 1, len, _m_stream); + return fwrite(buf, 1, len, _m_stream); } void seek(ssize_t off, Whence whence) noexcept override { - ::fseek(_m_stream, off, INTO_C_WHENCE[static_cast(whence)]); + fseek(_m_stream, off, INTO_C_WHENCE[static_cast(whence)]); } [[nodiscard]] size_t tell() const noexcept override { - return static_cast(::ftell(_m_stream)); + return static_cast(ftell(_m_stream)); } private: - ::FILE* _m_stream; + FILE* _m_stream; }; - class WriteStream ZKINT : public Write { + class WriteStream final ZKINT : public Write { public: explicit WriteStream(std::ostream* stream) : _m_stream(stream), _m_own(false) {} explicit WriteStream(std::filesystem::path const& path) @@ -396,7 +396,7 @@ namespace zenkit { } [[nodiscard]] size_t tell() const noexcept override { - return static_cast(_m_stream->tellp()); + return _m_stream->tellp(); } private: @@ -404,13 +404,13 @@ namespace zenkit { bool _m_own; }; - class WriteStatic ZKINT : public Write { + class WriteStatic final ZKINT : public Write { public: explicit WriteStatic(std::byte* buf, size_t len) : _m_bytes(buf), _m_length(len) {} size_t write(void const* buf, size_t len) noexcept override { len = _m_position + len > _m_length ? _m_length - _m_position : len; - ::memcpy(_m_bytes + _m_position, buf, len); + memcpy(_m_bytes + _m_position, buf, len); _m_position += len; return len; } @@ -419,7 +419,7 @@ namespace zenkit { auto new_position = seek_internal(_m_position, _m_length, off, whence); if (new_position > _m_length) return; - _m_position = static_cast(new_position); + _m_position = new_position; } [[nodiscard]] size_t tell() const noexcept override { @@ -431,7 +431,7 @@ namespace zenkit { size_t _m_length, _m_position {0}; }; - class WriteDynamic ZKINT : public Write { + class WriteDynamic final ZKINT : public Write { public: explicit WriteDynamic(std::vector* vec) : _m_vector(vec) {} @@ -466,7 +466,7 @@ namespace zenkit { }; } // namespace detail - std::unique_ptr Read::from(::FILE* stream) { + std::unique_ptr Read::from(FILE* stream) { return std::make_unique(stream); } @@ -508,7 +508,7 @@ namespace zenkit { return std::make_unique(path); } - std::unique_ptr Write::to(::FILE* stream) { + std::unique_ptr Write::to(FILE* stream) { return std::make_unique(stream); } diff --git a/src/Texture.cc b/src/Texture.cc index 2e5f7c26..22a4512c 100644 --- a/src/Texture.cc +++ b/src/Texture.cc @@ -8,7 +8,7 @@ #include "squish.h" namespace zenkit { - constexpr std::string_view const ZTEX_SIGNATURE = "ZTEX"; + constexpr std::string_view ZTEX_SIGNATURE = "ZTEX"; /// \brief Calculates the size in bytes of a texture at the given mipmap level. /// \return The size in bytes of a texture at the given mipmap level. @@ -58,17 +58,16 @@ namespace zenkit { } Texture Texture::parse(phoenix::buffer&& in) { - return Texture::parse(in); + return parse(in); } void Texture::load(Read* r) { if (r->read_string(4) != ZTEX_SIGNATURE) { - throw zenkit::ParserError {"texture", "invalid signature"}; + throw ParserError {"texture", "invalid signature"}; } - auto version = r->read_uint(); - if (version != 0) { - throw zenkit::ParserError {"texture", "invalid version"}; + if (r->read_uint() != 0) { + throw ParserError {"texture", "invalid version"}; } this->_m_format = static_cast(r->read_uint()); @@ -209,7 +208,7 @@ namespace zenkit { std::uint32_t idx = 0; for (std::uint32_t i = 0; i < map.size(); i += 2) { - auto* rgb = (r5g6b5*) &map[i]; + auto* rgb = reinterpret_cast(&map[i]); conv[idx++] = static_cast(static_cast(rgb->b) * 8.225806452f); conv[idx++] = static_cast(static_cast(rgb->g) * 4.047619048f); conv[idx++] = static_cast(static_cast(rgb->r) * 8.225806452f); @@ -233,9 +232,8 @@ namespace zenkit { return conv; } default: - throw zenkit::ParserError {"texture", - "cannot convert format to rgba: " + - std::to_string(static_cast(_m_format))}; + throw ParserError {"texture", + "cannot convert format to rgba: " + std::to_string(static_cast(_m_format))}; } } diff --git a/src/Vfs.cc b/src/Vfs.cc index 1ce87c32..a996794a 100644 --- a/src/Vfs.cc +++ b/src/Vfs.cc @@ -6,8 +6,6 @@ #include "phoenix/buffer.hh" -#include "Internal.hh" - #include #include #include @@ -19,7 +17,7 @@ namespace zenkit { static constexpr std::string_view VFS_DISK_SIGNATURE_G1 = "PSVDSC_V2.00\r\n\r\n"; static constexpr std::string_view VFS_DISK_SIGNATURE_G2 = "PSVDSC_V2.00\n\r\n\r"; - class ZKINT RawBufferBacking : public phoenix::buffer_backing { + class ZKINT RawBufferBacking final : public phoenix::buffer_backing { public: RawBufferBacking(std::byte const* bytes, uint64_t length) : _m_buffer(bytes), _m_size(length) {} @@ -88,7 +86,7 @@ namespace zenkit { } std::string_view trim_trailing_whitespace(std::string_view s) { - while (s.length() > 0 && std::isspace(s.back())) { + while (!s.empty() && std::isspace(s.back())) { s = s.substr(0, s.size() - 1); } @@ -115,7 +113,7 @@ namespace zenkit { VfsNode* VfsNode::create(VfsNode node) { auto& children = std::get(_m_data); - auto it = children.insert(node); + auto it = children.insert(std::move(node)); return const_cast(&*it.first); } @@ -217,8 +215,7 @@ namespace zenkit { auto* node = tree.top(); tree.pop(); - auto* child = node->child(name); - if (child != nullptr) return child; + if (auto* child = node->child(name); child != nullptr) return child; auto& children = node->children(); for (auto const& x : children) { @@ -290,7 +287,7 @@ namespace zenkit { } for (auto [off, dir] : dirs) { - auto here = write_catalog->tell(); + auto here = static_cast(write_catalog->tell()); write_catalog->seek(off, Whence::BEG); write_catalog->write_uint(index); write_catalog->seek(here, Whence::BEG); @@ -315,7 +312,7 @@ namespace zenkit { w->write_uint(off + catalog.size()); w->write_uint(off); w->write_uint(80); - w->seek(off, Whence::BEG); + w->seek(static_cast(off), Whence::BEG); w->write(catalog.data(), catalog.size()); } @@ -335,21 +332,21 @@ namespace zenkit { } static std::time_t vfs_dos_to_unix_time(std::uint32_t dos) noexcept { - struct tm t {}; + tm t {}; - t.tm_year = ((int32_t) ((dos >> 25) & 0x7F)) + 80; - t.tm_mon = ((int32_t) ((dos >> 21) & 0xF)) - 1; - t.tm_mday = (int32_t) ((dos >> 16) & 0x1F); - t.tm_hour = (int32_t) ((dos >> 11) & 0x1F); - t.tm_min = (int32_t) ((dos >> 5) & 0x3F); - t.tm_sec = ((int32_t) ((dos >> 0) & 0x1F)) * 2; + t.tm_year = static_cast((dos >> 25) & 0x7F) + 80; + t.tm_mon = static_cast((dos >> 21) & 0xF) - 1; + t.tm_mday = static_cast((dos >> 16) & 0x1F); + t.tm_hour = static_cast((dos >> 11) & 0x1F); + t.tm_min = static_cast((dos >> 5) & 0x3F); + t.tm_sec = static_cast((dos >> 0) & 0x1F) * 2; return mktime(&t); } void Vfs::mount_disk(phoenix::buffer buf, VfsOverwriteBehavior overwrite) { auto mem = std::make_unique(buf.limit()); - ::memcpy(mem.get(), buf.array(), buf.limit()); + memcpy(mem.get(), buf.array(), buf.limit()); this->mount_disk(mem.get(), buf.limit(), overwrite); _m_data.push_back(std::move(mem)); } @@ -433,9 +430,8 @@ namespace zenkit { } auto name = path.substr(0, next); - auto it = context->child(name); - if (it == nullptr) { + if (auto it = context->child(name); it == nullptr) { auto now = std::chrono::system_clock::now(); context = context->create(VfsNode::directory(name, std::chrono::system_clock::to_time_t(now))); } else if (it->type() == VfsNodeType::FILE) { @@ -515,10 +511,9 @@ namespace zenkit { auto timestamp = vfs_dos_to_unix_time(r->read_uint()); [[maybe_unused]] auto _size = r->read_uint(); auto catalog_offset = r->read_uint(); - auto version = r->read_uint(); // Check that we're not loading a compressed Union disk. - if (version != 80) { + if (r->read_uint() != 80) { throw VfsBrokenDiskError {"Detected unsupported Union disk"}; } diff --git a/src/World.cc b/src/World.cc index a50e7526..38aa1ec7 100644 --- a/src/World.cc +++ b/src/World.cc @@ -23,7 +23,7 @@ namespace zenkit { auto archive = ReadArchive::from(buf); if (archive->is_save_game()) { - throw zenkit::ParserError {"World", "cannot automatically detect world version for save-games!s"}; + throw ParserError {"World", "cannot automatically detect world version for save-games!s"}; } ArchiveObject chnk {}; @@ -54,7 +54,7 @@ namespace zenkit { } World World::parse(phoenix::buffer&& buf, GameVersion version) { - return World::parse(buf, version); + return parse(buf, version); } World World::parse(phoenix::buffer& buf) { @@ -67,7 +67,7 @@ namespace zenkit { } World World::parse(phoenix::buffer&& buf) { - return World::parse(buf); + return parse(buf); } void World::load(Read* r) { @@ -116,7 +116,7 @@ namespace zenkit { auto bsp_version = raw->read_uint(); (void) /* size = */ raw->read_uint(); - std::uint16_t chunk_type = 0; + std::uint16_t chunk_type; auto mesh_offset = raw->tell(); do { diff --git a/src/addon/daedalus.cc b/src/addon/daedalus.cc index 6f707013..9ce3424f 100644 --- a/src/addon/daedalus.cc +++ b/src/addon/daedalus.cc @@ -41,7 +41,7 @@ namespace zenkit { #define ZKLOG_CLASS(a, b) ZKLOGD("Daedalus", "Registering script class \"%s\" as zenkit::%s", a, b) -void zenkit::IGuildValues::register_(zenkit::DaedalusScript& s) { +void zenkit::IGuildValues::register_(DaedalusScript& s) { ZKLOG_CLASS("C_GILVALUES", "IGuildValues"); s.register_member("C_GILVALUES.WATER_DEPTH_KNEE", &IGuildValues::water_depth_knee); s.register_member("C_GILVALUES.WATER_DEPTH_CHEST", &IGuildValues::water_depth_chest); @@ -80,12 +80,12 @@ void zenkit::IGuildValues::register_(zenkit::DaedalusScript& s) { } } -void zenkit::IFightAi::register_(zenkit::DaedalusScript& s) { +void zenkit::IFightAi::register_(DaedalusScript& s) { ZKLOG_CLASS("C_FIGHTAI", "IFightAi"); s.register_member("C_FIGHTAI.MOVE", &IFightAi::move); } -void zenkit::ISoundEffect::register_(zenkit::DaedalusScript& s) { +void zenkit::ISoundEffect::register_(DaedalusScript& s) { ZKLOG_CLASS("C_SFX", "ISoundEffect"); s.register_member("C_SFX.FILE", &ISoundEffect::file); s.register_member("C_SFX.PITCHOFF", &ISoundEffect::pitch_off); @@ -98,7 +98,7 @@ void zenkit::ISoundEffect::register_(zenkit::DaedalusScript& s) { s.register_member("C_SFX.PFXNAME", &ISoundEffect::pfx_name); } -void zenkit::ISoundSystem::register_(zenkit::DaedalusScript& s) { +void zenkit::ISoundSystem::register_(DaedalusScript& s) { ZKLOG_CLASS("C_SNDSYS_CFG", "ISoundSystem"); s.register_member("C_SNDSYS_CFG.VOLUME", &ISoundSystem::volume); s.register_member("C_SNDSYS_CFG.BITRESOLUTION", &ISoundSystem::bit_resolution); @@ -108,7 +108,7 @@ void zenkit::ISoundSystem::register_(zenkit::DaedalusScript& s) { s.register_member("C_SNDSYS_CFG.USED3DPROVIDERNAME", &ISoundSystem::used_3d_provider_name); } -void zenkit::IParticleEffectEmitKey::register_(zenkit::DaedalusScript& s) { +void zenkit::IParticleEffectEmitKey::register_(DaedalusScript& s) { ZKLOG_CLASS("C_PARTICLEFXEMITKEY", "IParticleEffectEmitKey"); s.register_member("C_PARTICLEFXEMITKEY.VISNAME_S", &IParticleEffectEmitKey::vis_name_s); s.register_member("C_PARTICLEFXEMITKEY.VISSIZESCALE", &IParticleEffectEmitKey::vis_size_scale); @@ -145,7 +145,7 @@ void zenkit::IParticleEffectEmitKey::register_(zenkit::DaedalusScript& s) { s.register_member("C_PARTICLEFXEMITKEY.EMFXLIFESPAN", &IParticleEffectEmitKey::em_fx_lifespan); } -void zenkit::INpc::register_(zenkit::DaedalusScript& s) { +void zenkit::INpc::register_(DaedalusScript& s) { ZKLOG_CLASS("C_NPC", "INpc"); s.register_member("C_NPC.ID", &INpc::id); s.register_member("C_NPC.NAME", &INpc::name); @@ -185,7 +185,7 @@ void zenkit::INpc::register_(zenkit::DaedalusScript& s) { } } -void zenkit::IMission::register_(zenkit::DaedalusScript& s) { +void zenkit::IMission::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MISSION", "IMission"); s.register_member("C_MISSION.NAME", &IMission::name); s.register_member("C_MISSION.DESCRIPTION", &IMission::description); @@ -202,7 +202,7 @@ void zenkit::IMission::register_(zenkit::DaedalusScript& s) { s.register_member("C_MISSION.RUNNING", &IMission::running); } -void zenkit::IItem::register_(zenkit::DaedalusScript& s) { +void zenkit::IItem::register_(DaedalusScript& s) { ZKLOG_CLASS("C_ITEM", "IItem"); s.register_member("C_ITEM.ID", &IItem::id); s.register_member("C_ITEM.NAME", &IItem::name); @@ -254,7 +254,7 @@ void zenkit::IItem::register_(zenkit::DaedalusScript& s) { } } -void zenkit::IFocus::register_(zenkit::DaedalusScript& s) { +void zenkit::IFocus::register_(DaedalusScript& s) { ZKLOG_CLASS("C_FOCUS", "IFocus"); s.register_member("C_FOCUS.NPC_LONGRANGE", &IFocus::npc_longrange); s.register_member("C_FOCUS.NPC_RANGE1", &IFocus::npc_range1); @@ -277,7 +277,7 @@ void zenkit::IFocus::register_(zenkit::DaedalusScript& s) { s.register_member("C_FOCUS.MOB_PRIO", &IFocus::mob_prio); } -void zenkit::IInfo::register_(zenkit::DaedalusScript& s) { +void zenkit::IInfo::register_(DaedalusScript& s) { ZKLOG_CLASS("C_INFO", "IInfo"); s.register_member("C_INFO.NPC", &IInfo::npc); s.register_member("C_INFO.NR", &IInfo::nr); @@ -289,7 +289,7 @@ void zenkit::IInfo::register_(zenkit::DaedalusScript& s) { s.register_member("C_INFO.PERMANENT", &IInfo::permanent); } -void zenkit::IInfo::add_choice(zenkit::IInfoChoice const& ch) { +void zenkit::IInfo::add_choice(IInfoChoice const& ch) { choices.insert(choices.begin(), ch); } @@ -297,7 +297,7 @@ void zenkit::IInfo::remove_choice(std::size_t index) { choices.erase(choices.begin() + static_cast(index)); } -void zenkit::IItemReact::register_(zenkit::DaedalusScript& s) { +void zenkit::IItemReact::register_(DaedalusScript& s) { ZKLOG_CLASS("C_ITEMREACT", "IItemReact"); s.register_member("C_ITEMREACT.NPC", &IItemReact::npc); s.register_member("C_ITEMREACT.TRADE_ITEM", &IItemReact::trade_item); @@ -308,7 +308,7 @@ void zenkit::IItemReact::register_(zenkit::DaedalusScript& s) { s.register_member("C_ITEMREACT.REACTION", &IItemReact::reaction); } -void zenkit::ISpell::register_(zenkit::DaedalusScript& s) { +void zenkit::ISpell::register_(DaedalusScript& s) { ZKLOG_CLASS("C_SPELL", "ISpell"); s.register_member("C_SPELL.TIME_PER_MANA", &ISpell::time_per_mana); s.register_member("C_SPELL.DAMAGE_PER_LEVEL", &ISpell::damage_per_level); @@ -331,7 +331,7 @@ void zenkit::ISpell::register_(zenkit::DaedalusScript& s) { } \ } while (false) -void zenkit::ISvm::register_(zenkit::DaedalusScript& s) { +void zenkit::ISvm::register_(DaedalusScript& s) { ZKLOG_CLASS("C_SVM", "ISvm"); REG_IF_SYM_EXIST("C_SVM.MILGREETINGS", &ISvm::MILGREETINGS); REG_IF_SYM_EXIST("C_SVM.PALGREETINGS", &ISvm::PALGREETINGS); @@ -650,7 +650,7 @@ void zenkit::ISvm::register_(zenkit::DaedalusScript& s) { #undef REG_IF_SYM_EXIST -void zenkit::IMenu::register_(zenkit::DaedalusScript& s) { +void zenkit::IMenu::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MENU", "IMenu"); s.register_member("C_MENU.BACKPIC", &IMenu::back_pic); s.register_member("C_MENU.BACKWORLD", &IMenu::back_world); @@ -667,7 +667,7 @@ void zenkit::IMenu::register_(zenkit::DaedalusScript& s) { s.register_member("C_MENU.DEFAULTINGAME", &IMenu::default_ingame); } -void zenkit::IMenuItem::register_(zenkit::DaedalusScript& s) { +void zenkit::IMenuItem::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MENU_ITEM", "IMenuItem"); s.register_member("C_MENU_ITEM.FONTNAME", &IMenuItem::fontname); s.register_member("C_MENU_ITEM.TEXT", &IMenuItem::text); @@ -707,7 +707,7 @@ void zenkit::IMenuItem::register_(zenkit::DaedalusScript& s) { } } -void zenkit::ICamera::register_(zenkit::DaedalusScript& s) { +void zenkit::ICamera::register_(DaedalusScript& s) { ZKLOG_CLASS("CCAMSYS", "ICamera"); s.register_member("CCAMSYS.BESTRANGE", &ICamera::best_range); s.register_member("CCAMSYS.MINRANGE", &ICamera::min_range); @@ -734,7 +734,7 @@ void zenkit::ICamera::register_(zenkit::DaedalusScript& s) { s.register_member("CCAMSYS.COLLISION", &ICamera::collision); } -void zenkit::IMusicSystem::register_(zenkit::DaedalusScript& s) { +void zenkit::IMusicSystem::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MUSICSYS_CFG", "IMusicSystem"); s.register_member("C_MUSICSYS_CFG.VOLUME", &IMusicSystem::volume); s.register_member("C_MUSICSYS_CFG.BITRESOLUTION", &IMusicSystem::bit_resolution); @@ -744,7 +744,7 @@ void zenkit::IMusicSystem::register_(zenkit::DaedalusScript& s) { s.register_member("C_MUSICSYS_CFG.REVERBBUFFERSIZE", &IMusicSystem::reverb_buffer_size); } -void zenkit::IMusicTheme::register_(zenkit::DaedalusScript& s) { +void zenkit::IMusicTheme::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MUSICTHEME", "IMusicTheme"); s.register_member("C_MUSICTHEME.FILE", &IMusicTheme::file); s.register_member("C_MUSICTHEME.VOL", &IMusicTheme::vol); @@ -755,7 +755,7 @@ void zenkit::IMusicTheme::register_(zenkit::DaedalusScript& s) { s.register_member("C_MUSICTHEME.TRANSSUBTYPE", &IMusicTheme::transsubtype); } -void zenkit::IMusicJingle::register_(zenkit::DaedalusScript& s) { +void zenkit::IMusicJingle::register_(DaedalusScript& s) { ZKLOG_CLASS("C_MUSICJINGLE", "IMusicJingle"); s.register_member("C_MUSICJINGLE.NAME", &IMusicJingle::name); s.register_member("C_MUSICJINGLE.LOOP", &IMusicJingle::loop); @@ -763,7 +763,7 @@ void zenkit::IMusicJingle::register_(zenkit::DaedalusScript& s) { s.register_member("C_MUSICJINGLE.TRANSSUBTYPE", &IMusicJingle::transsubtype); } -void zenkit::IParticleEffect::register_(zenkit::DaedalusScript& s) { +void zenkit::IParticleEffect::register_(DaedalusScript& s) { ZKLOG_CLASS("C_PARTICLEFX", "IParticleEffect"); s.register_member("C_PARTICLEFX.PPSVALUE", &IParticleEffect::pps_value); s.register_member("C_PARTICLEFX.PPSSCALEKEYS_S", &IParticleEffect::pps_scale_keys_s); @@ -828,7 +828,7 @@ void zenkit::IParticleEffect::register_(zenkit::DaedalusScript& s) { } } -void zenkit::IEffectBase::register_(zenkit::DaedalusScript& s) { +void zenkit::IEffectBase::register_(DaedalusScript& s) { ZKLOG_CLASS("CFX_BASE", "IEffectBase"); s.register_member("CFX_BASE.VISNAME_S", &IEffectBase::vis_name_s); s.register_member("CFX_BASE.VISSIZE_S", &IEffectBase::vis_size_s); diff --git a/src/addon/texcvt.cc b/src/addon/texcvt.cc index f1e1a4b0..52d237a7 100644 --- a/src/addon/texcvt.cc +++ b/src/addon/texcvt.cc @@ -70,7 +70,7 @@ namespace zenkit { uint32_t dwReserved2; } DDSURFACEDESC2; - static void write_dds_header(Write* w, zenkit::Texture const& tex) { + static void write_dds_header(Write* w, Texture const& tex) { DDSURFACEDESC2 header {}; header.dwSize = sizeof(DDSURFACEDESC2); header.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS; @@ -217,7 +217,7 @@ namespace zenkit { w->write_uint(header.dwReserved2); } - static void write_dds_palette(Write* w, zenkit::Texture const& tex) { + static void write_dds_palette(Write* w, Texture const& tex) { for (auto i = 0; i < ZTEX_PALETTE_ENTRIES; ++i) { w->write_ubyte(tex.palette()[i].b); w->write_ubyte(tex.palette()[i].g); @@ -226,14 +226,14 @@ namespace zenkit { } } - static void write_dds_data(Write* w, zenkit::Texture const& tex) { + static void write_dds_data(Write* w, Texture const& tex) { for (uint32_t level = 0; level < tex.mipmaps(); ++level) { auto& data = tex.data(level); w->write(data.data(), data.size()); } } - std::vector to_dds(zenkit::Texture const& tex) { + std::vector to_dds(Texture const& tex) { std::vector buf {}; auto w = Write::to(&buf); diff --git a/src/archive/ArchiveAscii.cc b/src/archive/ArchiveAscii.cc index 36ce0b2f..4a093f6a 100644 --- a/src/archive/ArchiveAscii.cc +++ b/src/archive/ArchiveAscii.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include namespace zenkit { @@ -21,18 +20,18 @@ namespace zenkit { { std::string objects = read->read_line(true); if (objects.find("objects ") != 0) { - throw zenkit::ParserError {"ReadArchive.Ascii", "objects field missing"}; + throw ParserError {"ReadArchive.Ascii", "objects field missing"}; } try { _m_objects = std::stoi(objects.substr(objects.find(' ') + 1)); } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } if (read->read_line(true) != "END") { - throw zenkit::ParserError {"ReadArchive.Ascii", "second END missing"}; + throw ParserError {"ReadArchive.Ascii", "second END missing"}; } } @@ -91,9 +90,8 @@ namespace zenkit { auto colon = line.find(':'); if (line.substr(0, colon) != type) { - throw zenkit::ParserError {"ReadArchive.Ascii", - "type mismatch: expected " + std::string {type} + - ", got: " + line.substr(0, colon)}; + throw ParserError {"ReadArchive.Ascii", + "type mismatch: expected " + std::string {type} + ", got: " + line.substr(0, colon)}; } return line.substr(colon + 1); @@ -107,7 +105,7 @@ namespace zenkit { try { return std::stoi(read_entry("int")); } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -115,7 +113,7 @@ namespace zenkit { try { return std::stof(read_entry("float")); } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -123,7 +121,7 @@ namespace zenkit { try { return std::stoul(read_entry("int")) & 0xFF; } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -131,7 +129,7 @@ namespace zenkit { try { return std::stoul(read_entry("int")) & 0xFF'FF; } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -139,7 +137,7 @@ namespace zenkit { try { return std::stoul(read_entry("enum")) & 0xFFFF'FFFF; } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -147,7 +145,7 @@ namespace zenkit { try { return std::stoul(read_entry("bool")) != 0; } catch (std::invalid_argument const& e) { - throw zenkit::ParserError {"ReadArchive.Ascii", e, "reading int"}; + throw ParserError {"ReadArchive.Ascii", e, "reading int"}; } } @@ -156,7 +154,10 @@ namespace zenkit { std::uint16_t r, g, b, a; in >> r >> g >> b >> a; - return glm::u8vec4 {(std::uint8_t) r, (std::uint8_t) g, (std::uint8_t) b, (std::uint8_t) a}; + return glm::u8vec4 {static_cast(r), + static_cast(g), + static_cast(b), + static_cast(a)}; } glm::vec3 ReadArchiveAscii::read_vec3() { @@ -191,16 +192,14 @@ namespace zenkit { auto in = read_entry("raw"); if (in.length() < 2 /* 2 chars a byte */ * sizeof(float) * 9) { - throw zenkit::ParserError {"ReadArchive.Ascii", - "raw entry does not contain enough bytes to be a 3x3 matrix"}; + throw ParserError {"ReadArchive.Ascii", "raw entry does not contain enough bytes to be a 3x3 matrix"}; } auto beg_it = in.data(); glm::mat3x3 v {}; - std::uint8_t tmp[4]; - for (int32_t i = 0; i < 9; ++i) { + std::uint8_t tmp[4]; std::from_chars(beg_it + 0, beg_it + 2, tmp[0], 16); std::from_chars(beg_it + 2, beg_it + 4, tmp[1], 16); std::from_chars(beg_it + 4, beg_it + 6, tmp[2], 16); @@ -218,8 +217,10 @@ namespace zenkit { auto length = in.length() / 2; if (length < size) { - throw zenkit::ParserError {"ReadArchive.Ascii", "not enough raw bytes to read!"}; - } else if (length > size) { + throw ParserError {"ReadArchive.Ascii", "not enough raw bytes to read!"}; + } + + if (length > size) { ZKLOGW("ReadArchive.Ascii", "Reading %d bytes although %zu are actually available", size, length); } @@ -241,8 +242,10 @@ namespace zenkit { auto length = in.length() / 2; if (length < size) { - throw zenkit::ParserError {"ReadArchive.Ascii", "not enough raw bytes to read!"}; - } else if (length > size) { + throw ParserError {"ReadArchive.Ascii", "not enough raw bytes to read!"}; + } + + if (length > size) { ZKLOGW("ReadArchive.Ascii", "Reading %zu bytes although %zu are actually available", size, length); } diff --git a/src/archive/ArchiveAscii.hh b/src/archive/ArchiveAscii.hh index efc91489..40d80fbb 100644 --- a/src/archive/ArchiveAscii.hh +++ b/src/archive/ArchiveAscii.hh @@ -7,10 +7,10 @@ namespace zenkit { class ReadArchiveAscii final : public ReadArchive { public: - inline ReadArchiveAscii(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) + ReadArchiveAscii(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) : ReadArchive(std::forward(parent_header), r, std::move(owned)) {} - inline ReadArchiveAscii(ArchiveHeader&& parent_header, Read* r) + ReadArchiveAscii(ArchiveHeader&& parent_header, Read* r) : ReadArchive(std::forward(parent_header), r) {} bool read_object_begin(ArchiveObject& obj) override; @@ -40,7 +40,7 @@ namespace zenkit { int32_t _m_objects {0}; }; - class WriteArchiveAscii : public WriteArchive { + class WriteArchiveAscii final : public WriteArchive { public: explicit WriteArchiveAscii(Write* w); @@ -64,7 +64,7 @@ namespace zenkit { void write_raw(std::string_view name, std::vector const& v) override; void write_raw(std::string_view name, std::byte const* v, std::uint16_t length) override; void write_raw_float(std::string_view name, float const* v, std::uint16_t length) override; - void write_header() final; + void write_header() override; [[nodiscard]] Write* get_stream() const noexcept override { return _m_write; @@ -74,7 +74,6 @@ namespace zenkit { void write_indent(); void write_entry(std::string_view name, std::string_view type, std::string_view value); - private: Write* _m_write; std::uint32_t _m_index {0}; std::uint32_t _m_indent {0}; diff --git a/src/archive/ArchiveBinary.cc b/src/archive/ArchiveBinary.cc index 01c93b07..c5e3d87f 100644 --- a/src/archive/ArchiveBinary.cc +++ b/src/archive/ArchiveBinary.cc @@ -108,13 +108,13 @@ namespace zenkit { } phoenix::buffer ReadArchiveBinary::read_raw_bytes(uint32_t size) { - std::vector bytes(size, std::byte {}); + std::vector bytes(size, std::byte {}); read->read(bytes.data(), bytes.size()); return phoenix::buffer::of(std::move(bytes)); } std::unique_ptr ReadArchiveBinary::read_raw(std::size_t size) { - std::vector bytes(size, std::byte {}); + std::vector bytes(size, std::byte {}); read->read(bytes.data(), bytes.size()); return Read::from(std::move(bytes)); } diff --git a/src/archive/ArchiveBinary.hh b/src/archive/ArchiveBinary.hh index 7ad58269..687f0f37 100644 --- a/src/archive/ArchiveBinary.hh +++ b/src/archive/ArchiveBinary.hh @@ -9,10 +9,10 @@ namespace zenkit { class ReadArchiveBinary final : public ReadArchive { public: - inline ReadArchiveBinary(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) + ReadArchiveBinary(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) : ReadArchive(std::forward(parent_header), r, std::move(owned)) {} - inline ReadArchiveBinary(ArchiveHeader&& parent_header, Read* r) + ReadArchiveBinary(ArchiveHeader&& parent_header, Read* r) : ReadArchive(std::forward(parent_header), r) {} bool read_object_begin(ArchiveObject& obj) override; @@ -43,7 +43,7 @@ namespace zenkit { int32_t _m_objects {0}; }; - class WriteArchiveBinary : public WriteArchive { + class WriteArchiveBinary final : public WriteArchive { public: explicit WriteArchiveBinary(Write* w); @@ -67,7 +67,7 @@ namespace zenkit { void write_raw(std::string_view name, std::vector const& v) override; void write_raw(std::string_view name, std::byte const* v, std::uint16_t length) override; void write_raw_float(std::string_view name, float const* v, std::uint16_t length) override; - void write_header() final; + void write_header() override; [[nodiscard]] Write* get_stream() const noexcept override { return _m_write; diff --git a/src/archive/ArchiveBinsafe.cc b/src/archive/ArchiveBinsafe.cc index 051705ab..fc3b3aff 100644 --- a/src/archive/ArchiveBinsafe.cc +++ b/src/archive/ArchiveBinsafe.cc @@ -15,9 +15,9 @@ namespace zenkit { void ReadArchiveBinsafe::read_header() { _m_bs_version = read->read_uint(); _m_object_count = read->read_uint(); - auto hash_table_offset = read->read_uint(); { + auto hash_table_offset = read->read_uint(); auto mark = read->tell(); read->seek(hash_table_offset, Whence::BEG); @@ -101,7 +101,7 @@ namespace zenkit { std::string const& ReadArchiveBinsafe::get_entry_key() { if (static_cast(read->read_ubyte()) != ArchiveEntryType::HASH) { - throw zenkit::ParserError {"ReadArchive.Binsafe", "invalid format"}; + throw ParserError {"ReadArchive.Binsafe", "invalid format"}; } auto hash = read->read_uint(); @@ -209,7 +209,9 @@ namespace zenkit { if (length < size) { throw ParserError {"ReadArchive.Binsafe", "not enough raw bytes to read!"}; - } else if (length > size) { + } + + if (length > size) { ZKLOGW("ReadArchive.Binsafe", "Reading %d bytes although %d are actually available", size, length); } @@ -223,7 +225,9 @@ namespace zenkit { if (length < size) { throw ParserError {"ReadArchive.Binsafe", "not enough raw bytes to read!"}; - } else if (length > size) { + } + + if (length > size) { ZKLOGW("ReadArchive.Binsafe", "Reading %zu bytes although %d are actually available", size, length); } @@ -233,9 +237,7 @@ namespace zenkit { } void ReadArchiveBinsafe::skip_entry() { - auto type = static_cast(read->read_ubyte()); - - switch (type) { + switch (static_cast(read->read_ubyte())) { case ArchiveEntryType::STRING: case ArchiveEntryType::RAW: case ArchiveEntryType::RAW_FLOAT: @@ -415,7 +417,7 @@ namespace zenkit { void WriteArchiveBinsafe::write_header() { auto cur = this->_m_write->tell(); - this->_m_write->seek(_m_head, Whence::BEG); + this->_m_write->seek(static_cast(_m_head), Whence::BEG); char const* username = getenv("USER"); if (username == nullptr) username = getenv("USERNAME"); @@ -445,7 +447,7 @@ namespace zenkit { this->_m_write->write_uint(cur); if (cur != _m_head) { - this->_m_write->seek(cur, Whence::BEG); + this->_m_write->seek(static_cast(cur), Whence::BEG); } else { cur = this->_m_write->tell(); } @@ -469,7 +471,7 @@ namespace zenkit { } // Place the cursor before the hash table. - this->_m_write->seek(cur, Whence::BEG); + this->_m_write->seek(static_cast(cur), Whence::BEG); } void WriteArchiveBinsafe::write_entry(std::string_view name, ArchiveEntryType type) { diff --git a/src/archive/ArchiveBinsafe.hh b/src/archive/ArchiveBinsafe.hh index ca2dbf66..3d366f9f 100644 --- a/src/archive/ArchiveBinsafe.hh +++ b/src/archive/ArchiveBinsafe.hh @@ -8,7 +8,7 @@ #include namespace zenkit { - static constexpr std::uint8_t const type_sizes[] = { + static constexpr std::uint8_t type_sizes[] = { 0, // ? = 0x00 0, // bs_string = 0x01, sizeof(std::int32_t), // bs_int = 0x02, @@ -37,10 +37,10 @@ namespace zenkit { class ReadArchiveBinsafe final : public ReadArchive { public: - inline ReadArchiveBinsafe(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) + ReadArchiveBinsafe(ArchiveHeader&& parent_header, Read* r, std::unique_ptr owned) : ReadArchive(std::forward(parent_header), r, std::move(owned)) {} - inline ReadArchiveBinsafe(ArchiveHeader&& parent_header, Read* r) + ReadArchiveBinsafe(ArchiveHeader&& parent_header, Read* r) : ReadArchive(std::forward(parent_header), r) {} bool read_object_begin(ArchiveObject& obj) override; @@ -88,7 +88,7 @@ namespace zenkit { } }; - class WriteArchiveBinsafe : public WriteArchive { + class WriteArchiveBinsafe final : public WriteArchive { public: explicit WriteArchiveBinsafe(Write* w); @@ -112,7 +112,7 @@ namespace zenkit { void write_raw(std::string_view name, std::vector const& v) override; void write_raw(std::string_view name, std::byte const* v, std::uint16_t length) override; void write_raw_float(std::string_view name, float const* v, std::uint16_t length) override; - void write_header() final; + void write_header() override; [[nodiscard]] Write* get_stream() const noexcept override { return _m_write; @@ -121,7 +121,6 @@ namespace zenkit { private: void write_entry(std::string_view name, ArchiveEntryType type); - private: Write* _m_write; std::uint32_t _m_index {0}; std::map> _m_hash_keys; diff --git a/src/vobs/Misc.cc b/src/vobs/Misc.cc index f65b0a6a..b8aa49c4 100644 --- a/src/vobs/Misc.cc +++ b/src/vobs/Misc.cc @@ -599,7 +599,7 @@ namespace zenkit { if (w.is_save_game()) { // FIXME: Not implemented because original not understood. std::size_t count = version == GameVersion::GOTHIC_1 ? 5 : 12; - std::vector bytes {count * 4, std::byte {}}; + std::vector bytes {count * 4, std::byte {}}; w.write_raw("blend", bytes); w.write_raw("cinema", bytes); // w.write_raw("fovMorph", bytes); // diff --git a/src/vobs/MovableObject.cc b/src/vobs/MovableObject.cc index a34dbda0..8b46aaeb 100644 --- a/src/vobs/MovableObject.cc +++ b/src/vobs/MovableObject.cc @@ -3,8 +3,6 @@ #include "zenkit/vobs/MovableObject.hh" #include "zenkit/Archive.hh" -#include "../Internal.hh" - namespace zenkit { void VMovableObject::parse(VMovableObject& obj, ReadArchive& r, GameVersion version) { obj.load(r, version); diff --git a/src/vobs/Trigger.cc b/src/vobs/Trigger.cc index 0729284f..4f638f11 100644 --- a/src/vobs/Trigger.cc +++ b/src/vobs/Trigger.cc @@ -90,8 +90,7 @@ namespace zenkit { this->auto_rotate = r.read_bool(); // autoRotate } - auto keyframe_count = r.read_word(); // numKeyframes - if (keyframe_count > 0) { + if (auto keyframe_count = r.read_word(); keyframe_count > 0) { this->speed = r.read_float(); // moveSpeed this->lerp_mode = static_cast(r.read_enum()); // posLerpType this->speed_mode = static_cast(r.read_enum()); // speedType diff --git a/src/world/BspTree.cc b/src/world/BspTree.cc index ebc4caf2..48f29b37 100644 --- a/src/world/BspTree.cc +++ b/src/world/BspTree.cc @@ -48,20 +48,30 @@ namespace zenkit { } if ((flags & 0x01) != 0) { - node.front_index = std::int32_t(nodes.size()); - _parse_bsp_nodes(in, nodes, indices, version, std::int32_t(self_index), (flags & 0x04) != 0); + node.front_index = static_cast(nodes.size()); + _parse_bsp_nodes(in, + nodes, + indices, + version, + static_cast(self_index), + (flags & 0x04) != 0); } if ((flags & 0x02) != 0) { - node.back_index = std::int32_t(nodes.size()); - _parse_bsp_nodes(in, nodes, indices, version, std::int32_t(self_index), (flags & 0x08) != 0); + node.back_index = static_cast(nodes.size()); + _parse_bsp_nodes(in, + nodes, + indices, + version, + static_cast(self_index), + (flags & 0x08) != 0); } } } void BspTree::load(Read* r, std::uint32_t version) { proto::read_chunked(r, "BspTree", [this, version](Read* c, BspChunkType type) { - ZKLOGI("BspTree", "Parsing chunk %x", std::uint16_t(type)); + ZKLOGI("BspTree", "Parsing chunk %x", static_cast(type)); switch (type) { case BspChunkType::HEADER: @@ -224,8 +234,8 @@ namespace zenkit { } }); - proto::write_chunk(w, BspChunkType::END, [](Write* w) { - w->write_ubyte(0); // padding + proto::write_chunk(w, BspChunkType::END, [](Write* wr) { + wr->write_ubyte(0); // padding }); } } // namespace zenkit diff --git a/src/world/WayNet.cc b/src/world/WayNet.cc index 321d6127..9f05b00a 100644 --- a/src/world/WayNet.cc +++ b/src/world/WayNet.cc @@ -3,8 +3,6 @@ #include "zenkit/world/WayNet.hh" #include "zenkit/Archive.hh" -#include "../Internal.hh" - namespace zenkit { #ifndef ZK_FUTURE static void read_waypoint_data(WayPoint& wp, ReadArchive& in) { @@ -148,7 +146,7 @@ namespace zenkit { } w.write_int("numWays", this->edges.size()); - for (auto i = 0u; i < this->edges.size(); ++i) { + for (i = 0u; i < this->edges.size(); ++i) { auto& [wayl, wayr] = this->edges[i]; w.write_object("wayl" + std::to_string(i), wayl, version); w.write_object("wayr" + std::to_string(i), wayr, version); diff --git a/tests/TestDaedalusScript.cc b/tests/TestDaedalusScript.cc index 35f5d2f9..d09a251b 100644 --- a/tests/TestDaedalusScript.cc +++ b/tests/TestDaedalusScript.cc @@ -4,7 +4,8 @@ #include #include -[[maybe_unused]] static bool compare_instruction(zenkit::DaedalusInstruction a, zenkit::DaedalusInstruction b) { +[[maybe_unused]] static bool compare_instruction(zenkit::DaedalusInstruction const& a, + zenkit::DaedalusInstruction const& b) { return a.op == b.op && a.index == b.index && a.immediate == b.immediate && a.address == b.address && a.symbol == b.symbol; } diff --git a/tests/TestFont.cc b/tests/TestFont.cc index e4d28748..c79df9be 100644 --- a/tests/TestFont.cc +++ b/tests/TestFont.cc @@ -7,19 +7,19 @@ #include -static zenkit::FontGlyph const G1_GLYPH0 {0, {glm::vec2 {0.0f, 0.0f}, glm::vec2 {0.0f, 0.0f}}}; -static zenkit::FontGlyph const G1_GLYPH127 { +static constexpr zenkit::FontGlyph G1_GLYPH0 {0, {glm::vec2 {0.0f, 0.0f}, glm::vec2 {0.0f, 0.0f}}}; +static constexpr zenkit::FontGlyph G1_GLYPH127 { 8, {glm::vec2 {0.3984375f, 0.23828125f}, glm::vec2 {0.412109375f, 0.30859375f}}}; -static zenkit::FontGlyph const G1_GLYPH255 { +static constexpr zenkit::FontGlyph G1_GLYPH255 { 9, {glm::vec2 {0.95703125f, 0.55078125f}, glm::vec2 {0.97265625f, 0.62109375f}}}; -static zenkit::FontGlyph const G2_GLYPH0 {0, {glm::vec2 {0.0f, 0.0f}, glm::vec2 {0.0f, 0.0f}}}; -static zenkit::FontGlyph const G2_GLYPH127 { +static constexpr zenkit::FontGlyph G2_GLYPH0 {0, {glm::vec2 {0.0f, 0.0f}, glm::vec2 {0.0f, 0.0f}}}; +static constexpr zenkit::FontGlyph G2_GLYPH127 { 8, {glm::vec2 {0.3984375f, 0.23828125f}, glm::vec2 {0.412109375f, 0.30859375f}}}; -static zenkit::FontGlyph const G2_GLYPH255 { +static constexpr zenkit::FontGlyph G2_GLYPH255 { 10, {glm::vec2 {0.958984375f, 0.55078125f}, glm::vec2 {0.9765625f, 0.62109375f}}}; diff --git a/tests/TestModelAnimation.cc b/tests/TestModelAnimation.cc index 4dddfed1..c3e8f563 100644 --- a/tests/TestModelAnimation.cc +++ b/tests/TestModelAnimation.cc @@ -12,19 +12,21 @@ static std::vector const G1_NODE_INDICES {0, 1, 2, 3, 4, 5, 6, static std::vector const G2_NODE_INDICES {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 26, 27, 28, 29, 30, 31, 32, 33}; -static AnimationSample const G1_SAMPLE0 {glm::vec3 {12.635274887084961f, 88.75251770019531f, -1.093428611755371f}, - glm::quat {0.7771535515785217f, 0.0f, 0.6293110251426697f, 0.0f}}; -static AnimationSample const G1_SAMPLE249 {glm::vec3 {12.626323699951172f, -0.00145721435546875f, 22.643518447875977f}, - glm::quat {0.7071319222450256f, 0.0f, 0.70708167552948f, 0.0f}}; -static AnimationSample const G1_SAMPLE499 {glm::vec3 {12.626323699951172, -0.00145721435546875, 22.643518447875977}, - glm::quat {0.7071319222450256, 0.0, 0.70708167552948, 0.0}}; - -static AnimationSample const G2_SAMPLE0 {glm::vec3 {12.635274887084961f, 88.75251770019531f, -1.093428611755371f}, - glm::quat {0.7771535515785217f, 0.0f, 0.6293110251426697f, 0.0f}}; -static AnimationSample const G2_SAMPLE249 {glm::vec3 {12.626323699951172f, -0.00145721435546875f, 22.643518447875977f}, - glm::quat {0.7071319222450256f, 0.0f, 0.70708167552948f, 0.0f}}; -static AnimationSample const G2_SAMPLE499 {glm::vec3 {12.626323699951172, -0.00145721435546875, 22.643518447875977}, - glm::quat {0.7071319222450256, 0.0, 0.70708167552948, 0.0}}; +static constexpr AnimationSample G1_SAMPLE0 {glm::vec3 {12.635274887084961f, 88.75251770019531f, -1.093428611755371f}, + glm::quat {0.7771535515785217f, 0.0f, 0.6293110251426697f, 0.0f}}; +static constexpr AnimationSample G1_SAMPLE249 { + glm::vec3 {12.626323699951172f, -0.00145721435546875f, 22.643518447875977f}, + glm::quat {0.7071319222450256f, 0.0f, 0.70708167552948f, 0.0f}}; +static constexpr AnimationSample G1_SAMPLE499 {glm::vec3 {12.626323699951172, -0.00145721435546875, 22.643518447875977}, + glm::quat {0.7071319222450256, 0.0, 0.70708167552948, 0.0}}; + +static constexpr AnimationSample G2_SAMPLE0 {glm::vec3 {12.635274887084961f, 88.75251770019531f, -1.093428611755371f}, + glm::quat {0.7771535515785217f, 0.0f, 0.6293110251426697f, 0.0f}}; +static constexpr AnimationSample G2_SAMPLE249 { + glm::vec3 {12.626323699951172f, -0.00145721435546875f, 22.643518447875977f}, + glm::quat {0.7071319222450256f, 0.0f, 0.70708167552948f, 0.0f}}; +static constexpr AnimationSample G2_SAMPLE499 {glm::vec3 {12.626323699951172, -0.00145721435546875, 22.643518447875977}, + glm::quat {0.7071319222450256, 0.0, 0.70708167552948, 0.0}}; TEST_SUITE("ModelAnimation") { TEST_CASE("ModelAnimation.load(GOTHIC1)") { diff --git a/tests/TestModelScript.cc b/tests/TestModelScript.cc index 4d411beb..cb71cd37 100644 --- a/tests/TestModelScript.cc +++ b/tests/TestModelScript.cc @@ -57,7 +57,7 @@ TEST_SUITE("ModelScript") { CHECK_EQ(script.animations[1].events[0].attached, true); CHECK_EQ(script.animations[1].events[1].frame, 1); CHECK_EQ(script.animations[1].events[1].type, zenkit::MdsEventType::COMBO_WINDOW); - CHECK_EQ(script.animations[1].events[1].frames, std::vector {1, 2, 3, 4, 5}); + CHECK_EQ(script.animations[1].events[1].frames, std::vector {1, 2, 3, 4, 5}); CHECK_EQ(script.animations[1].events[1].attached, false); CHECK_EQ(script.animations[1].events[2].frame, 0); // Defaulted CHECK_EQ(script.animations[1].events[2].type, zenkit::MdsEventType::ITEM_CREATE); diff --git a/tests/TestMultiResolutionMesh.cc b/tests/TestMultiResolutionMesh.cc index d66ae79e..7329fc7a 100644 --- a/tests/TestMultiResolutionMesh.cc +++ b/tests/TestMultiResolutionMesh.cc @@ -8,7 +8,7 @@ static bool compare_triangle(zenkit::MeshTriangle a, zenkit::MeshTriangle b) { return a.wedges[0] == b.wedges[0] && a.wedges[1] == b.wedges[1] && a.wedges[2] == b.wedges[2]; } -static bool compare_wedge(zenkit::MeshWedge a, zenkit::MeshWedge b) { +static bool compare_wedge(zenkit::MeshWedge const& a, zenkit::MeshWedge const& b) { return a.normal == b.normal && a.texture == b.texture && a.index == b.index; } diff --git a/tests/TestVobsG1.cc b/tests/TestVobsG1.cc index 33c59d00..d395f390 100644 --- a/tests/TestVobsG1.cc +++ b/tests/TestVobsG1.cc @@ -270,7 +270,7 @@ TEST_SUITE("vobs") { } static std::vector const G1_LIGHT_RANGE_ANIMATION_SCALE {}; - static std::vector const G1_LIGHT_COLOR_ANIMATION_LIST { + static std::vector const G1_LIGHT_COLOR_ANIMATION_LIST { glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {225, 197, 100, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {227, 209, 106, 255}, glm::u8vec4 {223, 173, 117, 255}, glm::u8vec4 {211, 147, 107, 255}, diff --git a/tests/TestWorld.cc b/tests/TestWorld.cc index 0617d978..d111db14 100644 --- a/tests/TestWorld.cc +++ b/tests/TestWorld.cc @@ -228,9 +228,8 @@ TEST_SUITE("World") { auto& children = vob0->children; CHECK_EQ(children.size(), 7496); - auto& child1 = children[0]; - { + auto& child1 = children[0]; auto box1 = child1->bbox; CHECK_EQ(box1.min, glm::vec3 {-18596.9004, -161.17189, 4091.1333}); CHECK_EQ(box1.max, glm::vec3 {-18492.0723, -111.171906, 4191.26221}); @@ -263,7 +262,6 @@ TEST_SUITE("World") { CHECK_EQ(child1->dynamic_shadows, zenkit::ShadowType::NONE); CHECK_EQ(child1->bias, 0); CHECK_FALSE(child1->ambient); - CHECK_FALSE(child1->physics_enabled); CHECK(child1->children.empty()); }