From bdb920e83aba494f1fd8a5aa1c201663caeb0966 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 25 Jan 2026 11:30:11 +0800 Subject: [PATCH] fix: fix VxMath part --- .clang-format | 317 ++++++++ Assets/CodeGen/VectorGen/VxTypes.hpp.jinja | 2 +- LibCmo/LibCmo/CK2/CKBitmapData.cpp | 50 +- LibCmo/LibCmo/CK2/CKGlobals.cpp | 2 +- .../CK2/DataHandlers/CKBitmapHandler.cpp | 68 +- LibCmo/LibCmo/CK2/ObjImpls/CKTexture.cpp | 2 +- LibCmo/LibCmo/VxMath/VxMath.cpp | 2 +- LibCmo/LibCmo/VxMath/VxMemoryMappedFile.cpp | 37 +- LibCmo/LibCmo/VxMath/VxMemoryMappedFile.hpp | 11 +- LibCmo/LibCmo/VxMath/VxTypes.cpp | 742 ++++++++++-------- LibCmo/LibCmo/VxMath/VxTypes.hpp | 132 ++-- 11 files changed, 869 insertions(+), 496 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..22c0166 --- /dev/null +++ b/.clang-format @@ -0,0 +1,317 @@ +# yaml-language-server: $schema=https://json.schemastore.org/clang-format.json +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: false +BinPackParameters: false +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: None +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Attach +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +BreakTemplateDeclarations: Yes +ColumnLimit: 140 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - forever + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^GetPixelCount(); - std::unique_ptr alphabuf(new CKBYTE[pixelCount * VxMath::VxImageDescEx::ColorFactorSize]); + std::unique_ptr alphabuf(new CKBYTE[pixelCount * VxMath::VxImageDescEx::FACTOR_SIZE]); VxMath::VxCopyStructure( pixelCount, alphabuf.get(), - VxMath::VxImageDescEx::ColorFactorSize, - VxMath::VxImageDescEx::ColorFactorSize, - slot->GetImage() + 3 * VxMath::VxImageDescEx::ColorFactorSize, // move to A factor - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, + slot->GetImage() + 3 * VxMath::VxImageDescEx::FACTOR_SIZE, // move to A factor + VxMath::VxImageDescEx::PIXEL_SIZE ); // check whether alpha are the same value @@ -174,9 +174,9 @@ namespace LibCmo::CK2 { CKDWORD sameAlpha = 0; for (CKDWORD i = 0; i < pixelCount; ++i) { if (i == 0) { - sameAlpha = static_cast(alphabuf[i * VxMath::VxImageDescEx::ColorFactorSize]); + sameAlpha = static_cast(alphabuf[i * VxMath::VxImageDescEx::FACTOR_SIZE]); } else { - if (sameAlpha != static_cast(alphabuf[i * VxMath::VxImageDescEx::ColorFactorSize])) { + if (sameAlpha != static_cast(alphabuf[i * VxMath::VxImageDescEx::FACTOR_SIZE])) { isSameAlpha = false; break; } @@ -192,7 +192,7 @@ namespace LibCmo::CK2 { if (isSameAlpha) { chk->WriteStruct(sameAlpha); } else { - chk->WriteBuffer(alphabuf.get(), pixelCount * VxMath::VxImageDescEx::ColorFactorSize); + chk->WriteBuffer(alphabuf.get(), pixelCount * VxMath::VxImageDescEx::FACTOR_SIZE); } // free alphabuf @@ -240,7 +240,7 @@ namespace LibCmo::CK2 { // create 4 channel buf // we always write alpha channel data. CKDWORD pixelCount = slot->GetPixelCount(); - CKDWORD bufSize = pixelCount * VxMath::VxImageDescEx::ColorFactorSize; + CKDWORD bufSize = pixelCount * VxMath::VxImageDescEx::FACTOR_SIZE; std::unique_ptr redbuf(new CKBYTE[bufSize]); std::unique_ptr greenbuf(new CKBYTE[bufSize]); std::unique_ptr bluebuf(new CKBYTE[bufSize]); @@ -251,37 +251,37 @@ namespace LibCmo::CK2 { VxMath::VxCopyStructure( pixelCount, alphabuf.get(), - VxMath::VxImageDescEx::ColorFactorSize, - VxMath::VxImageDescEx::ColorFactorSize, - slot->GetImage() + (3 * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, + slot->GetImage() + (3 * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy r VxMath::VxCopyStructure( pixelCount, redbuf.get(), - VxMath::VxImageDescEx::ColorFactorSize, - VxMath::VxImageDescEx::ColorFactorSize, - slot->GetImage() + (2 * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, + slot->GetImage() + (2 * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy g VxMath::VxCopyStructure( pixelCount, greenbuf.get(), - VxMath::VxImageDescEx::ColorFactorSize, - VxMath::VxImageDescEx::ColorFactorSize, - slot->GetImage() + (1 * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, + slot->GetImage() + (1 * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy b VxMath::VxCopyStructure( pixelCount, bluebuf.get(), - VxMath::VxImageDescEx::ColorFactorSize, - VxMath::VxImageDescEx::ColorFactorSize, - slot->GetImage() + (0 * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, + slot->GetImage() + (0 * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // write 4 buf diff --git a/LibCmo/LibCmo/CK2/CKGlobals.cpp b/LibCmo/LibCmo/CK2/CKGlobals.cpp index 6d6dd0e..0abc0dc 100644 --- a/LibCmo/LibCmo/CK2/CKGlobals.cpp +++ b/LibCmo/LibCmo/CK2/CKGlobals.cpp @@ -1,5 +1,5 @@ #include "../VTUtils.hpp" -#if YYCC_OS == YYCC_OS_WINDOWS +#if defined(YYCC_OS_WINDOWS) #define ZLIB_WINAPI #endif #include diff --git a/LibCmo/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp b/LibCmo/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp index 00f3ff9..20352aa 100644 --- a/LibCmo/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp +++ b/LibCmo/LibCmo/CK2/DataHandlers/CKBitmapHandler.cpp @@ -16,7 +16,7 @@ namespace LibCmo::CK2::DataHandlers { */ // MARK: for std-image size, we use `n * CKSizeof(CKBYTE)` to calc offset. - // for virtools size, we use `VxMath::VxImageDescEx::ColorFactorSize` and `VxMath::VxImageDescEx::PixelSize` to calc offset. + // for virtools size, we use `VxMath::VxImageDescEx::FACTOR_SIZE` and `VxMath::VxImageDescEx::PIXEL_SIZE` to calc offset. static void ABGRToARGB(CKDWORD count, const void* _abgr, void* _argb) { const CKBYTE* abgr = static_cast(_abgr); @@ -24,36 +24,36 @@ namespace LibCmo::CK2::DataHandlers { // copy R VxMath::VxCopyStructure( count, - argb + (2u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize, - VxMath::VxImageDescEx::ColorFactorSize, + argb + (2u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, abgr + (0u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE) ); // copy G VxMath::VxCopyStructure( count, - argb + (1u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize, - VxMath::VxImageDescEx::ColorFactorSize, + argb + (1u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, abgr + (1u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE) ); // copy B VxMath::VxCopyStructure( count, - argb + (0u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize, - VxMath::VxImageDescEx::ColorFactorSize, + argb + (0u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, abgr + (2u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE) ); // copy A VxMath::VxCopyStructure( count, - argb + (3u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize, - VxMath::VxImageDescEx::ColorFactorSize, + argb + (3u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE, + VxMath::VxImageDescEx::FACTOR_SIZE, abgr + (3u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE) ); @@ -67,36 +67,36 @@ namespace LibCmo::CK2::DataHandlers { count, abgr + (0u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (2u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (2u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy G VxMath::VxCopyStructure( count, abgr + (1u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (1u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (1u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy B VxMath::VxCopyStructure( count, abgr + (2u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (0u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (0u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy A VxMath::VxCopyStructure( count, abgr + (3u * CKSizeof(CKBYTE)), 4u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (3u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (3u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); } @@ -108,27 +108,27 @@ namespace LibCmo::CK2::DataHandlers { count, bgr + (0u * CKSizeof(CKBYTE)), 3u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (2u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (2u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy G VxMath::VxCopyStructure( count, bgr + (1u * CKSizeof(CKBYTE)), 3u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (1u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (1u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // copy B VxMath::VxCopyStructure( count, bgr + (2u * CKSizeof(CKBYTE)), 3u * CKSizeof(CKBYTE), - VxMath::VxImageDescEx::ColorFactorSize, - argb + (0u * VxMath::VxImageDescEx::ColorFactorSize), - VxMath::VxImageDescEx::PixelSize + VxMath::VxImageDescEx::FACTOR_SIZE, + argb + (0u * VxMath::VxImageDescEx::FACTOR_SIZE), + VxMath::VxImageDescEx::PIXEL_SIZE ); // skip A factor } diff --git a/LibCmo/LibCmo/CK2/ObjImpls/CKTexture.cpp b/LibCmo/LibCmo/CK2/ObjImpls/CKTexture.cpp index b9bb2d0..966f40e 100644 --- a/LibCmo/LibCmo/CK2/ObjImpls/CKTexture.cpp +++ b/LibCmo/LibCmo/CK2/ObjImpls/CKTexture.cpp @@ -169,7 +169,7 @@ namespace LibCmo::CK2::ObjImpls { props.m_Format.Flags = static_cast(VxMath::VX_PIXELFORMAT::_32_ARGB8888); props.m_Format.Width = m_ImageHost.GetWidth(); props.m_Format.Height = m_ImageHost.GetHeight(); - props.m_Format.BytesPerLine = VxMath::VxImageDescEx::PixelSize * props.m_Format.Width; + props.m_Format.BytesPerLine = VxMath::VxImageDescEx::PIXEL_SIZE * props.m_Format.Width; props.m_Format.BitsPerPixel = 32; props.m_Format.RedMask = 0x00FF0000; diff --git a/LibCmo/LibCmo/VxMath/VxMath.cpp b/LibCmo/LibCmo/VxMath/VxMath.cpp index 00f71b2..f424646 100644 --- a/LibCmo/LibCmo/VxMath/VxMath.cpp +++ b/LibCmo/LibCmo/VxMath/VxMath.cpp @@ -63,7 +63,7 @@ namespace LibCmo::VxMath { // copy and swap data by line CKDWORD height = dst->GetHeight(), - rowsize = VxImageDescEx::PixelSize * dst->GetWidth(); + rowsize = VxImageDescEx::PIXEL_SIZE * dst->GetWidth(); for (CKDWORD row = 0; row < height; ++row) { std::memcpy( dst->GetMutableImage() + (row * rowsize), diff --git a/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.cpp b/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.cpp index 95ed02f..e9432dc 100644 --- a/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.cpp +++ b/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.cpp @@ -1,11 +1,16 @@ #include "VxMemoryMappedFile.hpp" -#include "../VTEncoding.hpp" +#include +#if defined(YYCC_OS_WINDOWS) +#include +#else +#include +#endif namespace LibCmo::VxMath { VxMemoryMappedFile::VxMemoryMappedFile(CKSTRING u8_filepath) : // Initialize members -#if YYCC_OS == YYCC_OS_WINDOWS +#if defined(YYCC_OS_WINDOWS) // Initialize Windows specific. m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL), m_dwFileSize(), @@ -22,12 +27,12 @@ namespace LibCmo::VxMath { m_szFilePath = u8_filepath; // Do real mapping work according to different platform. -#if YYCC_OS == YYCC_OS_WINDOWS +#if defined(YYCC_OS_WINDOWS) // Parse file name to wchar_t - std::wstring w_filename; - if (!YYCC::EncodingHelper::UTF8ToWchar(m_szFilePath, w_filename)) - return; + auto rv_w_filename = yycc::encoding::windows::to_wchar(m_szFilePath); + if (!rv_w_filename.has_value()) return; + std::wstring w_filename = std::move(rv_w_filename.value()); // Open file this->m_hFile = ::CreateFileW( @@ -80,12 +85,12 @@ namespace LibCmo::VxMath { } // Set base address m_pMemoryMappedFileBase = m_hFileMapView; - + #else // create file // we do not need provide mode_t, because is served for new created file. // we are opening a existed file. - this->m_hFile = open(YYCC::EncodingHelper::ToOrdinary(m_szFilePath.c_str()), O_RDONLY); + this->m_hFile = open(yycc::string::reinterpret::as_ordinary(m_szFilePath.c_str()), O_RDONLY); if (m_hFile == -1) { return; } @@ -98,13 +103,15 @@ namespace LibCmo::VxMath { close(m_hFile); return; } - // Setup size and check its range + // Setup size with checking its range this->m_offFileSize = sb.st_size; - if (this->m_offFileSize > static_cast(std::numeric_limits::max())) { - close(m_hFile); - return; + auto rv_cbFile = yycc::num::safe_cast::try_to(this->m_offFileSize); + if (rv_cbFile.has_value()) { + this->m_cbFile = rv_cbFile.value(); + } else { + close(m_hFile); + return; } - m_cbFile = static_cast(this->m_offFileSize); // map file this->m_pFileAddr = mmap( @@ -120,7 +127,7 @@ namespace LibCmo::VxMath { return; } // set base address - m_pMemoryMappedFileBase = m_pFileAddr; + this->m_pMemoryMappedFileBase = m_pFileAddr; #endif @@ -135,7 +142,7 @@ namespace LibCmo::VxMath { m_cbFile = 0; m_pMemoryMappedFileBase = nullptr; -#if YYCC_OS == YYCC_OS_WINDOWS +#if defined(YYCC_OS_WINDOWS) UnmapViewOfFile(this->m_hFileMapView); CloseHandle(m_hFileMapping); CloseHandle(m_hFile); diff --git a/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.hpp b/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.hpp index 525cd97..69fe5a9 100644 --- a/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.hpp +++ b/LibCmo/LibCmo/VxMath/VxMemoryMappedFile.hpp @@ -1,10 +1,11 @@ #pragma once #include "../VTInternal.hpp" -#if YYCC_OS == YYCC_OS_WINDOWS -#include +#include +#if defined(YYCC_OS_WINDOWS) +#include #include -#include +#include #else #include #include @@ -24,7 +25,7 @@ namespace LibCmo::VxMath { */ class VxMemoryMappedFile { private: -#if YYCC_OS == YYCC_OS_WINDOWS +#if defined(YYCC_OS_WINDOWS) HANDLE m_hFile; LARGE_INTEGER m_dwFileSize; HANDLE m_hFileMapping; @@ -48,7 +49,7 @@ namespace LibCmo::VxMath { */ VxMemoryMappedFile(CKSTRING u8_filepath); ~VxMemoryMappedFile(); - YYCC_DEL_CLS_COPY_MOVE(VxMemoryMappedFile); + YYCC_DELETE_COPY_MOVE(VxMemoryMappedFile) /** * @brief Returns a pointer to the mapped memory buffer. diff --git a/LibCmo/LibCmo/VxMath/VxTypes.cpp b/LibCmo/LibCmo/VxMath/VxTypes.cpp index 2d44258..a9a8648 100644 --- a/LibCmo/LibCmo/VxMath/VxTypes.cpp +++ b/LibCmo/LibCmo/VxMath/VxTypes.cpp @@ -5,378 +5,422 @@ namespace LibCmo::VxMath { #pragma region VxVector2 - VxVector2::VxVector2() :x(0.0f), y(0.0f) {} - VxVector2::VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {} - CKFLOAT& VxVector2::operator[](size_t i) { - switch (i) { - case 0: return x; - case 1: return y; - default: throw LogicException("Invalid index for VxVector2::operator[]."); - } - } - const CKFLOAT& VxVector2::operator[](size_t i) const { - switch (i) { - case 0: return x; - case 1: return y; - default: throw LogicException("Invalid index for VxVector2::operator[]."); - } - } - bool VxVector2::operator==(const VxVector2& rhs) const { - return (x == rhs.x && y == rhs.y); - } - auto VxVector2::operator<=>(const VxVector2& rhs) const { - if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; - return y <=> rhs.y; - } - VxVector2 VxVector2::operator+() const { - return *this; - } - VxVector2 VxVector2::operator-() const { - return VxVector2(-x, -y); - } - VxVector2& VxVector2::operator+=(const VxVector2& rhs) { - x += rhs.x; - y += rhs.y; - return *this; - } - VxVector2 operator+(const VxVector2& lhs, const VxVector2& rhs) { - return VxVector2(lhs.x + rhs.x, lhs.y + rhs.y); - } - VxVector2& VxVector2::operator-=(const VxVector2& rhs) { - x -= rhs.x; - y -= rhs.y; - return *this; - } - VxVector2 operator-(const VxVector2& lhs, const VxVector2& rhs) { - return VxVector2(lhs.x - rhs.x, lhs.y - rhs.y); - } - VxVector2& VxVector2::operator*=(CKFLOAT rhs) { - x *= rhs; - y *= rhs; - return *this; - } - VxVector2 operator*(const VxVector2& lhs, CKFLOAT rhs) { - return VxVector2(lhs.x * rhs, lhs.y * rhs); - } - VxVector2 operator*(CKFLOAT lhs, const VxVector2& rhs) { - return VxVector2(lhs * rhs.x, lhs * rhs.y); - } - CKFLOAT operator*(const VxVector2& lhs, const VxVector2& rhs) { - return (lhs.x * rhs.x + lhs.y * rhs.y); - } - VxVector2& VxVector2::operator/=(CKFLOAT rhs) { - if (rhs == 0.0f) return *this; - x /= rhs; - y /= rhs; - return *this; - } - VxVector2 operator/(const VxVector2& lhs, CKFLOAT rhs) { - if (rhs == 0.0f) return VxVector2(); - else return VxVector2(lhs.x / rhs, lhs.y / rhs); - } - CKFLOAT VxVector2::SquaredLength() const { - return (x * x + y * y); - } - CKFLOAT VxVector2::Length() const { - return std::sqrt(SquaredLength()); - } - void VxVector2::Normalized() { - CKFLOAT len = Length(); - if (len == 0.0f) return; - x /= len; - y /= len; - } - VxVector2 VxVector2::Normalize() const { - CKFLOAT len = Length(); - if (len == 0.0f) return VxVector2(); - else return VxVector2(x / len, y / len); - } + VxVector2::VxVector2() : x(0.0f), y(0.0f) {} + VxVector2::VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {} + CKFLOAT& VxVector2::operator[](size_t i) { + switch (i) { + case 0: + return x; + case 1: + return y; + default: + throw LogicException("Invalid index for VxVector2::operator[]."); + } + } + const CKFLOAT& VxVector2::operator[](size_t i) const { + switch (i) { + case 0: + return x; + case 1: + return y; + default: + throw LogicException("Invalid index for VxVector2::operator[]."); + } + } + bool VxVector2::operator==(const VxVector2& rhs) const { + return (x == rhs.x && y == rhs.y); + } + std::partial_ordering VxVector2::operator<=>(const VxVector2& rhs) const { + if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; + return y <=> rhs.y; + } + VxVector2 VxVector2::operator+() const { + return *this; + } + VxVector2 VxVector2::operator-() const { + return VxVector2(-x, -y); + } + VxVector2& VxVector2::operator+=(const VxVector2& rhs) { + x += rhs.x; + y += rhs.y; + return *this; + } + VxVector2 operator+(const VxVector2& lhs, const VxVector2& rhs) { + return VxVector2(lhs.x + rhs.x, lhs.y + rhs.y); + } + VxVector2& VxVector2::operator-=(const VxVector2& rhs) { + x -= rhs.x; + y -= rhs.y; + return *this; + } + VxVector2 operator-(const VxVector2& lhs, const VxVector2& rhs) { + return VxVector2(lhs.x - rhs.x, lhs.y - rhs.y); + } + VxVector2& VxVector2::operator*=(CKFLOAT rhs) { + x *= rhs; + y *= rhs; + return *this; + } + VxVector2 operator*(const VxVector2& lhs, CKFLOAT rhs) { + return VxVector2(lhs.x * rhs, lhs.y * rhs); + } + VxVector2 operator*(CKFLOAT lhs, const VxVector2& rhs) { + return VxVector2(lhs * rhs.x, lhs * rhs.y); + } + CKFLOAT operator*(const VxVector2& lhs, const VxVector2& rhs) { + return (lhs.x * rhs.x + lhs.y * rhs.y); + } + VxVector2& VxVector2::operator/=(CKFLOAT rhs) { + if (rhs == 0.0f) return *this; + x /= rhs; + y /= rhs; + return *this; + } + VxVector2 operator/(const VxVector2& lhs, CKFLOAT rhs) { + if (rhs == 0.0f) return VxVector2(); + else return VxVector2(lhs.x / rhs, lhs.y / rhs); + } + CKFLOAT VxVector2::SquaredLength() const { + return (x * x + y * y); + } + CKFLOAT VxVector2::Length() const { + return std::sqrt(SquaredLength()); + } + void VxVector2::Normalized() { + CKFLOAT len = Length(); + if (len == 0.0f) return; + x /= len; + y /= len; + } + VxVector2 VxVector2::Normalize() const { + CKFLOAT len = Length(); + if (len == 0.0f) return VxVector2(); + else return VxVector2(x / len, y / len); + } - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ #pragma endregion #pragma region VxVector3 - VxVector3::VxVector3() :x(0.0f), y(0.0f), z(0.0f) {} - VxVector3::VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {} - CKFLOAT& VxVector3::operator[](size_t i) { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - default: throw LogicException("Invalid index for VxVector3::operator[]."); - } - } - const CKFLOAT& VxVector3::operator[](size_t i) const { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - default: throw LogicException("Invalid index for VxVector3::operator[]."); - } - } - bool VxVector3::operator==(const VxVector3& rhs) const { - return (x == rhs.x && y == rhs.y && z == rhs.z); - } - auto VxVector3::operator<=>(const VxVector3& rhs) const { - if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; - if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; - return z <=> rhs.z; - } - VxVector3 VxVector3::operator+() const { - return *this; - } - VxVector3 VxVector3::operator-() const { - return VxVector3(-x, -y, -z); - } - VxVector3& VxVector3::operator+=(const VxVector3& rhs) { - x += rhs.x; - y += rhs.y; - z += rhs.z; - return *this; - } - VxVector3 operator+(const VxVector3& lhs, const VxVector3& rhs) { - return VxVector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z); - } - VxVector3& VxVector3::operator-=(const VxVector3& rhs) { - x -= rhs.x; - y -= rhs.y; - z -= rhs.z; - return *this; - } - VxVector3 operator-(const VxVector3& lhs, const VxVector3& rhs) { - return VxVector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z); - } - VxVector3& VxVector3::operator*=(CKFLOAT rhs) { - x *= rhs; - y *= rhs; - z *= rhs; - return *this; - } - VxVector3 operator*(const VxVector3& lhs, CKFLOAT rhs) { - return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs); - } - VxVector3 operator*(CKFLOAT lhs, const VxVector3& rhs) { - return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z); - } - CKFLOAT operator*(const VxVector3& lhs, const VxVector3& rhs) { - return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z); - } - VxVector3& VxVector3::operator/=(CKFLOAT rhs) { - if (rhs == 0.0f) return *this; - x /= rhs; - y /= rhs; - z /= rhs; - return *this; - } - VxVector3 operator/(const VxVector3& lhs, CKFLOAT rhs) { - if (rhs == 0.0f) return VxVector3(); - else return VxVector3(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs); - } - CKFLOAT VxVector3::SquaredLength() const { - return (x * x + y * y + z * z); - } - CKFLOAT VxVector3::Length() const { - return std::sqrt(SquaredLength()); - } - void VxVector3::Normalized() { - CKFLOAT len = Length(); - if (len == 0.0f) return; - x /= len; - y /= len; - z /= len; - } - VxVector3 VxVector3::Normalize() const { - CKFLOAT len = Length(); - if (len == 0.0f) return VxVector3(); - else return VxVector3(x / len, y / len, z / len); - } + VxVector3::VxVector3() : x(0.0f), y(0.0f), z(0.0f) {} + VxVector3::VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {} + CKFLOAT& VxVector3::operator[](size_t i) { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + throw LogicException("Invalid index for VxVector3::operator[]."); + } + } + const CKFLOAT& VxVector3::operator[](size_t i) const { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + throw LogicException("Invalid index for VxVector3::operator[]."); + } + } + bool VxVector3::operator==(const VxVector3& rhs) const { + return (x == rhs.x && y == rhs.y && z == rhs.z); + } + std::partial_ordering VxVector3::operator<=>(const VxVector3& rhs) const { + if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; + if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; + return z <=> rhs.z; + } + VxVector3 VxVector3::operator+() const { + return *this; + } + VxVector3 VxVector3::operator-() const { + return VxVector3(-x, -y, -z); + } + VxVector3& VxVector3::operator+=(const VxVector3& rhs) { + x += rhs.x; + y += rhs.y; + z += rhs.z; + return *this; + } + VxVector3 operator+(const VxVector3& lhs, const VxVector3& rhs) { + return VxVector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z); + } + VxVector3& VxVector3::operator-=(const VxVector3& rhs) { + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + return *this; + } + VxVector3 operator-(const VxVector3& lhs, const VxVector3& rhs) { + return VxVector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z); + } + VxVector3& VxVector3::operator*=(CKFLOAT rhs) { + x *= rhs; + y *= rhs; + z *= rhs; + return *this; + } + VxVector3 operator*(const VxVector3& lhs, CKFLOAT rhs) { + return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs); + } + VxVector3 operator*(CKFLOAT lhs, const VxVector3& rhs) { + return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z); + } + CKFLOAT operator*(const VxVector3& lhs, const VxVector3& rhs) { + return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z); + } + VxVector3& VxVector3::operator/=(CKFLOAT rhs) { + if (rhs == 0.0f) return *this; + x /= rhs; + y /= rhs; + z /= rhs; + return *this; + } + VxVector3 operator/(const VxVector3& lhs, CKFLOAT rhs) { + if (rhs == 0.0f) return VxVector3(); + else return VxVector3(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs); + } + CKFLOAT VxVector3::SquaredLength() const { + return (x * x + y * y + z * z); + } + CKFLOAT VxVector3::Length() const { + return std::sqrt(SquaredLength()); + } + void VxVector3::Normalized() { + CKFLOAT len = Length(); + if (len == 0.0f) return; + x /= len; + y /= len; + z /= len; + } + VxVector3 VxVector3::Normalize() const { + CKFLOAT len = Length(); + if (len == 0.0f) return VxVector3(); + else return VxVector3(x / len, y / len, z / len); + } - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ #pragma endregion #pragma region VxVector4 - VxVector4::VxVector4() :x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} - VxVector4::VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} - CKFLOAT& VxVector4::operator[](size_t i) { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - case 3: return w; - default: throw LogicException("Invalid index for VxVector4::operator[]."); - } - } - const CKFLOAT& VxVector4::operator[](size_t i) const { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - case 3: return w; - default: throw LogicException("Invalid index for VxVector4::operator[]."); - } - } - bool VxVector4::operator==(const VxVector4& rhs) const { - return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); - } - auto VxVector4::operator<=>(const VxVector4& rhs) const { - if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; - if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; - if (auto cmp = z <=> rhs.z; cmp != 0) return cmp; - return w <=> rhs.w; - } - VxVector4 VxVector4::operator+() const { - return *this; - } - VxVector4 VxVector4::operator-() const { - return VxVector4(-x, -y, -z, -w); - } - VxVector4& VxVector4::operator+=(const VxVector4& rhs) { - x += rhs.x; - y += rhs.y; - z += rhs.z; - w += rhs.w; - return *this; - } - VxVector4 operator+(const VxVector4& lhs, const VxVector4& rhs) { - return VxVector4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); - } - VxVector4& VxVector4::operator-=(const VxVector4& rhs) { - x -= rhs.x; - y -= rhs.y; - z -= rhs.z; - w -= rhs.w; - return *this; - } - VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs) { - return VxVector4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); - } - VxVector4& VxVector4::operator*=(CKFLOAT rhs) { - x *= rhs; - y *= rhs; - z *= rhs; - w *= rhs; - return *this; - } - VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs) { - return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs); - } - VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs) { - return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w); - } - CKFLOAT operator*(const VxVector4& lhs, const VxVector4& rhs) { - return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w); - } - VxVector4& VxVector4::operator/=(CKFLOAT rhs) { - if (rhs == 0.0f) return *this; - x /= rhs; - y /= rhs; - z /= rhs; - w /= rhs; - return *this; - } - VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs) { - if (rhs == 0.0f) return VxVector4(); - else return VxVector4(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs, lhs.w / rhs); - } - CKFLOAT VxVector4::SquaredLength() const { - return (x * x + y * y + z * z + w * w); - } - CKFLOAT VxVector4::Length() const { - return std::sqrt(SquaredLength()); - } - void VxVector4::Normalized() { - CKFLOAT len = Length(); - if (len == 0.0f) return; - x /= len; - y /= len; - z /= len; - w /= len; - } - VxVector4 VxVector4::Normalize() const { - CKFLOAT len = Length(); - if (len == 0.0f) return VxVector4(); - else return VxVector4(x / len, y / len, z / len, w / len); - } + VxVector4::VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} + VxVector4::VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} + CKFLOAT& VxVector4::operator[](size_t i) { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw LogicException("Invalid index for VxVector4::operator[]."); + } + } + const CKFLOAT& VxVector4::operator[](size_t i) const { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw LogicException("Invalid index for VxVector4::operator[]."); + } + } + bool VxVector4::operator==(const VxVector4& rhs) const { + return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); + } + std::partial_ordering VxVector4::operator<=>(const VxVector4& rhs) const { + if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; + if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; + if (auto cmp = z <=> rhs.z; cmp != 0) return cmp; + return w <=> rhs.w; + } + VxVector4 VxVector4::operator+() const { + return *this; + } + VxVector4 VxVector4::operator-() const { + return VxVector4(-x, -y, -z, -w); + } + VxVector4& VxVector4::operator+=(const VxVector4& rhs) { + x += rhs.x; + y += rhs.y; + z += rhs.z; + w += rhs.w; + return *this; + } + VxVector4 operator+(const VxVector4& lhs, const VxVector4& rhs) { + return VxVector4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w); + } + VxVector4& VxVector4::operator-=(const VxVector4& rhs) { + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + w -= rhs.w; + return *this; + } + VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs) { + return VxVector4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w); + } + VxVector4& VxVector4::operator*=(CKFLOAT rhs) { + x *= rhs; + y *= rhs; + z *= rhs; + w *= rhs; + return *this; + } + VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs) { + return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs); + } + VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs) { + return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w); + } + CKFLOAT operator*(const VxVector4& lhs, const VxVector4& rhs) { + return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w); + } + VxVector4& VxVector4::operator/=(CKFLOAT rhs) { + if (rhs == 0.0f) return *this; + x /= rhs; + y /= rhs; + z /= rhs; + w /= rhs; + return *this; + } + VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs) { + if (rhs == 0.0f) return VxVector4(); + else return VxVector4(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs, lhs.w / rhs); + } + CKFLOAT VxVector4::SquaredLength() const { + return (x * x + y * y + z * z + w * w); + } + CKFLOAT VxVector4::Length() const { + return std::sqrt(SquaredLength()); + } + void VxVector4::Normalized() { + CKFLOAT len = Length(); + if (len == 0.0f) return; + x /= len; + y /= len; + z /= len; + w /= len; + } + VxVector4 VxVector4::Normalize() const { + CKFLOAT len = Length(); + if (len == 0.0f) return VxVector4(); + else return VxVector4(x / len, y / len, z / len, w / len); + } - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ #pragma endregion #pragma region VxQuaternion - VxQuaternion::VxQuaternion() :x(0.0f), y(0.0f), z(0.0f), w(1.0f) {} // SET YOUR CUSTOM INIT - VxQuaternion::VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} - CKFLOAT& VxQuaternion::operator[](size_t i) { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - case 3: return w; - default: throw LogicException("Invalid index for VxQuaternion::operator[]."); - } - } - const CKFLOAT& VxQuaternion::operator[](size_t i) const { - switch (i) { - case 0: return x; - case 1: return y; - case 2: return z; - case 3: return w; - default: throw LogicException("Invalid index for VxQuaternion::operator[]."); - } - } - bool VxQuaternion::operator==(const VxQuaternion& rhs) const { - return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); - } - auto VxQuaternion::operator<=>(const VxQuaternion& rhs) const { - if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; - if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; - if (auto cmp = z <=> rhs.z; cmp != 0) return cmp; - return w <=> rhs.w; - } + VxQuaternion::VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} // SET YOUR CUSTOM INIT + VxQuaternion::VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {} + CKFLOAT& VxQuaternion::operator[](size_t i) { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw LogicException("Invalid index for VxQuaternion::operator[]."); + } + } + const CKFLOAT& VxQuaternion::operator[](size_t i) const { + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + case 3: + return w; + default: + throw LogicException("Invalid index for VxQuaternion::operator[]."); + } + } + bool VxQuaternion::operator==(const VxQuaternion& rhs) const { + return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w); + } + std::partial_ordering VxQuaternion::operator<=>(const VxQuaternion& rhs) const { + if (auto cmp = x <=> rhs.x; cmp != 0) return cmp; + if (auto cmp = y <=> rhs.y; cmp != 0) return cmp; + if (auto cmp = z <=> rhs.z; cmp != 0) return cmp; + return w <=> rhs.w; + } - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ #pragma endregion #pragma region VxColor - VxColor::VxColor() :r(0.0f), g(0.0f), b(0.0f), a(1.0f) {} // SET YOUR CUSTOM INIT - VxColor::VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {} - CKFLOAT& VxColor::operator[](size_t i) { - switch (i) { - case 0: return r; - case 1: return g; - case 2: return b; - case 3: return a; - default: throw LogicException("Invalid index for VxColor::operator[]."); - } - } - const CKFLOAT& VxColor::operator[](size_t i) const { - switch (i) { - case 0: return r; - case 1: return g; - case 2: return b; - case 3: return a; - default: throw LogicException("Invalid index for VxColor::operator[]."); - } - } - bool VxColor::operator==(const VxColor& rhs) const { - return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); - } - auto VxColor::operator<=>(const VxColor& rhs) const { - if (auto cmp = r <=> rhs.r; cmp != 0) return cmp; - if (auto cmp = g <=> rhs.g; cmp != 0) return cmp; - if (auto cmp = b <=> rhs.b; cmp != 0) return cmp; - return a <=> rhs.a; - } + VxColor::VxColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} // SET YOUR CUSTOM INIT + VxColor::VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {} + CKFLOAT& VxColor::operator[](size_t i) { + switch (i) { + case 0: + return r; + case 1: + return g; + case 2: + return b; + case 3: + return a; + default: + throw LogicException("Invalid index for VxColor::operator[]."); + } + } + const CKFLOAT& VxColor::operator[](size_t i) const { + switch (i) { + case 0: + return r; + case 1: + return g; + case 2: + return b; + case 3: + return a; + default: + throw LogicException("Invalid index for VxColor::operator[]."); + } + } + bool VxColor::operator==(const VxColor& rhs) const { + return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); + } + std::partial_ordering VxColor::operator<=>(const VxColor& rhs) const { + if (auto cmp = r <=> rhs.r; cmp != 0) return cmp; + if (auto cmp = g <=> rhs.g; cmp != 0) return cmp; + if (auto cmp = b <=> rhs.b; cmp != 0) return cmp; + return a <=> rhs.a; + } /* ===== BEGIN USER CUSTOM ===== */ VxColor::VxColor(CKDWORD argb) { FromARGB(argb); } @@ -427,7 +471,7 @@ namespace LibCmo::VxMath { bool VxMatrix::operator==(const VxMatrix& rhs) const { return ((*this)[0] == rhs[0] && (*this)[1] == rhs[1] && (*this)[2] == rhs[2] && (*this)[3] == rhs[3]); } - auto VxMatrix::operator<=>(const VxMatrix& rhs) const { + std::partial_ordering VxMatrix::operator<=>(const VxMatrix& rhs) const { if (auto cmp = (*this)[0] <=> rhs[0]; cmp != 0) return cmp; if (auto cmp = (*this)[1] <=> rhs[1]; cmp != 0) return cmp; if (auto cmp = (*this)[2] <=> rhs[2]; cmp != 0) return cmp; diff --git a/LibCmo/LibCmo/VxMath/VxTypes.hpp b/LibCmo/LibCmo/VxMath/VxTypes.hpp index b021205..95862cb 100644 --- a/LibCmo/LibCmo/VxMath/VxTypes.hpp +++ b/LibCmo/LibCmo/VxMath/VxTypes.hpp @@ -2,11 +2,13 @@ #include "../VTUtils.hpp" #include "../CK2/CKTypes.hpp" +#include #include "VxEnums.hpp" #include #include #include #include +#include /** * @brief The VxMath part of LibCmo. @@ -33,11 +35,11 @@ namespace LibCmo::VxMath { CKFLOAT x, y; VxVector2(); VxVector2(CKFLOAT _x, CKFLOAT _y); - YYCC_DEF_CLS_COPY_MOVE(VxVector2); + YYCC_DEFAULT_COPY_MOVE(VxVector2) CKFLOAT& operator[](size_t i); const CKFLOAT& operator[](size_t i) const; bool operator==(const VxVector2& rhs) const; - auto operator<=>(const VxVector2& rhs) const; + std::partial_ordering operator<=>(const VxVector2& rhs) const; VxVector2 operator+() const; VxVector2 operator-() const; VxVector2& operator+=(const VxVector2& rhs); @@ -59,6 +61,7 @@ namespace LibCmo::VxMath { /* ===== END USER CUSTOM ===== */ }; + /** * @brief The representation of a Vector in 3 dimensions * @remarks In original Virtools SDK, it was named VxVector. @@ -67,11 +70,11 @@ namespace LibCmo::VxMath { CKFLOAT x, y, z; VxVector3(); VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z); - YYCC_DEF_CLS_COPY_MOVE(VxVector3); + YYCC_DEFAULT_COPY_MOVE(VxVector3) CKFLOAT& operator[](size_t i); const CKFLOAT& operator[](size_t i) const; bool operator==(const VxVector3& rhs) const; - auto operator<=>(const VxVector3& rhs) const; + std::partial_ordering operator<=>(const VxVector3& rhs) const; VxVector3 operator+() const; VxVector3 operator-() const; VxVector3& operator+=(const VxVector3& rhs); @@ -101,35 +104,35 @@ namespace LibCmo::VxMath { * @remarks In original Virtools SDK, it was named VxVector4. Not changed. * @see VxVector3 */ - struct VxVector4 { - CKFLOAT x, y, z, w; - VxVector4(); - VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w); - YYCC_DEF_CLS_COPY_MOVE(VxVector4); - CKFLOAT& operator[](size_t i); - const CKFLOAT& operator[](size_t i) const; - bool operator==(const VxVector4& rhs) const; - auto operator<=>(const VxVector4& rhs) const; - VxVector4 operator+() const; - VxVector4 operator-() const; - VxVector4& operator+=(const VxVector4& rhs); - friend VxVector4 operator+(const VxVector4& lhs, const VxVector4& rhs); - VxVector4& operator-=(const VxVector4& rhs); - friend VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs); - VxVector4& operator*=(CKFLOAT rhs); - friend VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs); - friend VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs); - friend CKFLOAT operator*(const VxVector4& lhs, const VxVector4& rhs); - VxVector4& operator/=(CKFLOAT rhs); - friend VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs); - CKFLOAT SquaredLength() const; - CKFLOAT Length() const; - void Normalized(); - VxVector4 Normalize() const; + struct VxVector4 { + CKFLOAT x, y, z, w; + VxVector4(); + VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w); + YYCC_DEFAULT_COPY_MOVE(VxVector4) + CKFLOAT& operator[](size_t i); + const CKFLOAT& operator[](size_t i) const; + bool operator==(const VxVector4& rhs) const; + std::partial_ordering operator<=>(const VxVector4& rhs) const; + VxVector4 operator+() const; + VxVector4 operator-() const; + VxVector4& operator+=(const VxVector4& rhs); + friend VxVector4 operator+(const VxVector4& lhs, const VxVector4& rhs); + VxVector4& operator-=(const VxVector4& rhs); + friend VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs); + VxVector4& operator*=(CKFLOAT rhs); + friend VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs); + friend VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs); + friend CKFLOAT operator*(const VxVector4& lhs, const VxVector4& rhs); + VxVector4& operator/=(CKFLOAT rhs); + friend VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs); + CKFLOAT SquaredLength() const; + CKFLOAT Length() const; + void Normalized(); + VxVector4 Normalize() const; - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ - }; + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ + }; /** * @brief The representation of a quaternion. @@ -140,19 +143,19 @@ namespace LibCmo::VxMath { * Quaternions can be converted to VxMatrix or Euler Angles. * @see VxMatrix, VxVector3 */ - struct VxQuaternion { - CKFLOAT x, y, z, w; - VxQuaternion(); - VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w); - YYCC_DEF_CLS_COPY_MOVE(VxQuaternion); - CKFLOAT& operator[](size_t i); - const CKFLOAT& operator[](size_t i) const; - bool operator==(const VxQuaternion& rhs) const; - auto operator<=>(const VxQuaternion& rhs) const; + struct VxQuaternion { + CKFLOAT x, y, z, w; + VxQuaternion(); + VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w); + YYCC_DEFAULT_COPY_MOVE(VxQuaternion) + CKFLOAT& operator[](size_t i); + const CKFLOAT& operator[](size_t i) const; + bool operator==(const VxQuaternion& rhs) const; + std::partial_ordering operator<=>(const VxQuaternion& rhs) const; - /* ===== BEGIN USER CUSTOM ===== */ - /* ===== END USER CUSTOM ===== */ - }; + /* ===== BEGIN USER CUSTOM ===== */ + /* ===== END USER CUSTOM ===== */ + }; /** * @brief The representation of a color through 4 floats. @@ -162,15 +165,15 @@ namespace LibCmo::VxMath { * * Most methods are used to construct a VxColor or to convert it to a 32 bit ARGB format. */ - struct VxColor { - CKFLOAT r, g, b, a; - VxColor(); - VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a); - YYCC_DEF_CLS_COPY_MOVE(VxColor); - CKFLOAT& operator[](size_t i); - const CKFLOAT& operator[](size_t i) const; - bool operator==(const VxColor& rhs) const; - auto operator<=>(const VxColor& rhs) const; + struct VxColor { + CKFLOAT r, g, b, a; + VxColor(); + VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a); + YYCC_DEFAULT_COPY_MOVE(VxColor) + CKFLOAT& operator[](size_t i); + const CKFLOAT& operator[](size_t i) const; + bool operator==(const VxColor& rhs) const; + std::partial_ordering operator<=>(const VxColor& rhs) const; /* ===== BEGIN USER CUSTOM ===== */ VxColor(CKDWORD argb); @@ -193,11 +196,11 @@ namespace LibCmo::VxMath { public: VxMatrix(); VxMatrix(CKFLOAT m[4][4]); - YYCC_DEF_CLS_COPY_MOVE(VxMatrix); + YYCC_DEFAULT_COPY_MOVE(VxMatrix) VxVector4& operator[](size_t i); const VxVector4& operator[](size_t i) const; bool operator==(const VxMatrix& rhs) const; - auto operator<=>(const VxMatrix& rhs) const; + std::partial_ordering operator<=>(const VxMatrix& rhs) const; /* ===== BEGIN USER CUSTOM ===== */ void Clear(); @@ -300,7 +303,8 @@ namespace LibCmo::VxMath { * @brief Structure for storage of strided data. * @tparam _Ty The data pointer type this class stored. */ - template, int> = 0> + template + requires std::is_pointer_v class VxStridedData { public: /** @@ -310,7 +314,7 @@ namespace LibCmo::VxMath { * If you set stride to the size of underlying type of pointer, * this class will degenerate to the visitor of a plain data array. */ - VxStridedData(_Ty ptr, CKDWORD stride) : + VxStridedData(T ptr, CKDWORD stride) : m_Ptr(reinterpret_cast(ptr)), m_Stride(stride) {} ~VxStridedData() {} @@ -320,8 +324,8 @@ namespace LibCmo::VxMath { * @param[in] idx N-th * @return The pointer to n-th data. */ - _Ty operator[](size_t idx) { - return reinterpret_cast<_Ty>(m_Ptr + (m_Stride * idx)); + T operator[](size_t idx) { + return reinterpret_cast(m_Ptr + (m_Stride * idx)); } private: @@ -340,8 +344,8 @@ namespace LibCmo::VxMath { */ class VxImageDescEx { public: - static constexpr CKDWORD ColorFactorSize = 1u; /**< Single color factor (one of ARGB) occpied size in byte. */ - static constexpr CKDWORD PixelSize = ColorFactorSize * 4u; /**< Single pixel occpied size in byte. */ + static constexpr CKDWORD FACTOR_SIZE = 1u; /**< Single color factor (one of ARGB) occpied size in byte. */ + static constexpr CKDWORD PIXEL_SIZE = FACTOR_SIZE * 4u; /**< Single pixel occpied size in byte. */ public: /** * @brief Create a blank (invalid) image. @@ -364,7 +368,7 @@ namespace LibCmo::VxMath { CreateImage(rhs.m_Width, rhs.m_Height, rhs.m_Image); } } - VxImageDescEx(VxImageDescEx&& rhs) : + VxImageDescEx(VxImageDescEx&& rhs) noexcept : m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Image(rhs.m_Image) { // move image rhs.m_Height = 0; @@ -382,7 +386,7 @@ namespace LibCmo::VxMath { return *this; } - VxImageDescEx& operator=(VxImageDescEx&& rhs) { + VxImageDescEx& operator=(VxImageDescEx&& rhs) noexcept { FreeImage(); m_Height = rhs.m_Height; @@ -444,7 +448,7 @@ namespace LibCmo::VxMath { * Basically it is image width * height * (single pixel size). */ CKDWORD GetImageSize() const { - return static_cast(PixelSize * m_Width * m_Height); + return static_cast(PIXEL_SIZE * m_Width * m_Height); } /** * @brief Get a constant pointer to image in memory unit for viewing.