Fixed compiler warnings. Playing around with std::filesystem and std::fstream.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,6 +3,9 @@
|
|||||||
##
|
##
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# Project specific
|
||||||
|
*.esm
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.rsuser
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
|
|||||||
@@ -134,6 +134,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="esx_reader.cpp" />
|
||||||
<ClCompile Include="esx_reader_lut.cpp" />
|
<ClCompile Include="esx_reader_lut.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
<ClCompile Include="esx_reader_lut.cpp">
|
<ClCompile Include="esx_reader_lut.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="esx_reader.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="esx_reader.hpp">
|
<ClInclude Include="esx_reader.hpp">
|
||||||
|
|||||||
4
Navmesher/esx_reader.cpp
Normal file
4
Navmesher/esx_reader.cpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "esx_reader.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <compare>
|
#include <compare>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
@@ -62,11 +63,13 @@ using Node = std::variant<GroupNode, RecordNode>;
|
|||||||
// Aggregate types
|
// Aggregate types
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#pragma warning( push )
|
||||||
|
#pragma warning( disable : 4514 )
|
||||||
struct FourCC : utility::Store<uint32_t> {
|
struct FourCC : utility::Store<uint32_t> {
|
||||||
constexpr FourCC() noexcept = default;
|
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<FourCC>);
|
#pragma warning( pop )
|
||||||
|
|
||||||
struct FormID : utility::Store<uint32_t> { };
|
struct FormID : utility::Store<uint32_t> { };
|
||||||
struct Timestamp : utility::Store<uint16_t> { };
|
struct Timestamp : utility::Store<uint16_t> { };
|
||||||
@@ -117,7 +120,6 @@ struct GroupHeader {
|
|||||||
VCInfo version_control_information;
|
VCInfo version_control_information;
|
||||||
uint32_t unknown;
|
uint32_t unknown;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(GroupHeader) == 24);
|
|
||||||
|
|
||||||
struct RecordHeader {
|
struct RecordHeader {
|
||||||
struct Flags : utility::Store<uint32_t> { };
|
struct Flags : utility::Store<uint32_t> { };
|
||||||
@@ -132,7 +134,6 @@ struct RecordHeader {
|
|||||||
Version version;
|
Version version;
|
||||||
uint16_t unknown;
|
uint16_t unknown;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(RecordHeader) == 24);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Classes
|
// Classes
|
||||||
|
|||||||
@@ -1,7 +1,33 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "esx_reader.hpp"
|
#include "esx_reader.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
static constexpr auto esm_name = "Skyrim.esm";
|
||||||
|
|
||||||
|
/* Propagated Exceptions:
|
||||||
|
* - std::bad_alloc
|
||||||
|
* - std::filesystem::filesystem_error
|
||||||
|
* - std::ios_base::failure
|
||||||
|
*/
|
||||||
|
[[nodiscard]] static std::ifstream open_esm(void)
|
||||||
|
{
|
||||||
|
std::filesystem::path cwd = std::filesystem::current_path();
|
||||||
|
auto esm_path = cwd / esm_name;
|
||||||
|
auto esm_fs = std::ifstream(esm_path, std::ios::binary);
|
||||||
|
if (esm_fs.fail())
|
||||||
|
throw std::ios_base::failure("Could not open the esm file for reading.");
|
||||||
|
return esm_fs;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << esxr::flag_to_description({ esxr::RecordType::TES4, 0 }).value() << std::endl;
|
auto esm_fs = open_esm();
|
||||||
|
std::array<char, 4> fourcc{};
|
||||||
|
esm_fs.read(fourcc.data(), static_cast<std::streamsize>(fourcc.size()));
|
||||||
|
for (auto c : fourcc)
|
||||||
|
std::cout << c;
|
||||||
|
std::cout << '\n';
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ struct Store {
|
|||||||
friend constexpr auto operator<=>(const Store &, const Store &) noexcept = default;
|
friend constexpr auto operator<=>(const Store &, const Store &) noexcept = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convert a fourcc literal (e.g. "LITR" to a uint32_t)
|
// Convert a fourcc literal (e.g. "LITR") to a uint32_t
|
||||||
constexpr uint32_t fourcc_lit_to_val(const char(&a)[5]) noexcept
|
constexpr uint32_t fourcc_lit_to_val(const char(&a)[5]) noexcept
|
||||||
{
|
{
|
||||||
char temp[4] = { a[0], a[1], a[2], a[3] };
|
char temp[4] = { a[0], a[1], a[2], a[3] };
|
||||||
@@ -31,6 +31,7 @@ constexpr std::array<T, N> array_builtin_to_std(const T(&builtin)[N]) noexcept
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert a std::array of std::pairs to a std::pair of std::arrays
|
||||||
template <typename First, typename Second, std::size_t N>
|
template <typename First, typename Second, std::size_t N>
|
||||||
constexpr std::pair<std::array<First, N>, std::array<Second, N>> map_to_soa(std::array<std::pair<First, Second>, N> map) noexcept
|
constexpr std::pair<std::array<First, N>, std::array<Second, N>> map_to_soa(std::array<std::pair<First, Second>, N> map) noexcept
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,7 @@ constexpr std::optional<Second> soa_first_to_second(const std::pair<std::array<F
|
|||||||
if (lhs == soa.first.cend())
|
if (lhs == soa.first.cend())
|
||||||
return {};
|
return {};
|
||||||
auto index = std::distance(soa.first.cbegin(), lhs);
|
auto index = std::distance(soa.first.cbegin(), lhs);
|
||||||
return { soa.second[index] };
|
return { soa.second[static_cast<size_t>(index)] };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename First, typename Second, std::size_t N>
|
template <typename First, typename Second, std::size_t N>
|
||||||
@@ -60,7 +61,7 @@ constexpr std::optional<First> soa_second_to_first(const std::pair<std::array<Fi
|
|||||||
if (lhs == soa.second.cend())
|
if (lhs == soa.second.cend())
|
||||||
return {};
|
return {};
|
||||||
auto index = std::distance(soa.second.cbegin(), lhs);
|
auto index = std::distance(soa.second.cbegin(), lhs);
|
||||||
return { soa.first[index] };
|
return { soa.first[static_cast<size_t>(index)] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to inspect type sizes and values at compile time. Example:
|
// Used to inspect type sizes and values at compile time. Example:
|
||||||
|
|||||||
Reference in New Issue
Block a user