diff --git a/storm/Error.cpp b/storm/Error.cpp index 3f7c70c..fc995d0 100644 --- a/storm/Error.cpp +++ b/storm/Error.cpp @@ -78,9 +78,9 @@ void SErrPrepareAppFatal(const char* filename, int32_t linenumber) { void SErrSetLastError(uint32_t errorcode) { s_lasterror = errorcode; - #if defined(WHOA_SYSTEM_WIN) +#if defined(WHOA_SYSTEM_WIN) SetLastError(errorcode); - #endif +#endif } uint32_t SErrGetLastError() { diff --git a/storm/Error.hpp b/storm/Error.hpp index a59a0a7..5340043 100644 --- a/storm/Error.hpp +++ b/storm/Error.hpp @@ -14,14 +14,12 @@ #define ERROR_INVALID_PARAMETER 0x57 #endif - #ifdef _DEBUG #ifndef ASSERTIONS_ENABLED #define ASSERTIONS_ENABLED #endif #endif - #if defined(ASSERTIONS_ENABLED) #define STORM_ASSERT(x) \ if (!(x)) { \ @@ -38,7 +36,6 @@ #define STORM_ASSERT_FATAL(x) #endif - #if defined(NDEBUG) #define STORM_VALIDATE_BEGIN { bool __storm_result = true #define STORM_VALIDATE(x) __storm_result &= !!(x); STORM_ASSERT(x) @@ -59,7 +56,6 @@ #define STORM_VALIDATE_END_VOID } #endif - #define STORM_ERROR_ASSERTION 0x85100000 #define STORM_ERROR_BAD_ARGUMENT 0x85100065 #define STORM_ERROR_GAME_ALREADY_STARTED 0x85100066 @@ -96,14 +92,12 @@ #define STORM_ERROR_GAME_TYPE_UNAVAILABLE 0x85100085 #define STORM_ERROR_FATAL_CONDITION 0x85100086 - #define SERR_LINECODE_FUNCTION -1 #define SERR_LINECODE_OBJECT -2 #define SERR_LINECODE_HANDLE -3 #define SERR_LINECODE_FILE -4 #define SERR_LINECODE_EXCEPTION -5 // exception handler - [[noreturn]] void SErrDisplayAppFatal(const char* format, ...); int32_t SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7); diff --git a/storm/Memory.cpp b/storm/Memory.cpp index 7763f1c..986a9f6 100644 --- a/storm/Memory.cpp +++ b/storm/Memory.cpp @@ -2,10 +2,8 @@ #include - constexpr size_t ALIGNMENT = 8; - void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) { size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1); diff --git a/storm/Memory.hpp b/storm/Memory.hpp index 6bdb2c8..355fca0 100644 --- a/storm/Memory.hpp +++ b/storm/Memory.hpp @@ -4,9 +4,7 @@ #include #include - -#define SMEM_FLAG_ZEROMEMORY 8 - +#define SMEM_FLAG_ZEROMEMORY 0x8 void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags = 0); diff --git a/storm/Region.cpp b/storm/Region.cpp index a76bc89..24e13a3 100644 --- a/storm/Region.cpp +++ b/storm/Region.cpp @@ -5,16 +5,13 @@ #include "storm/Thread.hpp" #include - static TSExportTableSyncReuse s_rgntable; - void DeleteCombinedRect(TSGrowableArray* combinedArray, uint32_t index); void DeleteRect(RECTF* rect); void DeleteSourceRect(TSGrowableArray* sourceArray, uint32_t index); int32_t IsNullRect(const RECTF* rect); - void AddCombinedRect(TSGrowableArray* combinedArray, const RECTF* rect) { RECTF* newRect = combinedArray->New(); *newRect = *rect; @@ -115,14 +112,18 @@ int SortFoundParamsCallback(const void* elem1, const void* elem2) { } void FindSourceParams(RGN* rgnptr, const RECTF* rect) { - if (CompareRects(rect, &rgnptr->foundparamsrect)) return; + if (CompareRects(rect, &rgnptr->foundparamsrect)) { + return; + } rgnptr->foundparams.SetCount(0); uint32_t sourceRects = rgnptr->source.Count(); uint32_t params = 0; for (uint32_t i = 0; i < sourceRects; i++) { - if (!CheckForIntersection(rect, &rgnptr->source[i].rect)) continue; + if (!CheckForIntersection(rect, &rgnptr->source[i].rect)) { + continue; + } int32_t sequence = rgnptr->source[i].sequence; int32_t found = 0; @@ -366,8 +367,14 @@ int SortRectCallback(const void* elem1, const void* elem2) { double result = rct1->top == rct2->top ? rct1->left - rct2->left : rct1->top - rct2->top; - if (result > 0.0) return 1; - if (result < 0.0) return -1; + if (result > 0.0) { + return 1; + } + + if (result < 0.0) { + return -1; + } + return 0; } @@ -387,7 +394,10 @@ void ProduceCombinedRectangles(RGN* rgn) { std::qsort(rgn->combined.Ptr(), rgn->combined.Count(), sizeof(RECTF), SortRectCallback); for (uint32_t i = rgn->combined.Count(); i > 0; i = rgn->combined.Count()) { - if (!IsNullRect(&rgn->combined[i-1])) break; + if (!IsNullRect(&rgn->combined[i-1])) { + break; + } + rgn->combined.SetCount(i - 1); } } @@ -402,7 +412,9 @@ void SRgnCombineRectf(HSRGN handle, const RECTF* rect, void* param, int32_t comb HLOCKEDRGN lockedHandle; auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); - if (!rgn) return; + if (!rgn) { + return; + } if (combineMode == SRGN_OR || combineMode == SRGN_PARAMONLY) { if (!IsNullRect(rect)) { @@ -502,7 +514,9 @@ void SRgnGetBoundingRectf(HSRGN handle, RECTF* rect) { HLOCKEDRGN lockedHandle; auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); - if (!rgn) return; + if (!rgn) { + return; + } for (uint32_t i = 0; i < rgn->source.Count(); i++) { auto source = &rgn->source[i]; @@ -602,7 +616,9 @@ int32_t SRgnIsPointInRegionf(HSRGN handle, float x, float y) { HLOCKEDRGN lockedHandle; auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); - if (!rgn) return 0; + if (!rgn) { + return 0; + } int32_t result = 0; @@ -630,7 +646,9 @@ int32_t SRgnIsRectInRegionf(HSRGN handle, const RECTF* rect) { HLOCKEDRGN lockedHandle; auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); - if (!rgn) return 0; + if (!rgn) { + return 0; + } int32_t result = 0; @@ -656,7 +674,9 @@ void SRgnOffsetf(HSRGN handle, float xoffset, float yoffset) { HLOCKEDRGN lockedHandle; auto rgn = s_rgntable.Lock(handle, &lockedHandle, 0); - if (!rgn) return; + if (!rgn) { + return; + } SOURCE* sourceArray = rgn->source.Ptr(); uint32_t sourceRects = rgn->source.Count(); diff --git a/storm/String.hpp b/storm/String.hpp index 1a0971d..3a9cbc7 100644 --- a/storm/String.hpp +++ b/storm/String.hpp @@ -5,13 +5,11 @@ #include #include - #define STORM_MAX_PATH 260 #define STORM_MAX_STR 0x7FFFFFFF #define SSTR_HASH_CASESENSITIVE 1 - char* SStrChr(char* string, char search); const char* SStrChr(const char* string, char search); diff --git a/storm/region/RGN.hpp b/storm/region/RGN.hpp index b02d973..6a5a199 100644 --- a/storm/region/RGN.hpp +++ b/storm/region/RGN.hpp @@ -6,7 +6,7 @@ #include "storm/Hash.hpp" #include -// region flgs +// Region flags #define SF_NONE 0x00000000 #define SF_ADDING 0x00000001 #define SF_OVERLAPS 0x00000002 diff --git a/storm/thread/SSyncObject.cpp b/storm/thread/SSyncObject.cpp index 4df43b0..0aec97c 100644 --- a/storm/thread/SSyncObject.cpp +++ b/storm/thread/SSyncObject.cpp @@ -8,7 +8,7 @@ SSyncObject::SSyncObject() { #if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) - pthread_mutex_init(&this->m_mutex, 0); + pthread_mutex_init(&this->m_mutex, nullptr); #endif } diff --git a/test/Memory.cpp b/test/Memory.cpp index 87872e9..e19f9a4 100644 --- a/test/Memory.cpp +++ b/test/Memory.cpp @@ -5,7 +5,6 @@ #include #include - TEST_CASE("SMemAlloc", "[memory]") { SECTION("allocates memory") { void* ptr = SMemAlloc(16, __FILE__, __LINE__); diff --git a/test/Region.cpp b/test/Region.cpp index 8a9241d..2246531 100644 --- a/test/Region.cpp +++ b/test/Region.cpp @@ -1,7 +1,6 @@ #include "RegionTest.hpp" #include - TEST_CASE("SRgnClear", "[region]") { RgnDataTest region; diff --git a/test/RegionTest.hpp b/test/RegionTest.hpp index b9c21e9..5a29152 100644 --- a/test/RegionTest.hpp +++ b/test/RegionTest.hpp @@ -1,50 +1,50 @@ -#include "storm/Region.hpp" -#include "test/Test.hpp" -#include - -// Fixture for repetitive handling of Rgn objects. -struct RgnDataTest { - HSRGN rgn = nullptr; - - RgnDataTest() { - SRgnCreate(&rgn, 0); - } - - ~RgnDataTest() { - SRgnDelete(rgn); - rgn = nullptr; - } - - HSRGN* operator &() { return &rgn; } - operator HSRGN() const { return rgn; } - HSRGN operator->() const { return rgn; } -}; - -// Helpers for comparing RECTF structs -std::ostream& operator <<(std::ostream& os, RECTF const& value) { - os << "{ " << value.left << ", " << value.bottom << ", " << value.right << ", " << value.top << " }"; - return os; -} - -template -class RECTMatcher : public Catch::MatcherBase { -private: - T cmp; - -public: - RECTMatcher(T arg) : cmp(arg) {} - - bool match(T const& in) const override { - return cmp.left == in.left && cmp.bottom == in.bottom && cmp.right == in.right && cmp.top == in.top; - } - - std::string describe() const override { - std::ostringstream ss; - ss << "equals " << cmp; - return ss.str(); - } -}; - -RECTMatcher MatchesRect(RECTF arg) { - return { arg }; -} +#include "storm/Region.hpp" +#include "test/Test.hpp" +#include + +// Fixture for repetitive handling of Rgn objects. +struct RgnDataTest { + HSRGN rgn = nullptr; + + RgnDataTest() { + SRgnCreate(&rgn, 0); + } + + ~RgnDataTest() { + SRgnDelete(rgn); + rgn = nullptr; + } + + HSRGN* operator &() { return &rgn; } + operator HSRGN() const { return rgn; } + HSRGN operator->() const { return rgn; } +}; + +// Helpers for comparing RECTF structs +std::ostream& operator <<(std::ostream& os, RECTF const& value) { + os << "{ " << value.left << ", " << value.bottom << ", " << value.right << ", " << value.top << " }"; + return os; +} + +template +class RECTMatcher : public Catch::MatcherBase { + private: + T cmp; + + public: + RECTMatcher(T arg) : cmp(arg) {} + + bool match(T const& in) const override { + return cmp.left == in.left && cmp.bottom == in.bottom && cmp.right == in.right && cmp.top == in.top; + } + + std::string describe() const override { + std::ostringstream ss; + ss << "equals " << cmp; + return ss.str(); + } +}; + +RECTMatcher MatchesRect(RECTF arg) { + return { arg }; +} diff --git a/test/String.cpp b/test/String.cpp index 8a39b1f..f1e1b2b 100644 --- a/test/String.cpp +++ b/test/String.cpp @@ -2,11 +2,9 @@ #include "storm/Memory.hpp" #include "test/Test.hpp" -#include #include #include - TEST_CASE("SStrChr const", "[string]") { const char* string = "foobar"; diff --git a/test/Test.cpp b/test/Test.cpp index 9f59f24..fae4b8c 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -2,7 +2,5 @@ #include "test/Test.hpp" #include "storm/Big.hpp" - BigDataTest::BigDataTest() { SBigNew(&num); } BigDataTest::~BigDataTest() { SBigDel(num); } -