diff --git a/Navmesher/esx_reader.hpp b/Navmesher/esx_reader.hpp index 102993b..20496e7 100644 --- a/Navmesher/esx_reader.hpp +++ b/Navmesher/esx_reader.hpp @@ -25,16 +25,16 @@ class RecordNode; // This is defined by the file spec, do not change unless the file spec changes. enum class GroupType : int32_t { - Top = 0, - WorldChildren = 1, - InteriorCellBlock = 2, - InteriorCellSubBlock = 3, - ExteriorCellBlock = 4, - ExteriorCellSubBlock = 5, - CellChildren = 6, - TopicChildren = 7, + Top = 0, + WorldChildren = 1, + InteriorCellBlock = 2, + InteriorCellSubBlock = 3, + ExteriorCellBlock = 4, + ExteriorCellSubBlock = 5, + CellChildren = 6, + TopicChildren = 7, CellPersistentChildren = 8, - CellTemporaryChildren = 9, + CellTemporaryChildren = 9, }; enum class RecordType { @@ -62,24 +62,26 @@ using Node = std::variant; // Aggregate types // -struct FourCC : utility::Store { +struct FourCC : utility::Store { constexpr FourCC() noexcept = default; - explicit constexpr FourCC(const char (&str)[5]) noexcept : Store{ utility::fourcc_lit_to_val(str) } { } + explicit constexpr FourCC(const char(&str)[5]) noexcept : Store{ utility::fourcc_lit_to_val(str) } { } }; static_assert(std::is_trivial_v); -struct FormID : utility::Store { }; -struct Timestamp : utility::Store { }; -struct VCInfo : utility::Store { }; +struct FormID : utility::Store { }; +struct Timestamp : utility::Store { }; +struct VCInfo : utility::Store { }; struct Flag { RecordType type; unsigned bit; + friend constexpr auto operator<=>(const Flag &, const Flag &) noexcept = default; }; struct RefrFlag { RecordType refr_type; unsigned bit; + friend constexpr auto operator<=>(const RefrFlag &, const RefrFlag &) noexcept = default; }; struct GroupHeader { @@ -87,13 +89,13 @@ struct GroupHeader { int16_t y, x; }; - struct TopType : utility::Store { }; - struct ParentWorld : utility::Store { }; - struct BlockNumber : utility::Store { }; + struct TopType : utility::Store { }; + struct ParentWorld : utility::Store { }; + struct BlockNumber : utility::Store { }; struct SubBlockNumber : utility::Store { }; - struct BlockCoord : utility::Store { }; - struct SubBlockCoord : utility::Store { }; - struct ParentCell : utility::Store { }; + struct BlockCoord : utility::Store { }; + struct SubBlockCoord : utility::Store { }; + struct ParentCell : utility::Store { }; struct ParentDialogue : utility::Store { }; union GroupLabel { @@ -118,7 +120,7 @@ struct GroupHeader { static_assert(sizeof(GroupHeader) == 24); struct RecordHeader { - struct Flags : utility::Store { }; + struct Flags : utility::Store { }; struct Version : utility::Store { }; RecordType type; @@ -152,12 +154,13 @@ private: // Free functions // -[[nodiscard]] constexpr std::optional esxr_lut::group_type_to_name(GroupType group_type) noexcept; -[[nodiscard]] constexpr std::optional esxr_lut::record_type_to_fourcc(RecordType record_type) noexcept; -[[nodiscard]] constexpr std::optional esxr_lut::fourcc_to_record_type(FourCC fourcc) noexcept; -[[nodiscard]] constexpr std::optional esxr_lut::record_type_to_name(RecordType record_type) noexcept; -[[nodiscard]] constexpr std::optional esxr_lut::flag_to_description(Flag flag) noexcept; -[[nodiscard]] constexpr std::optional esxr_lut::refr_flag_to_description(RefrFlag refr_flag) noexcept; +[[nodiscard]] extern constexpr std::optional group_type_to_name(GroupType group_type) noexcept; +[[nodiscard]] extern constexpr std::optional record_type_to_fourcc(RecordType record_type) noexcept; +[[nodiscard]] extern constexpr std::optional fourcc_to_record_type(FourCC fourcc) noexcept; +[[nodiscard]] extern constexpr std::optional record_type_to_name(RecordType record_type) noexcept; +[[nodiscard]] extern constexpr std::optional flag_to_description(Flag flag) noexcept; +[[nodiscard]] extern constexpr std::optional refr_flag_to_description(RefrFlag refr_flag) noexcept; } + #endif diff --git a/Navmesher/esx_reader_lut.cpp b/Navmesher/esx_reader_lut.cpp index 373ad7c..37a6d2e 100644 --- a/Navmesher/esx_reader_lut.cpp +++ b/Navmesher/esx_reader_lut.cpp @@ -2,8 +2,6 @@ using namespace esxr; -namespace esxr_lut { - static constexpr std::pair group_type_name_map_builtin[] { {GroupType::Top , "Top Type" }, {GroupType::WorldChildren , "World Children" }, @@ -18,10 +16,6 @@ static constexpr std::pair group_type_name_map_buil }; static constexpr auto group_type_name_map_std = utility::array_builtin_to_std(group_type_name_map_builtin); static constexpr auto group_type_name_map = utility::map_to_soa(group_type_name_map_std); -[[nodiscard]] constexpr std::optional group_type_to_name(GroupType group_type) noexcept -{ - return utility::soa_first_to_second(group_type_name_map, group_type); -} static constexpr std::pair record_type_fourcc_map_builtin[] { {RecordType::AACT, FourCC("AACT")}, {RecordType::ACHR, FourCC("ACHR")}, @@ -95,14 +89,6 @@ static constexpr std::pair record_type_fourcc_map_builtin[] }; static constexpr auto record_type_fourcc_map_std = utility::array_builtin_to_std(record_type_fourcc_map_builtin); static constexpr auto record_type_fourcc_map = utility::map_to_soa(record_type_fourcc_map_std); -[[nodiscard]] constexpr std::optional record_type_to_fourcc(RecordType record_type) noexcept -{ - return utility::soa_first_to_second(record_type_fourcc_map, record_type); -} -[[nodiscard]] constexpr std::optional fourcc_to_record_type(FourCC fourcc) noexcept -{ - return utility::soa_second_to_first(record_type_fourcc_map, fourcc); -} static constexpr std::pair record_type_name_map_builtin[] { {RecordType::AACT, "Action" }, @@ -244,10 +230,6 @@ static constexpr std::pair record_type_name_map_bu }; static constexpr auto record_type_name_map_std = utility::array_builtin_to_std(record_type_name_map_builtin); static constexpr auto record_type_name_map = utility::map_to_soa(record_type_name_map_std); -[[nodiscard]] constexpr std::optional record_type_to_name(RecordType record_type) noexcept -{ - return utility::soa_first_to_second(record_type_name_map, record_type); -} static constexpr std::pair flag_description_map_builtin[] { {{RecordType::ACHR, 9}, "Starts Dead" }, @@ -420,10 +402,6 @@ static constexpr std::pair flag_description_map_builtin[ }; static constexpr auto flag_description_map_std = utility::array_builtin_to_std(flag_description_map_builtin); static constexpr auto flag_description_map = utility::map_to_soa(flag_description_map_std); -[[nodiscard]] constexpr std::optional flag_to_description(Flag flag) noexcept -{ - return utility::soa_first_to_second(flag_description_map, flag); -} static constexpr std::pair refr_flag_description_map_builtin[] { {{RecordType::ACTI, 9}, "Hidden From Local Map" }, @@ -606,6 +584,29 @@ static constexpr std::pair refr_flag_description_map }; static constexpr auto refr_flag_description_map_std = utility::array_builtin_to_std(refr_flag_description_map_builtin); static constexpr auto refr_flag_description_map = utility::map_to_soa(refr_flag_description_map_std); + +namespace esxr { + +[[nodiscard]] constexpr std::optional group_type_to_name(GroupType group_type) noexcept +{ + return utility::soa_first_to_second(group_type_name_map, group_type); +} +[[nodiscard]] constexpr std::optional record_type_to_fourcc(RecordType record_type) noexcept +{ + return utility::soa_first_to_second(record_type_fourcc_map, record_type); +} +[[nodiscard]] constexpr std::optional fourcc_to_record_type(FourCC fourcc) noexcept +{ + return utility::soa_second_to_first(record_type_fourcc_map, fourcc); +} +[[nodiscard]] constexpr std::optional record_type_to_name(RecordType record_type) noexcept +{ + return utility::soa_first_to_second(record_type_name_map, record_type); +} +[[nodiscard]] constexpr std::optional flag_to_description(Flag flag) noexcept +{ + return utility::soa_first_to_second(flag_description_map, flag); +} [[nodiscard]] constexpr std::optional refr_flag_to_description(RefrFlag refr_flag) noexcept { return utility::soa_first_to_second(refr_flag_description_map, refr_flag); diff --git a/Navmesher/main.cpp b/Navmesher/main.cpp index e630ae4..2d6fa4d 100644 --- a/Navmesher/main.cpp +++ b/Navmesher/main.cpp @@ -3,5 +3,5 @@ int main() { - std::cout << "Test" << std::endl; + std::cout << esxr::flag_to_description({ esxr::RecordType::TES4, 0 }).value() << std::endl; } \ No newline at end of file