diff --git a/Editor/Binary/Binary.ixx b/Editor/Binary/Binary.ixx index ae20050..5257a76 100644 --- a/Editor/Binary/Binary.ixx +++ b/Editor/Binary/Binary.ixx @@ -3,7 +3,7 @@ export module Binary; import std; export template -concept BinaryType = std::integral || std::floating_point; +concept BinaryType = std::integral || std::floating_point || std::same_as; template concept DerivedStream = std::derived_from; diff --git a/Editor/Binary/BinaryWriter.ixx b/Editor/Binary/BinaryWriter.ixx index c2a2744..01de197 100644 --- a/Editor/Binary/BinaryWriter.ixx +++ b/Editor/Binary/BinaryWriter.ixx @@ -15,18 +15,15 @@ public: BinaryWriter& operator=(BinaryWriter&&) = delete; template - void Write(T data) + void Write(const T& data) { - Stream->write(reinterpret_cast(&data), sizeof(T)); + Stream->write(reinterpret_cast(&data), sizeof(T)); } - void Write(const std::string& data, bool writeSize = true) + template<> + void Write(const std::string& data) { std::size_t size{ data.size() }; - if (writeSize) { - Stream->write(reinterpret_cast(&size), sizeof(std::uint32_t)); - } - Stream->write(data.c_str(), size); } @@ -42,8 +39,8 @@ public: [[nodiscard]] std::string ToString() const noexcept override { - if (std::ostringstream* d = dynamic_cast(Stream.get()); d != nullptr) { - return d->str(); + if (std::ostringstream* stream = dynamic_cast(Stream.get()); stream != nullptr) { + return stream->str(); } return std::string{}; diff --git a/Editor/Main.ixx b/Editor/Main.ixx index d960388..560a024 100644 --- a/Editor/Main.ixx +++ b/Editor/Main.ixx @@ -1,14 +1,13 @@ import std; import Xnb; -import BinaryReader; import Texture; int main() { - //std::expected file{ Xnb::Read("Images/Misc/profile_bg2-copy.xnb") }; + //std::expected file{ Xnb::Read("profile_bg.xnb") }; //if (!file.has_value()) return 1; - //file.value().Type->Export("Images/Misc/profile_bg2.png"); - //std::expected file{ Xnb::Write("Images/Misc/profile_bg2.png") }; + //file.value().Type->Export("profile_bg.png"); + std::expected file{ Xnb::Write("profile_bg.png") }; //for (const auto& entry : std::filesystem::recursive_directory_iterator("Images/Misc/SFDLogo")) { // if (entry.is_regular_file() && entry.path().extension() == ".png") { diff --git a/Editor/Parser/Texture.ixx b/Editor/Parser/Texture.ixx index bec04ef..4b46fe9 100644 --- a/Editor/Parser/Texture.ixx +++ b/Editor/Parser/Texture.ixx @@ -5,7 +5,6 @@ module; export module Texture; -import std; import Converter; import BinaryReader; import BinaryWriter; diff --git a/Editor/Parser/Xnb.ixx b/Editor/Parser/Xnb.ixx index 9b67630..353f20e 100644 --- a/Editor/Parser/Xnb.ixx +++ b/Editor/Parser/Xnb.ixx @@ -143,7 +143,7 @@ public: if (!std::filesystem::exists(file)) return std::unexpected("File does not exist"); BinaryWriter stream{ file.relative_path().replace_extension(".xnb") }; - stream.Write("XNB", false); + stream.Write("XNB"); stream.Write(static_cast('w')); stream.Write(5); stream.Write(128); @@ -161,12 +161,12 @@ public: BinaryWriter memoryStream{}; memoryStream.Write7BitEncodedInteger(1); - memoryStream.Write7BitEncodedInteger(type->ReaderName().size()); - memoryStream.Write(type->ReaderName(), false); + memoryStream.Write7BitEncodedInteger(static_cast(type->ReaderName().size())); + memoryStream.Write(type->ReaderName()); memoryStream.Write(0); memoryStream.Write7BitEncodedInteger(0); memoryStream.Write7BitEncodedInteger(1); - memoryStream.Write(type->Binary(), false); + memoryStream.Write(type->Binary()); const std::string decompressedData{ memoryStream.ToString() }; const std::size_t decompressedSize{ decompressedData.size() }; @@ -194,9 +194,9 @@ public: compressedData.resize(compressedSize); - stream.Write(compressedSize + _headerSize); - stream.Write(decompressedSize); - stream.Write(compressedData, false); + stream.Write(static_cast(compressedSize + _headerSize)); + stream.Write(static_cast(decompressedSize)); + stream.Write(compressedData); return std::expected( std::in_place,