Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmake/AddPrettyParser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ function(add_pretty_parser TARGET)
target_link_libraries(${TARGET} PUBLIC ${PROJECT_NAME} ${OPTIONS_DEPS_PUBLIC})
target_link_libraries(${TARGET} INTERFACE ${OPTIONS_DEPS_INTERFACE})

# Enable warnings, warnings are errors
if(PROJECT_IS_TOP_LEVEL)
if(MSVC)
target_compile_options(${TARGET} PRIVATE /W4 /WX)
else()
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wpedantic)
endif()
set_target_properties(${TARGET} PROPERTIES
COMPILE_WARNING_AS_ERROR ON
LINK_WARNING_AS_ERROR ON)
endif()

# Define DEBUG macro
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:DEBUG>")

Expand Down
2 changes: 1 addition & 1 deletion include/sourcepp/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ template<std::unsigned_integral T>

[[nodiscard]] constexpr uint16_t paddingForAlignment(uint16_t alignment, uint64_t n) {
if (const auto rest = n % alignment; rest > 0) {
return alignment - rest;
return static_cast<uint16_t>(alignment - rest);
}
return 0;
}
Expand Down
19 changes: 19 additions & 0 deletions include/vpkpp/PackFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
#include <vector>

#include <sourcepp/Macros.h>

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

#include <tsl/htrie_map.h>

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "Attribute.h"
#include "Entry.h"
#include "Options.h"
Expand Down Expand Up @@ -226,10 +236,19 @@ class PackFile {

static std::unordered_map<std::string, std::vector<OpenFactoryFunction>>& getOpenExtensionRegistry();

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
#endif

static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunctionBasic& factory);

static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunction& factory);

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

std::string fullFilePath;
EntryTrie entries;
EntryTrie unbakedEntries;
Expand Down
2 changes: 1 addition & 1 deletion lang/c/include/vtfppc/SHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ VTFPP_EXTERN typedef struct {
vtfpp_sht_sequence_frame_bounds_t bounds[4];
} vtfpp_sht_sequence_frame_t;

#define VTFPP_SHT_SEQUENCE_FRAME_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_sequence_frame_t) {.duration = 0.f})
#define VTFPP_SHT_SEQUENCE_FRAME_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_sequence_frame_t) {.duration = 0.f, .bounds = {{0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}}})

VTFPP_EXTERN typedef struct {
uint32_t id;
Expand Down
2 changes: 1 addition & 1 deletion lang/c/src/sourceppc/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SOURCEPP_API sourcepp_string_array_t sourcepp_string_array_new(size_t size) {

SOURCEPP_API void sourcepp_string_array_free(sourcepp_string_array_t* array) {
if (array->data) {
for (size_t i = 0; i < array->size; i++) {
for (int64_t i = 0; i < array->size; i++) {
if (char* str = array->data[i]) {
std::free(str);
array->data[i] = nullptr;
Expand Down
16 changes: 11 additions & 5 deletions src/bsppp/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,17 @@ bool BSP::setLump(BSPLump lumpIndex, uint32_t version, std::span<const std::byte
return false;
}
this->stagedLumps[lump] = std::make_pair<Lump, std::vector<std::byte>>({
.version = version, .uncompressedLength = static_cast<uint32_t>(data.size()),
.offset = 0,
.length = 0,
.version = version,
.uncompressedLength = static_cast<uint32_t>(data.size()),
}, {compressedData->begin(), compressedData->end()});
} else {
this->stagedLumps[lump] = std::make_pair<Lump, std::vector<std::byte>>({
.version = version, .uncompressedLength = 0,
.offset = 0,
.length = 0,
.version = version,
.uncompressedLength = 0,
}, {data.begin(), data.end()});
}
return true;
Expand Down Expand Up @@ -258,6 +264,7 @@ bool BSP::setGameLump(BSPGameLump::Signature signature, uint16_t version, std::s
.version = version,
.offset = 0,
.uncompressedLength = static_cast<uint32_t>(data.size()),
.data = {},
};

if (compressLevel) {
Expand Down Expand Up @@ -286,8 +293,7 @@ void BSP::resetLump(BSPLump lumpIndex) {
this->stagedGameLumps = this->parseGameLumps(false);
return;
}
const auto lump = static_cast<std::underlying_type_t<BSPLump>>(lumpIndex);
if (this->stagedLumps.contains(lump)) {
if (const auto lump = static_cast<std::underlying_type_t<BSPLump>>(lumpIndex); this->stagedLumps.contains(lump)) {
this->stagedLumps.erase(lump);
}
}
Expand Down Expand Up @@ -378,7 +384,7 @@ bool BSP::bake(std::string_view outputPath) {
}

const auto lumpsHeaderOffset = stream.tell();
for (int i = 0; i < sizeof(Header::lumps); i++) {
for (size_t i = 0; i < sizeof(Header::lumps); i++) {
stream.write<uint8_t>(0);
}

Expand Down
16 changes: 8 additions & 8 deletions src/bsppp/EntityLump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uint64_t BSPEntityKeyValues::getKeyValuesCount() const {
uint64_t BSPEntityKeyValues::getKeyValuesCount(std::string_view childKey) const {
uint64_t count = 0;
for (const auto& element : this->keyvalues) {
if (sourcepp::string::iequals(element.getKey(), childKey)) {
if (string::iequals(element.getKey(), childKey)) {
++count;
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator[](std::string_view chi

const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey) const {
for (const auto& element : this->keyvalues) {
if (sourcepp::string::iequals(element.getKey(), childKey)) {
if (string::iequals(element.getKey(), childKey)) {
return element;
}
}
Expand All @@ -73,7 +73,7 @@ const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_vi

BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey) {
for (auto& element : this->keyvalues) {
if (sourcepp::string::iequals(element.getKey(), childKey)) {
if (string::iequals(element.getKey(), childKey)) {
return element;
}
}
Expand All @@ -83,7 +83,7 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view chi
const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey, unsigned int n) const {
unsigned int count = 0;
for (const auto& element : this->keyvalues) {
if (sourcepp::string::iequals(element.getKey(), childKey)) {
if (string::iequals(element.getKey(), childKey)) {
if (count == n) {
return element;
}
Expand All @@ -96,7 +96,7 @@ const BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_vi
BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view childKey, unsigned int n) {
unsigned int count = 0;
for (auto& element: this->keyvalues) {
if (sourcepp::string::iequals(element.getKey(), childKey)) {
if (string::iequals(element.getKey(), childKey)) {
if (count == n) {
return element;
}
Expand All @@ -107,9 +107,9 @@ BSPEntityKeyValues::Element& BSPEntityKeyValues::operator()(std::string_view chi
}

void BSPEntityKeyValues::removeKeyValue(std::string_view childKey, int n) {
unsigned int count = 0;
int count = 0;
for (auto element = this->keyvalues.begin(); element != this->keyvalues.end(); ++element) {
if (sourcepp::string::iequals(element->getKey(), childKey)) {
if (string::iequals(element->getKey(), childKey)) {
if (n < 0 || count == n) {
element = this->keyvalues.erase(element);
if (count == n) {
Expand All @@ -130,6 +130,6 @@ std::string BSPEntityKeyValues::bake(bool useEscapes) const {
out += parser::text::convertSpecialCharsToEscapes(elem.getValue(), parser::text::getDefaultEscapeSequencesOrNone(useEscapes));
out += "\"\n";
}
out += "}";
out += '}';
return out;
}
15 changes: 7 additions & 8 deletions src/fspp/fspp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
if (searchPathKVs.isInvalid()) {
return;
}
for (int i = 0; i < searchPathKVs.getChildCount(); i++) {
for (uint64_t i = 0; i < searchPathKVs.getChildCount(); i++) {
auto searches = string::split(string::toLower(searchPathKVs[i].getKey()), '+');
auto path = std::string{string::toLower(searchPathKVs[i].getValue())};

Expand All @@ -67,7 +67,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
} else if (path.starts_with(GAMEINFO_PATH)) {
path = gameID + '/' + path.substr(GAMEINFO_PATH.length());
}
if (path.ends_with(".") && !path.ends_with("..")) {
if (path.ends_with('.') && !path.ends_with("..")) {
path.pop_back();
}
string::normalizeSlashes(path);
Expand All @@ -89,8 +89,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
if (!this->searchPathVPKs.contains(search)) {
this->searchPathVPKs[search] = std::vector<std::unique_ptr<PackFile>>{};
}
auto packFile = PackFile::open(fullPath);
if (packFile) {
if (auto packFile = PackFile::open(fullPath)) {
this->searchPathVPKs[search].push_back(std::move(packFile));
}
}
Expand All @@ -102,7 +101,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
if (path.ends_with("/*")) {
// Add the glob dir searchpath
if (const auto globParentPath = this->rootPath + '/' + path.substr(0, path.length() - 2); std::filesystem::exists(globParentPath) && std::filesystem::is_directory(globParentPath)) {
for (const auto directoryIterator : std::filesystem::directory_iterator{globParentPath, std::filesystem::directory_options::skip_permission_denied}) {
for (const auto& directoryIterator : std::filesystem::directory_iterator{globParentPath, std::filesystem::directory_options::skip_permission_denied}) {
auto globChildPath = std::filesystem::relative(directoryIterator.path(), this->rootPath).string();
string::normalizeSlashes(globChildPath);
this->searchPathDirs[search].push_back(globChildPath);
Expand Down Expand Up @@ -143,8 +142,8 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
} else {
this->searchPathDirs["executable_path"] = {};
}
this->searchPathDirs["executable_path"].push_back("bin");
this->searchPathDirs["executable_path"].push_back("");
this->searchPathDirs["executable_path"].emplace_back("bin");
this->searchPathDirs["executable_path"].emplace_back("");
}

// Add PLATFORM if it doesn't exist, point it at "platform"
Expand All @@ -161,7 +160,7 @@ FileSystem::FileSystem(std::string_view gamePath, const FileSystemOptions& optio
}
}
if (!foundPlatform) {
this->searchPathDirs["game"].push_back("platform");
this->searchPathDirs["game"].emplace_back("platform");
}
}

Expand Down
Loading
Loading