mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
correctness
This commit is contained in:
@@ -1,22 +1,10 @@
|
||||
cmake_minimum_required(VERSION "3.12" FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION "3.15" FATAL_ERROR)
|
||||
project(tmx2gba VERSION "0.3")
|
||||
|
||||
# Options
|
||||
option(TMX2GBA_DKP_INSTALL "Install into DEVKITPRO prefix" OFF)
|
||||
option(ASAN "Enable address sanitiser" OFF)
|
||||
|
||||
# C++20 & C99
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
# Enable strong warnings
|
||||
if (MSVC)
|
||||
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REPLACE "/W3" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
else()
|
||||
add_compile_options(-Wall)
|
||||
endif()
|
||||
|
||||
if (ASAN)
|
||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||
add_link_options(-fsanitize=address -shared-libasan)
|
||||
|
||||
@@ -8,6 +8,17 @@ add_executable(tmx2gba
|
||||
headerwriter.hpp headerwriter.cpp
|
||||
tmx2gba.cpp)
|
||||
|
||||
set_target_properties(tmx2gba PROPERTIES
|
||||
# C++20 & C99
|
||||
CXX_STANDARD 20
|
||||
C_STANDARD 99)
|
||||
|
||||
# Enable strong warnings
|
||||
target_compile_options(tmx2gba PRIVATE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/Wall>
|
||||
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic>
|
||||
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Weverything>)
|
||||
|
||||
target_link_libraries(tmx2gba
|
||||
External::base64
|
||||
External::miniz
|
||||
|
||||
@@ -151,6 +151,8 @@ bool ArgParse::ArgParser::CheckParse(ArgParse::ParseErr err) const
|
||||
case ParseErr::ARG_RANGE:
|
||||
DisplayError("Argument out of range.", false);
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +209,7 @@ bool ArgParse::ReadParamFile(std::vector<std::string>& tokens, std::istream& fil
|
||||
}
|
||||
else
|
||||
{
|
||||
quoteStr.push_back(c);
|
||||
quoteStr.push_back(static_cast<char>(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ namespace ArgParse
|
||||
{
|
||||
const std::vector<Option> options;
|
||||
|
||||
inline Options(const std::initializer_list<Option>&& rhs)
|
||||
: options(std::move(rhs)) {}
|
||||
inline Options(const std::initializer_list<Option>&& rhs) : options(rhs) {}
|
||||
|
||||
void ShowShortUsage(const std::string_view name, std::ostream& out) const;
|
||||
void ShowHelpUsage(const std::string_view name, std::ostream& out) const;
|
||||
@@ -99,7 +98,7 @@ namespace ArgParse
|
||||
ParserState state(handler, options);
|
||||
for (auto arg : args)
|
||||
{
|
||||
ParseErr err;
|
||||
ParseErr err = ParseErr::UNEXPECTED;
|
||||
switch (state.Next(arg))
|
||||
{
|
||||
case ParseCtrl::CONTINUE: continue;
|
||||
|
||||
@@ -11,30 +11,30 @@ template <> constexpr std::string_view DatType<uint32_t>() { return "unsigned in
|
||||
void HeaderWriter::WriteSize(int width, int height)
|
||||
{
|
||||
stream << std::endl;
|
||||
WriteDefine(name + "Width", width);
|
||||
WriteDefine(name + "Height", height);
|
||||
WriteDefine(mName + "Width", width);
|
||||
WriteDefine(mName + "Height", height);
|
||||
}
|
||||
|
||||
void HeaderWriter::WriteCharacterMap(const std::span<uint16_t> charData)
|
||||
{
|
||||
stream << std::endl;
|
||||
WriteDefine(name + "TilesLen", charData.size() * 2);
|
||||
WriteSymbol(name + "Tiles", DatType<uint16_t>(), charData.size());
|
||||
WriteDefine(mName + "TilesLen", charData.size() * 2);
|
||||
WriteSymbol(mName + "Tiles", DatType<uint16_t>(), charData.size());
|
||||
}
|
||||
|
||||
void HeaderWriter::WriteCollision(const std::span<uint8_t> collisionData)
|
||||
{
|
||||
stream << std::endl;
|
||||
WriteDefine(name + "CollisionLen", collisionData.size());
|
||||
WriteSymbol(name + "Collision", DatType<uint8_t>(), collisionData.size());
|
||||
WriteDefine(mName + "CollisionLen", collisionData.size());
|
||||
WriteSymbol(mName + "Collision", DatType<uint8_t>(), collisionData.size());
|
||||
}
|
||||
|
||||
void HeaderWriter::WriteObjects(const std::span<uint32_t> objData)
|
||||
{
|
||||
stream << std::endl;
|
||||
WriteDefine(name + "ObjCount", objData.size() / 3);
|
||||
WriteDefine(name + "ObjdatLen", objData.size() * sizeof(int));
|
||||
WriteSymbol(name + "Objdat", DatType<uint32_t>(), objData.size());
|
||||
WriteDefine(mName + "ObjCount", objData.size() / 3);
|
||||
WriteDefine(mName + "ObjdatLen", objData.size() * sizeof(int));
|
||||
WriteSymbol(mName + "Objdat", DatType<uint32_t>(), objData.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -49,14 +49,14 @@ static std::string GuardName(const std::string_view name)
|
||||
|
||||
void HeaderWriter::WriteGuardStart()
|
||||
{
|
||||
const std::string guard = GuardName(name);
|
||||
const std::string guard = GuardName(mName);
|
||||
stream << "#ifndef " << guard << std::endl;
|
||||
stream << "#define " << guard << std::endl;
|
||||
}
|
||||
|
||||
void HeaderWriter::WriteGuardEnd()
|
||||
{
|
||||
const std::string guard = GuardName(name);
|
||||
const std::string guard = GuardName(mName);
|
||||
stream << std::endl << "#endif//" << guard << std::endl;
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ HeaderWriter::~HeaderWriter()
|
||||
}
|
||||
|
||||
|
||||
bool HeaderWriter::Open(const std::string_view path, const std::string_view name)
|
||||
bool HeaderWriter::Open(const std::filesystem::path& path, const std::string_view name)
|
||||
{
|
||||
this->name = name;
|
||||
mName = name;
|
||||
stream.open(path);
|
||||
if (!stream.is_open())
|
||||
return false;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <span>
|
||||
#include <concepts>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
template <typename T>
|
||||
concept NumericType = std::integral<T> || std::floating_point<T>;
|
||||
@@ -17,7 +18,7 @@ concept NumericType = std::integral<T> || std::floating_point<T>;
|
||||
class HeaderWriter
|
||||
{
|
||||
std::ofstream stream;
|
||||
std::string name;
|
||||
std::string mName;
|
||||
|
||||
void WriteGuardStart();
|
||||
void WriteGuardEnd();
|
||||
@@ -25,7 +26,7 @@ class HeaderWriter
|
||||
public:
|
||||
~HeaderWriter();
|
||||
|
||||
[[nodiscard]] bool Open(const std::string_view path, const std::string_view name);
|
||||
[[nodiscard]] bool Open(const std::filesystem::path& path, const std::string_view name);
|
||||
|
||||
void WriteDefine(const std::string_view name, const std::string_view value);
|
||||
void WriteSymbol(const std::string_view name, const std::string_view type, std::size_t count);
|
||||
|
||||
@@ -10,16 +10,19 @@
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
namespace GccIsDumb
|
||||
{
|
||||
template <typename T> constexpr const char* DatType();
|
||||
template <> constexpr const char* DatType<uint8_t>() { return ".byte"; }
|
||||
template <> constexpr const char* DatType<uint16_t>() { return ".hword"; }
|
||||
template <> constexpr const char* DatType<uint32_t>() { return ".word"; }
|
||||
}
|
||||
|
||||
class SWriter
|
||||
{
|
||||
std::ofstream stream;
|
||||
int writes = 0;
|
||||
|
||||
template <typename T> static constexpr const char* DatType();
|
||||
template <> constexpr const char* DatType<uint8_t>() { return ".byte"; }
|
||||
template <> constexpr const char* DatType<uint16_t>() { return ".hword"; }
|
||||
template <> constexpr const char* DatType<uint32_t>() { return ".word"; }
|
||||
|
||||
template <typename T>
|
||||
static void WriteArray(std::ostream& aOut, const std::vector<T>& aDat, int aPerCol = 16)
|
||||
{
|
||||
@@ -32,7 +35,7 @@ class SWriter
|
||||
for (T element : aDat)
|
||||
{
|
||||
if (col == 0)
|
||||
aOut << "\t" << DatType<T>() << " ";
|
||||
aOut << "\t" << GccIsDumb::DatType<T>() << " ";
|
||||
|
||||
aOut << std::hex << (int)element;
|
||||
|
||||
@@ -54,7 +57,7 @@ class SWriter
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] bool Open(const std::string_view path)
|
||||
[[nodiscard]] bool Open(const std::filesystem::path& path)
|
||||
{
|
||||
stream.open(path);
|
||||
return stream.is_open();
|
||||
|
||||
@@ -67,8 +67,8 @@ bool ParseArgs(int argc, char** argv, Arguments& params)
|
||||
default: return ParseCtrl::QUIT_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
catch (std::invalid_argument const& e) { return ParseCtrl::QUIT_ERR_INVALID; }
|
||||
catch (std::out_of_range const& e) { return ParseCtrl::QUIT_ERR_RANGE; }
|
||||
catch (std::invalid_argument const&) { return ParseCtrl::QUIT_ERR_INVALID; }
|
||||
catch (std::out_of_range const&) { return ParseCtrl::QUIT_ERR_RANGE; }
|
||||
});
|
||||
|
||||
if (!parser.Parse(std::span(argv + 1, argc - 1)))
|
||||
|
||||
Reference in New Issue
Block a user