From 0df55c3a7f91d9715407ceb5628bf13f4fdd4944 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:10:08 -0700 Subject: [PATCH 01/16] enabling warn format security and some fixes Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/Util/MemoryBlock.cpp | 2 +- .../Include/AzManipulatorTestFramework/ActionDispatcher.h | 4 ++-- .../Source/RetainedModeActionDispatcher.cpp | 6 +++--- Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp | 4 +--- Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp | 5 +---- Code/Legacy/CrySystem/Log.cpp | 4 ++-- Code/Legacy/CrySystem/SystemCFG.cpp | 2 +- Code/Legacy/CrySystem/XConsole.cpp | 4 ++-- Gems/AssetMemoryAnalyzer/Code/Source/DebugImGUI.cpp | 4 ++-- cmake/Platform/Common/Clang/Configurations_clang.cmake | 1 - 10 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Code/Editor/Util/MemoryBlock.cpp b/Code/Editor/Util/MemoryBlock.cpp index e840a1735e..b7ae017113 100644 --- a/Code/Editor/Util/MemoryBlock.cpp +++ b/Code/Editor/Util/MemoryBlock.cpp @@ -78,7 +78,7 @@ bool CMemoryBlock::Allocate(int size, int uncompressedSize) { QString str; str = QStringLiteral("CMemoryBlock::Allocate failed to allocate %1Mb of Memory").arg(size / (1024 * 1024)); - CryLogAlways(str.toUtf8().data()); + CryLogAlways("%s", str.toUtf8().data()); QMessageBox::critical(QApplication::activeWindow(), QString(), str + QString("\r\nSandbox will try to reduce its working memory set to free memory for this allocation.")); GetIEditor()->ReduceMemory(); diff --git a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h index 11ed31e864..523e6a30a7 100644 --- a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h +++ b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h @@ -150,7 +150,7 @@ namespace AzManipulatorTestFramework template DerivedDispatcherT* ActionDispatcher::MouseLButtonDown() { - Log("Mouse left button down"); + Log("%s", "Mouse left button down"); MouseLButtonDownImpl(); return static_cast(this); } @@ -158,7 +158,7 @@ namespace AzManipulatorTestFramework template DerivedDispatcherT* ActionDispatcher::MouseLButtonUp() { - Log("Mouse left button up"); + Log("%s", "Mouse left button up"); MouseLButtonUpImpl(); return static_cast(this); } diff --git a/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp b/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp index ca08142371..8f82bb09b1 100644 --- a/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp +++ b/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp @@ -24,7 +24,7 @@ namespace AzManipulatorTestFramework { const char* error = "Couldn't add action to sequence, dispatcher is locked (you must call ResetSequence() \ before adding actions to this dispatcher)"; - Log(error); + Log("%s", error); AZ_Assert(false, "Error: %s", error); } @@ -108,7 +108,7 @@ namespace AzManipulatorTestFramework RetainedModeActionDispatcher* RetainedModeActionDispatcher::ResetSequence() { - Log("Resetting the action sequence"); + Log("%s", "Resetting the action sequence"); m_actions.clear(); m_dispatcher.ResetEvent(); m_locked = false; @@ -117,7 +117,7 @@ namespace AzManipulatorTestFramework RetainedModeActionDispatcher* RetainedModeActionDispatcher::Execute() { - Log("Executing %u actions", m_actions.size()); + Log("%s", "Executing %u actions", m_actions.size()); for (auto& action : m_actions) { action(); diff --git a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp index fe87c3f784..d5ef2dd3b8 100644 --- a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp +++ b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp @@ -824,9 +824,7 @@ void CLevelSystem::LogLoadingTime() sChain = " (Chained)"; } - AZStd::string text; - text.format("Game Level Load Time: [%s] Level %s loaded in %.2f seconds%s", vers, m_lastLevelName.c_str(), m_fLastLevelLoadTime, sChain); - gEnv->pLog->Log(text.c_str()); + gEnv->pLog->Log("Game Level Load Time: [%s] Level %s loaded in %.2f seconds%s", vers, m_lastLevelName.c_str(), m_fLastLevelLoadTime, sChain); } void CLevelSystem::GetMemoryUsage(ICrySizer* pSizer) const diff --git a/Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp b/Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp index 72d74ea1c1..a82c4a6914 100644 --- a/Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp +++ b/Code/Legacy/CrySystem/LevelSystem/SpawnableLevelSystem.cpp @@ -468,10 +468,7 @@ namespace LegacyLevelSystem sChain = " (Chained)"; } - AZStd::string text; - text.format( - "Game Level Load Time: [%s] Level %s loaded in %.2f seconds%s", vers, m_lastLevelName.c_str(), m_fLastLevelLoadTime, sChain); - gEnv->pLog->Log(text.c_str()); + gEnv->pLog->Log("Game Level Load Time: [%s] Level %s loaded in %.2f seconds%s", vers, m_lastLevelName.c_str(), m_fLastLevelLoadTime, sChain); } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Legacy/CrySystem/Log.cpp b/Code/Legacy/CrySystem/Log.cpp index 68b9621f74..c08d5870e9 100644 --- a/Code/Legacy/CrySystem/Log.cpp +++ b/Code/Legacy/CrySystem/Log.cpp @@ -593,11 +593,11 @@ void CLog::LogPlus(const char* szFormat, ...) if (bfile) { - LogToFilePlus(szTemp); + LogToFilePlus("%s", szTemp); } if (bconsole) { - LogToConsolePlus(szTemp); + LogToConsolePlus("%s", szTemp); } } diff --git a/Code/Legacy/CrySystem/SystemCFG.cpp b/Code/Legacy/CrySystem/SystemCFG.cpp index 0f67fdc2e1..b6b664f62d 100644 --- a/Code/Legacy/CrySystem/SystemCFG.cpp +++ b/Code/Legacy/CrySystem/SystemCFG.cpp @@ -190,7 +190,7 @@ void CSystem::LogVersion() #else strftime(s, 128, "Log Started at %c", today); #endif - CryLogAlways(s); + CryLogAlways("%s", s); CryLogAlways("Built on " __DATE__ " " __TIME__); diff --git a/Code/Legacy/CrySystem/XConsole.cpp b/Code/Legacy/CrySystem/XConsole.cpp index bb8316981a..1677cb06a5 100644 --- a/Code/Legacy/CrySystem/XConsole.cpp +++ b/Code/Legacy/CrySystem/XConsole.cpp @@ -376,12 +376,12 @@ void CXConsole::LogChangeMessage(const char* name, const bool isConst, const boo if (allowChange) { - gEnv->pLog->LogWarning(logMessage.c_str()); + gEnv->pLog->LogWarning("%s", logMessage.c_str()); gEnv->pLog->LogWarning("Modifying marked variables will not be allowed in Release mode!"); } else { - gEnv->pLog->LogError(logMessage.c_str()); + gEnv->pLog->LogError("%s", logMessage.c_str()); } } diff --git a/Gems/AssetMemoryAnalyzer/Code/Source/DebugImGUI.cpp b/Gems/AssetMemoryAnalyzer/Code/Source/DebugImGUI.cpp index aecac5fa34..c9c123cf70 100644 --- a/Gems/AssetMemoryAnalyzer/Code/Source/DebugImGUI.cpp +++ b/Gems/AssetMemoryAnalyzer/Code/Source/DebugImGUI.cpp @@ -200,7 +200,7 @@ namespace AssetMemoryAnalyzer switch (ap->m_codePoint->m_category) { case AllocationCategories::HEAP: - ImGui::Text(FormatUtils::FormatCodePoint(*ap->m_codePoint)); + ImGui::Text("%s", FormatUtils::FormatCodePoint(*ap->m_codePoint)); heapSummary.m_allocationCount = static_cast(ap->m_allocations.size()); heapSummary.m_allocatedMemory = ap->m_totalAllocatedMemory; break; @@ -247,7 +247,7 @@ namespace AssetMemoryAnalyzer { if (text) { - ImGui::Text(text); + ImGui::Text("%s", text); ImGui::SameLine(); } diff --git a/cmake/Platform/Common/Clang/Configurations_clang.cmake b/cmake/Platform/Common/Clang/Configurations_clang.cmake index 17a89fc1cd..dbaf9b0bf0 100644 --- a/cmake/Platform/Common/Clang/Configurations_clang.cmake +++ b/cmake/Platform/Common/Clang/Configurations_clang.cmake @@ -22,7 +22,6 @@ ly_append_configurations_options( "-Wno-#pragma-messages" -Wno-absolute-value -Wno-dynamic-class-memaccess - -Wno-format-security -Wno-inconsistent-missing-override -Wno-invalid-offsetof -Wno-multichar From e8495cf8290c813aab7165bc84c32d9dbeabcfe9 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:11:04 -0700 Subject: [PATCH 02/16] adds equivalent warnign for windows Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- cmake/Platform/Common/MSVC/Configurations_msvc.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/Platform/Common/MSVC/Configurations_msvc.cmake b/cmake/Platform/Common/MSVC/Configurations_msvc.cmake index 647ced54a2..237db5a2ce 100644 --- a/cmake/Platform/Common/MSVC/Configurations_msvc.cmake +++ b/cmake/Platform/Common/MSVC/Configurations_msvc.cmake @@ -41,12 +41,14 @@ ly_append_configurations_options( # Enabling warnings that are disabled by default from /W4 # https://docs.microsoft.com/en-us/cpp/preprocessor/compiler-warnings-that-are-off-by-default?view=vs-2019 /we4296 # 'operator': expression is always false - /we5233 # explicit lambda capture 'identifier' is not used /we4426 # optimization flags changed after including header, may be due to #pragma optimize() #/we4619 # #pragma warning: there is no warning number 'number'. Unfortunately some versions of MSVC 16.X dont filter this warning coming from external headers and Qt has a bad warning in QtCore/qvector.h(340,12) + /we4774 # 'string' : format string expected in argument number is not a string literal /we4777 # 'function' : format string 'string' requires an argument of type 'type1', but variadic argument number has type 'type2 /we5031 # #pragma warning(pop): likely mismatch, popping warning state pushed in different file /we5032 # detected #pragma warning(push) with no corresponding #pragma warning(pop) + /we5233 # explicit lambda capture 'identifier' is not used + /Zc:forScope # Force Conformance in for Loop Scope /diagnostics:caret # Compiler diagnostic options: includes the column where the issue was found and places a caret (^) under the location in the line of code where the issue was detected. From 6773af91bcbd7a871ebcc882d126c64e2c5e044c Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:11:28 -0700 Subject: [PATCH 03/16] fixes windows warnings Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../TrackView/SequenceBatchRenderDialog.cpp | 3 +- Code/Editor/Util/ImageASC.cpp | 2 +- Code/Editor/Util/ImageUtil.cpp | 2 +- .../AzFramework/Logging/LogFile.cpp | 20 ++++- Code/LauncherUnified/Launcher.cpp | 18 +++- Code/Legacy/CrySystem/SystemInit.cpp | 89 ------------------- .../AssetMemoryAnalyzerSystemComponent.cpp | 7 +- .../ImGui/v1.82/imgui/imgui_widgets.cpp | 1 + 8 files changed, 37 insertions(+), 105 deletions(-) diff --git a/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp b/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp index 33f1b0d441..b510315995 100644 --- a/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp +++ b/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp @@ -719,8 +719,7 @@ bool CSequenceBatchRenderDialog::GetResolutionFromCustomResText(const char* cust int scannedWidth = retCustomWidth; // initialize with default fall-back values - they'll be overwritten in the case of a succesful sscanf below. int scannedHeight = retCustomHeight; - QString strFormat = QString::fromLatin1(customResFormat).replace(QRegularExpression(QStringLiteral("%\\d")), QStringLiteral("%d")); - scanSuccess = (azsscanf(customResText, strFormat.toStdString().c_str(), &scannedWidth, &scannedHeight) == 2); + scanSuccess = (azsscanf(customResText, "Custom(%d x %d)...", &scannedWidth, &scannedHeight) == 2); if (scanSuccess) { retCustomWidth = scannedWidth; diff --git a/Code/Editor/Util/ImageASC.cpp b/Code/Editor/Util/ImageASC.cpp index a72ea8b9fd..1c4a8acf73 100644 --- a/Code/Editor/Util/ImageASC.cpp +++ b/Code/Editor/Util/ImageASC.cpp @@ -52,7 +52,7 @@ bool CImageASC::Save(const QString& fileName, const CFloatImage& image) } // First print the file header - fprintf(file, fileHeader.c_str()); + fprintf(file, "%s", fileHeader.c_str()); // Then print all the pixels. for (uint32 y = 0; y < height; y++) diff --git a/Code/Editor/Util/ImageUtil.cpp b/Code/Editor/Util/ImageUtil.cpp index c8432a3d1a..45d39f1f02 100644 --- a/Code/Editor/Util/ImageUtil.cpp +++ b/Code/Editor/Util/ImageUtil.cpp @@ -103,7 +103,7 @@ bool CImageUtil::SavePGM(const QString& fileName, const CImageEx& image) } // First print the file header - fprintf(file, fileHeader.c_str()); + fprintf(file, "%s", fileHeader.c_str()); // Then print all the pixels. for (uint32 y = 0; y < height; y++) diff --git a/Code/Framework/AzFramework/AzFramework/Logging/LogFile.cpp b/Code/Framework/AzFramework/AzFramework/Logging/LogFile.cpp index 506d4a8861..bd9b52fa86 100644 --- a/Code/Framework/AzFramework/AzFramework/Logging/LogFile.cpp +++ b/Code/Framework/AzFramework/AzFramework/Logging/LogFile.cpp @@ -311,7 +311,6 @@ namespace AzFramework // On some platforms, threadid is just a number but on other platforms it is a pointer of some kind // uintptr_t will ensure that the data will always fit uintptr_t threadID = threadId ? threadId : (uintptr_t)(AZStd::this_thread::get_id().m_id); - const char* printFormatter = m_machineReadable ? "~~%p~~%s~~" : "{%p}[%14s]"; // while it may be tempting to check the fileio Pointer here, any emit of any warning or error would be fatal // since we're already logging, and we don't want to log while you log. @@ -331,7 +330,14 @@ namespace AzFramework azsnprintf(buffer, 80, "~~%llu~~%i", rawTime, severity); m_fileIO->Write(m_fileHandle, buffer, strlen(buffer)); - azsnprintf(buffer, 80, printFormatter, threadID, categoryActual); + if (m_machineReadable) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected) + { + azsnprintf(buffer, 80, "~~%p~~%s~~", reinterpret_cast(threadID), categoryActual); + } + else + { + azsnprintf(buffer, 80, "{%p}[%14s]", reinterpret_cast(threadID), categoryActual); + } m_fileIO->Write(m_fileHandle, buffer, strlen(buffer)); m_fileIO->Write(m_fileHandle, dataSource, dataLength); @@ -349,8 +355,14 @@ namespace AzFramework { return; } - - azsnprintf(categorybuffer, 64, printFormatter, threadID, categoryActual); + if (m_machineReadable) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected) + { + azsnprintf(categorybuffer, 64, "~~%p~~%s~~", reinterpret_cast(threadID), categoryActual); + } + else + { + azsnprintf(categorybuffer, 64, "{%p}[%14s]", reinterpret_cast(threadID), categoryActual); + } if ((category) && (categoryLen)) { diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 07da69cbe9..f5da40ccad 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -305,10 +305,20 @@ namespace O3DELauncher m_commandLine[m_commandLineLen++] = ' '; } - azsnprintf(m_commandLine + m_commandLineLen, - AZ_COMMAND_LINE_LEN - m_commandLineLen, - needsQuote ? "\"%s\"" : "%s", - arg); + if (needsQuote) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected) + { + azsnprintf(m_commandLine + m_commandLineLen, + AZ_COMMAND_LINE_LEN - m_commandLineLen, + "\"%s\"", + arg); + } + else + { + azsnprintf(m_commandLine + m_commandLineLen, + AZ_COMMAND_LINE_LEN - m_commandLineLen, + "%s", + arg); + } // Inject the argument in the argument buffer to preserve/replicate argC and argV azstrncpy(&m_commandLineArgBuffer[m_nextCommandLineArgInsertPoint], diff --git a/Code/Legacy/CrySystem/SystemInit.cpp b/Code/Legacy/CrySystem/SystemInit.cpp index d5efff2748..81d4ee5730 100644 --- a/Code/Legacy/CrySystem/SystemInit.cpp +++ b/Code/Legacy/CrySystem/SystemInit.cpp @@ -516,95 +516,6 @@ void CSystem::ShutdownModuleLibraries() #endif // !defined(AZ_MONOLITHIC_BUILD) } -///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// - -#if defined(WIN32) || defined(WIN64) -AZStd::wstring GetErrorStringUnsupportedGPU(const char* gpuName, unsigned int gpuVendorId, unsigned int gpuDeviceId) -{ - const size_t fullLangID = (size_t) GetKeyboardLayout(0); - const size_t primLangID = fullLangID & 0x3FF; - - const wchar_t* pFmt = L"Unsupported video card detected! Continuing to run might lead to unexpected results or crashes. " - L"Please check the manual for further information on hardware requirements.\n\n\"%S\" [vendor id = 0x%.4x, device id = 0x%.4x]"; - - switch (primLangID) - { - case 0x04: // Chinese - { - static const wchar_t fmt[] = {0x5075, 0x6E2C, 0x5230, 0x4E0D, 0x652F, 0x63F4, 0x7684, 0x986F, 0x793A, 0x5361, 0xFF01, 0x7E7C, 0x7E8C, 0x57F7, 0x884C, 0x53EF, 0x80FD, 0x5C0E, 0x81F4, 0x7121, 0x6CD5, 0x9810, 0x671F, 0x7684, 0x7D50, 0x679C, 0x6216, 0x7576, 0x6A5F, 0x3002, 0x8ACB, 0x6AA2, 0x67E5, 0x8AAA, 0x660E, 0x66F8, 0x4E0A, 0x7684, 0x786C, 0x9AD4, 0x9700, 0x6C42, 0x4EE5, 0x53D6, 0x5F97, 0x66F4, 0x591A, 0x76F8, 0x95DC, 0x8CC7, 0x8A0A, 0x3002, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x5EE0, 0x5546, 0x7DE8, 0x865F, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x88DD, 0x7F6E, 0x7DE8, 0x865F, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x05: // Czech - { - static const wchar_t fmt[] = {0x0042, 0x0079, 0x006C, 0x0061, 0x0020, 0x0064, 0x0065, 0x0074, 0x0065, 0x006B, 0x006F, 0x0076, 0x00E1, 0x006E, 0x0061, 0x0020, 0x0067, 0x0072, 0x0061, 0x0066, 0x0069, 0x0063, 0x006B, 0x00E1, 0x0020, 0x006B, 0x0061, 0x0072, 0x0074, 0x0061, 0x002C, 0x0020, 0x006B, 0x0074, 0x0065, 0x0072, 0x00E1, 0x0020, 0x006E, 0x0065, 0x006E, 0x00ED, 0x0020, 0x0070, 0x006F, 0x0064, 0x0070, 0x006F, 0x0072, 0x006F, 0x0076, 0x00E1, 0x006E, 0x0061, 0x002E, 0x0020, 0x0050, 0x006F, 0x006B, 0x0072, 0x0061, 0x010D, 0x006F, 0x0076, 0x00E1, 0x006E, 0x00ED, 0x0020, 0x006D, 0x016F, 0x017E, 0x0065, 0x0020, 0x0076, 0x00E9, 0x0073, 0x0074, 0x0020, 0x006B, 0x0065, 0x0020, 0x006B, 0x0072, 0x0069, 0x0074, 0x0069, 0x0063, 0x006B, 0x00FD, 0x006D, 0x0020, 0x0063, 0x0068, 0x0079, 0x0062, 0x00E1, 0x006D, 0x0020, 0x006E, 0x0065, 0x0062, 0x006F, 0x0020, 0x006E, 0x0065, 0x0073, 0x0074, 0x0061, 0x0062, 0x0069, 0x006C, 0x0069, 0x0074, 0x011B, 0x0020, 0x0073, 0x0079, 0x0073, 0x0074, 0x00E9, 0x006D, 0x0075, 0x002E, 0x0020, 0x0050, 0x0159, 0x0065, 0x010D, 0x0074, 0x011B, 0x0074, 0x0065, 0x0020, 0x0073, 0x0069, 0x0020, 0x0070, 0x0072, 0x006F, 0x0073, 0x00ED, 0x006D, 0x0020, 0x0075, 0x017E, 0x0069, 0x0076, 0x0061, 0x0074, 0x0065, 0x006C, 0x0073, 0x006B, 0x006F, 0x0075, 0x0020, 0x0070, 0x0159, 0x00ED, 0x0072, 0x0075, 0x010D, 0x006B, 0x0075, 0x0020, 0x0070, 0x0072, 0x006F, 0x0020, 0x0070, 0x006F, 0x0064, 0x0072, 0x006F, 0x0062, 0x006E, 0x00E9, 0x0020, 0x0069, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x0063, 0x0065, 0x0020, 0x006F, 0x0020, 0x0073, 0x0079, 0x0073, 0x0074, 0x00E9, 0x006D, 0x006F, 0x0076, 0x00FD, 0x0063, 0x0068, 0x0020, 0x0070, 0x006F, 0x017E, 0x0061, 0x0064, 0x0061, 0x0076, 0x0063, 0x00ED, 0x0063, 0x0068, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x07: // German - { - static const wchar_t fmt[] = {0x004E, 0x0069, 0x0063, 0x0068, 0x0074, 0x002D, 0x0075, 0x006E, 0x0074, 0x0065, 0x0072, 0x0073, 0x0074, 0x00FC, 0x0074, 0x007A, 0x0074, 0x0065, 0x0020, 0x0056, 0x0069, 0x0064, 0x0065, 0x006F, 0x006B, 0x0061, 0x0072, 0x0074, 0x0065, 0x0020, 0x0067, 0x0065, 0x0066, 0x0075, 0x006E, 0x0064, 0x0065, 0x006E, 0x0021, 0x0020, 0x0046, 0x006F, 0x0072, 0x0074, 0x0066, 0x0061, 0x0068, 0x0072, 0x0065, 0x006E, 0x0020, 0x006B, 0x0061, 0x006E, 0x006E, 0x0020, 0x007A, 0x0075, 0x0020, 0x0075, 0x006E, 0x0065, 0x0072, 0x0077, 0x0061, 0x0072, 0x0074, 0x0065, 0x0074, 0x0065, 0x006E, 0x0020, 0x0045, 0x0072, 0x0067, 0x0065, 0x0062, 0x006E, 0x0069, 0x0073, 0x0073, 0x0065, 0x006E, 0x0020, 0x006F, 0x0064, 0x0065, 0x0072, 0x0020, 0x0041, 0x0062, 0x0073, 0x0074, 0x00FC, 0x0072, 0x007A, 0x0065, 0x006E, 0x0020, 0x0066, 0x00FC, 0x0068, 0x0072, 0x0065, 0x006E, 0x002E, 0x0020, 0x0042, 0x0069, 0x0074, 0x0074, 0x0065, 0x0020, 0x006C, 0x0069, 0x0065, 0x0073, 0x0020, 0x0064, 0x0061, 0x0073, 0x0020, 0x004D, 0x0061, 0x006E, 0x0075, 0x0061, 0x006C, 0x0020, 0x0066, 0x00FC, 0x0072, 0x0020, 0x0077, 0x0065, 0x0069, 0x0074, 0x0065, 0x0072, 0x0065, 0x0020, 0x0049, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x0074, 0x0069, 0x006F, 0x006E, 0x0065, 0x006E, 0x0020, 0x007A, 0x0075, 0x0020, 0x0048, 0x0061, 0x0072, 0x0064, 0x0077, 0x0061, 0x0072, 0x0065, 0x002D, 0x0041, 0x006E, 0x0066, 0x006F, 0x0072, 0x0064, 0x0065, 0x0072, 0x0075, 0x006E, 0x0067, 0x0065, 0x006E, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x0a: // Spanish - { - static const wchar_t fmt[] = {0x0053, 0x0065, 0x0020, 0x0068, 0x0061, 0x0020, 0x0064, 0x0065, 0x0074, 0x0065, 0x0063, 0x0074, 0x0061, 0x0064, 0x006F, 0x0020, 0x0075, 0x006E, 0x0061, 0x0020, 0x0074, 0x0061, 0x0072, 0x006A, 0x0065, 0x0074, 0x0061, 0x0020, 0x0067, 0x0072, 0x00E1, 0x0066, 0x0069, 0x0063, 0x0061, 0x0020, 0x006E, 0x006F, 0x0020, 0x0063, 0x006F, 0x006D, 0x0070, 0x0061, 0x0074, 0x0069, 0x0062, 0x006C, 0x0065, 0x002E, 0x0020, 0x0053, 0x0069, 0x0020, 0x0073, 0x0069, 0x0067, 0x0075, 0x0065, 0x0073, 0x0020, 0x0065, 0x006A, 0x0065, 0x0063, 0x0075, 0x0074, 0x0061, 0x006E, 0x0064, 0x006F, 0x0020, 0x0065, 0x006C, 0x0020, 0x006A, 0x0075, 0x0065, 0x0067, 0x006F, 0x002C, 0x0020, 0x0065, 0x0073, 0x0020, 0x0070, 0x006F, 0x0073, 0x0069, 0x0062, 0x006C, 0x0065, 0x0020, 0x0071, 0x0075, 0x0065, 0x0020, 0x0073, 0x0065, 0x0020, 0x0070, 0x0072, 0x006F, 0x0064, 0x0075, 0x007A, 0x0063, 0x0061, 0x006E, 0x0020, 0x0065, 0x0066, 0x0065, 0x0063, 0x0074, 0x006F, 0x0073, 0x0020, 0x0069, 0x006E, 0x0065, 0x0073, 0x0070, 0x0065, 0x0072, 0x0061, 0x0064, 0x006F, 0x0073, 0x0020, 0x006F, 0x0020, 0x0071, 0x0075, 0x0065, 0x0020, 0x0065, 0x006C, 0x0020, 0x0070, 0x0072, 0x006F, 0x0067, 0x0072, 0x0061, 0x006D, 0x0061, 0x0020, 0x0064, 0x0065, 0x006A, 0x0065, 0x0020, 0x0064, 0x0065, 0x0020, 0x0066, 0x0075, 0x006E, 0x0063, 0x0069, 0x006F, 0x006E, 0x0061, 0x0072, 0x002E, 0x0020, 0x0050, 0x006F, 0x0072, 0x0020, 0x0066, 0x0061, 0x0076, 0x006F, 0x0072, 0x002C, 0x0020, 0x0063, 0x006F, 0x006D, 0x0070, 0x0072, 0x0075, 0x0065, 0x0062, 0x0061, 0x0020, 0x0065, 0x006C, 0x0020, 0x006D, 0x0061, 0x006E, 0x0075, 0x0061, 0x006C, 0x0020, 0x0070, 0x0061, 0x0072, 0x0061, 0x0020, 0x006F, 0x0062, 0x0074, 0x0065, 0x006E, 0x0065, 0x0072, 0x0020, 0x006D, 0x00E1, 0x0073, 0x0020, 0x0069, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x0063, 0x0069, 0x00F3, 0x006E, 0x0020, 0x0061, 0x0063, 0x0065, 0x0072, 0x0063, 0x0061, 0x0020, 0x0064, 0x0065, 0x0020, 0x006C, 0x006F, 0x0073, 0x0020, 0x0072, 0x0065, 0x0071, 0x0075, 0x0069, 0x0073, 0x0069, 0x0074, 0x006F, 0x0073, 0x0020, 0x0064, 0x0065, 0x006C, 0x0020, 0x0073, 0x0069, 0x0073, 0x0074, 0x0065, 0x006D, 0x0061, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x0c: // French - { - static const wchar_t fmt[] = {0x0041, 0x0074, 0x0074, 0x0065, 0x006E, 0x0074, 0x0069, 0x006F, 0x006E, 0x002C, 0x0020, 0x006C, 0x0061, 0x0020, 0x0063, 0x0061, 0x0072, 0x0074, 0x0065, 0x0020, 0x0076, 0x0069, 0x0064, 0x00E9, 0x006F, 0x0020, 0x0064, 0x00E9, 0x0074, 0x0065, 0x0063, 0x0074, 0x00E9, 0x0065, 0x0020, 0x006E, 0x2019, 0x0065, 0x0073, 0x0074, 0x0020, 0x0070, 0x0061, 0x0073, 0x0020, 0x0073, 0x0075, 0x0070, 0x0070, 0x006F, 0x0072, 0x0074, 0x00E9, 0x0065, 0x0020, 0x0021, 0x0020, 0x0050, 0x006F, 0x0075, 0x0072, 0x0073, 0x0075, 0x0069, 0x0076, 0x0072, 0x0065, 0x0020, 0x006C, 0x2019, 0x0061, 0x0070, 0x0070, 0x006C, 0x0069, 0x0063, 0x0061, 0x0074, 0x0069, 0x006F, 0x006E, 0x0020, 0x0070, 0x006F, 0x0075, 0x0072, 0x0072, 0x0061, 0x0069, 0x0074, 0x0020, 0x0065, 0x006E, 0x0067, 0x0065, 0x006E, 0x0064, 0x0072, 0x0065, 0x0072, 0x0020, 0x0064, 0x0065, 0x0073, 0x0020, 0x0069, 0x006E, 0x0073, 0x0074, 0x0061, 0x0062, 0x0069, 0x006C, 0x0069, 0x0074, 0x00E9, 0x0073, 0x0020, 0x006F, 0x0075, 0x0020, 0x0064, 0x0065, 0x0073, 0x0020, 0x0063, 0x0072, 0x0061, 0x0073, 0x0068, 0x0073, 0x002E, 0x0020, 0x0056, 0x0065, 0x0075, 0x0069, 0x006C, 0x006C, 0x0065, 0x007A, 0x0020, 0x0076, 0x006F, 0x0075, 0x0073, 0x0020, 0x0072, 0x0065, 0x0070, 0x006F, 0x0072, 0x0074, 0x0065, 0x0072, 0x0020, 0x0061, 0x0075, 0x0020, 0x006D, 0x0061, 0x006E, 0x0075, 0x0065, 0x006C, 0x0020, 0x0070, 0x006F, 0x0075, 0x0072, 0x0020, 0x0070, 0x006C, 0x0075, 0x0073, 0x0020, 0x0064, 0x2019, 0x0069, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x0074, 0x0069, 0x006F, 0x006E, 0x0073, 0x0020, 0x0073, 0x0075, 0x0072, 0x0020, 0x006C, 0x0065, 0x0073, 0x0020, 0x0070, 0x0072, 0x00E9, 0x002D, 0x0072, 0x0065, 0x0071, 0x0075, 0x0069, 0x0073, 0x0020, 0x006D, 0x0061, 0x0074, 0x00E9, 0x0072, 0x0069, 0x0065, 0x006C, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x10: // Italian - { - static const wchar_t fmt[] = {0x00C8, 0x0020, 0x0073, 0x0074, 0x0061, 0x0074, 0x0061, 0x0020, 0x0072, 0x0069, 0x006C, 0x0065, 0x0076, 0x0061, 0x0074, 0x0061, 0x0020, 0x0075, 0x006E, 0x0061, 0x0020, 0x0073, 0x0063, 0x0068, 0x0065, 0x0064, 0x0061, 0x0020, 0x0067, 0x0072, 0x0061, 0x0066, 0x0069, 0x0063, 0x0061, 0x0020, 0x006E, 0x006F, 0x006E, 0x0020, 0x0073, 0x0075, 0x0070, 0x0070, 0x006F, 0x0072, 0x0074, 0x0061, 0x0074, 0x0061, 0x0021, 0x0020, 0x0053, 0x0065, 0x0020, 0x0073, 0x0069, 0x0020, 0x0063, 0x006F, 0x006E, 0x0074, 0x0069, 0x006E, 0x0075, 0x0061, 0x002C, 0x0020, 0x0073, 0x0069, 0x0020, 0x0070, 0x006F, 0x0074, 0x0072, 0x0065, 0x0062, 0x0062, 0x0065, 0x0072, 0x006F, 0x0020, 0x0076, 0x0065, 0x0072, 0x0069, 0x0066, 0x0069, 0x0063, 0x0061, 0x0072, 0x0065, 0x0020, 0x0072, 0x0069, 0x0073, 0x0075, 0x006C, 0x0074, 0x0061, 0x0074, 0x0069, 0x0020, 0x0069, 0x006E, 0x0061, 0x0074, 0x0074, 0x0065, 0x0073, 0x0069, 0x0020, 0x006F, 0x0020, 0x0063, 0x0072, 0x0061, 0x0073, 0x0068, 0x002E, 0x0020, 0x0043, 0x006F, 0x006E, 0x0073, 0x0075, 0x006C, 0x0074, 0x0061, 0x0020, 0x0069, 0x006C, 0x0020, 0x006D, 0x0061, 0x006E, 0x0075, 0x0061, 0x006C, 0x0065, 0x0020, 0x0070, 0x0065, 0x0072, 0x0020, 0x0075, 0x006C, 0x0074, 0x0065, 0x0072, 0x0069, 0x006F, 0x0072, 0x0069, 0x0020, 0x0069, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x007A, 0x0069, 0x006F, 0x006E, 0x0069, 0x0020, 0x0073, 0x0075, 0x0069, 0x0020, 0x0072, 0x0065, 0x0071, 0x0075, 0x0069, 0x0073, 0x0069, 0x0074, 0x0069, 0x0020, 0x0064, 0x0069, 0x0020, 0x0073, 0x0069, 0x0073, 0x0074, 0x0065, 0x006D, 0x0061, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x11: // Japanese - { - static const wchar_t fmt[] = {0x30B5, 0x30DD, 0x30FC, 0x30C8, 0x3055, 0x308C, 0x3066, 0x3044, 0x306A, 0x3044, 0x30D3, 0x30C7, 0x30AA, 0x30AB, 0x30FC, 0x30C9, 0x304C, 0x691C, 0x51FA, 0x3055, 0x308C, 0x307E, 0x3057, 0x305F, 0xFF01, 0x0020, 0x3053, 0x306E, 0x307E, 0x307E, 0x7D9A, 0x3051, 0x308B, 0x3068, 0x4E88, 0x671F, 0x3057, 0x306A, 0x3044, 0x7D50, 0x679C, 0x3084, 0x30AF, 0x30E9, 0x30C3, 0x30B7, 0x30E5, 0x306E, 0x6050, 0x308C, 0x304C, 0x3042, 0x308A, 0x307E, 0x3059, 0x3002, 0x0020, 0x30DE, 0x30CB, 0x30E5, 0x30A2, 0x30EB, 0x306E, 0x5FC5, 0x8981, 0x52D5, 0x4F5C, 0x74B0, 0x5883, 0x3092, 0x3054, 0x78BA, 0x8A8D, 0x304F, 0x3060, 0x3055, 0x3044, 0x3002, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x30D9, 0x30F3, 0x30C0, 0x30FC, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x30C7, 0x30D0, 0x30A4, 0x30B9, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x15: // Polish - { - static const wchar_t fmt[] = {0x0057, 0x0079, 0x006B, 0x0072, 0x0079, 0x0074, 0x006F, 0x0020, 0x006E, 0x0069, 0x0065, 0x006F, 0x0062, 0x0073, 0x0142, 0x0075, 0x0067, 0x0069, 0x0077, 0x0061, 0x006E, 0x0105, 0x0020, 0x006B, 0x0061, 0x0072, 0x0074, 0x0119, 0x0020, 0x0067, 0x0072, 0x0061, 0x0066, 0x0069, 0x0063, 0x007A, 0x006E, 0x0105, 0x0021, 0x0020, 0x0044, 0x0061, 0x006C, 0x0073, 0x007A, 0x0065, 0x0020, 0x006B, 0x006F, 0x0072, 0x007A, 0x0079, 0x0073, 0x0074, 0x0061, 0x006E, 0x0069, 0x0065, 0x0020, 0x007A, 0x0020, 0x0070, 0x0072, 0x006F, 0x0064, 0x0075, 0x006B, 0x0074, 0x0075, 0x0020, 0x006D, 0x006F, 0x017C, 0x0065, 0x0020, 0x0073, 0x0070, 0x006F, 0x0077, 0x006F, 0x0064, 0x006F, 0x0077, 0x0061, 0x0107, 0x0020, 0x006E, 0x0069, 0x0065, 0x0070, 0x006F, 0x017C, 0x0105, 0x0064, 0x0061, 0x006E, 0x0065, 0x0020, 0x007A, 0x0061, 0x0063, 0x0068, 0x006F, 0x0077, 0x0061, 0x006E, 0x0069, 0x0065, 0x0020, 0x006C, 0x0075, 0x0062, 0x0020, 0x0077, 0x0073, 0x0074, 0x0072, 0x007A, 0x0079, 0x006D, 0x0061, 0x006E, 0x0069, 0x0065, 0x0020, 0x0070, 0x0072, 0x006F, 0x0067, 0x0072, 0x0061, 0x006D, 0x0075, 0x002E, 0x0020, 0x0041, 0x0062, 0x0079, 0x0020, 0x0075, 0x007A, 0x0079, 0x0073, 0x006B, 0x0061, 0x0107, 0x0020, 0x0077, 0x0069, 0x0119, 0x0063, 0x0065, 0x006A, 0x0020, 0x0069, 0x006E, 0x0066, 0x006F, 0x0072, 0x006D, 0x0061, 0x0063, 0x006A, 0x0069, 0x002C, 0x0020, 0x0073, 0x006B, 0x006F, 0x006E, 0x0073, 0x0075, 0x006C, 0x0074, 0x0075, 0x006A, 0x0020, 0x0073, 0x0069, 0x0119, 0x0020, 0x007A, 0x0020, 0x0069, 0x006E, 0x0073, 0x0074, 0x0072, 0x0075, 0x006B, 0x0063, 0x006A, 0x0105, 0x0020, 0x006F, 0x0062, 0x0073, 0x0142, 0x0075, 0x0067, 0x0069, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x19: // Russian - { - static const wchar_t fmt[] = {0x0412, 0x0430, 0x0448, 0x0430, 0x0020, 0x0432, 0x0438, 0x0434, 0x0435, 0x043E, 0x0020, 0x043A, 0x0430, 0x0440, 0x0442, 0x0430, 0x0020, 0x043D, 0x0435, 0x0020, 0x043F, 0x043E, 0x0434, 0x0434, 0x0435, 0x0440, 0x0436, 0x0438, 0x0432, 0x0430, 0x0435, 0x0442, 0x0441, 0x044F, 0x0021, 0x0020, 0x042D, 0x0442, 0x043E, 0x0020, 0x043C, 0x043E, 0x0436, 0x0435, 0x0442, 0x0020, 0x043F, 0x0440, 0x0438, 0x0432, 0x0435, 0x0441, 0x0442, 0x0438, 0x0020, 0x043A, 0x0020, 0x043D, 0x0435, 0x043F, 0x0440, 0x0435, 0x0434, 0x0441, 0x043A, 0x0430, 0x0437, 0x0443, 0x0435, 0x043C, 0x043E, 0x043C, 0x0443, 0x0020, 0x043F, 0x043E, 0x0432, 0x0435, 0x0434, 0x0435, 0x043D, 0x0438, 0x044E, 0x0020, 0x0438, 0x0020, 0x0437, 0x0430, 0x0432, 0x0438, 0x0441, 0x0430, 0x043D, 0x0438, 0x044E, 0x0020, 0x0438, 0x0433, 0x0440, 0x044B, 0x002E, 0x0020, 0x0414, 0x043B, 0x044F, 0x0020, 0x043F, 0x043E, 0x043B, 0x0443, 0x0447, 0x0435, 0x043D, 0x0438, 0x044F, 0x0020, 0x0438, 0x043D, 0x0444, 0x043E, 0x0440, 0x043C, 0x0430, 0x0446, 0x0438, 0x0438, 0x0020, 0x043E, 0x0020, 0x0441, 0x0438, 0x0441, 0x0442, 0x0435, 0x043C, 0x043D, 0x044B, 0x0445, 0x0020, 0x0442, 0x0440, 0x0435, 0x0431, 0x043E, 0x0432, 0x0430, 0x043D, 0x0438, 0x044F, 0x0445, 0x0020, 0x043E, 0x0431, 0x0440, 0x0430, 0x0442, 0x0438, 0x0442, 0x0435, 0x0441, 0x044C, 0x0020, 0x043A, 0x0020, 0x0440, 0x0443, 0x043A, 0x043E, 0x0432, 0x043E, 0x0434, 0x0441, 0x0442, 0x0432, 0x0443, 0x0020, 0x043F, 0x043E, 0x043B, 0x044C, 0x0437, 0x043E, 0x0432, 0x0430, 0x0442, 0x0435, 0x043B, 0x044F, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - case 0x1f: // Turkish - { - static const wchar_t fmt[] = {0x0044, 0x0065, 0x0073, 0x0074, 0x0065, 0x006B, 0x006C, 0x0065, 0x006E, 0x006D, 0x0065, 0x0079, 0x0065, 0x006E, 0x0020, 0x0062, 0x0069, 0x0072, 0x0020, 0x0065, 0x006B, 0x0072, 0x0061, 0x006E, 0x0020, 0x006B, 0x0061, 0x0072, 0x0074, 0x0131, 0x0020, 0x0061, 0x006C, 0x0067, 0x0131, 0x006C, 0x0061, 0x006E, 0x0064, 0x0131, 0x0021, 0x0020, 0x0044, 0x0065, 0x0076, 0x0061, 0x006D, 0x0020, 0x0065, 0x0074, 0x006D, 0x0065, 0x006B, 0x0020, 0x0062, 0x0065, 0x006B, 0x006C, 0x0065, 0x006E, 0x006D, 0x0065, 0x0064, 0x0069, 0x006B, 0x0020, 0x0073, 0x006F, 0x006E, 0x0075, 0x00E7, 0x006C, 0x0061, 0x0072, 0x0061, 0x0020, 0x0076, 0x0065, 0x0020, 0x00E7, 0x00F6, 0x006B, 0x006D, 0x0065, 0x006C, 0x0065, 0x0072, 0x0065, 0x0020, 0x0079, 0x006F, 0x006C, 0x0020, 0x0061, 0x00E7, 0x0061, 0x0062, 0x0069, 0x006C, 0x0069, 0x0072, 0x002E, 0x0020, 0x0044, 0x006F, 0x006E, 0x0061, 0x006E, 0x0131, 0x006D, 0x0020, 0x0067, 0x0065, 0x0072, 0x0065, 0x006B, 0x006C, 0x0069, 0x006C, 0x0069, 0x006B, 0x006C, 0x0065, 0x0072, 0x0069, 0x0020, 0x0069, 0x00E7, 0x0069, 0x006E, 0x0020, 0x006C, 0x00FC, 0x0074, 0x0066, 0x0065, 0x006E, 0x0020, 0x0072, 0x0065, 0x0068, 0x0062, 0x0065, 0x0072, 0x0069, 0x006E, 0x0069, 0x007A, 0x0065, 0x0020, 0x0062, 0x0061, 0x015F, 0x0076, 0x0075, 0x0072, 0x0075, 0x006E, 0x002E, 0x000A, 0x000A, 0x0022, 0x0025, 0x0053, 0x0022, 0x0020, 0x005B, 0x0076, 0x0065, 0x006E, 0x0064, 0x006F, 0x0072, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x002C, 0x0020, 0x0064, 0x0065, 0x0076, 0x0069, 0x0063, 0x0065, 0x0020, 0x0069, 0x0064, 0x0020, 0x003D, 0x0020, 0x0030, 0x0078, 0x0025, 0x002E, 0x0034, 0x0078, 0x005D, 0}; - pFmt = fmt; - break; - } - - case 0x09: // English - default: - break; - } - - wchar_t msg[1024]; - msg[0] = L'\0'; - msg[sizeof(msg) / sizeof(msg[0]) - 1] = L'\0'; - azsnwprintf(msg, sizeof(msg) / sizeof(msg[0]) - 1, pFmt, gpuName, gpuVendorId, gpuDeviceId); - - return msg; -} -#endif - ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// bool CSystem::InitConsole() diff --git a/Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzerSystemComponent.cpp b/Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzerSystemComponent.cpp index bc9763496c..bf03342149 100644 --- a/Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzerSystemComponent.cpp +++ b/Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzerSystemComponent.cpp @@ -30,17 +30,16 @@ namespace AssetMemoryAnalyzer if (customFilename) { - azsnprintf(sharedBuffer, sizeof(sharedBuffer), "@log@/%s", customFilename); + azsnprintf(sharedBuffer, AZ_ARRAY_SIZE(sharedBuffer), "@log@/%s", customFilename); } else { - char timestampBuffer[64]; time_t ltime; time(<ime); struct tm timeInfo; AZ_TRAIT_CTIME_LOCALTIME(&timeInfo, <ime); - strftime(timestampBuffer, sizeof(timestampBuffer), "@log@/assetmem-%Y-%m-%d-%H-%M-%S.%%s", &timeInfo); - azsnprintf(sharedBuffer, sizeof(sharedBuffer), timestampBuffer, extension); + strftime(sharedBuffer, AZ_ARRAY_SIZE(sharedBuffer), "@log@/assetmem-%Y-%m-%d-%H-%M-%S.", &timeInfo); + azstrcat(sharedBuffer, AZ_ARRAY_SIZE(sharedBuffer), extension); } return sharedBuffer; diff --git a/Gems/ImGui/External/ImGui/v1.82/imgui/imgui_widgets.cpp b/Gems/ImGui/External/ImGui/v1.82/imgui/imgui_widgets.cpp index 86381358fa..d3b6f5826c 100644 --- a/Gems/ImGui/External/ImGui/v1.82/imgui/imgui_widgets.cpp +++ b/Gems/ImGui/External/ImGui/v1.82/imgui/imgui_widgets.cpp @@ -58,6 +58,7 @@ Index of this file: #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later #pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types +#pragma warning (disable: 4774) // format string expected in argument 2 is not a string literal #endif #endif From ec8e6bcadf19d684cab8a01140c5175e81bf1934 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 3 Sep 2021 13:27:31 -0700 Subject: [PATCH 04/16] Fixes clang cases Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/Commands/CommandManager.cpp | 15 ++---- Code/Editor/ConsoleDialog.cpp | 2 +- Code/Editor/LogFile.cpp | 6 +-- Code/Editor/Objects/ObjectManager.cpp | 2 +- Code/Editor/Plugins/FFMPEGPlugin/main.cpp | 6 +-- Code/Editor/PythonEditorFuncs.cpp | 2 +- .../ActionDispatcher.h | 3 +- .../Include/Atom/Utils/ImGuiCpuProfiler.inl | 8 +-- .../Include/Atom/Utils/ImGuiGpuProfiler.inl | 38 +++++++------- .../Code/Include/Atom/Utils/ImGuiPassTree.inl | 4 +- .../Include/Atom/Utils/ImGuiShaderMetrics.inl | 2 +- Gems/Atom/Utils/Code/atom_utils_files.cmake | 2 + .../AtomFont/Code/Source/AtomFont.cpp | 16 ++---- .../AtomFont/Code/Source/FontRenderer.cpp | 3 +- Gems/AudioSystem/Code/Source/Engine/ATL.cpp | 42 ++++++--------- .../Code/Source/Engine/FileCacheManager.cpp | 4 +- .../LYCommonMenu/ImGuiLYEntityOutliner.cpp | 52 +++++++++---------- .../Code/Source/Animation/AzEntityNode.cpp | 20 +++---- .../Code/Source/UiInteractableState.cpp | 5 +- 19 files changed, 96 insertions(+), 136 deletions(-) diff --git a/Code/Editor/Commands/CommandManager.cpp b/Code/Editor/Commands/CommandManager.cpp index 5f194971f5..4943621493 100644 --- a/Code/Editor/Commands/CommandManager.cpp +++ b/Code/Editor/Commands/CommandManager.cpp @@ -236,10 +236,7 @@ QString CEditorCommandManager::Execute(const AZStd::string& module, const AZStd: } else { - QString errMsg; - - errMsg = QStringLiteral("Error: Trying to execute a unknown command, '%1'!").arg(fullName.c_str()); - CryLogAlways(errMsg.toUtf8().data()); + CryLogAlways("Error: Trying to execute a unknown command, '%s'!", fullName.c_str()); } return ""; @@ -272,10 +269,7 @@ QString CEditorCommandManager::Execute(const AZStd::string& cmdLine) } else { - QString errMsg; - - errMsg = QStringLiteral("Error: Trying to execute a unknown command, '%1'!").arg(cmdLine.c_str()); - CryLogAlways(errMsg.toUtf8().data()); + CryLogAlways("Error: Trying to execute a unknown command, '%s'!", cmdLine.c_str()); } return ""; @@ -294,10 +288,7 @@ void CEditorCommandManager::Execute(int commandId) } else { - QString errMsg; - - errMsg = QStringLiteral("Error: Trying to execute a unknown command of ID '%1'!").arg(commandId); - CryLogAlways(errMsg.toUtf8().data()); + CryLogAlways("Error: Trying to execute a unknown command of ID '%d'!", commandId); } } diff --git a/Code/Editor/ConsoleDialog.cpp b/Code/Editor/ConsoleDialog.cpp index 2f1c3e6f58..7edb12c18c 100644 --- a/Code/Editor/ConsoleDialog.cpp +++ b/Code/Editor/ConsoleDialog.cpp @@ -36,7 +36,7 @@ void CConsoleDialog::SetInfoText(const char* text) { if (gEnv && gEnv->pLog) // before log system was initialized { - CryLogAlways(text); + CryLogAlways("%s", text); } } diff --git a/Code/Editor/LogFile.cpp b/Code/Editor/LogFile.cpp index 92186901d7..0812740efe 100644 --- a/Code/Editor/LogFile.cpp +++ b/Code/Editor/LogFile.cpp @@ -67,7 +67,7 @@ SANDBOX_API void ErrorV(const char* format, va_list argList) str += szBuffer; //CLogFile::WriteLine( str ); - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, str.toUtf8().data()); + CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, "%s", str.toUtf8().data()); if (!CCryEditApp::instance()->IsInTestMode() && !CCryEditApp::instance()->IsInExportMode() && !CCryEditApp::instance()->IsInLevelLoadTestMode()) { @@ -95,7 +95,7 @@ SANDBOX_API void WarningV(const char* format, va_list argList) char szBuffer[MAX_LOGBUFFER_SIZE]; azvsnprintf(szBuffer, MAX_LOGBUFFER_SIZE, format, argList); - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, szBuffer); + CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "%s", szBuffer); bool bNoUI = false; ICVar* pCVar = gEnv->pConsole->GetCVar("sys_no_crash_dialog"); @@ -478,7 +478,7 @@ void CLogFile::WriteString(const char* pszString) { if (gEnv && gEnv->pLog) { - gEnv->pLog->LogPlus(pszString); + gEnv->pLog->LogPlus("%s", pszString); } } diff --git a/Code/Editor/Objects/ObjectManager.cpp b/Code/Editor/Objects/ObjectManager.cpp index 30ee1fc57b..55b6fea57c 100644 --- a/Code/Editor/Objects/ObjectManager.cpp +++ b/Code/Editor/Objects/ObjectManager.cpp @@ -709,7 +709,7 @@ void CObjectManager::ShowDuplicationMsgWarning(CBaseObject* obj, const QString& ); // If id is taken. - CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, sRenameWarning.toUtf8().data()); + CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "%s", sRenameWarning.toUtf8().data()); if (bShowMsgBox) { diff --git a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp index ce0e91942b..847d426922 100644 --- a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp +++ b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp @@ -24,11 +24,9 @@ PLUGIN_API IPlugin* CreatePluginInstance(PLUGIN_INIT_PARAM* pInitParam) // Make sure the ffmpeg command can be executed before registering the command if (!CFFMPEGPlugin::RuntimeTest()) { - AZStd::string msg = - "FFMPEG plugin: Failed to execute FFmepg. Please run Setup Assistant, " + GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmepg. Please run Setup Assistant, " "go to the 'Optional software' section of the 'Install software' tab, " - "and make sure the FFmpeg executable is correctly configured."; - GetIEditor()->GetSystem()->GetILog()->Log(msg.c_str()); + "and make sure the FFmpeg executable is correctly configured."); } else { diff --git a/Code/Editor/PythonEditorFuncs.cpp b/Code/Editor/PythonEditorFuncs.cpp index 342cc607d7..200fd28f87 100644 --- a/Code/Editor/PythonEditorFuncs.cpp +++ b/Code/Editor/PythonEditorFuncs.cpp @@ -313,7 +313,7 @@ namespace { if (strcmp(pMessage, "") != 0) { - CryLogAlways(pMessage); + CryLogAlways("%s", pMessage); } } diff --git a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h index 523e6a30a7..6ae09340e3 100644 --- a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h +++ b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h @@ -92,8 +92,7 @@ namespace AzManipulatorTestFramework { if (m_logging) { - AZStd::string message = AZStd::string::format(format, args...); - AZ_Printf("[ActionDispatcher] %s", message.c_str()); + AZ_Printf("ActionDispatcher", format, args...); } } diff --git a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiCpuProfiler.inl b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiCpuProfiler.inl index cd9e4fc2b5..61f68197b6 100644 --- a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiCpuProfiler.inl +++ b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiCpuProfiler.inl @@ -288,11 +288,11 @@ namespace AZ continue; } - ImGui::Text(statistics->m_groupName.c_str()); + ImGui::Text("%s", statistics->m_groupName.c_str()); const ImVec2 topLeftBound = ImGui::GetItemRectMin(); ImGui::TableNextColumn(); - ImGui::Text(statistics->m_regionName.c_str()); + ImGui::Text("%s", statistics->m_regionName.c_str()); ImGui::TableNextColumn(); ImGui::Text("%.2f", CpuProfilerImGuiHelper::TicksToMs(statistics->m_runningAverageTicks)); @@ -313,7 +313,7 @@ namespace AZ if (ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect(topLeftBound, botRightBound, false)) { ImGui::BeginTooltip(); - ImGui::Text(statistics->GetExecutingThreadsLabel().c_str()); + ImGui::Text("%s", statistics->GetExecutingThreadsLabel().c_str()); ImGui::EndTooltip(); } } @@ -363,7 +363,7 @@ namespace AZ const auto ShowRow = [&ShowTimeInMs](const char* regionLabel, AZStd::sys_time_t duration) { - ImGui::Text(regionLabel); + ImGui::Text("%s", regionLabel); ImGui::NextColumn(); ShowTimeInMs(duration); diff --git a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiGpuProfiler.inl b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiGpuProfiler.inl index 9b2f2b0dd9..80dcace2df 100644 --- a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiGpuProfiler.inl +++ b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiGpuProfiler.inl @@ -279,13 +279,13 @@ namespace AZ const AZStd::string totalPassCountLabel = AZStd::string::format("%s: %u", "Total Pass Count", static_cast(passEntryDatabase.size())); - ImGui::Text(totalPassCountLabel.c_str()); + ImGui::Text("%s", totalPassCountLabel.c_str()); // Display listed pass count. const AZStd::string listedPassCountLabel = AZStd::string::format("%s: %u", "Listed Pass Count", static_cast(m_passEntryReferences.size())); - ImGui::Text(listedPassCountLabel.c_str()); + ImGui::Text("%s", listedPassCountLabel.c_str()); } } @@ -404,7 +404,7 @@ namespace AZ passName = AZStd::string::format("%s (%s)", passName.c_str(), passTreeState); } - ImGui::Text(passName.c_str()); + ImGui::Text("%s", passName.c_str()); // Show a HoverMarker if the text is bigger than the column. const ImVec2 textSize = ImGui::CalcTextSize(passName.c_str()); @@ -480,7 +480,7 @@ namespace AZ } else { - ImGui::Text(label.c_str()); + ImGui::Text("%s", label.c_str()); } if (textColorChanged) @@ -683,7 +683,7 @@ namespace AZ // Draw the frame time (GPU). const AZStd::string formattedTimestamp = FormatTimestampLabel(gpuTimestamp.GetDurationInNanoseconds()); const AZStd::string headerFrameTime = AZStd::string::format("Total frame duration (GPU): %s", formattedTimestamp.c_str()); - ImGui::Text(headerFrameTime.c_str()); + ImGui::Text("%s", headerFrameTime.c_str()); // Draw the viewing option. ImGui::RadioButton("Hierarchical", reinterpret_cast(&m_viewType), static_cast(ProfilerViewType::Hierarchical)); @@ -810,7 +810,7 @@ namespace AZ { const int32_t timestampMetricUnitNumeric = static_cast(m_timestampMetricUnit); const AZStd::string metricUnitText = AZStd::string::format("Time in %s", MetricUnitText[timestampMetricUnitNumeric]); - ImGui::Text(metricUnitText.c_str()); + ImGui::Text("%s", metricUnitText.c_str()); ImGui::NextColumn(); } @@ -818,7 +818,7 @@ namespace AZ { const int32_t frameWorkloadViewNumeric = static_cast(m_frameWorkloadView); const AZStd::string frameWorkloadViewText = AZStd::string::format("Frame workload in %s FPS", FrameWorkloadUnit[frameWorkloadViewNumeric]); - ImGui::Text(frameWorkloadViewText.c_str()); + ImGui::Text("%s", frameWorkloadViewText.c_str()); ImGui::NextColumn(); } @@ -853,7 +853,7 @@ namespace AZ const int32_t frameWorkloadViewNumeric = static_cast(m_frameWorkloadView); const AZStd::string frameWorkloadViewText = AZStd::string::format("Frame workload in %s FPS", FrameWorkloadUnit[frameWorkloadViewNumeric]); - ImGui::Text(frameWorkloadViewText.c_str()); + ImGui::Text("%s", frameWorkloadViewText.c_str()); ImGui::NextColumn(); } @@ -907,7 +907,7 @@ namespace AZ } else { - ImGui::Text(entryTime.c_str()); + ImGui::Text("%s", entryTime.c_str()); ImGui::NextColumn(); DrawFrameWorkloadBar(NormalizeFrameWorkload(entry->m_interpolatedTimestampInNanoseconds)); ImGui::NextColumn(); @@ -927,7 +927,7 @@ namespace AZ if (entry->m_children.empty()) { // Draw the workload bar when it doesn't have children. - ImGui::Text(entry->m_name.GetCStr()); + ImGui::Text("%s", entry->m_name.GetCStr()); // Show a HoverMarker if the text is bigger than the column. createHoverMarker(entry->m_name.GetCStr()); @@ -991,9 +991,9 @@ namespace AZ } const AZStd::string entryTime = FormatTimestampLabel(entry->m_interpolatedTimestampInNanoseconds); - ImGui::Text(entry->m_name.GetCStr()); + ImGui::Text("%s", entry->m_name.GetCStr()); ImGui::NextColumn(); - ImGui::Text(entryTime.c_str()); + ImGui::Text("%s", entryTime.c_str()); ImGui::NextColumn(); DrawFrameWorkloadBar(NormalizeFrameWorkload(entry->m_interpolatedTimestampInNanoseconds)); ImGui::NextColumn(); @@ -1131,13 +1131,13 @@ namespace AZ continue; } - ImGui::Text(tableRow.m_parentPoolName.GetCStr()); + ImGui::Text("%s", tableRow.m_parentPoolName.GetCStr()); ImGui::TableNextColumn(); - ImGui::Text(tableRow.m_bufImgName.GetCStr()); + ImGui::Text("%s", tableRow.m_bufImgName.GetCStr()); ImGui::TableNextColumn(); ImGui::Text("%.4f", 1.0f * tableRow.m_sizeInBytes / GpuProfilerImGuiHelper::MB); ImGui::TableNextColumn(); - ImGui::Text(tableRow.m_bindFlags.c_str()); + ImGui::Text("%s", tableRow.m_bindFlags.c_str()); ImGui::TableNextColumn(); } } @@ -1244,20 +1244,20 @@ namespace AZ { if (ImGui::BeginChild(savedHeap.m_name.GetCStr(), { ImGui::GetWindowWidth() / m_savedHeaps.size(), 250 }), ImGuiWindowFlags_NoScrollbar) { - ImGui::Text(savedHeap.m_name.GetCStr()); + ImGui::Text("%s", savedHeap.m_name.GetCStr()); ImGui::Columns(2, "HeapData", true); - ImGui::Text("Resident (MB): "); + ImGui::Text("%s", "Resident (MB): "); ImGui::NextColumn(); ImGui::Text("%.2f", 1.0 * savedHeap.m_memoryUsage.m_residentInBytes.load() / GpuProfilerImGuiHelper::MB); ImGui::NextColumn(); - ImGui::Text("Reserved (MB): "); + ImGui::Text("%s", "Reserved (MB): "); ImGui::NextColumn(); ImGui::Text("%.2f", 1.0 * savedHeap.m_memoryUsage.m_reservedInBytes.load() / GpuProfilerImGuiHelper::MB); ImGui::NextColumn(); - ImGui::Text("Budget (MB): "); + ImGui::Text("%s", "Budget (MB): "); ImGui::NextColumn(); ImGui::Text("%.2f", 1.0 * savedHeap.m_memoryUsage.m_budgetInBytes / GpuProfilerImGuiHelper::MB); diff --git a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiPassTree.inl b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiPassTree.inl index a9eff68c7a..fa649ed47b 100644 --- a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiPassTree.inl +++ b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiPassTree.inl @@ -100,7 +100,7 @@ namespace AZ::Render } } - ImGui::TextWrapped(m_attachmentReadbackInfo.c_str()); + ImGui::TextWrapped("%s", m_attachmentReadbackInfo.c_str()); } if (m_previewAttachment && m_selectedChanged) @@ -211,7 +211,7 @@ namespace AZ::Render else { // Only draw text (not selectable) if there is no attachment binded to the slot. - ImGui::Text(label.c_str()); + ImGui::Text("%s", label.c_str()); } } diff --git a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiShaderMetrics.inl b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiShaderMetrics.inl index 772be4d4a8..73517c66ca 100644 --- a/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiShaderMetrics.inl +++ b/Gems/Atom/Utils/Code/Include/Atom/Utils/ImGuiShaderMetrics.inl @@ -61,7 +61,7 @@ namespace AZ ImGui::Text("%d", request.m_requestCount); ImGui::NextColumn(); - ImGui::Text(request.m_shaderName.GetCStr()); + ImGui::Text("%s", request.m_shaderName.GetCStr()); ImGui::NextColumn(); ImGui::Text("%d", request.m_shaderVariantStableId.GetIndex()); diff --git a/Gems/Atom/Utils/Code/atom_utils_files.cmake b/Gems/Atom/Utils/Code/atom_utils_files.cmake index 06b78a49c4..b1f8170317 100644 --- a/Gems/Atom/Utils/Code/atom_utils_files.cmake +++ b/Gems/Atom/Utils/Code/atom_utils_files.cmake @@ -19,6 +19,8 @@ set(FILES Include/Atom/Utils/ImGuiPassTree.inl Include/Atom/Utils/ImGuiFrameVisualizer.h Include/Atom/Utils/ImGuiFrameVisualizer.inl + Include/Atom/Utils/ImGuiShaderMetrics.h + Include/Atom/Utils/ImGuiShaderMetrics.inl Include/Atom/Utils/ImGuiTransientAttachmentProfiler.h Include/Atom/Utils/ImGuiTransientAttachmentProfiler.inl Include/Atom/Utils/PpmFile.h diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFont.cpp index 8c88a49b12..5711e3ff6e 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFont.cpp @@ -731,20 +731,14 @@ IFFont* AZ::AtomFont::LoadFont(const char* fontName) font = NewFont(fontNameLower.c_str()); if (!font) { - AZStd::string errorMsg = "Error creating a new font named "; - errorMsg += fontNameLower; - errorMsg += "."; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, errorMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "Error creating a new font named %s.", fontNameLower.c_str()); } else { // creating font adds one to its refcount so no need for AddRef here if (!font->Load(fontNameLower.c_str())) { - AZStd::string errorMsg = "Error loading a font from "; - errorMsg += fontNameLower; - errorMsg += "."; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, errorMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "Error loading a font from %s.", fontNameLower.c_str()); font->Release(); font = nullptr; } @@ -792,8 +786,7 @@ bool AZ::AtomFont::AddFontFamilyToMaps(const char* fontFamilyFilename, const cha AZStd::to_lower(loweredFilename.begin(), loweredFilename.end()); if (m_fontFamilies.find(loweredFilename) != m_fontFamilies.end()) { - AZStd::string warnMsg = AZStd::string::format("Couldn't load Font Family '%s': already loaded", fontFamilyFilename); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Couldn't load Font Family '%s': already loaded", fontFamilyFilename); return false; } @@ -803,8 +796,7 @@ bool AZ::AtomFont::AddFontFamilyToMaps(const char* fontFamilyFilename, const cha AZStd::to_lower(loweredFontFamilyName.begin(), loweredFontFamilyName.end()); if (m_fontFamilies.find(loweredFontFamilyName) != m_fontFamilies.end()) { - AZStd::string warnMsg = AZStd::string::format("Couldn't load Font Family '%s': already loaded", fontFamilyName); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Couldn't load Font Family '%s': already loaded", fontFamilyName); return false; } diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp index f1fc8be965..ed5e0e50bc 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp @@ -311,8 +311,7 @@ Vec2 AZ::FontRenderer::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph) #if !defined(_RELEASE) if (0 != ftError) { - AZStd::string warnMsg = AZStd::string::format("FT_Get_Kerning returned %d", ftError); - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "FT_Get_Kerning returned %d", ftError); } #endif } diff --git a/Gems/AudioSystem/Code/Source/Engine/ATL.cpp b/Gems/AudioSystem/Code/Source/Engine/ATL.cpp index 8fbb8fffc0..e43f7beba7 100644 --- a/Gems/AudioSystem/Code/Source/Engine/ATL.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/ATL.cpp @@ -2170,25 +2170,15 @@ namespace Audio const AZ::Color yellowColor(colorMax, colorMax, colorMin, 0.9f); const AZ::Color redColor(colorMax, colorMin, colorMin, 0.9f); - constexpr const char* tableHeaderNames[] = { - "ID", - "Name", - "Curr Used", - "Peak Used", - "%% of Used", - "Allocs", - "Frees", - }; - constexpr size_t numColumns = AZStd::size(tableHeaderNames); - constexpr float xTablePositions[numColumns] = { 0.f, 40.f, 300.f, 400.f, 500.f, 600.f, 700.f }; - float posY = fPosY; - - // Draw the header info: - for (int column = 0; column < numColumns; ++column) - { - auxGeom.Draw2dLabel(fPosX + xTablePositions[column], posY, textSize, color, false, tableHeaderNames[column]); - } + constexpr float xTablePositions[7] = { 0.f, 40.f, 300.f, 400.f, 500.f, 600.f, 700.f }; + auxGeom.Draw2dLabel(fPosX + xTablePositions[0], posY, textSize, color, false, "ID"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY, textSize, color, false, "Name"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY, textSize, color, false, "Curr Used"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY, textSize, color, false, "Peak Used"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[4], posY, textSize, color, false, "%% of Used"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[5], posY, textSize, color, false, "Allocs"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[6], posY, textSize, color, false, "Frees"); // Get the memory pool information... AZStd::vector poolInfos; @@ -2232,15 +2222,15 @@ namespace Audio auxGeom.Draw2dLabel(fPosX + xTablePositions[0], posY, textSize, color, false, "%d", poolInfo.m_poolId); // Name - auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY, textSize, color, false, poolInfo.m_poolName); + auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY, textSize, color, false, "%s", poolInfo.m_poolName); // Current Used (bytes) BytesToString(poolInfo.m_memoryUsed, buffer, bufferSize); - auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY, textSize, color, false, buffer); + auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY, textSize, color, false, "%s", buffer); // Peak Used (bytes) BytesToString(poolInfo.m_peakUsed, buffer, bufferSize); - auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY, textSize, color, false, buffer); + auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY, textSize, color, false, "%s", buffer); // % of Used (percent) auxGeom.Draw2dLabel(fPosX + xTablePositions[4], posY, textSize, color, false, "%.1f %%", percentUsed); @@ -2255,20 +2245,20 @@ namespace Audio whiteColor.StoreToFloat4(color); posY += (2.f * lineHeight); - auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY, textSize, color, false, tableHeaderNames[1]); - auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY + lineHeight, textSize, color, false, globalInfo.m_poolName); + auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY, textSize, color, false, "Name"); + auxGeom.Draw2dLabel(fPosX + xTablePositions[1], posY + lineHeight, textSize, color, false, "%s", globalInfo.m_poolName); auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY, textSize, color, false, "Total Used"); BytesToString(globalInfo.m_memoryUsed, buffer, bufferSize); - auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY + lineHeight, textSize, color, false, buffer); + auxGeom.Draw2dLabel(fPosX + xTablePositions[2], posY + lineHeight, textSize, color, false, "%s", buffer); auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY, textSize, color, false, "Total Peak"); BytesToString(totalPeak, buffer, bufferSize); - auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY + lineHeight, textSize, color, false, buffer); + auxGeom.Draw2dLabel(fPosX + xTablePositions[3], posY + lineHeight, textSize, color, false, "%s", buffer); auxGeom.Draw2dLabel(fPosX + xTablePositions[4], posY, textSize, color, false, "Total Size"); BytesToString(globalInfo.m_memoryReserved, buffer, bufferSize); - auxGeom.Draw2dLabel(fPosX + xTablePositions[4], posY + lineHeight, textSize, color, false, buffer); + auxGeom.Draw2dLabel(fPosX + xTablePositions[4], posY + lineHeight, textSize, color, false, "%s", buffer); auxGeom.Draw2dLabel(fPosX + xTablePositions[5], posY, textSize, color, false, "Total Allocs"); auxGeom.Draw2dLabel(fPosX + xTablePositions[5], posY + lineHeight, textSize, color, false, "%" PRIu64, totalAllocs); diff --git a/Gems/AudioSystem/Code/Source/Engine/FileCacheManager.cpp b/Gems/AudioSystem/Code/Source/Engine/FileCacheManager.cpp index b106c4f9d2..b7ed9229d8 100644 --- a/Gems/AudioSystem/Code/Source/Engine/FileCacheManager.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/FileCacheManager.cpp @@ -446,13 +446,13 @@ namespace Audio } // Format: "relative/path/filename.ext (230 KiB) [2]" - AZStd::string displayString = AZStd::string::format("%s (%zu %s) [%zu]", + auxGeom.Draw2dLabel(positionX, positionY, entryDrawSize, color, false, + "%s (%zu %s) [%zu]", audioFileEntry->m_filePath.c_str(), fileSize, kiloBytes ? "KiB" : "Bytes", audioFileEntry->m_useCount); - auxGeom.Draw2dLabel(positionX, positionY, entryDrawSize, color, false, displayString.c_str()); color[3] = originalAlpha; positionY += entryStepSize; } diff --git a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYEntityOutliner.cpp b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYEntityOutliner.cpp index 7f4877347f..2df6c9984b 100644 --- a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYEntityOutliner.cpp +++ b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYEntityOutliner.cpp @@ -84,99 +84,99 @@ namespace ImGui ImGui::Columns(3); ImGui::TextColored(m_displayName.m_color, "Display Name"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayNameCB", &m_displayName.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayNameCol", reinterpret_cast(&m_displayName.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayChildCount.m_color, "Display Child Count"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayChildCountCB", &m_displayChildCount.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayChildCountCol", reinterpret_cast(&m_displayChildCount.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayDescentdantCount.m_color, "Display Descendant Count"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayDescendantCountCB", &m_displayDescentdantCount.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayDescendantCountCol", reinterpret_cast(&m_displayDescentdantCount.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayEntityState.m_color, "Display Entity Status"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayEntityStateCB", &m_displayEntityState.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayEntityStateCol", reinterpret_cast(&m_displayEntityState.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayParentInfo.m_color, "Display Parent Info"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayParentInfoCB", &m_displayParentInfo.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayParentInfoCol", reinterpret_cast(&m_displayParentInfo.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayLocalPos.m_color, "Display Local Position"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayLocalPosCB", &m_displayLocalPos.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayLocalPosCol", reinterpret_cast(&m_displayLocalPos.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayLocalRotation.m_color, "Display Local Rotation"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayLocalRotationCB", &m_displayLocalRotation.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayLocalRotationCol", reinterpret_cast(&m_displayLocalRotation.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayWorldPos.m_color, "Display World Position"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayWorldPosCB", &m_displayWorldPos.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayWorldPosCol", reinterpret_cast(&m_displayWorldPos.m_color)); ImGui::NextColumn(); ImGui::TextColored(m_displayWorldRotation.m_color, "Display World Rotation"); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_OnText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_OnText); ImGui::SameLine(); ImGui::Checkbox("##DisplayWorldRotationCB", &m_displayWorldRotation.m_enabled); ImGui::NextColumn(); - ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, s_ColorText); + ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "%s", s_ColorText); ImGui::SameLine(); ImGui::ColorEdit4("##DisplayWorldRotationCol", reinterpret_cast(&m_displayWorldRotation.m_color)); @@ -508,7 +508,7 @@ namespace ImGui } else if (sameLine) { - if (ImGui::TreeNode(childTreeNodeStr.c_str(), childTreeNodeStr.c_str())) + if (ImGui::TreeNode(childTreeNodeStr.c_str(), "%s", childTreeNodeStr.c_str())) { ImGuiUpdate_RecursivelyDisplayEntityInfoAndDecendants_DrawDisplayOptions(node, drawInspectButton, drawTargetButton, drawDebugButton, sameLine, drawComponents); @@ -528,7 +528,7 @@ namespace ImGui { ImGuiUpdate_RecursivelyDisplayEntityInfoAndDecendants_DrawDisplayOptions(node, drawInspectButton, drawTargetButton, drawDebugButton, sameLine, drawComponents); childTreeNodeStr = AZStd::string::format("Children ##%s", childTreeNodeStr.c_str()); - if (ImGui::TreeNode(childTreeNodeStr.c_str(), childTreeNodeStr.c_str())) + if (ImGui::TreeNode(childTreeNodeStr.c_str(), "%s", childTreeNodeStr.c_str())) { for (int i = 0; i < node->m_children.size(); i++) { @@ -542,7 +542,7 @@ namespace ImGui else if (!justDrawChildren) { ImGui::TextColored(ImGui::Colors::s_PlainLabelColor, "->"); ImGui::SameLine(); - ImGui::Text(childTreeNodeStr.c_str()); + ImGui::Text("%s", childTreeNodeStr.c_str()); ImGuiUpdate_RecursivelyDisplayEntityInfoAndDecendants_DrawDisplayOptions(node, drawInspectButton, drawTargetButton, drawDebugButton, sameLine, drawComponents); } } @@ -561,7 +561,7 @@ namespace ImGui { ImGui::SameLine(); } - ImGui::TextColored(m_displayName.m_color, entityName.c_str()); + ImGui::TextColored(m_displayName.m_color, "%s", entityName.c_str()); } // Draw EntityViewer Button @@ -762,7 +762,7 @@ namespace ImGui { // Draw collapsible menu for the components set AZStd::string uiLabel = AZStd::string::format("Components##%s", node->m_entityId.ToString().c_str()); - if (ImGui::TreeNode(uiLabel.c_str(), uiLabel.c_str())) + if (ImGui::TreeNode(uiLabel.c_str(), "%s", uiLabel.c_str())) { AZ::Entity::ComponentArrayType components = entity->GetComponents(); // we should sort our array of components based on their names. @@ -781,7 +781,7 @@ namespace ImGui bool hasDebug = ComponentHasDebug(component->RTTI_GetType()); // Draw a collapsible menu for each component uiLabel = AZStd::string::format("%s##%s", component->RTTI_GetTypeName(), node->m_entityId.ToString().c_str()); - if (ImGui::TreeNode(uiLabel.c_str(), uiLabel.c_str())) + if (ImGui::TreeNode(uiLabel.c_str(), "%s", uiLabel.c_str())) { if (hasDebug) { @@ -795,7 +795,7 @@ namespace ImGui // Draw a collapsible menu for all Reflected Properties uiLabel = AZStd::string::format("Reflected Properties##%s", node->m_entityId.ToString().c_str()); - if (ImGui::TreeNode(uiLabel.c_str(), uiLabel.c_str())) + if (ImGui::TreeNode(uiLabel.c_str(), "%s", uiLabel.c_str())) { AZ::SerializeContext *serializeContext = nullptr; AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); @@ -820,7 +820,7 @@ namespace ImGui if (hasDebug) { uiLabel = AZStd::string::format("Debug##%s", node->m_entityId.ToString().c_str()); - if (ImGui::TreeNode(uiLabel.c_str(), uiLabel.c_str())) + if (ImGui::TreeNode(uiLabel.c_str(), "%s", uiLabel.c_str())) { // Attempt to draw any debug information for this component ImGuiUpdateDebugComponentListenerBus::Event(ImGuiEntComponentId(node->m_entityId, component->RTTI_GetType()) diff --git a/Gems/LyShine/Code/Source/Animation/AzEntityNode.cpp b/Gems/LyShine/Code/Source/Animation/AzEntityNode.cpp index cc4e70e010..2b31726d3e 100644 --- a/Gems/LyShine/Code/Source/Animation/AzEntityNode.cpp +++ b/Gems/LyShine/Code/Source/Animation/AzEntityNode.cpp @@ -256,20 +256,12 @@ const AZ::SerializeContext::ClassElement* CUiAnimAzEntityNode::ComputeOffsetFrom if (mismatch) { - AZStd::string warnMsg = "Data mismatch reading animation data for type "; - warnMsg += classData->m_typeId.ToString(); - warnMsg += ". The field \""; - warnMsg += paramData.GetName(); - if (!element) - { - warnMsg += "\" cannot be found."; - } - else - { - warnMsg += "\" has a different type to that in the animation data."; - } - warnMsg += " This part of the animation data will be ignored."; - CryWarning(VALIDATOR_MODULE_SHINE, VALIDATOR_WARNING, warnMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SHINE, VALIDATOR_WARNING, + "Data mismatch reading animation data for type %s. The field \"%s\" %s. This part of the animation data will be ignored.", + classData->m_typeId.ToString().c_str(), + paramData.GetName(), + (!element ? "cannot be found" : "has a different type to that in the animation data") + ); return nullptr; } } diff --git a/Gems/LyShine/Code/Source/UiInteractableState.cpp b/Gems/LyShine/Code/Source/UiInteractableState.cpp index e81c48a43a..6027ecf3d7 100644 --- a/Gems/LyShine/Code/Source/UiInteractableState.cpp +++ b/Gems/LyShine/Code/Source/UiInteractableState.cpp @@ -575,10 +575,7 @@ void UiInteractableStateFont::SetFontPathname(const AZStd::string& pathname) fontFamily = gEnv->pCryFont->LoadFontFamily(fileName.c_str()); if (!fontFamily) { - AZStd::string errorMsg = "Error loading a font from "; - errorMsg += fileName.c_str(); - errorMsg += "."; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, errorMsg.c_str()); + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "Error loading a font from %s.", fileName.c_str()); } } From 51fe681dbd81030756b0b60763b2a05d4969eb5e Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 3 Sep 2021 15:21:32 -0700 Subject: [PATCH 05/16] address PR comments Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/Plugins/FFMPEGPlugin/main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp index 847d426922..fed0ec8678 100644 --- a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp +++ b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp @@ -24,9 +24,7 @@ PLUGIN_API IPlugin* CreatePluginInstance(PLUGIN_INIT_PARAM* pInitParam) // Make sure the ffmpeg command can be executed before registering the command if (!CFFMPEGPlugin::RuntimeTest()) { - GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmepg. Please run Setup Assistant, " - "go to the 'Optional software' section of the 'Install software' tab, " - "and make sure the FFmpeg executable is correctly configured."); + GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmepg. Please install FFmepg."); } else { From b28349be7368ad310e5a7ff7a44769e8a579e376 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Fri, 3 Sep 2021 15:36:48 -0700 Subject: [PATCH 06/16] Fixes for Android Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../AzCore/Platform/Android/AzCore/Debug/Trace_Android.cpp | 2 +- Code/LauncherUnified/Platform/Android/Launcher_Android.cpp | 2 +- Code/Tools/AzTestRunner/Platform/Android/platform_android.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Trace_Android.cpp b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Trace_Android.cpp index 07a132d2b9..5bd68b3ed6 100644 --- a/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Trace_Android.cpp +++ b/Code/Framework/AzCore/Platform/Android/AzCore/Debug/Trace_Android.cpp @@ -18,7 +18,7 @@ namespace AZ { void OutputToDebugger([[maybe_unused]] const char* window, [[maybe_unused]] const char* message) { - __android_log_print(ANDROID_LOG_INFO, window, message); + __android_log_print(ANDROID_LOG_INFO, window, "%s", message); } } } diff --git a/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp b/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp index f158426184..de548a49d7 100644 --- a/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp +++ b/Code/LauncherUnified/Platform/Android/Launcher_Android.cpp @@ -426,7 +426,7 @@ void android_main(android_app* appState) if (status != ReturnCode::Success) { - MAIN_EXIT_FAILURE(appState, GetReturnCodeString(status)); + MAIN_EXIT_FAILURE(appState, "%s", GetReturnCodeString(status)); } } diff --git a/Code/Tools/AzTestRunner/Platform/Android/platform_android.cpp b/Code/Tools/AzTestRunner/Platform/Android/platform_android.cpp index 9e0ea304ef..a1bcc1ec5f 100644 --- a/Code/Tools/AzTestRunner/Platform/Android/platform_android.cpp +++ b/Code/Tools/AzTestRunner/Platform/Android/platform_android.cpp @@ -278,7 +278,7 @@ static void *thread_logger_func(void*) --readSize; } logBuffer[readSize] = '\0'; - ((void) __android_log_print(ANDROID_LOG_INFO, s_logTag, logBuffer)); + ((void) __android_log_print(ANDROID_LOG_INFO, s_logTag, "%s", logBuffer)); } } return 0; From d1df0fbe477d298a9085d9fa1107d9347cf2d7d3 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 7 Sep 2021 08:17:06 -0700 Subject: [PATCH 07/16] reverting one that was changed by mistake Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../Source/RetainedModeActionDispatcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp b/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp index 8f82bb09b1..34ae4aaf4a 100644 --- a/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp +++ b/Code/Framework/AzManipulatorTestFramework/Source/RetainedModeActionDispatcher.cpp @@ -117,7 +117,7 @@ namespace AzManipulatorTestFramework RetainedModeActionDispatcher* RetainedModeActionDispatcher::Execute() { - Log("%s", "Executing %u actions", m_actions.size()); + Log("Executing %u actions", m_actions.size()); for (auto& action : m_actions) { action(); From 4d5b047c1b31eb57c37078feffa5ab77beec3365 Mon Sep 17 00:00:00 2001 From: moudgils <47460854+moudgils@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:03:11 -0700 Subject: [PATCH 08/16] Fix PipelineLibraries (DX12 backend). (#3768) * Fix loading of PipelineLibraries from disk for DX12 backend. Signed-off-by: moudgils * Disabled Saving out PipelineLibraries (for DX12) if pix or Renderdoc is enabled. Addressed some feedback Signed-off-by: moudgils * Fixed an issue withe loading PipelineLibraries and added a cleaner abstraction to not save empty libraries for dx12 Signed-off-by: moudgils --- .../Code/Include/Atom/RHI/PipelineLibrary.h | 78 +++++++++---------- .../RHI/Code/Source/RHI/PipelineLibrary.cpp | 5 ++ .../Code/Source/RHI/PipelineStateCache.cpp | 34 ++++---- .../Platform/Windows/RHI/DX12_Windows.h | 4 +- .../DX12/Code/Source/RHI/PipelineLibrary.cpp | 28 +++++-- .../DX12/Code/Source/RHI/PipelineLibrary.h | 1 + .../Code/Source/RHI/AsyncUploadQueue.cpp | 2 +- .../Include/Atom/RPI.Public/Shader/Shader.h | 8 +- .../Code/Source/RPI.Public/Shader/Shader.cpp | 76 +++++++++--------- 9 files changed, 130 insertions(+), 106 deletions(-) diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/PipelineLibrary.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/PipelineLibrary.h index 0c5cfd1182..3a49b121cd 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/PipelineLibrary.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/PipelineLibrary.h @@ -19,25 +19,24 @@ namespace AZ /// A handle typed to the pipeline library. Used by the PipelineStateCache to abstract access. using PipelineLibraryHandle = Handle; - /** - * PipelineState initialization is an expensive operation on certain platforms. If multiple pipeline states - * are created with little variation between them, the contents are still duplicated. This class is an allocation - * context for pipeline states, provided at PipelineState::Init, which will perform de-duplication of - * internal pipeline state components and cache the results. - * - * Practically speaking, if many pipeline states are created with shared data between them (e.g. permutations - * of the same shader), then providing a PipelineLibrary instance will reduce the memory footprint and cost - * of compilation. - * - * Additionally, the PipelineLibrary is able to serialize the internal driver-contents to and from an opaque - * data blob. This enables building up a pipeline state cache on disk, which can dramatically reduce pipeline - * state compilation cost when run from a pre-warmed cache. - * - * PipelineLibrary is thread-safe, in the sense that it will take a lock during compilation. It is possible - * to initialize pipeline states across threads using the same PipelineLibrary instance, but this will - * result in the two calls serializing on the mutex. Instead, see PipelineStateCache which stores - * a PipelineLibrary instance per thread to avoid this contention. - */ + + //! PipelineState initialization is an expensive operation on certain platforms. If multiple pipeline states + //! are created with little variation between them, the contents are still duplicated. This class is an allocation + //! context for pipeline states, provided at PipelineState::Init, which will perform de-duplication of + //! internal pipeline state components and cache the results. + //! + //! Practically speaking, if many pipeline states are created with shared data between them (e.g. permutations + //! of the same shader), then providing a PipelineLibrary instance will reduce the memory footprint and cost + //! of compilation. + //! + //! Additionally, the PipelineLibrary is able to serialize the internal driver-contents to and from an opaque + //! data blob. This enables building up a pipeline state cache on disk, which can dramatically reduce pipeline + //! state compilation cost when run from a pre-warmed cache. + //! + //! PipelineLibrary is thread-safe, in the sense that it will take a lock during compilation. It is possible + //! to initialize pipeline states across threads using the same PipelineLibrary instance, but this will + //! result in the two calls serializing on the mutex. Instead, see PipelineStateCache which stores + //! a PipelineLibrary instance per thread to avoid this contention. class PipelineLibrary : public DeviceObject { @@ -45,34 +44,31 @@ namespace AZ AZ_RTTI(PipelineLibrary, "{843579BE-57E4-4527-AB00-C0217885AEA9}"); virtual ~PipelineLibrary() = default; - /** - * Initializes the pipeline library from a platform-specific data payload. This data is generated - * by calling GetSerializedData in a previous run of the application. When run for the first - * time, the serialized data should be empty. When the application completes, the library can be - * serialized and the contents saved to disk. Subsequent loads will experience much faster pipeline - * state creation times (on supported platforms). On success, the library is transitioned to the - * initialized state. On failure, the library remains uninitialized. - * @param serializedData The initial serialized data used to initialize the library. It can be null. - */ + //! Initializes the pipeline library from a platform-specific data payload. This data is generated + //! by calling GetSerializedData in a previous run of the application. When run for the first + //! time, the serialized data should be empty. When the application completes, the library can be + //! serialized and the contents saved to disk. Subsequent loads will experience much faster pipeline + //! state creation times (on supported platforms). On success, the library is transitioned to the + //! initialized state. On failure, the library remains uninitialized. + //! @param serializedData The initial serialized data used to initialize the library. It can be null. ResultCode Init(Device& device, const PipelineLibraryData* serializedData); - /** - * Merges the contents of other libraries into this library. This method must be called - * on an initialized library. A common use case for this method is to construct thread-local - * libraries and merge them into a single unified library. The serialized data can then be - * extracted from the unified library. An error code is returned on failure and the behavior - * is as if the method was never called. - */ + //! Merges the contents of other libraries into this library. This method must be called + //! on an initialized library. A common use case for this method is to construct thread-local + //! libraries and merge them into a single unified library. The serialized data can then be + //! extracted from the unified library. An error code is returned on failure and the behavior + //! is as if the method was never called. ResultCode MergeInto(AZStd::array_view librariesToMerge); - /** - * Serializes the platform-specific data and returns it as a new PipelineLibraryData instance. - * The data is opaque to the user and can only be used to re-initialize the library. Use - * this method to extract serialized data prior to application shutdown, save it to disk, and - * use it when initializing on subsequent runs. - */ + //! Serializes the platform-specific data and returns it as a new PipelineLibraryData instance. + //! The data is opaque to the user and can only be used to re-initialize the library. Use + //! this method to extract serialized data prior to application shutdown, save it to disk, and + //! use it when initializing on subsequent runs. ConstPtr GetSerializedData() const; + //! Returns whether the current library need to be merged + virtual bool IsMergeRequired() const; + private: bool ValidateIsInitialized() const; diff --git a/Gems/Atom/RHI/Code/Source/RHI/PipelineLibrary.cpp b/Gems/Atom/RHI/Code/Source/RHI/PipelineLibrary.cpp index 2212ae1591..be0428bc91 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/PipelineLibrary.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/PipelineLibrary.cpp @@ -72,5 +72,10 @@ namespace AZ return GetSerializedDataInternal(); } + + bool PipelineLibrary::IsMergeRequired() const + { + return true; + } } } diff --git a/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp b/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp index 52093f7b4c..a2a2736106 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/PipelineStateCache.cpp @@ -166,16 +166,12 @@ namespace AZ } AZStd::unique_lock lock(m_mutex); - const GlobalLibraryEntry& entry = m_globalLibrarySet[handle.GetIndex()]; - /** - * Each thread has its own PipelineLibrary instance. To produce the final serialized data, we - * coalesce data from each individual library by merging the thread-local ones into a single - * global (temporary) library. The data is then extracted from this global library and returned. - * This operation is designed to happen once at application shutdown; certainly not every frame. - */ - + //! Each thread has its own PipelineLibrary instance. To produce the final serialized data, we + //! coalesce data from each individual library by merging the thread-local ones into a single + //! global (temporary) library. The data is then extracted from this global library and returned. + //! This operation is designed to happen once at application shutdown; certainly not every frame. AZStd::vector threadLibraries; m_threadLibrarySet.ForEach([handle, &threadLibraries](const ThreadLibrarySet& threadLibrarySet) { @@ -188,16 +184,26 @@ namespace AZ } }); - Ptr pipelineLibrary = Factory::Get().CreatePipelineLibrary(); - ResultCode resultCode = pipelineLibrary->Init(*m_device, entry.m_serializedData.get()); - - if (resultCode == ResultCode::Success) + bool doesPSODataExist = entry.m_serializedData.get(); + for (const RHI::PipelineLibrary* libraryBase : threadLibraries) { - resultCode = pipelineLibrary->MergeInto(threadLibraries); + const PipelineLibrary* library = static_cast(libraryBase); + doesPSODataExist |= library->IsMergeRequired(); + } + + if (doesPSODataExist) + { + Ptr pipelineLibrary = Factory::Get().CreatePipelineLibrary(); + ResultCode resultCode = pipelineLibrary->Init(*m_device, entry.m_serializedData.get()); if (resultCode == ResultCode::Success) { - return pipelineLibrary->GetSerializedData(); + resultCode = pipelineLibrary->MergeInto(threadLibraries); + + if (resultCode == ResultCode::Success) + { + return pipelineLibrary->GetSerializedData(); + } } } diff --git a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/DX12_Windows.h b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/DX12_Windows.h index b07b9e9e58..3f9079422c 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/DX12_Windows.h +++ b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/DX12_Windows.h @@ -20,8 +20,8 @@ #include -// This define is enabled if winpixeventruntime SDK is downloaded and it's path is hooked up to Environment var ATOM_PIX_PATH. -// Enabling this define will allow the runtime code to add PIX markers which will hel pwith pix and renderdoc gpu captures +// This define is enabled if LY_PIX_ENABLED is enabled during configure. You can use LY_PIX_PATH to point where pix is downloaded. +// Enabling this define will allow the runtime code to add PIX markers which will help with pix and renderdoc gpu captures #ifdef USE_PIX #include #else diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.cpp index 06a0511162..d0a9ef0c07 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.cpp @@ -66,15 +66,20 @@ namespace AZ switch (hr) { case D3D12_ERROR_DRIVER_VERSION_MISMATCH: - case DXGI_ERROR_UNSUPPORTED: AZ_Warning("PipelineLibrary", false, "Failed to use pipeline library blob due to driver version mismatch. Contents will be rebuilt."); break; + case DXGI_ERROR_UNSUPPORTED: + AZ_Warning("PipelineLibrary", false, "Failed to use pipeline library blob due to the specified device interface or feature level not supported on this system. Contents will be rebuilt."); + break; case D3D12_ERROR_ADAPTER_NOT_FOUND: AZ_Warning("PipelineLibrary", false, "Failed to use pipeline library blob due to mismatched hardware. Contents will be rebuilt."); break; case E_INVALIDARG: AZ_Assert(false, "Failed to use pipeline library blob due to invalid arguments. Contents will be rebuilt."); break; + case DXGI_ERROR_DEVICE_REMOVED: + AZ_Assert(false, "Failed to use pipeline library blob due to DXGI_ERROR_DEVICE_REMOVED."); + break; default: AZ_Warning("PipelineLibrary", false, "Failed to use pipeline library blob for unknown reason. Contents will be rebuilt."); } @@ -200,23 +205,29 @@ namespace AZ RHI::ResultCode PipelineLibrary::MergeIntoInternal([[maybe_unused]] AZStd::array_view pipelineLibraries) { +#if defined(USE_PIX) || defined(USE_RENDERDOC) + // StorePipeline api does not function properly if Pix or RenderDoc is enabled + return RHI::ResultCode::Fail; +#else + #if defined (AZ_DX12_USE_PIPELINE_LIBRARY) AZStd::lock_guard lock(m_mutex); - for (const RHI::PipelineLibrary* libraryBase : pipelineLibraries) { const PipelineLibrary* library = static_cast(libraryBase); - for (const auto& pipelineStateEntry : library->m_pipelineStates) { - m_library->StorePipeline(pipelineStateEntry.first.c_str(), pipelineStateEntry.second.get()); + if (m_pipelineStates.find(pipelineStateEntry.first) == m_pipelineStates.end()) + { + m_library->StorePipeline(pipelineStateEntry.first.c_str(), pipelineStateEntry.second.get()); - m_pipelineStates.emplace(pipelineStateEntry.first, pipelineStateEntry.second); + m_pipelineStates.emplace(pipelineStateEntry.first, pipelineStateEntry.second); + } } } #endif - return RHI::ResultCode::Success; +#endif } RHI::ConstPtr PipelineLibrary::GetSerializedDataInternal() const @@ -238,5 +249,10 @@ namespace AZ return nullptr; #endif } + + bool PipelineLibrary::IsMergeRequired() const + { + return !m_pipelineStates.empty(); + } } } diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.h b/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.h index d43abe4cb1..b970882246 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.h +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/PipelineLibrary.h @@ -35,6 +35,7 @@ namespace AZ void ShutdownInternal() override; RHI::ResultCode MergeIntoInternal(AZStd::array_view libraries) override; RHI::ConstPtr GetSerializedDataInternal() const override; + bool IsMergeRequired() const; ////////////////////////////////////////////////////////////////////////// ID3D12DeviceX* m_dx12Device = nullptr; diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/AsyncUploadQueue.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/AsyncUploadQueue.cpp index 47cde358ba..7a8499ab9d 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/AsyncUploadQueue.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/AsyncUploadQueue.cpp @@ -210,7 +210,7 @@ namespace AZ // ImageHeight must be bigger than or equal to the Image's row count. Images with a RowCount that is less than the ImageHeight indicates a block compression. // Images with a RowCount which is higher than the ImageHeight indicates a planar image, which is not supported for streaming images. - AZ_Error("StreamingImage", subresourceLayout.m_size.m_height < subresourceLayout.m_rowCount, "AsyncUploadQueue::QueueUpload expects ImageHeight '%d' to be bigger than or equal to the image's RowCount '%d'.", subresourceLayout.m_size.m_height, subresourceLayout.m_rowCount); + AZ_Error("StreamingImage", subresourceLayout.m_size.m_height >= subresourceLayout.m_rowCount, "AsyncUploadQueue::QueueUpload expects ImageHeight '%d' to be bigger than or equal to the image's RowCount '%d'.", subresourceLayout.m_size.m_height, subresourceLayout.m_rowCount); // The final staging size for each CopyTextureRegion command uint32_t stagingSize = stagingSlicePitch; diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h index 6684eec0f7..e2568f3b61 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Shader/Shader.h @@ -18,7 +18,7 @@ #include #include - +#include #include namespace AZ @@ -175,9 +175,6 @@ namespace AZ // And of course we don't need to handle OnShaderReinitialized because this *is* this Shader. /////////////////////////////////////////////////////////////////// - //! Returns the path to the pipeline library cache file. - AZStd::string GetPipelineLibraryPath() const; - //! A strong reference to the shader asset. Data::Asset m_asset; @@ -206,6 +203,9 @@ namespace AZ //! DrawListTag associated with this shader. RHI::DrawListTag m_drawListTag; + + //! PipelineLibrary file name + char m_pipelineLibraryPath[AZ_MAX_PATH_LEN] = { 0 }; }; } } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp index 4440b96f79..e602e3e91b 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Shader/Shader.cpp @@ -7,18 +7,14 @@ */ #include -#include - -#include - -#include #include - +#include +#include #include - -#include -#include #include +#include +#include + namespace AZ { @@ -75,6 +71,29 @@ namespace AZ Shutdown(); } + static bool GetPipelineLibraryPath(char* pipelineLibraryPath, size_t pipelineLibraryPathLength, const ShaderAsset& shaderAsset) + { + if (auto* fileIOBase = IO::FileIOBase::GetInstance()) + { + const Data::AssetId& assetId = shaderAsset.GetId(); + + Name platformName = RHI::Factory::Get().GetName(); + Name shaderName = shaderAsset.GetName(); + + AZStd::string uuidString; + assetId.m_guid.ToString(uuidString, false, false); + + char pipelineLibraryPathTemp[AZ_MAX_PATH_LEN]; + azsnprintf( + pipelineLibraryPathTemp, AZ_MAX_PATH_LEN, "@user@/Atom/PipelineStateCache/%s/%s_%s_%d.bin", platformName.GetCStr(), + shaderName.GetCStr(), uuidString.data(), assetId.m_subId); + + fileIOBase->ResolvePath(pipelineLibraryPathTemp, pipelineLibraryPath, pipelineLibraryPathLength); + return true; + } + return false; + } + RHI::ResultCode Shader::Init(ShaderAsset& shaderAsset) { Data::AssetBus::Handler::BusDisconnect(); @@ -87,6 +106,8 @@ namespace AZ m_asset = { &shaderAsset, AZ::Data::AssetLoadBehavior::PreLoad }; m_pipelineStateType = shaderAsset.GetPipelineStateType(); + GetPipelineLibraryPath(m_pipelineLibraryPath, AZ_MAX_PATH_LEN, *m_asset); + { AZStd::unique_lock lock(m_variantCacheMutex); m_shaderVariants.clear(); @@ -123,7 +144,7 @@ namespace AZ AZ_Error("Shader", false, "Failed to acquire a DrawListTag. Entries are full."); } } - + ShaderVariantFinderNotificationBus::Handler::BusConnect(m_asset.GetId()); Data::AssetBus::Handler::BusConnect(m_asset.GetId()); ShaderReloadNotificationBus::Handler::BusConnect(m_asset.GetId()); @@ -249,49 +270,28 @@ namespace AZ } } /////////////////////////////////////////////////////////////////// - - + ConstPtr Shader::LoadPipelineLibrary() const - { - if (IO::FileIOBase::GetInstance()) + { + if (m_pipelineLibraryPath[0] != 0) { - return Utils::LoadObjectFromFile(GetPipelineLibraryPath()); + return Utils::LoadObjectFromFile(m_pipelineLibraryPath); } return nullptr; } void Shader::SavePipelineLibrary() const { - if (auto* fileIOBase = IO::FileIOBase::GetInstance()) + if (m_pipelineLibraryPath[0] != 0) { RHI::ConstPtr serializedData = m_pipelineStateCache->GetLibrarySerializedData(m_pipelineLibraryHandle); if (serializedData) { - const AZStd::string pipelineLibraryPath = GetPipelineLibraryPath(); - - char pipelineLibraryPathResolved[AZ_MAX_PATH_LEN] = { 0 }; - fileIOBase->ResolvePath(pipelineLibraryPath.c_str(), pipelineLibraryPathResolved, AZ_MAX_PATH_LEN); - Utils::SaveObjectToFile(pipelineLibraryPathResolved, DataStream::ST_BINARY, serializedData.get()); + Utils::SaveObjectToFile(m_pipelineLibraryPath, DataStream::ST_BINARY, serializedData.get()); } } - else - { - AZ_Error("Shader", false, "FileIOBase is not initialized"); - } } - - AZStd::string Shader::GetPipelineLibraryPath() const - { - const Data::InstanceId& instanceId = GetId(); - Name platformName = RHI::Factory::Get().GetName(); - Name shaderName = m_asset->GetName(); - - AZStd::string uuidString; - instanceId.m_guid.ToString(uuidString, false, false); - - return AZStd::string::format("@user@/Atom/PipelineStateCache/%s/%s_%s_%d.bin", platformName.GetCStr(), shaderName.GetCStr(), uuidString.data(), instanceId.m_subId); - } - + ShaderOptionGroup Shader::CreateShaderOptionGroup() const { return ShaderOptionGroup(m_asset->GetShaderOptionGroupLayout()); From 1d98ab3a1c2c5e3009162132ee92937ad9312681 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:09:31 -0700 Subject: [PATCH 09/16] Fixes renderdoc define Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Gems/Atom/RHI/3rdParty/Findrenderdoc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/Atom/RHI/3rdParty/Findrenderdoc.cmake b/Gems/Atom/RHI/3rdParty/Findrenderdoc.cmake index 7b7c312169..f8f17392b3 100644 --- a/Gems/Atom/RHI/3rdParty/Findrenderdoc.cmake +++ b/Gems/Atom/RHI/3rdParty/Findrenderdoc.cmake @@ -11,5 +11,5 @@ ly_add_external_target( 3RDPARTY_ROOT_DIRECTORY "${LY_RENDERDOC_PATH}" VERSION INCLUDE_DIRECTORIES . - COMPILE_DEFINITIONS USE_RENDER_DOC + COMPILE_DEFINITIONS USE_RENDERDOC ) From 2a2847b15d205b0a7b2e599a70b2a24b3d59b1c2 Mon Sep 17 00:00:00 2001 From: Artur K <96597+nemerle@users.noreply.github.com> Date: Tue, 7 Sep 2021 20:14:16 +0200 Subject: [PATCH 10/16] Legacy code cleanup - part 3 (#3903) * Legacy cleanup - part 3 Not much is left that can be easily removed, so I think this will be last cleanup before the legacy functionality is replaced. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * fix windows build, remove a few more things, re-add one file Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove legacy RenderBus + more cleanups Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove MaterialOwnerBus.h Clean-up in Cry_Matrix34/33 Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> --- Code/Editor/Controls/ConsoleSCB.cpp | 10 +- Code/Editor/CryEditDoc.cpp | 10 - Code/Editor/CryEditDoc.h | 2 - Code/Editor/ErrorReport.cpp | 54 - Code/Editor/ErrorReport.h | 5 - Code/Editor/GameEngine.cpp | 5 - Code/Editor/GameExporter.h | 8 +- Code/Editor/IEditor.h | 1 - Code/Editor/IEditorImpl.cpp | 12 - Code/Editor/IEditorImpl.h | 1 - Code/Editor/IconManager.cpp | 5 +- Code/Editor/Include/Command.h | 13 +- Code/Editor/Include/IEditorMaterial.h | 2 +- Code/Editor/Include/IEditorMaterialManager.h | 2 +- Code/Editor/Include/IErrorReport.h | 15 +- Code/Editor/Include/IObjectManager.h | 1 - Code/Editor/Lib/Tests/IEditorMock.h | 1 - Code/Editor/Objects/BaseObject.cpp | 4 +- Code/Editor/Objects/ObjectManager.cpp | 11 - Code/Editor/Objects/ObjectManager.h | 1 - .../Objects/ComponentEntityObject.cpp | 1 - Code/Editor/Undo/Undo.cpp | 36 - Code/Editor/Undo/Undo.h | 19 +- Code/Editor/Util/EditorUtils.h | 3 - Code/Editor/Util/KDTree.h | 2 +- Code/Legacy/CryCommon/BaseTypes.h | 5 - Code/Legacy/CryCommon/BitFiddling.h | 543 ------ Code/Legacy/CryCommon/Common_TypeInfo.cpp | 21 - Code/Legacy/CryCommon/CryCrc32.h | 210 -- Code/Legacy/CryCommon/CryEndian.h | 75 - Code/Legacy/CryCommon/CryFile.h | 163 -- Code/Legacy/CryCommon/CryHalf.inl | 7 - Code/Legacy/CryCommon/CryListenerSet.h | 10 +- Code/Legacy/CryCommon/CryPodArray.h | 212 --- Code/Legacy/CryCommon/CrySizer.h | 563 ------ Code/Legacy/CryCommon/Cry_Camera.h | 1689 +---------------- Code/Legacy/CryCommon/Cry_Color.h | 779 -------- Code/Legacy/CryCommon/Cry_Geo.h | 797 +------- Code/Legacy/CryCommon/Cry_HWMatrix.h | 85 - Code/Legacy/CryCommon/Cry_HWVector3.h | 278 --- Code/Legacy/CryCommon/Cry_Math.h | 188 +- Code/Legacy/CryCommon/Cry_Matrix33.h | 277 +-- Code/Legacy/CryCommon/Cry_Matrix34.h | 511 +---- Code/Legacy/CryCommon/Cry_Matrix44.h | 16 +- Code/Legacy/CryCommon/Cry_Quat.h | 1136 ----------- Code/Legacy/CryCommon/Cry_Vector2.h | 8 - Code/Legacy/CryCommon/Cry_Vector3.h | 47 +- Code/Legacy/CryCommon/Cry_Vector4.h | 150 +- Code/Legacy/CryCommon/FunctorBaseFunction.h | 93 - Code/Legacy/CryCommon/FunctorBaseMember.h | 97 - Code/Legacy/CryCommon/IConsole.h | 30 +- Code/Legacy/CryCommon/IEntityRenderState.h | 25 +- Code/Legacy/CryCommon/IFont.h | 8 - Code/Legacy/CryCommon/IIndexedMesh.h | 50 - Code/Legacy/CryCommon/ILevelSystem.h | 9 - Code/Legacy/CryCommon/ILocalizationManager.h | 4 - Code/Legacy/CryCommon/ILog.h | 7 - Code/Legacy/CryCommon/IMaterial.h | 6 - Code/Legacy/CryCommon/IMovieSystem.h | 47 - Code/Legacy/CryCommon/IPathfinder.h | 1 + Code/Legacy/CryCommon/IReadWriteXMLSink.h | 105 - Code/Legacy/CryCommon/IRenderAuxGeom.h | 252 +-- Code/Legacy/CryCommon/IRenderer.h | 29 - Code/Legacy/CryCommon/ISerialize.h | 805 +------- Code/Legacy/CryCommon/IShader.h | 5 - Code/Legacy/CryCommon/ISplines.h | 4 +- Code/Legacy/CryCommon/IStatObj.h | 500 +---- Code/Legacy/CryCommon/ISurfaceType.h | 244 --- Code/Legacy/CryCommon/ISystem.h | 42 +- Code/Legacy/CryCommon/ITexture.h | 71 - Code/Legacy/CryCommon/IValidator.h | 54 +- Code/Legacy/CryCommon/IXml.h | 79 +- Code/Legacy/CryCommon/Linux_Win32Wrapper.h | 1 - .../Legacy/CryCommon/LocalizationManagerBus.h | 1 - .../CryCommon/LyShine/Bus/UiTransform2dBus.h | 8 +- Code/Legacy/CryCommon/MTPseudoRandom.cpp | 75 - Code/Legacy/CryCommon/MTPseudoRandom.h | 166 -- Code/Legacy/CryCommon/MathConversion.h | 29 - Code/Legacy/CryCommon/MetaUtils.h | 135 -- Code/Legacy/CryCommon/Mocks/ICVarMock.h | 5 +- Code/Legacy/CryCommon/Mocks/IConsoleMock.h | 3 - Code/Legacy/CryCommon/Mocks/ILogMock.h | 2 - .../Legacy/CryCommon/MultiThread_Containers.h | 30 - Code/Legacy/CryCommon/Random.h | 35 - Code/Legacy/CryCommon/RenderBus.h | 111 -- Code/Legacy/CryCommon/SFunctor.h | 112 -- Code/Legacy/CryCommon/SerializationTypes.h | 3 - Code/Legacy/CryCommon/SerializeFwd.h | 8 - Code/Legacy/CryCommon/SimpleSerialize.h | 148 +- Code/Legacy/CryCommon/StatObjBus.h | 39 +- Code/Legacy/CryCommon/Synchronization.h | 45 - Code/Legacy/CryCommon/TimeValue.h | 4 - Code/Legacy/CryCommon/VertexFormats.h | 420 +--- Code/Legacy/CryCommon/WinBase.cpp | 15 - Code/Legacy/CryCommon/crycommon_files.cmake | 15 - Code/Legacy/CryCommon/platform_impl.cpp | 67 - Code/Legacy/CrySystem/CrySystem_precompiled.h | 1 - Code/Legacy/CrySystem/Huffman.h | 18 - .../CrySystem/LevelSystem/LevelSystem.cpp | 14 - .../CrySystem/LevelSystem/LevelSystem.h | 4 - .../CrySystem/LocalizedStringManager.cpp | 20 - .../Legacy/CrySystem/LocalizedStringManager.h | 44 - Code/Legacy/CrySystem/Log.h | 19 +- Code/Legacy/CrySystem/System.cpp | 4 - Code/Legacy/CrySystem/System.h | 80 +- Code/Legacy/CrySystem/SystemCFG.cpp | 121 +- Code/Legacy/CrySystem/SystemCFG.h | 44 - Code/Legacy/CrySystem/SystemInit.cpp | 3 - Code/Legacy/CrySystem/ViewSystem/View.cpp | 14 - Code/Legacy/CrySystem/ViewSystem/View.h | 4 - .../CrySystem/ViewSystem/ViewSystem.cpp | 18 - Code/Legacy/CrySystem/ViewSystem/ViewSystem.h | 2 - Code/Legacy/CrySystem/XConsole.cpp | 94 +- Code/Legacy/CrySystem/XConsole.h | 142 +- Code/Legacy/CrySystem/XConsoleVariable.cpp | 844 ++++---- Code/Legacy/CrySystem/XConsoleVariable.h | 652 +------ Code/Legacy/CrySystem/XML/ReadWriteXMLSink.h | 43 - Code/Legacy/CrySystem/XML/ReadXMLSink.cpp | 683 ------- .../CrySystem/XML/SerializeXMLReader.cpp | 46 - .../Legacy/CrySystem/XML/SerializeXMLReader.h | 29 +- .../CrySystem/XML/SerializeXMLWriter.cpp | 17 - .../Legacy/CrySystem/XML/SerializeXMLWriter.h | 16 +- Code/Legacy/CrySystem/XML/WriteXMLSource.cpp | 432 ----- Code/Legacy/CrySystem/XML/XMLBinaryNode.cpp | 47 +- Code/Legacy/CrySystem/XML/XMLBinaryNode.h | 9 - Code/Legacy/CrySystem/XML/XMLBinaryWriter.cpp | 54 +- Code/Legacy/CrySystem/XML/XMLBinaryWriter.h | 2 +- Code/Legacy/CrySystem/XML/XMLPatcher.cpp | 423 ----- Code/Legacy/CrySystem/XML/XMLPatcher.h | 81 - Code/Legacy/CrySystem/XML/XmlUtils.cpp | 226 +-- Code/Legacy/CrySystem/XML/XmlUtils.h | 43 +- Code/Legacy/CrySystem/XML/xml.cpp | 142 +- Code/Legacy/CrySystem/XML/xml.h | 12 - Code/Legacy/CrySystem/XML/xml_string.h | 17 - Code/Legacy/CrySystem/crysystem_files.cmake | 7 - .../AtomLyIntegration/AtomFont/AtomFont.h | 1 - .../AtomLyIntegration/AtomFont/AtomNullFont.h | 3 - .../AtomLyIntegration/AtomFont/FBitmap.h | 2 - .../AtomLyIntegration/AtomFont/FFont.h | 24 +- .../AtomLyIntegration/AtomFont/FontRenderer.h | 2 - .../AtomLyIntegration/AtomFont/FontTexture.h | 4 - .../AtomLyIntegration/AtomFont/GlyphBitmap.h | 4 - .../AtomLyIntegration/AtomFont/GlyphCache.h | 4 - Gems/Blast/Code/Source/Family/DamageManager.h | 2 + .../LYCommonMenu/ImGuiLYAssetExplorer.cpp | 1 - .../LmbrCentral/Rendering/MaterialHandle.h | 28 +- .../LmbrCentral/Rendering/MaterialOwnerBus.h | 134 -- .../include/LmbrCentral/Rendering/MeshAsset.h | 2 +- Gems/LmbrCentral/Code/lmbrcentral_files.cmake | 1 - .../Tests/internal/test_UiTextComponent.cpp | 44 +- Gems/LyShine/Code/Source/UiTextComponent.cpp | 88 +- .../LyShineExamples/UiCustomImageBus.h | 8 +- .../Cinematics/CharacterTrackAnimator.h | 7 +- .../Code/Source/Cinematics/MaterialNode.cpp | 30 +- .../Code/Source/Cinematics/MaterialNode.h | 2 +- Gems/Maestro/Code/Source/Cinematics/Movie.cpp | 10 +- Gems/Maestro/Code/Source/Cinematics/Movie.h | 3 - .../Code/Source/Cinematics/SoundTrack.h | 23 +- .../Components/EditorSystemComponent.cpp | 1 - .../ScriptEventsLegacyDefinitions.h | 26 +- Gems/Vegetation/Code/Tests/VegetationMocks.h | 7 - 161 files changed, 894 insertions(+), 16076 deletions(-) delete mode 100644 Code/Legacy/CryCommon/BitFiddling.h delete mode 100644 Code/Legacy/CryCommon/Common_TypeInfo.cpp delete mode 100644 Code/Legacy/CryCommon/CryCrc32.h delete mode 100644 Code/Legacy/CryCommon/CryPodArray.h delete mode 100644 Code/Legacy/CryCommon/CrySizer.h delete mode 100644 Code/Legacy/CryCommon/Cry_HWMatrix.h delete mode 100644 Code/Legacy/CryCommon/Cry_HWVector3.h delete mode 100644 Code/Legacy/CryCommon/FunctorBaseFunction.h delete mode 100644 Code/Legacy/CryCommon/FunctorBaseMember.h delete mode 100644 Code/Legacy/CryCommon/IReadWriteXMLSink.h delete mode 100644 Code/Legacy/CryCommon/ISurfaceType.h delete mode 100644 Code/Legacy/CryCommon/MTPseudoRandom.cpp delete mode 100644 Code/Legacy/CryCommon/MTPseudoRandom.h delete mode 100644 Code/Legacy/CryCommon/MetaUtils.h delete mode 100644 Code/Legacy/CryCommon/RenderBus.h delete mode 100644 Code/Legacy/CryCommon/SFunctor.h delete mode 100644 Code/Legacy/CrySystem/SystemCFG.h delete mode 100644 Code/Legacy/CrySystem/XML/ReadWriteXMLSink.h delete mode 100644 Code/Legacy/CrySystem/XML/ReadXMLSink.cpp delete mode 100644 Code/Legacy/CrySystem/XML/WriteXMLSource.cpp delete mode 100644 Code/Legacy/CrySystem/XML/XMLPatcher.cpp delete mode 100644 Code/Legacy/CrySystem/XML/XMLPatcher.h delete mode 100644 Code/Legacy/CrySystem/XML/xml_string.h delete mode 100644 Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialOwnerBus.h diff --git a/Code/Editor/Controls/ConsoleSCB.cpp b/Code/Editor/Controls/ConsoleSCB.cpp index 4997fa4bec..51d6f8e2e1 100644 --- a/Code/Editor/Controls/ConsoleSCB.cpp +++ b/Code/Editor/Controls/ConsoleSCB.cpp @@ -26,9 +26,6 @@ #include #include -// CryCommon -#include - // Editor #include "QtViewPaneManager.h" #include "Core/QtEditorApplication.h" @@ -392,7 +389,7 @@ void CConsoleSCB::RegisterViewClass() opts.showInMenu = true; opts.builtInActionId = ID_VIEW_CONSOLEWINDOW; opts.shortcut = QKeySequence(Qt::Key_QuoteLeft); - + AzToolsFramework::RegisterViewPane(LyViewPane::Console, LyViewPane::CategoryTools, opts); } @@ -606,8 +603,7 @@ static CVarBlock* VarBlockFromConsoleVars() // Add our on change handler so we can update the CVariable created for // the matching ICVar that has been modified - SFunctor onChange; - onChange.Set(OnVariableUpdated, i, pCVar); + AZStd::function onChange = [row=i,pCVar=pCVar]() { OnVariableUpdated(row,pCVar); }; pCVar->AddOnChangeFunctor(onChange); pVariable->SetDescription(pCVar->GetHelp()); @@ -929,7 +925,7 @@ QWidget* ConsoleVariableItemDelegate::createEditor(QWidget* parent, const QStyle return editor; } } - + // If we get here, value being edited is a string, so use our styled line // edit widget AzQtComponents::StyledLineEdit* lineEdit = new AzQtComponents::StyledLineEdit(parent); diff --git a/Code/Editor/CryEditDoc.cpp b/Code/Editor/CryEditDoc.cpp index 9a7e7cc846..ec9a00d1ac 100644 --- a/Code/Editor/CryEditDoc.cpp +++ b/Code/Editor/CryEditDoc.cpp @@ -1887,16 +1887,6 @@ void CCryEditDoc::SetDocumentReady(bool bReady) m_bDocumentReady = bReady; } -void CCryEditDoc::GetMemoryUsage(ICrySizer* pSizer) const -{ - { - SIZER_COMPONENT_NAME(pSizer, "UndoManager(estimate)"); - GetIEditor()->GetUndoManager()->GetMemoryUsage(pSizer); - } - - pSizer->Add(*this); -} - void CCryEditDoc::RegisterConsoleVariables() { doc_validate_surface_types = gEnv->pConsole->GetCVar("doc_validate_surface_types"); diff --git a/Code/Editor/CryEditDoc.h b/Code/Editor/CryEditDoc.h index a96e9428b6..9c4c4b3fd9 100644 --- a/Code/Editor/CryEditDoc.h +++ b/Code/Editor/CryEditDoc.h @@ -129,8 +129,6 @@ public: // Create from serialization only void RegisterListener(IDocListener* listener); void UnregisterListener(IDocListener* listener); - void GetMemoryUsage(ICrySizer* pSizer) const; - static bool IsBackupOrTempLevelSubdirectory(const QString& folderName); protected: diff --git a/Code/Editor/ErrorReport.cpp b/Code/Editor/ErrorReport.cpp index 7914511fbe..4fd7d41a96 100644 --- a/Code/Editor/ErrorReport.cpp +++ b/Code/Editor/ErrorReport.cpp @@ -249,60 +249,6 @@ void CErrorReport::SetImmediateMode(bool bEnable) } } -////////////////////////////////////////////////////////////////////////// -void CErrorReport::Report(SValidatorRecord& record) -{ - if ((record.flags & VALIDATOR_FLAG_IGNORE_IN_EDITOR)) - { - return; - } - - CErrorRecord err; - if (record.text) - { - err.error = record.text; - } - if (record.description) - { - err.description = record.description; - } - if (record.file) - { - err.file = record.file; - } - else - { - err.file = m_currentFilename; - } - err.severity = (CErrorRecord::ESeverity)record.severity; - - err.assetScope = record.assetScope; - - err.flags = 0; - if (record.flags & VALIDATOR_FLAG_FILE) - { - err.flags |= CErrorRecord::FLAG_NOFILE; - } - if (record.flags & VALIDATOR_FLAG_TEXTURE) - { - err.flags |= CErrorRecord::FLAG_TEXTURE; - } - if (record.flags & VALIDATOR_FLAG_SCRIPT) - { - err.flags |= CErrorRecord::FLAG_SCRIPT; - } - if (record.flags & VALIDATOR_FLAG_AI) - { - err.flags |= CErrorRecord::FLAG_AI; - } - - err.module = record.module; - err.pObject = m_pObject; - err.pItem = m_pItem; - - ReportError(err); -} - ////////////////////////////////////////////////////////////////////////// void CErrorReport::SetCurrentValidatorObject(CBaseObject* pObject) { diff --git a/Code/Editor/ErrorReport.h b/Code/Editor/ErrorReport.h index 2bef4105f8..3b9a860301 100644 --- a/Code/Editor/ErrorReport.h +++ b/Code/Editor/ErrorReport.h @@ -121,11 +121,6 @@ public: //! Assign current filename. void SetCurrentFile(const QString& file); - ////////////////////////////////////////////////////////////////////////// - // Implement IValidator interface. - ////////////////////////////////////////////////////////////////////////// - virtual void Report(SValidatorRecord& record); - private: //! Array of all error records added to report. std::vector m_errors; diff --git a/Code/Editor/GameEngine.cpp b/Code/Editor/GameEngine.cpp index 4b463efe0a..5f3545e593 100644 --- a/Code/Editor/GameEngine.cpp +++ b/Code/Editor/GameEngine.cpp @@ -176,11 +176,6 @@ struct SSystemUserCallback return CryMessageBox(text, caption, uType); } - void GetMemoryUsage(ICrySizer* pSizer) override - { - GetIEditor()->GetMemoryUsage(pSizer); - } - void OnSplashScreenDone() { m_pLogo = nullptr; diff --git a/Code/Editor/GameExporter.h b/Code/Editor/GameExporter.h index 19ec601ff7..ee4e8df3d9 100644 --- a/Code/Editor/GameExporter.h +++ b/Code/Editor/GameExporter.h @@ -5,10 +5,6 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - - -#ifndef CRYINCLUDE_EDITOR_GAMEEXPORTER_H -#define CRYINCLUDE_EDITOR_GAMEEXPORTER_H #pragma once #include "Util/PakFile.h" @@ -62,7 +58,7 @@ public: // In auto exporting mode, highest possible settings will be chosen and no UI dialogs will be shown. void SetAutoExportMode(bool bAuto) { m_bAutoExportMode = bAuto; } - bool Export(unsigned int flags = 0, EEndian eExportEndian = GetPlatformEndian(), const char* subdirectory = 0); + bool Export(unsigned int flags = 0, EEndian eExportEndian = eEndianness_Little, const char* subdirectory = 0); static CGameExporter* GetCurrentExporter() { return m_pCurrentExporter; } @@ -116,5 +112,3 @@ void SetupTerrainInfo(const size_t octreeCompiledDataSize, Func&& setupTerrainFn setupTerrainFn(octreeCompiledDataSize); } } - -#endif // CRYINCLUDE_EDITOR_GAMEEXPORTER_H diff --git a/Code/Editor/IEditor.h b/Code/Editor/IEditor.h index de7b0ec3f9..7c49819d83 100644 --- a/Code/Editor/IEditor.h +++ b/Code/Editor/IEditor.h @@ -701,7 +701,6 @@ struct IEditor virtual CUIEnumsDatabase* GetUIEnumsDatabase() = 0; virtual void AddUIEnums() = 0; - virtual void GetMemoryUsage(ICrySizer* pSizer) = 0; virtual void ReduceMemory() = 0; //! Export manager for exporting objects and a terrain from the game to DCC tools diff --git a/Code/Editor/IEditorImpl.cpp b/Code/Editor/IEditorImpl.cpp index c7e6cd8ad6..51ef0dedc3 100644 --- a/Code/Editor/IEditorImpl.cpp +++ b/Code/Editor/IEditorImpl.cpp @@ -1506,18 +1506,6 @@ void CEditorImpl::ShowStatusText(bool bEnable) m_bShowStatusText = bEnable; } -void CEditorImpl::GetMemoryUsage(ICrySizer* pSizer) -{ - SIZER_COMPONENT_NAME(pSizer, "Editor"); - - if (GetDocument()) - { - SIZER_COMPONENT_NAME(pSizer, "Document"); - - GetDocument()->GetMemoryUsage(pSizer); - } -} - void CEditorImpl::ReduceMemory() { GetIEditor()->GetUndoManager()->ClearRedoStack(); diff --git a/Code/Editor/IEditorImpl.h b/Code/Editor/IEditorImpl.h index 2cf6c7805b..762dd1db11 100644 --- a/Code/Editor/IEditorImpl.h +++ b/Code/Editor/IEditorImpl.h @@ -280,7 +280,6 @@ public: void SetMatEditMode(bool bIsMatEditMode); CUIEnumsDatabase* GetUIEnumsDatabase() { return m_pUIEnumsDatabase; }; void AddUIEnums(); - void GetMemoryUsage(ICrySizer* pSizer); void ReduceMemory(); // Get Export manager IExportManager* GetExportManager(); diff --git a/Code/Editor/IconManager.cpp b/Code/Editor/IconManager.cpp index 7732ae8155..820213bbd9 100644 --- a/Code/Editor/IconManager.cpp +++ b/Code/Editor/IconManager.cpp @@ -64,10 +64,7 @@ void CIconManager::Reset() int i; for (i = 0; i < sizeof(m_objects) / sizeof(m_objects[0]); i++) { - if (m_objects[i]) - { - m_objects[i]->Release(); - } + delete m_objects[i]; m_objects[i] = nullptr; } for (i = 0; i < eIcon_COUNT; i++) diff --git a/Code/Editor/Include/Command.h b/Code/Editor/Include/Command.h index dfdcec78ef..b3b0641c9d 100644 --- a/Code/Editor/Include/Command.h +++ b/Code/Editor/Include/Command.h @@ -24,16 +24,15 @@ inline AZStd::string ToString(const QString& s) class CCommand { - static inline bool FromString(int32 &val, const char* s) { - if(!s) + static inline bool FromString(int32& val, const char* s) + { + if (!s) { return false; } - val = (int)strtol(s, nullptr, 10); - if(val==0 && errno!=0) { - return false; - } - return true; + val = static_cast(strtol(s, nullptr, 10)); + const bool parsing_error = val == 0 && errno != 0; + return !parsing_error; } public: CCommand( diff --git a/Code/Editor/Include/IEditorMaterial.h b/Code/Editor/Include/IEditorMaterial.h index 487246eb60..329b0ae53f 100644 --- a/Code/Editor/Include/IEditorMaterial.h +++ b/Code/Editor/Include/IEditorMaterial.h @@ -15,6 +15,6 @@ struct IEditorMaterial : public CBaseLibraryItem { virtual int GetFlags() const = 0; - virtual _smart_ptr GetMatInfo(bool bUseExistingEngineMaterial = false) = 0; + virtual IMaterial* GetMatInfo(bool bUseExistingEngineMaterial = false) = 0; virtual void DisableHighlightForFrame() = 0; }; diff --git a/Code/Editor/Include/IEditorMaterialManager.h b/Code/Editor/Include/IEditorMaterialManager.h index 92e68085c1..d76ec32829 100644 --- a/Code/Editor/Include/IEditorMaterialManager.h +++ b/Code/Editor/Include/IEditorMaterialManager.h @@ -19,7 +19,7 @@ struct IEditorMaterialManager { - virtual void GotoMaterial(_smart_ptr pMaterial) = 0; + virtual void GotoMaterial(IMaterial* pMaterial) = 0; }; #endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H diff --git a/Code/Editor/Include/IErrorReport.h b/Code/Editor/Include/IErrorReport.h index a516633f25..7bf00d6973 100644 --- a/Code/Editor/Include/IErrorReport.h +++ b/Code/Editor/Include/IErrorReport.h @@ -9,23 +9,18 @@ // Description : Class that collects error reports to present them later. - -#ifndef CRYINCLUDE_EDITOR_INTERFACE_ERRORREPORT_H -#define CRYINCLUDE_EDITOR_INTERFACE_ERRORREPORT_H #pragma once -#include - // forward declarations. class CParticleItem; class CBaseObject; class CBaseLibraryItem; class CErrorRecord; +class QString; /*! Error report manages collection of errors occurred during map analyzes or level load. */ struct IErrorReport - : public IValidator { virtual ~IErrorReport(){} @@ -62,12 +57,4 @@ struct IErrorReport //! Assign current filename. virtual void SetCurrentFile(const QString& file) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Implement IValidator interface. - ////////////////////////////////////////////////////////////////////////// - virtual void Report(SValidatorRecord& record) = 0; }; - - -#endif // CRYINCLUDE_EDITOR_ERRORREPORT_H diff --git a/Code/Editor/Include/IObjectManager.h b/Code/Editor/Include/IObjectManager.h index fb99a50bb0..0a7bc8dcca 100644 --- a/Code/Editor/Include/IObjectManager.h +++ b/Code/Editor/Include/IObjectManager.h @@ -89,7 +89,6 @@ public: //! Get array of objects, managed by manager (not contain sub objects of groups). //! @param layer if 0 get objects for all layers, or layer to get objects from. virtual void GetObjects(CBaseObjectsArray& objects) const = 0; - //virtual void GetObjects(DynArray& objects) const = 0; //! Get array of objects that pass the filter. //! @param filter The filter functor, return true if you want to get the certain obj, return false if want to skip it. diff --git a/Code/Editor/Lib/Tests/IEditorMock.h b/Code/Editor/Lib/Tests/IEditorMock.h index 30f1d23576..cb01757b9c 100644 --- a/Code/Editor/Lib/Tests/IEditorMock.h +++ b/Code/Editor/Lib/Tests/IEditorMock.h @@ -170,7 +170,6 @@ public: MOCK_METHOD0(IsSourceControlConnected, bool()); MOCK_METHOD0(GetUIEnumsDatabase, CUIEnumsDatabase* ()); MOCK_METHOD0(AddUIEnums, void()); - MOCK_METHOD1(GetMemoryUsage, void(ICrySizer* )); MOCK_METHOD0(ReduceMemory, void()); MOCK_METHOD0(GetExportManager, IExportManager* ()); MOCK_METHOD2(SetEditorConfigSpec, void(ESystemConfigSpec , ESystemConfigPlatform )); diff --git a/Code/Editor/Objects/BaseObject.cpp b/Code/Editor/Objects/BaseObject.cpp index 0d5f982bd4..14291a3e4d 100644 --- a/Code/Editor/Objects/BaseObject.cpp +++ b/Code/Editor/Objects/BaseObject.cpp @@ -2735,7 +2735,7 @@ bool CBaseObject::IntersectRayMesh(const Vec3& raySrc, const Vec3& rayDir, SRayH return false; } - Matrix34A worldTM; + Matrix34 worldTM; IStatObj* pStatObj = pRenderNode->GetEntityStatObj(0, 0, &worldTM); if (!pStatObj) { @@ -2743,7 +2743,7 @@ bool CBaseObject::IntersectRayMesh(const Vec3& raySrc, const Vec3& rayDir, SRayH } // transform decal into object space - Matrix34A worldTM_Inverted = worldTM.GetInverted(); + Matrix34 worldTM_Inverted = worldTM.GetInverted(); Matrix33 worldRot(worldTM_Inverted); worldRot.Transpose(); // put hit direction into the object space diff --git a/Code/Editor/Objects/ObjectManager.cpp b/Code/Editor/Objects/ObjectManager.cpp index 30ee1fc57b..8330c4aad7 100644 --- a/Code/Editor/Objects/ObjectManager.cpp +++ b/Code/Editor/Objects/ObjectManager.cpp @@ -759,17 +759,6 @@ void CObjectManager::GetObjects(CBaseObjectsArray& objects) const } } -//void CObjectManager::GetObjects(DynArray& objects) const -//{ -// CBaseObjectsArray objectArray; -// GetObjects(objectArray); -// objects.clear(); -// for (size_t i = 0, iCount(objectArray.size()); i < iCount; ++i) -// { -// objects.push_back(objectArray[i]); -// } -//} - void CObjectManager::GetObjects(CBaseObjectsArray& objects, BaseObjectFilterFunctor const& filter) const { objects.clear(); diff --git a/Code/Editor/Objects/ObjectManager.h b/Code/Editor/Objects/ObjectManager.h index a2e0822a2b..de0a4ce849 100644 --- a/Code/Editor/Objects/ObjectManager.h +++ b/Code/Editor/Objects/ObjectManager.h @@ -122,7 +122,6 @@ public: //! Get array of objects, managed by manager (not contain sub objects of groups). //! @param layer if 0 get objects for all layers, or layer to get objects from. void GetObjects(CBaseObjectsArray& objects) const; - //void GetObjects(DynArray& objects) const; //! Get array of objects that pass the filter. //! @param filter The filter functor, return true if you want to get the certain obj, return false if want to skip it. diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp b/Code/Editor/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp index 29ced334ef..8957b6ced6 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/Code/Editor/Undo/Undo.cpp b/Code/Editor/Undo/Undo.cpp index 910a670bee..603f651ee0 100644 --- a/Code/Editor/Undo/Undo.cpp +++ b/Code/Editor/Undo/Undo.cpp @@ -62,17 +62,6 @@ public: } } - // to get memory statistics - void GetMemoryUsage(ICrySizer* pSizer) - { - for (int i = 0; i < m_undoSteps.size(); i++) - { - m_undoSteps[i]->GetMemoryUsage(pSizer); - } - - pSizer->Add(*this); - } - private: //! Undo steps included in this step. std::vector m_undoSteps; @@ -746,31 +735,6 @@ int CUndoManager::GetMaxUndoStep() const return GetIEditor()->GetEditorSettings()->undoLevels; } -void CUndoManager::GetMemoryUsage(ICrySizer* pSizer) -{ - if (m_currentUndo) - { - m_currentUndo->GetMemoryUsage(pSizer); - } - - if (m_superUndo) - { - m_superUndo->GetMemoryUsage(pSizer); - } - - for (std::list::const_iterator it = m_undoStack.begin(); it != m_undoStack.end(); it++) - { - (*it)->GetMemoryUsage(pSizer); - } - - for (std::list::const_iterator it = m_redoStack.begin(); it != m_redoStack.end(); it++) - { - (*it)->GetMemoryUsage(pSizer); - } - - pSizer->Add(*this); -} - void CUndoManager::AddListener(IUndoManagerListener* pListener) { stl::push_back_unique(m_listeners, pListener); diff --git a/Code/Editor/Undo/Undo.h b/Code/Editor/Undo/Undo.h index b9d8132a40..f4ee045919 100644 --- a/Code/Editor/Undo/Undo.h +++ b/Code/Editor/Undo/Undo.h @@ -12,9 +12,9 @@ #pragma once #include "IUndoManagerListener.h" -#include "CrySizer.h" // ICrySizer #include "IUndoObject.h" #include +#include struct IUndoObject; class CSuperUndoStep; @@ -79,20 +79,6 @@ public: } } - // to get memory statistics - void GetMemoryUsage(ICrySizer* pSizer) - { - size_t nThisSize = sizeof(*this); - - for (int i = 0; i < m_undoObjects.size(); i++) - { - nThisSize += m_undoObjects[i]->GetSize(); - } - - pSizer->Add(m_name); - pSizer->Add(this, nThisSize); - } - // get undo object at index i IUndoObject* GetUndoObject(int i = 0) { @@ -241,9 +227,6 @@ public: void ClearUndoStack(int num); void ClearRedoStack(int num); - // to get memory statistics - void GetMemoryUsage(ICrySizer* pSizer); - void AddListener(IUndoManagerListener* pListener); void RemoveListener(IUndoManagerListener* pListener); diff --git a/Code/Editor/Util/EditorUtils.h b/Code/Editor/Util/EditorUtils.h index 5008cbcc5c..e950d75012 100644 --- a/Code/Editor/Util/EditorUtils.h +++ b/Code/Editor/Util/EditorUtils.h @@ -20,9 +20,6 @@ #include #include -//! Typedef for quaternion. -//typedef CryQuat Quat; - #include #include #include diff --git a/Code/Editor/Util/KDTree.h b/Code/Editor/Util/KDTree.h index c2ea086175..df25a9ded7 100644 --- a/Code/Editor/Util/KDTree.h +++ b/Code/Editor/Util/KDTree.h @@ -37,7 +37,7 @@ public: struct SStatObj { Matrix34 tm; - _smart_ptr pStatObj; + IStatObj* pStatObj; }; private: diff --git a/Code/Legacy/CryCommon/BaseTypes.h b/Code/Legacy/CryCommon/BaseTypes.h index 0c588184a5..6aac00e4e6 100644 --- a/Code/Legacy/CryCommon/BaseTypes.h +++ b/Code/Legacy/CryCommon/BaseTypes.h @@ -6,9 +6,6 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_BASETYPES_H -#define CRYINCLUDE_CRYCOMMON_BASETYPES_H #pragma once static_assert(sizeof(char) == 1); @@ -78,5 +75,3 @@ typedef float f32; typedef double f64; static_assert(sizeof(f32) == 4); static_assert(sizeof(f64) == 8); - -#endif // CRYINCLUDE_CRYCOMMON_BASETYPES_H diff --git a/Code/Legacy/CryCommon/BitFiddling.h b/Code/Legacy/CryCommon/BitFiddling.h deleted file mode 100644 index 36173c5e53..0000000000 --- a/Code/Legacy/CryCommon/BitFiddling.h +++ /dev/null @@ -1,543 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : various integer bit fiddling hacks - - -#pragma once - -#include - -// Section dictionary -#if defined(AZ_RESTRICTED_PLATFORM) -#define BITFIDDLING_H_SECTION_TRAITS 1 -#define BITFIDDLING_H_SECTION_INTEGERLOG2 2 -#endif - -// Traits -#if defined(AZ_RESTRICTED_PLATFORM) - #define AZ_RESTRICTED_SECTION BITFIDDLING_H_SECTION_TRAITS - #include AZ_RESTRICTED_FILE(BitFiddling_h) -#elif defined(LINUX) || defined(APPLE) -#define BITFIDDLING_H_TRAIT_HAS_COUNT_LEADING_ZEROS 1 -#endif - -#if BITFIDDLING_H_TRAIT_HAS_COUNT_LEADING_ZEROS -#define countLeadingZeros32(x) __builtin_clz(x) -#else // Windows implementation -ILINE uint32 countLeadingZeros32(uint32 x) -{ - DWORD result = 32 ^ 31; // assumes result is unmodified if _BitScanReverse returns 0 - _BitScanReverse(&result, x); - result ^= 31; // needed because the index is from LSB (whereas all other implementations are from MSB) - return result; -} -#endif - -inline uint32 circularShift(uint32 nbits, uint32 i) -{ - return (i << nbits) | (i >> (32 - nbits)); -} - -template -inline size_t countTrailingZeroes(T v) -{ - size_t n = 0; - - v = ~v & (v - 1); - while (v) - { - ++n; - v >>= 1; - } - - return n; -} - -// this function returns the integer logarithm of various numbers without branching -#define IL2VAL(mask, shift) \ - c |= ((x & mask) != 0) * shift; \ - x >>= ((x & mask) != 0) * shift - -template -inline bool IsPowerOfTwo(TInteger x) -{ - return (x & (x - 1)) == 0; -} - -inline uint32 NextPower2(uint32 n) -{ - n--; - n |= n >> 1; - n |= n >> 2; - n |= n >> 4; - n |= n >> 8; - n |= n >> 16; - n++; - return n; -} - -inline uint8 IntegerLog2(uint8 x) -{ - uint8 c = 0; - IL2VAL(0xf0, 4); - IL2VAL(0xc, 2); - IL2VAL(0x2, 1); - return c; -} -inline uint16 IntegerLog2(uint16 x) -{ - uint16 c = 0; - IL2VAL(0xff00, 8); - IL2VAL(0xf0, 4); - IL2VAL(0xc, 2); - IL2VAL(0x2, 1); - return c; -} - -inline uint32 IntegerLog2(uint32 x) -{ - return 31 - countLeadingZeros32(x); -} - -inline uint64 IntegerLog2(uint64 x) -{ - uint64 c = 0; - IL2VAL(0xffffffff00000000ull, 32); - IL2VAL(0xffff0000u, 16); - IL2VAL(0xff00, 8); - IL2VAL(0xf0, 4); - IL2VAL(0xc, 2); - IL2VAL(0x2, 1); - return c; -} - -#if defined(APPLE) || defined(LINUX) -inline unsigned long int IntegerLog2(unsigned long int x) -{ - #if defined(PLATFORM_64BIT) - return IntegerLog2((uint64)x); - #else - return IntegerLog2((uint32)x); - #endif -} -#endif -#undef IL2VAL - -#if defined(AZ_RESTRICTED_PLATFORM) - #define AZ_RESTRICTED_SECTION BITFIDDLING_H_SECTION_INTEGERLOG2 - #include AZ_RESTRICTED_FILE(BitFiddling_h) -#endif - -template -inline TInteger IntegerLog2_RoundUp(TInteger x) -{ - return 1 + IntegerLog2(x - 1); -} - -static ILINE uint8 BitIndex(uint8 v) -{ - uint32 vv = v; - return aznumeric_caster(31 - countLeadingZeros32(vv)); -} - -static ILINE uint8 BitIndex(uint16 v) -{ - uint32 vv = v; - return aznumeric_caster(31 - countLeadingZeros32(vv)); -} - -static ILINE uint8 BitIndex(uint32 v) -{ - return aznumeric_caster(31 - countLeadingZeros32(v)); -} - -static ILINE uint8 CountBits(uint8 v) -{ - uint8 c = v; - c = ((c >> 1) & 0x55) + (c & 0x55); - c = ((c >> 2) & 0x33) + (c & 0x33); - c = ((c >> 4) & 0x0f) + (c & 0x0f); - return c; -} - -static ILINE uint8 CountBits(uint16 v) -{ - return CountBits((uint8)(v & 0xff)) + - CountBits((uint8)((v >> 8) & 0xff)); -} - -static ILINE uint8 CountBits(uint32 v) -{ - return CountBits((uint8)(v & 0xff)) + - CountBits((uint8)((v >> 8) & 0xff)) + - CountBits((uint8)((v >> 16) & 0xff)) + - CountBits((uint8)((v >> 24) & 0xff)); -} - -// Branchless version of return v < 0 ? alt : v; -ILINE int32 Isel32(int32 v, int32 alt) -{ - return ((static_cast(v) >> 31) & alt) | ((static_cast(~v) >> 31) & v); -} - -// Character-to-bitfield mapping - -inline uint32 AlphaBit(char c) -{ - return c >= 'a' && c <= 'z' ? 1 << (c - 'z' + 31) : 0; -} - -inline uint64 AlphaBit64(char c) -{ - return (c >= 'a' && c <= 'z' ? 1U << (c - 'z' + 31) : 0) | - (c >= 'A' && c <= 'Z' ? 1LL << (c - 'Z' + 63) : 0); -} - -inline uint32 AlphaBits(uint32 wc) -{ - // Handle wide multi-char constants, can be evaluated at compile-time. - return AlphaBit((char)wc) - | AlphaBit((char)(wc >> 8)) - | AlphaBit((char)(wc >> 16)) - | AlphaBit((char)(wc >> 24)); -} - -inline uint32 AlphaBits(const char* s) -{ - // Handle string of any length. - uint32 n = 0; - while (*s) - { - n |= AlphaBit(*s++); - } - return n; -} - -inline uint64 AlphaBits64(const char* s) -{ - // Handle string of any length. - uint64 n = 0; - while (*s) - { - n |= AlphaBit64(*s++); - } - return n; -} - -// s should point to a buffer at least 65 chars long -inline void BitsAlpha64(uint64 n, char* s) -{ - for (int i = 0; n != 0; n >>= 1, i++) - { - if (n & 1) - { - *s++ = i < 32 ? static_cast(i + 'z' - 31) : static_cast(i + 'Z' - 63); - } - } - *s++ = '\0'; -} - - -// if hardware doesn't support 3Dc we can convert to DXT5 (different channels are used) -// with almost the same quality but the same memory requirements -inline void ConvertBlock3DcToDXT5(uint8 pDstBlock[16], const uint8 pSrcBlock[16]) -{ - assert(pDstBlock != pSrcBlock); // does not work in place - - // 4x4 block requires 8 bytes in DXT5 or 3DC - - // DXT5: 8 bit alpha0, 8 bit alpha1, 16*3 bit alpha lerp - // 16bit col0, 16 bit col1 (R5G6B5 low byte then high byte), 16*2 bit color lerp - - // 3DC: 8 bit x0, 8 bit x1, 16*3 bit x lerp - // 8 bit y0, 8 bit y1, 16*3 bit y lerp - - for (uint32 dwK = 0; dwK < 8; ++dwK) - { - pDstBlock[dwK] = pSrcBlock[dwK]; - } - for (uint32 dwK = 8; dwK < 16; ++dwK) - { - pDstBlock[dwK] = 0; - } - - // 6 bit green channel (highest bits) - // by using all 3 channels with a slight offset we can get more precision but then a dot product would be needed in PS - // because of bilinear filter we cannot just distribute bits to get perfect result - uint16 colDst0 = (((uint16)pSrcBlock[8] + 2) >> 2) << 5; - uint16 colDst1 = (((uint16)pSrcBlock[9] + 2) >> 2) << 5; - - bool bFlip = colDst0 <= colDst1; - - if (bFlip) - { - uint16 help = colDst0; - colDst0 = colDst1; - colDst1 = help; - } - - bool bEqual = colDst0 == colDst1; - - // distribute bytes by hand to not have problems with endianess - pDstBlock[8 + 0] = (uint8)colDst0; - pDstBlock[8 + 1] = (uint8)(colDst0 >> 8); - pDstBlock[8 + 2] = (uint8)colDst1; - pDstBlock[8 + 3] = (uint8)(colDst1 >> 8); - - uint16* pSrcBlock16 = (uint16*)(pSrcBlock + 10); - uint16* pDstBlock16 = (uint16*)(pDstBlock + 12); - - // distribute 16 3 bit values to 16 2 bit values (loosing LSB) - for (uint32 dwK = 0; dwK < 16; ++dwK) - { - uint32 dwBit0 = dwK * 3 + 0; - uint32 dwBit1 = dwK * 3 + 1; - uint32 dwBit2 = dwK * 3 + 2; - - uint8 hexDataIn = (((pSrcBlock16[(dwBit2 >> 4)] >> (dwBit2 & 0xf)) & 1) << 2) // get HSB - | (((pSrcBlock16[(dwBit1 >> 4)] >> (dwBit1 & 0xf)) & 1) << 1) - | ((pSrcBlock16[(dwBit0 >> 4)] >> (dwBit0 & 0xf)) & 1); // get LSB - - uint8 hexDataOut = 0; - - switch (hexDataIn) - { - case 0: - hexDataOut = 0; - break; // color 0 - case 1: - hexDataOut = 1; - break; // color 1 - - case 2: - hexDataOut = 0; - break; // mostly color 0 - case 3: - hexDataOut = 2; - break; - case 4: - hexDataOut = 2; - break; - case 5: - hexDataOut = 3; - break; - case 6: - hexDataOut = 3; - break; - case 7: - hexDataOut = 1; - break; // mostly color 1 - - default: - assert(0); - } - - if (bFlip) - { - if (hexDataOut < 2) - { - hexDataOut = 1 - hexDataOut; // 0<->1 - } - else - { - hexDataOut = 5 - hexDataOut; // 2<->3 - } - } - - if (bEqual) - { - if (hexDataOut == 3) - { - hexDataOut = 1; - } - } - - pDstBlock16[(dwK >> 3)] |= (hexDataOut << ((dwK & 0x7) << 1)); - } -} - - - - -// is a bit on in a new bit field, but off in an old bit field -static ILINE bool TurnedOnBit(unsigned bit, unsigned oldBits, unsigned newBits) -{ - return (newBits & bit) != 0 && (oldBits & bit) == 0; -} - - - - - - - -inline uint32 cellUtilCountLeadingZero(uint32 x) -{ - uint32 y; - uint32 n = 32; - - y = x >> 16; - if (y != 0) - { - n = n - 16; - x = y; - } - y = x >> 8; - if (y != 0) - { - n = n - 8; - x = y; - } - y = x >> 4; - if (y != 0) - { - n = n - 4; - x = y; - } - y = x >> 2; - if (y != 0) - { - n = n - 2; - x = y; - } - y = x >> 1; - if (y != 0) - { - return n - 2; - } - return n - x; -} - -inline uint32 cellUtilLog2(uint32 x) -{ - return 31 - cellUtilCountLeadingZero(x); -} - - - - -inline void convertSwizzle(uint8*& dst, const uint8*& src, - const uint32 SrcPitch, const uint32 depth, - const uint32 xpos, const uint32 ypos, - const uint32 SciX1, const uint32 SciY1, - const uint32 SciX2, const uint32 SciY2, - const uint32 level) -{ - if (level == 1) - { - switch (depth) - { - case 16: - if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2) - { - // *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos]; - // *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+1]; - // *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+2]; - // *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+3]; - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16))); - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 4))); - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 8))); - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 12))); - } - else - { - ((uint32*&)dst) += 4; - } - break; - case 8: - if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2) - { - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 8))); - *((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 8 + 4))); - } - else - { - ((uint32*&)dst) += 2; - } - break; - case 4: - if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2) - { - *((uint32*&)dst) = *((uint32*)(src + (ypos * SrcPitch + xpos * 4))); - } - dst += 4; - break; - case 3: - if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2) - { - *dst++ = src[ypos * SrcPitch + xpos * depth]; - *dst++ = src[ypos * SrcPitch + xpos * depth + 1]; - *dst++ = src[ypos * SrcPitch + xpos * depth + 2]; - } - else - { - dst += 3; - } - break; - case 1: - if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2) - { - *dst++ = src[ypos * SrcPitch + xpos * depth]; - } - else - { - dst++; - } - break; - default: - assert(0); - } - return; - } - else - { - convertSwizzle(dst, src, SrcPitch, depth, xpos, ypos, SciX1, SciY1, SciX2, SciY2, level - 1); - convertSwizzle(dst, src, SrcPitch, depth, xpos + (1U << (level - 2)), ypos, SciX1, SciY1, SciX2, SciY2, level - 1); - convertSwizzle(dst, src, SrcPitch, depth, xpos, ypos + (1U << (level - 2)), SciX1, SciY1, SciX2, SciY2, level - 1); - convertSwizzle(dst, src, SrcPitch, depth, xpos + (1U << (level - 2)), ypos + (1U << (level - 2)), SciX1, SciY1, SciX2, SciY2, level - 1); - } -} - - - - -inline void Linear2Swizzle(uint8* dst, - const uint8* src, - const uint32 SrcPitch, - const uint32 width, - const uint32 height, - const uint32 depth, - const uint32 SciX1, const uint32 SciY1, - const uint32 SciX2, const uint32 SciY2) -{ - src -= SciY1 * SrcPitch + SciX1 * depth; - if (width == height) - { - convertSwizzle(dst, src, SrcPitch, depth, 0, 0, SciX1, SciY1, SciX2, SciY2, cellUtilLog2(width) + 1); - } - else - if (width > height) - { - uint32 baseLevel = cellUtilLog2(width) - (cellUtilLog2(width) - cellUtilLog2(height)); - for (uint32 i = 0; i < (1UL << (cellUtilLog2(width) - cellUtilLog2(height))); i++) - { - convertSwizzle(dst, src, SrcPitch, depth, (1U << baseLevel) * i, 0, SciX1, SciY1, SciX2, SciY2, baseLevel + 1); - } - } - else - // if (width < height)//wtf - { - uint32 baseLevel = cellUtilLog2(height) - (cellUtilLog2(height) - cellUtilLog2(width)); - for (uint32 i = 0; i < (1UL << (cellUtilLog2(height) - cellUtilLog2(width))); i++) - { - convertSwizzle(dst, src, SrcPitch, depth, 0, (1U << baseLevel) * i, SciX1, SciY1, SciX2, SciY2, baseLevel + 1); - } - } -} diff --git a/Code/Legacy/CryCommon/Common_TypeInfo.cpp b/Code/Legacy/CryCommon/Common_TypeInfo.cpp deleted file mode 100644 index ccb28cbc3d..0000000000 --- a/Code/Legacy/CryCommon/Common_TypeInfo.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include "Cry_Geo.h" -#include "Cry_Color.h" -#include "Cry_Vector3.h" - -// Manually instantiate templates as needed here. -template struct Vec3_tpl; -template struct Vec4_tpl; -template struct Vec2_tpl; -template struct Ang3_tpl; -template struct Plane_tpl; -template struct Matrix33_tpl; -template struct Color_tpl; diff --git a/Code/Legacy/CryCommon/CryCrc32.h b/Code/Legacy/CryCommon/CryCrc32.h deleted file mode 100644 index 9584f84185..0000000000 --- a/Code/Legacy/CryCommon/CryCrc32.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#pragma once - -#include "BaseTypes.h" - -// CRC-32 -// -// Polynomial: -// 0x04C11DB7 -// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 -// -// Validation: -// CCrc32::Compute("123456789") == 0xCBF43926 -// -// Examples of using: -// -// printf("crc32: %08x\n", (unsigned)CCrc32::Compute(ptr, size)); -// -// CCrc32 crc; -// crc.Add(ptr0, size0); -// crc.Add(ptr1, size1); -// printf("crc32: %08x\n", (unsigned)crc.Get()); - -class CCrc32 -{ -public: - static uint32 Compute(const void* const pData, const size_t sizeInBytes) - { - CCrc32 c; - c.Add(pData, sizeInBytes); - return c.Get(); - } - - static uint32 Compute(const char* const szData) - { - CCrc32 c; - c.Add(szData); - return c.Get(); - } - - static uint32 ComputeLowercase(const char* const pData, const size_t sizeInBytes) - { - CCrc32 c; - c.AddLowercase(pData, sizeInBytes); - return c.Get(); - } - - static uint32 ComputeLowercase(const char* const szData) - { - CCrc32 c; - c.AddLowercase(szData); - return c.Get(); - } - - - CCrc32() - : m_crc(0xFFFFffff) - , m_pTable(GetTable()) - { - } - - CCrc32(unsigned int initializer) - : m_crc(initializer) - , m_pTable(GetTable()) - { - } - - void Reset() - { - m_crc = 0xFFFFffff; - } - - uint32 Get() const - { - return ~m_crc; - } - - unsigned int Add(const void* const pData, size_t sizeInBytes) - { - const uint8* p = (const uint8*)pData; - while (sizeInBytes--) - { - m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ (*p++)]; - } - return Get(); - } - - unsigned int Add(const char* szData) - { - while (*szData) - { - m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ uint8(*szData++)]; - } - return Get(); - } - -#if defined(CRY_TMP_ASCII_TO_LOWER) -# error CRY_TMP_ASCII_TO_LOWER already defined -#endif -#define CRY_TMP_ASCII_TO_LOWER(c) uint8(((c) <= 'Z' && (c) >= 'A') ? (c) + ('a' - 'A') : (c)) - - unsigned int AddLowercase(const char* pData, size_t sizeInBytes) - { - while (sizeInBytes--) - { - const uint8 c = *pData++; - m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ CRY_TMP_ASCII_TO_LOWER(c)]; - } - return Get(); - } - - unsigned int AddLowercase(const char* szData) - { - while (*szData) - { - const uint8 c = *szData++; - m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ CRY_TMP_ASCII_TO_LOWER(c)]; - } - return Get(); - } - -#undef CRY_TMP_ASCII_TO_LOWER - -private: - static const uint32* GetTable() - { - static const uint32 table[256] = - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, - 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, - 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, - 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, - 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, - 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, - 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, - 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, - 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, - 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, - 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, - 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, - 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, - 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, - 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, - 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, - 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, - 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, - 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, - 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, - 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, - 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, - 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, - 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, - 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, - 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, - 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, - 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, - 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, - 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, - 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, - 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, - 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D - }; - return &table[0]; - } - -private: - uint32 m_crc; - const uint32* const m_pTable; -}; - -// eof diff --git a/Code/Legacy/CryCommon/CryEndian.h b/Code/Legacy/CryCommon/CryEndian.h index 94fa8f7ea2..2f424c5ee2 100644 --- a/Code/Legacy/CryCommon/CryEndian.h +++ b/Code/Legacy/CryCommon/CryEndian.h @@ -6,9 +6,6 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_CRYENDIAN_H -#define CRYINCLUDE_CRYCOMMON_CRYENDIAN_H #pragma once #include @@ -68,18 +65,6 @@ enum EEndianness #endif }; - -// Legacy macros -#define GetPlatformEndian() false - -///////////////////////////////////////////////////////////////////////////////////// - -inline bool IsSystemLittleEndian() -{ - const int a = 1; - return 1 == *(const char*)&a; -} - ///////////////////////////////////////////////////////////////////////////////////// // SwapEndian function, using TypeInfo. @@ -233,63 +218,3 @@ inline void SwapEndian(T& t, bool bSwapEndian = eLittleEndian) SwapEndianBase(&t, 1); } } - -template -inline T SwapEndianValue(T t, bool bSwapEndian = eLittleEndian) -{ - if (bSwapEndian) - { - SwapEndianBase(&t, 1); - } - return t; -} - -//--------------------------------------------------------------------------- -// Object-oriented data extraction for endian-swapping reading. -template -inline T* StepData(D*& pData, size_t nCount, bool bSwapEndian) -{ - T* Elems = (T*)pData; - SwapEndian(Elems, nCount, bSwapEndian); - pData = (D*)((T*)pData + nCount); - return Elems; -} - -template -inline T* StepData(D*& pData, bool bSwapEndian) -{ - return StepData(pData, 1, bSwapEndian); -} - -template -inline void StepData(T*& Result, D*& pData, size_t nCount, bool bSwapEndian) -{ - Result = StepData(pData, nCount, bSwapEndian); -} - -template -inline void StepDataCopy(T* Dest, D*& pData, size_t nCount, bool bSwapEndian) -{ - memcpy(Dest, pData, nCount * sizeof(T)); - SwapEndian(Dest, nCount, bSwapEndian); - pData = (D*)((T*)pData + nCount); -} - -template -inline void StepDataWrite(D*& pDest, const T* aSrc, size_t nCount, bool bSwapEndian) -{ - memcpy(pDest, aSrc, nCount * sizeof(T)); - if (bSwapEndian) - { - SwapEndianBase((T*)pDest, nCount, true); - } - (T*&)pDest += nCount; -} - -template -inline void StepDataWrite(D*& pDest, const T& Src, bool bSwapEndian) -{ - StepDataWrite(pDest, &Src, 1, bSwapEndian); -} - -#endif // CRYINCLUDE_CRYCOMMON_CRYENDIAN_H diff --git a/Code/Legacy/CryCommon/CryFile.h b/Code/Legacy/CryCommon/CryFile.h index 0d2dac7c16..56d7097344 100644 --- a/Code/Legacy/CryCommon/CryFile.h +++ b/Code/Legacy/CryCommon/CryFile.h @@ -6,12 +6,7 @@ * */ - // Description : File wrapper. - - -#ifndef CRYINCLUDE_CRYCOMMON_CRYFILE_H -#define CRYINCLUDE_CRYCOMMON_CRYFILE_H #pragma once #include @@ -20,86 +15,16 @@ #include #include -////////////////////////////////////////////////////////////////////////// -// Defines for CryEngine filetypes extensions. -////////////////////////////////////////////////////////////////////////// -#define CRY_GEOMETRY_FILE_EXT "cgf" -#define CRY_SKEL_FILE_EXT "chr" //will be a SKEL soon -#define CRY_SKIN_FILE_EXT "skin" -#define CRY_CHARACTER_ANIMATION_FILE_EXT "caf" -#define CRY_CHARACTER_DEFINITION_FILE_EXT "cdf" -#define CRY_CHARACTER_LIST_FILE_EXT "cid" -#define CRY_ANIM_GEOMETRY_FILE_EXT "cga" -#define CRY_ANIM_GEOMETRY_ANIMATION_FILE_EXT "anm" -#define CRY_COMPILED_FILE_EXT "(c)" -#define CRY_BINARY_XML_FILE_EXT "binxml" -#define CRY_XML_FILE_EXT "xml" -#define CRY_CHARACTER_PARAM_FILE_EXT "chrparams" -#define CRY_GEOM_CACHE_FILE_EXT "cax" ////////////////////////////////////////////////////////////////////////// #define CRYFILE_MAX_PATH 260 ////////////////////////////////////////////////////////////////////////// -inline const char* CryGetExt(const char* filepath) -{ - const char* str = filepath; - size_t len = strlen(filepath); - for (const char* p = str + len - 1; p >= str; --p) - { - switch (*p) - { - case ':': - case '/': - case '\\': - // we've reached a path separator - it means there's no extension in this name - return ""; - case '.': - // there's an extension in this file name - return p + 1; - } - } - return ""; -} - -// Summary: -// Checks if specified file name is a character file. -// Summary: -// Checks if specified file name is a character file. -inline bool IsCharacterFile(const char* filename) -{ - const char* ext = CryGetExt(filename); - if (_stricmp(ext, CRY_SKEL_FILE_EXT) == 0 || _stricmp(ext, CRY_SKIN_FILE_EXT) == 0 || _stricmp(ext, CRY_CHARACTER_DEFINITION_FILE_EXT) == 0 || _stricmp(ext, CRY_ANIM_GEOMETRY_FILE_EXT) == 0) - { - return true; - } - else - { - return false; - } -} - -// Description: -// Checks if specified file name is a static geometry file. -inline bool IsStatObjFile(const char* filename) -{ - const char* ext = CryGetExt(filename); - if (_stricmp(ext, CRY_GEOMETRY_FILE_EXT) == 0) - { - return true; - } - else - { - return false; - } -} - // Summary: // Wrapper on file system. class CCryFile { public: CCryFile(); - CCryFile(AZ::IO::IArchive* pIArchive); // allow an alternative IArchiveinterface CCryFile(const char* filename, const char* mode); ~CCryFile(); @@ -112,13 +37,6 @@ public: // Summary: // Reads data from a file at the current file position. size_t ReadRaw(void* lpBuf, size_t nSize); - // Summary: - // Template version, for automatic size support. - template - inline size_t ReadTypeRaw(T* pDest, size_t nCount = 1) - { - return ReadRaw(pDest, sizeof(T) * nCount); - } // Summary: // Automatic endian-swapping version. @@ -137,27 +55,6 @@ public: // Summary: // Moves the current file pointer to the specified position. size_t Seek(size_t seek, int mode); - // Summary: - // Moves the current file pointer at the beginning of the file. - void SeekToBegin(); - // Summary: - // Moves the current file pointer at the end of the file. - size_t SeekToEnd(); - // Summary: - // Retrieves the current file pointer. - size_t GetPosition(); - - // Summary: - // Tests for end-of-file on a selected file. - bool IsEof(); - - // Summary: - // Flushes any data yet to be written. - void Flush(); - - // Summary: - // Gets a handle to a pack object. - AZ::IO::HandleType GetHandle() const { return m_fileHandle; }; // Description: // Retrieves the filename of the selected file. @@ -193,12 +90,6 @@ inline CCryFile::CCryFile() m_pIArchive = gEnv ? gEnv->pCryPak : NULL; } -inline CCryFile::CCryFile(AZ::IO::IArchive* pIArchive) -{ - m_fileHandle = AZ::IO::InvalidHandle; - m_pIArchive = pIArchive; -} - ////////////////////////////////////////////////////////////////////////// inline CCryFile::CCryFile(const char* filename, const char* mode) { @@ -336,58 +227,6 @@ inline size_t CCryFile::Seek(size_t seek, int mode) return 1; } -////////////////////////////////////////////////////////////////////////// -inline void CCryFile::SeekToBegin() -{ - Seek(0, SEEK_SET); -} - -////////////////////////////////////////////////////////////////////////// -inline size_t CCryFile::SeekToEnd() -{ - return Seek(0, SEEK_END); -} - -////////////////////////////////////////////////////////////////////////// -inline size_t CCryFile::GetPosition() -{ - assert(m_fileHandle != AZ::IO::InvalidHandle); - if (m_pIArchive) - { - return m_pIArchive->FTell(m_fileHandle); - } - - AZ::u64 tellOffset = 0; - AZ::IO::FileIOBase::GetInstance()->Tell(m_fileHandle, tellOffset); - - return static_cast(tellOffset); -} - -////////////////////////////////////////////////////////////////////////// -inline bool CCryFile::IsEof() -{ - assert(m_fileHandle != AZ::IO::InvalidHandle); - if (m_pIArchive) - { - return m_pIArchive->FEof(m_fileHandle) != 0; - } - - return AZ::IO::FileIOBase::GetInstance()->Eof(m_fileHandle); -} - -////////////////////////////////////////////////////////////////////////// -inline void CCryFile::Flush() -{ - assert(m_fileHandle != AZ::IO::InvalidHandle); - - if (m_pIArchive) - { - m_pIArchive->FFlush(m_fileHandle); - } - - AZ::IO::FileIOBase::GetInstance()->Flush(m_fileHandle); -} - ////////////////////////////////////////////////////////////////////////// inline bool CCryFile::IsInPak() const { @@ -433,5 +272,3 @@ inline const char* CCryFile::GetAdjustedFilename() const } return szAdjustedFile; } - -#endif // CRYINCLUDE_CRYCOMMON_CRYFILE_H diff --git a/Code/Legacy/CryCommon/CryHalf.inl b/Code/Legacy/CryCommon/CryHalf.inl index a9683540e1..678dc36581 100644 --- a/Code/Legacy/CryCommon/CryHalf.inl +++ b/Code/Legacy/CryCommon/CryHalf.inl @@ -15,7 +15,6 @@ typedef uint16 CryHalf; -class ICrySizer; typedef union floatint_union { @@ -138,9 +137,6 @@ struct CryHalf2 { return x != rhs.x || y != rhs.y; } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - }; struct CryHalf4 @@ -193,9 +189,6 @@ struct CryHalf4 { return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w; } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - }; #endif // #ifndef CRY_HALF_INL diff --git a/Code/Legacy/CryCommon/CryListenerSet.h b/Code/Legacy/CryCommon/CryListenerSet.h index e5be89aa9f..1c67275d41 100644 --- a/Code/Legacy/CryCommon/CryListenerSet.h +++ b/Code/Legacy/CryCommon/CryListenerSet.h @@ -21,7 +21,8 @@ #pragma once -#include +#include "Cry_Math.h" +#include /************************************************************************ Core elements: @@ -151,13 +152,6 @@ public: // Allow TListeners::Notifier style usage typedef class CListenerNotifier Notifier; - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddContainer(m_listeners); -#if defined(CRY_LISTENERSET_DEBUG) - pSizer->AddContainer(m_allocatedNames); -#endif - } private: // DO NOT REMOVE - following methods only to be accessed only via CNotifier struct ListenerRecord diff --git a/Code/Legacy/CryCommon/CryPodArray.h b/Code/Legacy/CryCommon/CryPodArray.h deleted file mode 100644 index 20693b29ac..0000000000 --- a/Code/Legacy/CryCommon/CryPodArray.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Simple POD types container - -#ifndef CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H -#define CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H -#pragma once - -#include - -////////////////////////////////////////////////////////////////////////// -// POD Array -// vector like class (random access O(1)) without construction/destructor/copy constructor/assignment handling -// over-allocation allows safe prefetching where required without worrying about memory page boundaries -////////////////////////////////////////////////////////////////////////// -template -class PodArray -{ - AZStd::vector m_elements; - -public: - typedef T value_type; - typedef T* iterator; - typedef const T* const_iterator; - - ////////////////////////////////////////////////////////////////////////// - // STL compatible interface - ////////////////////////////////////////////////////////////////////////// - void resize(size_t numElements) - { - m_elements.resize(numElements); - } - ////////////////////////////////////////////////////////////////////////// - ILINE void reserve(unsigned numElements) { m_elements.reserve(numElements); } - ILINE void push_back(const T& rElement) { m_elements.push_back(rElement); } - ILINE size_t size() const { return m_elements.size(); } - ILINE size_t capacity() const { return m_elements.capacity(); } - - ILINE void clear() { m_elements.clear(); } - ILINE T* begin() { return m_elements.begin(); } - ILINE T* end() { return m_elements.end(); } - ILINE const T* begin() const { return m_elements.begin(); } - ILINE const T* end() const { return m_elements.end(); } - ILINE bool empty() const { return m_elements.empty(); } - - ILINE const T& front() const { return m_elements.front(); } - ILINE T& front() { return m_elements.front(); } - - ILINE const T& back() const { return m_elements.back(); } - ILINE T& back() { return m_elements.back(); } - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - PodArray() - : m_elements() - { - } - PodArray(int elem_count, int nNewCount = 0) - { - m_elements.reserve(elem_count); - m_elements.resize(nNewCount); - } - PodArray(const PodArray& from) - : m_elements(from.m_elements) - { - } - ~PodArray() - { - } - - void Reset() { m_elements.clear(); } - void Free() - { - m_elements.clear(); - m_elements.shrink_to_fit(); - } - - ILINE void Clear() - { - m_elements.clear(); - } - - int Find(const T& p) - { - const auto it = AZStd::find(m_elements.begin(), m_elements.end(), p); - if (it != m_elements.end()) - { - return static_cast(AZStd::distance(m_elements.begin(), it)); - } - return -1; - } - - inline void AddList(const PodArray& lstAnother) - { - AZStd::copy(lstAnother.m_elements.begin(), lstAnother.m_elements.end(), AZStd::back_inserter(m_elements)); - } - - inline void AddList(T* pAnotherArray, int nAnotherCount) - { - AZStd::copy(pAnotherArray, pAnotherArray + nAnotherCount, AZStd::back_inserter(m_elements)); - } - - ILINE void Add(const T& p) - { - m_elements.push_back(p); - } - - ILINE T& AddNew() - { - m_elements.emplace_back(); - return m_elements.back(); - } - - void InsertBefore(const T& p, const unsigned int nBefore) - { - m_elements.insert(m_elements.begin() + nBefore, p); - } - - void CheckAllocated(int elem_count) - { - if (m_elements.size() < elem_count) - { - m_elements.resize(elem_count); - } - } - - void PreAllocate(int elem_count, int nNewCount = -1) - { - m_elements.reserve(elem_count); - if (nNewCount >= 0) - { - m_elements.resize(nNewCount); - } - } - - inline void Delete(const int nElemId, const int nElemCount = 1) - { - AZ_Assert(nElemId >= 0 && nElemId + nElemCount <= size(), "Index out of bounds"); - m_elements.erase(m_elements.begin() + nElemId, m_elements.begin() + nElemId + nElemCount); - } - - inline void DeleteFastUnsorted(const int nElemId, const int nElemCount = 1) - { - AZ_Assert(nElemId >= 0 && nElemId + nElemCount <= size(), "Index out of bounds"); - m_elements.erase(m_elements.begin() + nElemId, m_elements.begin() + nElemId + nElemCount); - } - - inline bool Delete(const T& del) - { - const size_t numElements = m_elements.size(); - m_elements.erase(std::remove(m_elements.begin(), m_elements.end(), del), m_elements.end()); - return numElements != m_elements.size(); - } - - ILINE size_t Count() const { return m_elements.size(); } - ILINE size_t Size() const { return m_elements.size(); } - - ILINE int IsEmpty() const { return m_elements.empty(); } - - ILINE const T& operator [] (int i) const { return m_elements[i]; } - ILINE T& operator [] (int i) { return m_elements[i]; } - ILINE const T& GetAt(int i) const { return m_elements[i]; } - ILINE T& GetAt(int i) { return m_elements[i]; } - ILINE const T* Get(int i) const { return &m_elements[i]; } - ILINE T* Get(int i) { return &m_elements[i]; } - ILINE const T* GetElements() const { return m_elements.data(); } - ILINE T* GetElements() { return m_elements.data(); } - - ILINE unsigned int GetDataSize() const { return m_elements.size() * sizeof(T); } - - const T& Last() const { return m_elements.back(); } - T& Last() { return m_elements.back(); } - - ILINE void DeleteLast() - { - assert(!m_elements.empty()); - m_elements.pop_back(); - } - - PodArray& operator=(const PodArray& source_list) - { - m_elements = source_list.m_elements; - return *this; - } - - ////////////////////////////////////////////////////////////////////////// - // Return true if arrays have the same data. - bool Compare(const PodArray& l) const - { - return m_elements == l.m_elements; - } - - // for statistics - ILINE size_t ComputeSizeInMemory() const - { - return (sizeof(*this) + sizeof(T) * m_elements.capacity()) + overAllocBytes; - } - - ILINE void RemoveIf(AZStd::function testFunc) - { - m_elements.erase(AZStd::remove_if(m_elements.begin(), m_elements.end(), testFunc), m_elements.end()); - } -}; - -#endif // CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H diff --git a/Code/Legacy/CryCommon/CrySizer.h b/Code/Legacy/CryCommon/CrySizer.h deleted file mode 100644 index 27323368ab..0000000000 --- a/Code/Legacy/CryCommon/CrySizer.h +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Declaration and definition of the CrySizer class, which is used to -// calculate the memory usage by the subsystems and components, to help -// the artists keep the memory budged low. - - -#ifndef CRYINCLUDE_CRYCOMMON_CRYSIZER_H -#define CRYINCLUDE_CRYCOMMON_CRYSIZER_H -#pragma once - - -////////////////////////////////////////////////////////////////////////// - -// common containers for overloads -#include - -#include "Cry_Math.h" -#include -#include -#include -#include -#include -#include -#include - -// forward declarations for overloads -struct AABB; -struct SVF_P3F; -struct SVF_P3F_C4B_T2F; -struct SVF_P3S_C4B_T2S; -struct SPipTangents; - -#ifdef WIN64 -#include // workaround for Amd64 compiler -#endif - -namespace AZ -{ - class Vector3; -} - -// flags applicable to the ICrySizer (retrieved via getFlags() method) -// -enum ICrySizerFlagsEnum -{ - // if this flag is set, during getSize(), the subsystem must count all the objects - // it uses in the other subsystems also - CSF_RecurseSubsystems = 1 << 0, - - CSF_Reserved1 = 1 << 1, - CSF_Reserved2 = 1 << 2 -}; - -////////////////////////////////////////////////////////////////////////// -// Helper functions to calculate size of the std containers. -////////////////////////////////////////////////////////////////////////// -namespace stl -{ - template - inline size_t size_of_map(const Map& m) - { - if (!m.empty()) - { - return m.size() * sizeof(typename Map::value_type) + m.size() * sizeof(MapLikeStruct); - } - return 0; - } - template - inline size_t size_of_set(const Map& m) - { - if (!m.empty()) - { - return m.size() * sizeof(typename Map::value_type) + m.size() * sizeof(MapLikeStruct); - } - return 0; - } - template - inline size_t size_of_list(const List& c) - { - if (!c.empty()) - { - return c.size() * sizeof(typename List::value_type) + c.size() * sizeof(void*) * 2; // sizeof stored type + 2 pointers prev,next - } - return 0; - } - template - inline size_t size_of_deque(const Deque& c) - { - if (!c.empty()) - { - return c.size() * sizeof(typename Deque::value_type); - } - return 0; - } -}; - -////////////////////////////////////////////////////////////////////////// -// interface ICrySizer -// USAGE -// An instance of this class is passed down to each and every component in the system. -// Every component it's passed to optionally pushes its name on top of the -// component name stack (thus ensuring that all the components calculated down -// the tree will be assigned the correct subsystem/component name) -// Every component must Add its size with one of the Add* functions, and Add the -// size of all its subcomponents recursively -// In order to push the component/system name on the name stack, the clients must -// use the SIZER_COMPONENT_NAME macro or CrySizerComponentNameHelper class: -// -// void X::getSize (ICrySizer* pSizer) -// { -// SIZER_COMPONENT_NAME(pSizer, X); -// if (!pSizer->Add (this)) -// return; -// pSizer->Add (m_arrMySimpleArray); -// pSizer->Add (m_setMySimpleSet); -// m_pSubobject->getSize (pSizer); -// } -// -// The Add* functions return bool. If they return true, then the object has been added -// to the set for the first time, and you should go on recursively adding all its children. -// If it returns false, then you can spare time and rather not go on into recursion; -// however it doesn't reflect on the results: an object that's added more than once is -// counted only once. -// -// WARNING: -// If you have an array (pointer), you should Add its size with addArray -class ICrySizer -{ -public: - virtual ~ICrySizer(){} - // this class is used to push/pop the name to/from the stack automatically - // (to exclude stack overruns or underruns at runtime) - friend class CrySizerComponentNameHelper; - - virtual void Release() = 0; - - // Return total calculated size. - virtual size_t GetTotalSize() = 0; - - // Return total objects added. - virtual size_t GetObjectCount() = 0; - - // Resets the counting. - virtual void Reset() = 0; - - virtual void End() = 0; - - // adds an object identified by the unique pointer (it needs not be - // the actual object position in the memory, though it would be nice, - // but it must be unique throughout the system and unchanging for this object) - // nCount parameter is only used for counting number of objects, it doesnt affect the size of the object. - // RETURNS: true if the object has actually been added (for the first time) - // and calculated - virtual bool AddObject (const void* pIdentifier, size_t nSizeBytes, int nCount = 1) = 0; - - template - bool AddObjectSize(const Type* pObj) - { - return AddObject(pObj, sizeof *pObj); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // temp dummy function while checking in the CrySizer changes, will be removed soon - - template - void AddObject(const Type& rObj) - { - (void)rObj; - } - - template - void AddObject(Type* pObj) - { - if (pObj) - { - //forward to reference object to allow function overload - this->AddObject(*pObj); - } - } - - // overloads for smart_ptr and other common objects - template - void AddObject(const _smart_ptr& rObj) { this->AddObject(rObj.get()); } - template - void AddObject(const AZStd::shared_ptr& rObj) { this->AddObject(rObj.get()); } - template - void AddObject(const std::shared_ptr& rObj) { this->AddObject(rObj.get()); } - template - void AddObject(const std::unique_ptr& rObj) { this->AddObject(rObj.get()); } - template - void AddObject(const std::pair& rPair) - { - this->AddObject(rPair.first); - this->AddObject(rPair.second); - } - template - void AddObject(const AZStd::pair& rPair) - { - this->AddObject(rPair.first); - this->AddObject(rPair.second); - } - void AddObject(const AZStd::string& rString) {this->AddObject(rString.c_str(), rString.capacity()); } - void AddObject(const wchar_t&) {} - void AddObject(const char&) {} - void AddObject(const unsigned char&) {} - void AddObject(const signed char&) {} - void AddObject(const short&) {} - void AddObject(const unsigned short&) {} - void AddObject(const int&) {} - void AddObject(const unsigned int&) {} - void AddObject(const long&) {} - void AddObject(const unsigned long&) {} - void AddObject(const float&) {} - void AddObject(const bool&) {} - void AddObject(const unsigned long long&) {} - void AddObject(const long long&) {} - void AddObject(const double&) {} - void AddObject(const Vec2&) {} - void AddObject(const Vec3&) {} - void AddObject(const Vec4&) {} - void AddObject(const Ang3&) {} - void AddObject(const Matrix34&) {} - void AddObject(const Quat&) {} - void AddObject(const QuatT&) {} - void AddObject(const QuatTS&) {} - void AddObject(const ColorF&) {} - void AddObject(const AABB&) {} - void AddObject(const SVF_P3F&) {} - void AddObject(const SVF_P3F_C4B_T2F&) {} - void AddObject(const SVF_P3S_C4B_T2S&) {} - void AddObject(const SPipTangents&) {} - void AddObject([[maybe_unused]] const AZ::Vector3& rObj) {} - void AddObject(void*) {} - - // overloads for container, will automaticly traverse the content - template - void AddObject(const std::list& rList) - { - // dummy struct to get correct element size - struct Dummy - { - void* a; - void* b; - T t; - }; - - for (typename std::list::const_iterator it = rList.begin(); it != rList.end(); ++it) - { - if (this->AddObject(&(*it), sizeof(Dummy))) - { - this->AddObject(*it); - } - } - } - template - void AddObject([[maybe_unused]] const AZStd::unordered_map& rVector) - { - - } - - template - void AddObject(const std::vector& rVector) - { - if (rVector.empty()) - { - this->AddObject(&rVector, rVector.capacity() * sizeof(T)); - return; - } - - if (!this->AddObject(&rVector[0], rVector.capacity() * sizeof(T))) - { - return; - } - - for (typename std::vector::const_iterator it = rVector.begin(); it != rVector.end(); ++it) - { - this->AddObject(*it); - } - } - - template - void AddObject(const std::deque& rVector) - { - for (typename std::deque::const_iterator it = rVector.begin(); it != rVector.end(); ++it) - { - if (this->AddObject(&(*it), sizeof(T))) - { - this->AddObject(*it); - } - } - } - - template - void AddObject(const PodArray& rVector) - { - if (!this->AddObject(rVector.begin(), rVector.capacity() * sizeof(T))) - { - return; - } - - for (typename PodArray::const_iterator it = rVector.begin(); it != rVector.end(); ++it) - { - this->AddObject(*it); - } - } - - template - void AddObject(const std::map& rVector) - { - // dummy struct to get correct element size - struct Dummy - { - void* a; - void* b; - void* c; - void* d; - K k; - T t; - }; - - for (typename std::map::const_iterator it = rVector.begin(); it != rVector.end(); ++it) - { - if (this->AddObject(&(*it), sizeof(Dummy))) - { - this->AddObject(it->first); - this->AddObject(it->second); - } - } - } - - template - void AddObject(const std::set& rVector) - { - // dummy struct to get correct element size - struct Dummy - { - void* a; - void* b; - void* c; - void* d; - T t; - }; - - for (typename std::set::const_iterator it = rVector.begin(); it != rVector.end(); ++it) - { - if (this->AddObject(&(*it), sizeof(Dummy))) - { - this->AddObject(*it); - } - } - } - - template - void AddObject (const std::multimap& rContainer) - { - AddContainer(rContainer); - } - //////////////////////////////////////////////////////////////////////////////////////// - template - bool Add (const T* pId, size_t num) - { - return AddObject(pId, num * sizeof(T)); - } - - template - bool Add (const T& rObject) - { - return AddObject (&rObject, sizeof(T)); - } - - bool Add (const char* szText) - { - return AddObject(szText, strlen(szText) + 1); - } - - template - bool AddString (const StringCls& strText) - { - if (!strText.empty()) - { - return AddObject (strText.c_str(), strText.size()); - } - else - { - return false; - } - } -#ifdef _XSTRING_ - template - bool Add (const std::basic_string& strText) - { - AddString (strText); - return true; - } -#endif - - #ifndef NOT_USE_CRY_STRING - bool Add (const AZStd::string& strText) - { - AddString(strText); - return true; - } - #endif - - - // Template helper function to add generic stl container - template - bool AddContainer (const Container& rContainer) - { - if (rContainer.capacity()) - { - return AddObject (&rContainer, rContainer.capacity() * sizeof(typename Container::value_type)); - } - return false; - } - template - bool AddHashMap(const Container& rContainer) - { - if (!rContainer.empty()) - { - return AddObject (&(*rContainer.begin()), rContainer.size() * sizeof(typename Container::value_type)); - } - return false; - } - - // Specialization of the AddContainer for the std::list - template - bool AddContainer (const std::list& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), stl::size_of_list(rContainer)); - } - return false; - } - // Specialization of the AddContainer for the std::deque - template - bool AddContainer (const std::deque& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), stl::size_of_deque(rContainer)); - } - return false; - } - // Specialization of the AddContainer for the std::map - template - bool AddContainer (const std::map& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), stl::size_of_map(rContainer)); - } - return false; - } - // Specialization of the AddContainer for the std::multimap - template - bool AddContainer (const std::multimap& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), stl::size_of_map(rContainer)); - } - return false; - } - // Specialization of the AddContainer for the std::set - template - bool AddContainer (const std::set& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), stl::size_of_set(rContainer)); - } - return false; - } - - // Specialization of the AddContainer for the AZStd::unordered_map - template - bool AddContainer(const AZStd::unordered_map& rContainer) - { - if (!rContainer.empty()) - { - return AddObject(&(*rContainer.begin()), rContainer.size() * sizeof(typename AZStd::unordered_map::value_type)); - } - else - { - return false; - } - } - - void Test() - { - std::map mymap; - AddContainer(mymap); - } - - // returns the flags - unsigned GetFlags() const {return m_nFlags; } - -protected: - // these functions must operate on the component name stack - // they are to be only accessible from within class CrySizerComponentNameHelper - // which should be used through macro SIZER_COMPONENT_NAME - virtual void Push (const char* szComponentName) = 0; - // pushes the name that is the name of the previous component . (dot) this name - virtual void PushSubcomponent (const char* szSubcomponentName) = 0; - virtual void Pop () = 0; - - unsigned m_nFlags; -}; - -////////////////////////////////////////////////////////////////////////// -// This is on-stack class that is only used to push/pop component names -// to/from the sizer name stack. -// -// USAGE: -// -// Create an instance of this class at the start of a function, before -// calling Add* methods of the sizer interface. Everything added in the -// function and below will be considered this component, unless -// explicitly set otherwise. -// -class CrySizerComponentNameHelper -{ -public: - // pushes the component name on top of the name stack of the given sizer - CrySizerComponentNameHelper (ICrySizer* pSizer, const char* szComponentName, bool bSubcomponent) - : m_pSizer(pSizer) - { - if (bSubcomponent) - { - pSizer->PushSubcomponent (szComponentName); - } - else - { - pSizer->Push (szComponentName); - } - } - - // pops the component name off top of the name stack of the sizer - ~CrySizerComponentNameHelper() - { - m_pSizer->Pop(); - } - -protected: - ICrySizer* m_pSizer; -}; - -// use this to push (and automatically pop) the sizer component name at the beginning of the -// getSize() function -#define SIZER_COMPONENT_NAME(pSizerPointer, szComponentName) CrySizerComponentNameHelper AZ_JOIN(sizerHelper, __LINE__)(pSizerPointer, szComponentName, false) -#define SIZER_SUBCOMPONENT_NAME(pSizerPointer, szComponentName) CrySizerComponentNameHelper AZ_JOIN(sizerHelper, __LINE__)(pSizerPointer, szComponentName, true) - -#endif // CRYINCLUDE_CRYCOMMON_CRYSIZER_H diff --git a/Code/Legacy/CryCommon/Cry_Camera.h b/Code/Legacy/CryCommon/Cry_Camera.h index 852467d787..668d15cbc1 100644 --- a/Code/Legacy/CryCommon/Cry_Camera.h +++ b/Code/Legacy/CryCommon/Cry_Camera.h @@ -8,9 +8,6 @@ // Description : Common Camera class implementation - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_CAMERA_H -#define CRYINCLUDE_CRYCOMMON_CRY_CAMERA_H #pragma once @@ -48,450 +45,6 @@ enum cull CULL_INCLUSION // The whole object is inside frustum. }; -class CameraViewParameters -{ -public: - CameraViewParameters(); - - void LookAt(const Vec3& Eye, const Vec3& ViewRefPt, const Vec3& ViewUp); - void Perspective(float Yfov, float Aspect, float Ndist, float Fdist); - void Frustum(float l, float r, float b, float t, float Ndist, float Fdist); - const Vec3& wCOP() const; - Vec3 ViewDir() const; - Vec3 ViewDirOffAxis() const; - - float* GetXform_Screen2Obj(float* M, int WW, int WH) const; - float* GetXform_Obj2Screen(float* M, int WW, int WH) const; - - float* GetModelviewMatrix(float* M) const; - float* GetProjectionMatrix(float* M) const; - float* GetViewportMatrix(float* M, int WW, int WH) const; - - void SetModelviewMatrix(const float* M); - - void GetLookAtParams(Vec3* Eye, Vec3* ViewRefPt, Vec3* ViewUp) const; - void GetPerspectiveParams(float* Yfov, float* Xfov, float* Aspect, float* Ndist, float* Fdist) const; - void GetFrustumParams(float* l, float* r, float* b, float* t, float* Ndist, float* Fdist) const; - - float* GetInvModelviewMatrix(float* M) const; - float* GetInvProjectionMatrix(float* M) const; - float* GetInvViewportMatrix(float* M, int WW, int WH) const; - - Vec3 WorldToCam(const Vec3& wP) const; - float WorldToCamZ(const Vec3& wP) const; - Vec3 CamToWorld(const Vec3& cP) const; - - void LoadIdentityXform(); - void Xform(const float M[16]); - - void Translate(const Vec3& trans); - void Rotate(const float M[9]); - - void GetPixelRay(float sx, float sy, int ww, int wh, Vec3* Start, Vec3* Dir) const; - - void CalcVerts(Vec3* V) const; - void CalcTileVerts(Vec3* V, f32 nPosX, f32 nPosY, f32 nGridSizeX, f32 nGridSizeY) const; - void CalcRegionVerts(Vec3* V, const Vec2& vMin, const Vec2& vMax) const; - void CalcTiledRegionVerts(Vec3* V, Vec2& vMin, Vec2& vMax, f32 nPosX, f32 nPosY, f32 nGridSizeX, f32 nGridSizeY) const; - - Vec3 vX, vY, vZ; - Vec3 vOrigin; - float fWL, fWR, fWB, fWT; - float fNear, fFar; -}; - -inline float* Frustum16fv(float* M, float l, float r, float b, float t, float n, float f) -{ - M[0] = (2 * n) / (r - l); - M[4] = 0; - M[8] = (r + l) / (r - l); - M[12] = 0; - M[1] = 0; - M[5] = (2 * n) / (t - b); - M[9] = (t + b) / (t - b); - M[13] = 0; - M[2] = 0; - M[6] = 0; - M[10] = -(f + n) / (f - n); - M[14] = (-2 * f * n) / (f - n); - M[3] = 0; - M[7] = 0; - M[11] = -1; - M[15] = 0; - - return M; -} - -inline float* Viewing16fv(float* M, const Vec3 X, const Vec3 Y, const Vec3 Z, const Vec3 O) -{ - M[0] = X.x; - M[4] = X.y; - M[8] = X.z; - M[12] = -X | O; - M[1] = Y.x; - M[5] = Y.y; - M[9] = Y.z; - M[13] = -Y | O; - M[2] = Z.x; - M[6] = Z.y; - M[10] = Z.z; - M[14] = -Z | O; - M[3] = 0; - M[7] = 0; - M[11] = 0; - M[15] = 1; - return M; -} - - -inline CameraViewParameters::CameraViewParameters() -{ - vX.Set(1, 0, 0); - vY.Set(0, 1, 0); - vZ.Set(0, 0, 1); - vOrigin.Set(0, 0, 0); - fNear = 1.4142f; - fFar = 10; - fWL = -1; - fWR = 1; - fWT = 1; - fWB = -1; -} - -inline void CameraViewParameters::LookAt(const Vec3& Eye, const Vec3& ViewRefPt, const Vec3& ViewUp) -{ - vZ = Eye - ViewRefPt; - vZ.NormalizeSafe(); - vX = ViewUp % vZ; - vX.NormalizeSafe(); - vY = vZ % vX; - vY.NormalizeSafe(); - vOrigin = Eye; -} - -inline void CameraViewParameters::Perspective(float Yfov, float Aspect, float Ndist, float Fdist) -{ - fNear = Ndist; - fFar = Fdist; - fWT = tanf(Yfov * 0.5f) * fNear; - fWB = -fWT; - fWR = fWT * Aspect; - fWL = -fWR; -} - -inline void CameraViewParameters::Frustum(float l, float r, float b, float t, float Ndist, float Fdist) -{ - fNear = Ndist; - fFar = Fdist; - fWR = r; - fWL = l; - fWB = b; - fWT = t; -} - - -inline void CameraViewParameters::GetLookAtParams(Vec3* Eye, Vec3* ViewRefPt, Vec3* ViewUp) const -{ - *Eye = vOrigin; - *ViewRefPt = vOrigin - vZ; - *ViewUp = vY; -} - -inline void CameraViewParameters::GetPerspectiveParams(float* Yfov, float* Xfov, float* Aspect, float* Ndist, float* Fdist) const -{ - *Yfov = atanf(fWT / fNear) * 57.29578f * 2.0f; - *Xfov = atanf(fWR / fNear) * 57.29578f * 2.0f; - *Aspect = fWT / fWR; - *Ndist = fNear; - *Fdist = fFar; -} - -inline void CameraViewParameters::GetFrustumParams(float* l, float* r, float* b, float* t, float* Ndist, float* Fdist) const -{ - *l = fWL; - *r = fWR; - *b = fWB; - *t = fWT; - *Ndist = fNear; - *Fdist = fFar; -} - -inline const Vec3& CameraViewParameters::wCOP() const -{ - return(vOrigin); -} - -inline Vec3 CameraViewParameters::ViewDir() const -{ - return(-vZ); -} - -inline Vec3 CameraViewParameters::ViewDirOffAxis() const -{ - float fX = (fWL + fWR) * 0.5f, fY = (fWT + fWB) * 0.5f; // MIDPOINT ON VIEWPLANE WINDOW - Vec3 ViewDir = vX * fX + vY * fY - vZ * fNear; - ViewDir.Normalize(); - return ViewDir; -} - -inline Vec3 CameraViewParameters::WorldToCam(const Vec3& wP) const -{ - Vec3 sP(wP - vOrigin); - Vec3 cP(vX | sP, vY | sP, vZ | sP); - return cP; -} - -inline float CameraViewParameters::WorldToCamZ(const Vec3& wP) const -{ - Vec3 sP(wP - vOrigin); - float zdist = vZ | sP; - return zdist; -} - -inline Vec3 CameraViewParameters::CamToWorld(const Vec3& cP) const -{ - Vec3 wP(vX * cP.x + vY * cP.y + vZ * cP.z + vOrigin); - return wP; -} - -inline void CameraViewParameters::LoadIdentityXform() -{ - vX.Set(1, 0, 0); - vY.Set(0, 1, 0); - vZ.Set(0, 0, 1); - vOrigin.Set(0, 0, 0); -} - -inline void CameraViewParameters::Xform(const float M[16]) -{ - vX.Set(vX.x * M[0] + vX.y * M[4] + vX.z * M[8], - vX.x * M[1] + vX.y * M[5] + vX.z * M[9], - vX.x * M[2] + vX.y * M[6] + vX.z * M[10]); - vY.Set(vY.x * M[0] + vY.y * M[4] + vY.z * M[8], - vY.x * M[1] + vY.y * M[5] + vY.z * M[9], - vY.x * M[2] + vY.y * M[6] + vY.z * M[10]); - vZ.Set(vZ.x * M[0] + vZ.y * M[4] + vZ.z * M[8], - vZ.x * M[1] + vZ.y * M[5] + vZ.z * M[9], - vZ.x * M[2] + vZ.y * M[6] + vZ.z * M[10]); - vOrigin.Set(vOrigin.x * M[0] + vOrigin.y * M[4] + vOrigin.z * M[8] + M[12], - vOrigin.x * M[1] + vOrigin.y * M[5] + vOrigin.z * M[9] + M[13], - vOrigin.x * M[2] + vOrigin.y * M[6] + vOrigin.z * M[10] + M[14]); - - float Scale = vX.GetLength(); - vX /= Scale; - vY /= Scale; - vZ /= Scale; - - fWL *= Scale; - fWR *= Scale; - fWB *= Scale; - fWT *= Scale; - fNear *= Scale; - fFar *= Scale; -}; - -inline void CameraViewParameters::Translate(const Vec3& trans) -{ - vOrigin += trans; -} - -inline void CameraViewParameters::Rotate(const float M[9]) -{ - vX.Set(vX.x * M[0] + vX.y * M[3] + vX.z * M[6], - vX.x * M[1] + vX.y * M[4] + vX.z * M[7], - vX.x * M[2] + vX.y * M[5] + vX.z * M[8]); - vY.Set(vY.x * M[0] + vY.y * M[3] + vY.z * M[6], - vY.x * M[1] + vY.y * M[4] + vY.z * M[7], - vY.x * M[2] + vY.y * M[5] + vY.z * M[8]); - vZ.Set(vZ.x * M[0] + vZ.y * M[3] + vZ.z * M[6], - vZ.x * M[1] + vZ.y * M[4] + vZ.z * M[7], - vZ.x * M[2] + vZ.y * M[5] + vZ.z * M[8]); -} - -inline float* CameraViewParameters::GetModelviewMatrix(float* M) const -{ - Viewing16fv(M, vX, vY, vZ, vOrigin); - return M; -} - -inline float* CameraViewParameters::GetProjectionMatrix(float* M) const -{ - Frustum16fv(M, fWL, fWR, fWB, fWT, fNear, fFar); - return(M); -} - -inline void CameraViewParameters::GetPixelRay(float sx, float sy, int ww, int wh, Vec3* Start, Vec3* Dir) const -{ - Vec3 wTL = vOrigin + (vX * fWL) + (vY * fWT) - (vZ * fNear); // FIND LOWER-LEFT - Vec3 dX = (vX * (fWR - fWL)) / (float)ww; // WORLD WIDTH OF PIXEL - Vec3 dY = (vY * (fWT - fWB)) / (float)wh; // WORLD HEIGHT OF PIXEL - wTL += (dX * sx - dY * sy); // INCR TO WORLD PIXEL - wTL += (dX * 0.5f - dY * 0.5f); // INCR TO PIXEL CNTR - *Start = vOrigin; - *Dir = wTL - vOrigin; -} - -inline void CameraViewParameters::CalcVerts(Vec3* V) const -{ - float NearZ = -fNear; - V[0].Set(fWR, fWT, NearZ); - V[1].Set(fWL, fWT, NearZ); - V[2].Set(fWL, fWB, NearZ); - V[3].Set(fWR, fWB, NearZ); - - float FarZ = -fFar, FN = fFar / fNear; - float fwL = fWL * FN, fwR = fWR * FN, fwB = fWB * FN, fwT = fWT * FN; - V[4].Set(fwR, fwT, FarZ); - V[5].Set(fwL, fwT, FarZ); - V[6].Set(fwL, fwB, FarZ); - V[7].Set(fwR, fwB, FarZ); - - for (int i = 0; i < 8; i++) - { - V[i] = CamToWorld(V[i]); - } -} - -inline void CameraViewParameters::CalcTileVerts(Vec3* V, f32 nPosX, f32 nPosY, f32 nGridSizeX, f32 nGridSizeY) const -{ - float NearZ = -fNear; - - float TileWidth = abs(fWR - fWL) / nGridSizeX; - float TileHeight = abs(fWT - fWB) / nGridSizeY; - float TileL = fWL + TileWidth * nPosX; - float TileR = fWL + TileWidth * (nPosX + 1); - float TileB = fWB + TileHeight * nPosY; - float TileT = fWB + TileHeight * (nPosY + 1); - - V[0].Set(TileR, TileT, NearZ); - V[1].Set(TileL, TileT, NearZ); - V[2].Set(TileL, TileB, NearZ); - V[3].Set(TileR, TileB, NearZ); - - float FarZ = -fFar, FN = fFar / fNear; - float fwL = fWL * FN, fwR = fWR * FN, fwB = fWB * FN, fwT = fWT * FN; - - float TileFarWidth = abs(fwR - fwL) / nGridSizeX; - float TileFarHeight = abs(fwT - fwB) / nGridSizeY; - float TileFarL = fwL + TileFarWidth * nPosX; - float TileFarR = fwL + TileFarWidth * (nPosX + 1); - float TileFarB = fwB + TileFarHeight * nPosY; - float TileFarT = fwB + TileFarHeight * (nPosY + 1); - - V[4].Set(TileFarR, TileFarT, FarZ); - V[5].Set(TileFarL, TileFarT, FarZ); - V[6].Set(TileFarL, TileFarB, FarZ); - V[7].Set(TileFarR, TileFarB, FarZ); - - for (int i = 0; i < 8; i++) - { - V[i] = CamToWorld(V[i]); - } -} - -inline void CameraViewParameters::CalcTiledRegionVerts(Vec3* V, Vec2& vMin, Vec2& vMax, f32 nPosX, f32 nPosY, f32 nGridSizeX, f32 nGridSizeY) const -{ - float NearZ = -fNear; - - Vec2 vTileMin, vTileMax; - - vMin.x = max(vMin.x, nPosX / nGridSizeX); - vMax.x = min(vMax.x, (nPosX + 1) / nGridSizeX); - - vMin.y = max(vMin.y, nPosY / nGridSizeY); - vMax.y = min(vMax.y, (nPosY + 1) / nGridSizeY); - - vTileMin.x = abs(fWR - fWL) * vMin.x; - vTileMin.y = abs(fWT - fWB) * vMin.y; - vTileMax.x = abs(fWR - fWL) * vMax.x; - vTileMax.y = abs(fWT - fWB) * vMax.y; - - - float TileL = fWL + vTileMin.x; - float TileR = fWL + vTileMax.x; - float TileB = fWB + vTileMin.y; - float TileT = fWB + vTileMax.y; - - V[0].Set(TileR, TileT, NearZ); - V[1].Set(TileL, TileT, NearZ); - V[2].Set(TileL, TileB, NearZ); - V[3].Set(TileR, TileB, NearZ); - - float FarZ = -fFar, FN = fFar / fNear; - float fwL = fWL * FN, fwR = fWR * FN, fwB = fWB * FN, fwT = fWT * FN; - - Vec2 vTileFarMin, vTileFarMax; - - vTileFarMin.x = abs(fwR - fwL) * vMin.x; - vTileFarMin.y = abs(fwT - fwB) * vMin.y; - vTileFarMax.x = abs(fwR - fwL) * vMax.x; - vTileFarMax.y = abs(fwT - fwB) * vMax.y; - - - float TileFarL = fwL + vTileFarMin.x; - float TileFarR = fwL + vTileFarMax.x; - float TileFarB = fwB + vTileFarMin.y; - float TileFarT = fwB + vTileFarMax.y; - - V[4].Set(TileFarR, TileFarT, FarZ); - V[5].Set(TileFarL, TileFarT, FarZ); - V[6].Set(TileFarL, TileFarB, FarZ); - V[7].Set(TileFarR, TileFarB, FarZ); - - for (int i = 0; i < 8; i++) - { - V[i] = CamToWorld(V[i]); - } -} - - -inline void CameraViewParameters::CalcRegionVerts(Vec3* V, const Vec2& vMin, const Vec2& vMax) const -{ - float NearZ = -fNear; - - Vec2 vTileMin, vTileMax; - - vTileMin.x = abs(fWR - fWL) * vMin.x; - vTileMin.y = abs(fWT - fWB) * vMin.y; - vTileMax.x = abs(fWR - fWL) * vMax.x; - vTileMax.y = abs(fWT - fWB) * vMax.y; - - float TileL = fWL + vTileMin.x; - float TileR = fWL + vTileMax.x; - float TileB = fWB + vTileMin.y; - float TileT = fWB + vTileMax.y; - - V[0].Set(TileR, TileT, NearZ); - V[1].Set(TileL, TileT, NearZ); - V[2].Set(TileL, TileB, NearZ); - V[3].Set(TileR, TileB, NearZ); - - float FarZ = -fFar, FN = fFar / fNear; - float fwL = fWL * FN, fwR = fWR * FN, fwB = fWB * FN, fwT = fWT * FN; - - Vec2 vTileFarMin, vTileFarMax; - - vTileFarMin.x = abs(fwR - fwL) * vMin.x; - vTileFarMin.y = abs(fwT - fwB) * vMin.y; - vTileFarMax.x = abs(fwR - fwL) * vMax.x; - vTileFarMax.y = abs(fwT - fwB) * vMax.y; - - float TileFarL = fwL + vTileFarMin.x; - float TileFarR = fwL + vTileFarMax.x; - float TileFarB = fwB + vTileFarMin.y; - float TileFarT = fwB + vTileFarMax.y; - - V[4].Set(TileFarR, TileFarT, FarZ); - V[5].Set(TileFarL, TileFarT, FarZ); - V[6].Set(TileFarL, TileFarB, FarZ); - V[7].Set(TileFarR, TileFarB, FarZ); - - for (int i = 0; i < 8; i++) - { - V[i] = CamToWorld(V[i]); - } -} - /////////////////////////////////////////////////////////////////////////////// // Implements essential operations like calculation of a view-matrix and // frustum-culling with simple geometric primitives (Point, Sphere, AABB, OBB). @@ -538,98 +91,31 @@ public: ILINE static Matrix33 CreateOrientationYPR(const Ang3& ypr); ILINE static Ang3 CreateAnglesYPR(const Matrix33& m); ILINE static Ang3 CreateAnglesYPR(const Vec3& vdir, f32 r = 0); - ILINE static Vec3 CreateViewdir(const Ang3& ypr); - ILINE static Vec3 CreateViewdir(const Matrix33& m) { return m.GetColumn1(); }; ILINE void SetMatrix(const Matrix34& mat) { assert(mat.IsOrthonormal()); m_Matrix = mat; UpdateFrustum(); }; - ILINE void SetMatrixNoUpdate(const Matrix34& mat) { assert(mat.IsOrthonormal()); m_Matrix = mat; }; ILINE const Matrix34& GetMatrix() const { return m_Matrix; }; ILINE Vec3 GetViewdir() const { return m_Matrix.GetColumn1(); }; - ILINE void SetEntityRotation(const Quat& entityRot) { m_entityRot = entityRot; } - ILINE Quat GetEntityRotation() { return m_entityRot; } - ILINE void SetEntityPos(const Vec3& entityPos) { m_entityPos = entityPos; } - ILINE Vec3 GetEntityPos() const { return m_entityPos; }; - - ILINE Matrix34 GetViewMatrix() const { return m_Matrix.GetInverted(); }; ILINE Vec3 GetPosition() const { return m_Matrix.GetTranslation(); } ILINE void SetPosition(const Vec3& p) { m_Matrix.SetTranslation(p); UpdateFrustum(); } - ILINE void SetPositionNoUpdate(const Vec3& p) { m_Matrix.SetTranslation(p); } - ILINE Vec3 GetUp() const { return m_Matrix.GetColumn2(); } //------------------------------------------------------------ void SetFrustum(int nWidth, int nHeight, f32 FOV = DEFAULT_FOV, f32 nearplane = DEFAULT_NEAR, f32 farplane = DEFAULT_FAR, f32 fPixelAspectRatio = 1.0f); - ILINE void SetAsymmetry(float l, float r, float b, float t) { m_asymLeft = l; m_asymRight = r; m_asymBottom = b; m_asymTop = t; UpdateFrustum(); } - ILINE int GetViewSurfaceX() const { return m_Width; } ILINE int GetViewSurfaceZ() const { return m_Height; } ILINE f32 GetFov() const { return m_fov; } - ILINE float GetHorizontalFov() const; - ILINE f32 GetNearPlane() const { return m_edge_nlt.y; } - ILINE f32 GetFarPlane() const { return m_edge_flt.y; } - ILINE f32 GetProjRatio() const { return(m_ProjectionRatio); } - ILINE f32 GetAngularResolution() const { return m_Height / m_fov; } ILINE f32 GetPixelAspectRatio() const { return m_PixelAspectRatio; } - ILINE Vec3 GetEdgeP() const { return m_edge_plt; } - ILINE Vec3 GetEdgeN() const { return m_edge_nlt; } - ILINE Vec3 GetEdgeF() const { return m_edge_flt; } - - ILINE f32 GetAsymL() const { return m_asymLeft; } - ILINE f32 GetAsymR() const { return m_asymRight; } - ILINE f32 GetAsymB() const { return m_asymBottom; } - ILINE f32 GetAsymT() const { return m_asymTop; } - - ILINE const Vec3& GetNPVertex(int nId) const; //get near-plane vertices - ILINE const Vec3& GetFPVertex(int nId) const; //get far-plane vertices - ILINE const Vec3& GetPPVertex(int nId) const; //get projection-plane vertices - - ILINE const Plane_tpl* GetFrustumPlane(int numplane) const { return &m_fp[numplane]; } - - ////////////////////////////////////////////////////////////////////////// - // Z-Buffer ranges. - // This values are defining near/far clipping plane, it only used to specify z-buffer range. - // Use it only when you want to override default z-buffer range. - // Valid values for are: 0 <= zrange <= 1 - ////////////////////////////////////////////////////////////////////////// - ILINE void SetZRange(float zmin, float zmax) - { - // Clamp to 0-1 range. - m_zrangeMin = min(1.0f, max(0.0f, zmin)); - m_zrangeMax = min(1.0f, max(0.0f, zmax)); - }; - ILINE float GetZRangeMin() const { return m_zrangeMin; } - ILINE float GetZRangeMax() const { return m_zrangeMax; } ////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------------- //-------- Frustum-Culling ---------------------------- //----------------------------------------------------------------------------------- - //Check if a point lies within camera's frustum - bool IsPointVisible(const Vec3& p) const; - - //sphere-frustum test - bool IsSphereVisible_F(const ::Sphere& s) const; - uint8 IsSphereVisible_FH(const ::Sphere& s) const; //this is going to be the exact version of sphere-culling - // AABB-frustum test // Fast bool IsAABBVisible_F(const ::AABB& aabb) const; - uint8 IsAABBVisible_FH(const ::AABB& aabb, bool* pAllInside) const; - uint8 IsAABBVisible_FH(const ::AABB& aabb) const; - - // Exact - bool IsAABBVisible_E(const ::AABB& aabb) const; - uint8 IsAABBVisible_EH(const ::AABB& aabb, bool* pAllInside) const; - uint8 IsAABBVisible_EH(const ::AABB& aabb) const; - - //OBB-frustum test - bool IsOBBVisible_F(const Vec3& wpos, const OBB& obb) const; - uint8 IsOBBVisible_FH(const Vec3& wpos, const OBB& obb) const; - bool IsOBBVisible_E(const Vec3& wpos, const OBB& obb, f32 uscale) const; - uint8 IsOBBVisible_EH(const Vec3& wpos, const OBB& obb, f32 uscale) const; //## constructor/destructor CCamera() @@ -640,56 +126,23 @@ public: m_asymBottom = 0; m_asymTop = 0; SetFrustum(640, 480); - m_zrangeMin = 0.0f; - m_zrangeMax = 1.0f; - m_pPortal = NULL; - m_JustActivated = 0; m_nPosX = m_nPosY = m_nSizeX = m_nSizeY = 0; m_entityPos = Vec3(0, 0, 0); - m_entityRot = Quat(0, 0, 0, 1); } ~CCamera() {} - void GetFrustumVertices(Vec3* pVerts) const; - void GetFrustumVerticesCam(Vec3* pVerts) const; - - void SetJustActivated(const bool justActivated) {m_JustActivated = (int)justActivated; } - bool IsJustActivated() const {return m_JustActivated != 0; } - - void SetViewPort(int nPosX, int nPosY, int nSizeX, int nSizeY) - { - m_nPosX = nPosX; - m_nPosY = nPosY; - m_nSizeX = nSizeX; - m_nSizeY = nSizeY; - } - - void GetViewPort(int& nPosX, int& nPosY, int& nSizeX, int& nSizeY) const - { - nPosX = m_nPosX; - nPosY = m_nPosY; - nSizeX = m_nSizeX; - nSizeY = m_nSizeY; - } + void SetJustActivated([[maybe_unused]] const bool justActivated) {} void UpdateFrustum(); - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { /*nothing*/} - - CameraViewParameters m_viewParameters; private: - bool AdditionalCheck(const AABB& aabb) const; - bool AdditionalCheck(const Vec3& wpos, const OBB& obb, f32 uscale) const; - Matrix34 m_Matrix; // world space-matrix f32 m_fov; // vertical fov in radiants [0..1*PI[ int m_Width; // surface width-resolution int m_Height; // surface height-resolution - f32 m_ProjectionRatio; // ratio between width and height of view-surface f32 m_PixelAspectRatio; // accounts for aspect ratio and non-square pixels - Quat m_entityRot; //The rotation of this camera's entity (does not include HMD orientation) Vec3 m_entityPos; //The position of this camera's entity (does not include HMD position or stereo offsets) Vec3 m_edge_nlt; // this is the left/upper vertex of the near-plane @@ -709,81 +162,9 @@ private: uint32 m_idx1[FRUSTUM_PLANES], m_idy1[FRUSTUM_PLANES], m_idz1[FRUSTUM_PLANES]; // uint32 m_idx2[FRUSTUM_PLANES], m_idy2[FRUSTUM_PLANES], m_idz2[FRUSTUM_PLANES]; // - // Near Far range of the z-buffer to use for this camera. - float m_zrangeMin; - float m_zrangeMax; - int m_nPosX, m_nPosY, m_nSizeX, m_nSizeY; - - //------------------------------------------------------------------------ - //--- OLD STUFF - //------------------------------------------------------------------------ -public: - - void SetFrustumVertices(Vec3* arrvVerts) - { - m_clbp = arrvVerts[0]; - m_cltp = arrvVerts[1]; - m_crtp = arrvVerts[2]; - m_crbp = arrvVerts[3]; - } - inline void SetFrustumPlane(int i, const Plane_tpl& plane) - { - m_fp[i] = plane; - //do not break strict aliasing rules, use union instead of reinterpret_casts - union f32_u - { - float floatVal; - uint32 uintVal; - }; - - { - f32_u ux; - ux.floatVal = m_fp[i].n.x; - f32_u uy; - uy.floatVal = m_fp[i].n.y; - f32_u uz; - uz.floatVal = m_fp[i].n.z; - uint32 bitX = ux.uintVal >> 31; - uint32 bitY = uy.uintVal >> 31; - uint32 bitZ = uz.uintVal >> 31; - m_idx1[i] = bitX * 3 + 0; - m_idx2[i] = (1 - bitX) * 3 + 0; - m_idy1[i] = bitY * 3 + 1; - m_idy2[i] = (1 - bitY) * 3 + 1; - m_idz1[i] = bitZ * 3 + 2; - m_idz2[i] = (1 - bitZ) * 3 + 2; - } - } - - inline Ang3 GetAngles() const { return CreateAnglesYPR(Matrix33(m_Matrix)); } - void SetAngles(const Ang3& angles) { SetMatrix(Matrix34::CreateRotationXYZ(angles)); } - - - struct IVisArea* m_pPortal; // pointer to portal used to create this camera - struct ScissorInfo - { - ScissorInfo() { x1 = y1 = x2 = y2 = 0; } - uint16 x1, y1, x2, y2; - }; - ScissorInfo m_ScissorInfo; - - Vec3 m_OccPosition; //Position for calculate occlusions (needed for portals rendering) - inline const Vec3& GetOccPos() const { return(m_OccPosition); } - - int m_JustActivated; //Camera activated in this frame, used for disabling motion blur effect at camera changes in movies }; -inline float CCamera::GetHorizontalFov() const -{ - float fFractionVert = tanf(m_fov * 0.5f); - float fFractionHoriz = fFractionVert * GetProjRatio(); - float fHorizFov = atanf(fFractionHoriz) * 2; - - return fHorizFov; -} - - // Description // This function builds a 3x3 orientation matrix using YPR-angles // Rotation order for the orientation-matrix is Z-X-Y. (Zaxis=YAW / Xaxis=PITCH / Yaxis=ROLL) @@ -866,23 +247,6 @@ ILINE Ang3 CCamera::CreateAnglesYPR(const Vec3& vdir, f32 r) } } -// Description -//
-//x=yaw
-//y=pitch
-//z=roll (we ignore this element, since its not possible to convert the roll-component into a vector)
-// 
-ILINE Vec3 CCamera::CreateViewdir(const Ang3& ypr) -{ - assert(ypr.IsInRangePI()); //all angles need to be in range between -pi and +pi - f32 sz, cz; - sincos_tpl(ypr.x, &sz, &cz); //YAW - f32 sx, cx; - sincos_tpl(ypr.y, &sx, &cx); //PITCH - return Vec3(-sz * cx, cz * cx, sx); //calculate the view-direction -} - - //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- @@ -901,7 +265,6 @@ inline void CCamera::SetFrustum(int nWidth, int nHeight, f32 FOV, f32 nearplane, f32 fWidth = (((f32)nWidth) / fPixelAspectRatio); f32 fHeight = (f32) nHeight; - m_ProjectionRatio = fWidth / fHeight; // projection ratio (1.0 for square pixels) m_PixelAspectRatio = fPixelAspectRatio; @@ -1022,272 +385,8 @@ inline void CCamera::UpdateFrustum() m_idz1[i] = bitZ * 3 + 2; m_idz2[i] = (1 - bitZ) * 3 + 2; } - m_OccPosition = GetPosition(); } -// Summary -// Return frustum vertices in world space -// Description -// Takes pointer to array of 8 elements -inline void CCamera::GetFrustumVertices(Vec3* pVerts) const -{ - Matrix33 m33 = Matrix33(m_Matrix); - - /* - The frustum array contains points in the following order - - frustum[0] = far left top - frustum[1] = far left bottom - frustum[2] = far right bottom - frustum[3] = far right top - - frustum[4] = near left top - frustum[5] = near left bottom - frustum[6] = near right bottom - frustum[7] = near right top - */ - - int i = 0; - - pVerts[i++] = m33 * Vec3(+m_edge_flt.x, +m_edge_flt.y, +m_edge_flt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(+m_edge_flt.x, +m_edge_flt.y, -m_edge_flt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(-m_edge_flt.x, +m_edge_flt.y, -m_edge_flt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(-m_edge_flt.x, +m_edge_flt.y, +m_edge_flt.z) + GetPosition(); - - pVerts[i++] = m33 * Vec3(+m_edge_nlt.x, +m_edge_nlt.y, +m_edge_nlt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(+m_edge_nlt.x, +m_edge_nlt.y, -m_edge_nlt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(-m_edge_nlt.x, +m_edge_nlt.y, -m_edge_nlt.z) + GetPosition(); - pVerts[i++] = m33 * Vec3(-m_edge_nlt.x, +m_edge_nlt.y, +m_edge_nlt.z) + GetPosition(); -} - -inline void CCamera::GetFrustumVerticesCam(Vec3* pVerts) const -{ - int i = 0; - - //near plane - pVerts[i++] = Vec3(+m_edge_nlt.x, +m_edge_nlt.y, +m_edge_nlt.z); - pVerts[i++] = Vec3(+m_edge_nlt.x, +m_edge_nlt.y, -m_edge_nlt.z); - pVerts[i++] = Vec3(-m_edge_nlt.x, +m_edge_nlt.y, -m_edge_nlt.z); - pVerts[i++] = Vec3(-m_edge_nlt.x, +m_edge_nlt.y, +m_edge_nlt.z); - - //far plane - pVerts[i++] = Vec3(+m_edge_flt.x, +m_edge_flt.y, +m_edge_flt.z); - pVerts[i++] = Vec3(+m_edge_flt.x, +m_edge_flt.y, -m_edge_flt.z); - pVerts[i++] = Vec3(-m_edge_flt.x, +m_edge_flt.y, -m_edge_flt.z); - pVerts[i++] = Vec3(-m_edge_flt.x, +m_edge_flt.y, +m_edge_flt.z); -} - -//get near-plane vertices -ILINE const Vec3& CCamera::GetNPVertex(int nId) const -{ - switch (nId) - { - case 0: - return m_clbn; - case 1: - return m_cltn; - case 2: - return m_crtn; - case 3: - return m_crbn; - } - assert(0); - return m_clbn; -} -//get far-plane vertices -ILINE const Vec3& CCamera::GetFPVertex(int nId) const -{ - switch (nId) - { - case 0: - return m_clbf; - case 1: - return m_cltf; - case 2: - return m_crtf; - case 3: - return m_crbf; - } - assert(0); - return m_clbf; -} -ILINE const Vec3& CCamera::GetPPVertex(int nId) const -{ - switch (nId) - { - case 0: - return m_clbp; - case 1: - return m_cltp; - case 2: - return m_crtp; - case 3: - return m_crbp; - } - assert(0); - return m_clbp; -} - - - - -// Description -// Check if a point lies within camera's frustum -// -// Example -// u8 InOut=camera.IsPointVisible(point); -// -// return values -// CULL_EXCLUSION = point outside of frustum -// CULL_INTERSECT = point inside of frustum -inline bool CCamera::IsPointVisible(const Vec3& p) const -{ - if ((m_fp[FR_PLANE_NEAR ] | p) > 0) - { - return CULL_EXCLUSION; - } - if ((m_fp[FR_PLANE_RIGHT ] | p) > 0) - { - return CULL_EXCLUSION; - } - if ((m_fp[FR_PLANE_LEFT ] | p) > 0) - { - return CULL_EXCLUSION; - } - if ((m_fp[FR_PLANE_TOP ] | p) > 0) - { - return CULL_EXCLUSION; - } - if ((m_fp[FR_PLANE_BOTTOM] | p) > 0) - { - return CULL_EXCLUSION; - } - if ((m_fp[FR_PLANE_FAR ] | p) > 0) - { - return CULL_EXCLUSION; - } - return CULL_OVERLAP; -} - - - - - - - - -// Description -// Conventional method to check if a sphere and the camera-frustum overlap -// The center of the sphere is assumed to be in world-space. -// -// Example -// u8 InOut=camera.IsSphereVisible_F(sphere); -// -// return values -// CULL_EXCLUSION = sphere outside of frustum (very fast rejection-test) -// CULL_INTERSECT = sphere and frustum intersects or sphere in completely inside frustum -inline bool CCamera::IsSphereVisible_F(const ::Sphere& s) const -{ - if ((m_fp[0] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((m_fp[1] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((m_fp[2] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((m_fp[3] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((m_fp[4] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((m_fp[5] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - return CULL_OVERLAP; -} - -// Description -// Conventional method to check if a sphere and the camera-frustum overlap, or -// if the sphere is completely inside the camera-frustum. The center of the -// sphere is assumed to be in world-space. -// -// Example -// u8 InOut=camera.IsSphereVisible_FH(sphere); -// -// return values -// CULL_EXCLUSION = sphere outside of frustum (very fast rejection-test) -// CULL_INTERSECT = sphere intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = sphere is complete inside the frustum, no further checks necessary -inline uint8 CCamera::IsSphereVisible_FH(const ::Sphere& s) const -{ - f32 nc, rc, lc, tc, bc, cc; - if ((nc = m_fp[0] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((rc = m_fp[1] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((lc = m_fp[2] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((tc = m_fp[3] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((bc = m_fp[4] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - if ((cc = m_fp[5] | s.center) > s.radius) - { - return CULL_EXCLUSION; - } - - //now we have to check if it is completely in frustum - f32 r = -s.radius; - if (nc > r) - { - return CULL_OVERLAP; - } - if (lc > r) - { - return CULL_OVERLAP; - } - if (rc > r) - { - return CULL_OVERLAP; - } - if (tc > r) - { - return CULL_OVERLAP; - } - if (bc > r) - { - return CULL_OVERLAP; - } - if (cc > r) - { - return CULL_OVERLAP; - } - return CULL_INCLUSION; -} - - - - - // Description // Simple approach to check if an AABB and the camera-frustum overlap. The AABB // is assumed to be in world-space. This is a very fast method, just one single @@ -1349,789 +448,3 @@ inline bool CCamera::IsAABBVisible_F(const AABB& aabb) const } return CULL_OVERLAP; } - - -// Description -// Hierarchical approach to check if an AABB and the camera-frustum overlap, or if the AABB -// is totally inside the camera-frustum. The AABB is assumed to be in world-space. -// -// Example -// int InOut=camera.IsAABBVisible_FH(aabb); -// -// return values -// CULL_EXCLUSION = AABB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = AABB intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = AABB is complete inside the frustum, no further checks necessary - -inline uint8 CCamera::IsAABBVisible_FH(const AABB& aabb, bool* pAllInside) const -{ - assert(pAllInside && *pAllInside == false); - if (IsAABBVisible_F(aabb) == CULL_EXCLUSION) - { - return CULL_EXCLUSION; - } - const f32* p = &aabb.min.x; - uint32 x, y, z; - x = m_idx2[0]; - y = m_idy2[0]; - z = m_idz2[0]; - if ((m_fp[0] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[1]; - y = m_idy2[1]; - z = m_idz2[1]; - if ((m_fp[1] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[2]; - y = m_idy2[2]; - z = m_idz2[2]; - if ((m_fp[2] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[3]; - y = m_idy2[3]; - z = m_idz2[3]; - if ((m_fp[3] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[4]; - y = m_idy2[4]; - z = m_idz2[4]; - if ((m_fp[4] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[5]; - y = m_idy2[5]; - z = m_idz2[5]; - if ((m_fp[5] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - *pAllInside = true; - return CULL_INCLUSION; -} - -// Description -// Hierarchical approach to check if an AABB and the camera-frustum overlap, or if the AABB -// is totally inside the camera-frustum. The AABB is assumed to be in world-space. -// -// Example -// int InOut=camera.IsAABBVisible_FH(aabb); -// -// return values -// CULL_EXCLUSION = AABB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = AABB intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = AABB is complete inside the frustum, no further checks necessary -inline uint8 CCamera::IsAABBVisible_FH(const AABB& aabb) const -{ - if (IsAABBVisible_F(aabb) == CULL_EXCLUSION) - { - return CULL_EXCLUSION; - } - const f32* p = &aabb.min.x; - uint32 x, y, z; - x = m_idx2[0]; - y = m_idy2[0]; - z = m_idz2[0]; - if ((m_fp[0] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[1]; - y = m_idy2[1]; - z = m_idz2[1]; - if ((m_fp[1] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[2]; - y = m_idy2[2]; - z = m_idz2[2]; - if ((m_fp[2] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[3]; - y = m_idy2[3]; - z = m_idz2[3]; - if ((m_fp[3] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[4]; - y = m_idy2[4]; - z = m_idz2[4]; - if ((m_fp[4] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - x = m_idx2[5]; - y = m_idy2[5]; - z = m_idz2[5]; - if ((m_fp[5] | Vec3(p[x], p[y], p[z])) > 0) - { - return CULL_OVERLAP; - } - return CULL_INCLUSION; -} - - -// Description -// This function checks if an AABB and the camera-frustum overlap. The AABB is assumed to be in world-space. -// This test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. -// IMPORTANT: -// This function is only useful if you really need exact-culling. -// It's about 30% slower then "IsAABBVisible_F(aabb)" -// -// Example: -// int InOut=camera.IsAABBVisible_E(aabb); -// -// return values: -// CULL_EXCLUSION = AABB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = AABB either intersects the borders of the frustum or is totally inside -inline bool CCamera::IsAABBVisible_E(const AABB& aabb) const -{ - uint8 o = IsAABBVisible_FH(aabb); - if (o == CULL_EXCLUSION) - { - return CULL_EXCLUSION; - } - if (o == CULL_INCLUSION) - { - return CULL_OVERLAP; - } - return AdditionalCheck(aabb); //result is either "exclusion" or "overlap" -} - -// Description: -// Improved approach to check if an AABB and the camera-frustum overlap, or if the AABB -// is totally inside the camera-frustum. The AABB is assumed to be in world-space. This -// test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. -// IMPORTANT: -// This function is only useful if you really need exact-culling. -// It's about 30% slower then "IsAABBVisible_FH(aabb)" -// -// Example: -// int InOut=camera.IsAABBVisible_EH(aabb); -// -// return values: -// CULL_EXCLUSION = AABB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = AABB intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = AABB is complete inside the frustum, no further checks necessary -inline uint8 CCamera::IsAABBVisible_EH(const AABB& aabb, bool* pAllInside) const -{ - uint8 o = IsAABBVisible_FH(aabb, pAllInside); - if (o == CULL_EXCLUSION) - { - return CULL_EXCLUSION; - } - if (o == CULL_INCLUSION) - { - return CULL_INCLUSION; - } - return AdditionalCheck(aabb); //result is either "exclusion" or "overlap" -} - -// Description: -// Improved approach to check if an AABB and the camera-frustum overlap, or if the AABB -// is totally inside the camera-frustum. The AABB is assumed to be in world-space. This -// test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. -// IMPORTANT: -// This function is only useful if you really need exact-culling. -// It's about 30% slower then "IsAABBVisible_FH(aabb)" -// -// Example: -// int InOut=camera.IsAABBVisible_EH(aabb); -// -// return values: -// CULL_EXCLUSION = AABB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = AABB intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = AABB is complete inside the frustum, no further checks necessary -inline uint8 CCamera::IsAABBVisible_EH(const AABB& aabb) const -{ - uint8 o = IsAABBVisible_FH(aabb); - if (o == CULL_EXCLUSION) - { - return CULL_EXCLUSION; - } - if (o == CULL_INCLUSION) - { - return CULL_INCLUSION; - } - return AdditionalCheck(aabb); //result is either "exclusion" or "overlap" -} - - - -// Description -// Fast check if an OBB and the camera-frustum overlap, using the separating-axis-theorem (SAT) -// The center of the OOBB is assumed to be in world-space. -// NOTE: even if the OBB is totally inside the frustum, this function returns CULL_OVERLAP -// For hierarchical frustum-culling this function is not perfect. -// -// Example: -// bool InOut=camera.IsOBBVisibleFast(obb); -// -// return values: -// CULL_EXCLUSION = OBB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = OBB and frustum intersects or OBB in totally inside frustum -inline bool CCamera::IsOBBVisible_F(const Vec3& wpos, const OBB& obb) const -{ - CRY_ASSERT(obb.m33.IsOrthonormalRH(0.001f)); - - //transform the obb-center into world-space - Vec3 p = obb.m33 * obb.c + wpos; - - //extract the orientation-vectors from the columns of the 3x3 matrix - //and scale them by the half-lengths - Vec3 ax = obb.m33.GetColumn0() * obb.h.x; - Vec3 ay = obb.m33.GetColumn1() * obb.h.y; - Vec3 az = obb.m33.GetColumn2() * obb.h.z; - - //we project the axes of the OBB onto the normal of each of the 6 planes. - //If the absolute value of the distance from the center of the OBB to the plane - //is larger then the "radius" of the OBB, then the OBB is outside the frustum. - f32 t; - if ((t = m_fp[0] | p) > 0.0f) - { - if (t > (fabsf(m_fp[0].n | ax) + fabsf(m_fp[0].n | ay) + fabsf(m_fp[0].n | az))) - { - return CULL_EXCLUSION; - } - } - if ((t = m_fp[1] | p) > 0.0f) - { - if (t > (fabsf(m_fp[1].n | ax) + fabsf(m_fp[1].n | ay) + fabsf(m_fp[1].n | az))) - { - return CULL_EXCLUSION; - } - } - if ((t = m_fp[2] | p) > 0.0f) - { - if (t > (fabsf(m_fp[2].n | ax) + fabsf(m_fp[2].n | ay) + fabsf(m_fp[2].n | az))) - { - return CULL_EXCLUSION; - } - } - if ((t = m_fp[3] | p) > 0.0f) - { - if (t > (fabsf(m_fp[3].n | ax) + fabsf(m_fp[3].n | ay) + fabsf(m_fp[3].n | az))) - { - return CULL_EXCLUSION; - } - } - if ((t = m_fp[4] | p) > 0.0f) - { - if (t > (fabsf(m_fp[4].n | ax) + fabsf(m_fp[4].n | ay) + fabsf(m_fp[4].n | az))) - { - return CULL_EXCLUSION; - } - } - if ((t = m_fp[5] | p) > 0.0f) - { - if (t > (fabsf(m_fp[5].n | ax) + fabsf(m_fp[5].n | ay) + fabsf(m_fp[5].n | az))) - { - return CULL_EXCLUSION; - } - } - - //probably the OBB is visible! - //With this test we can't be sure if the OBB partially visible or totally included or - //totally outside the frustum but still intersecting one of the 6 planes (=worst case) - return CULL_OVERLAP; -} - -ILINE uint8 CCamera::IsOBBVisible_FH([[maybe_unused]] const Vec3& wpos, [[maybe_unused]] const OBB& obb) const -{ - //not implemented yet - return CULL_EXCLUSION; -} - -// Description: -// This function checks if an OBB and the camera-frustum overlap. -// This test can reject even such OBBs that overlap a frustum-plane -// far outside the view-frustum. -// IMPORTANT: It is about 10% slower then "IsOBBVisibleFast(obb)" -// -// Example: -// int InOut=camera.IsOBBVisible_E(OBB); -// -// return values: -// CULL_EXCLUSION = OBB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = OBB intersects the borders of the frustum or is totally inside -inline bool CCamera::IsOBBVisible_E(const Vec3& wpos, const OBB& obb, f32 uscale = 1.0f) const -{ - assert(obb.m33.IsOrthonormalRH(0.001f)); - - //transform the obb-center into world-space - Vec3 p = obb.m33 * obb.c * uscale + wpos; - - //extract the orientation-vectors from the columns of the 3x3 matrix - //and scale them by the half-lengths - Vec3 ax = obb.m33.GetColumn0() * obb.h.x * uscale; - Vec3 ay = obb.m33.GetColumn1() * obb.h.y * uscale; - Vec3 az = obb.m33.GetColumn2() * obb.h.z * uscale; - - //we project the axes of the OBB onto the normal of each of the 6 planes. - //If the absolute value of the distance from the center of the OBB to the plane - //is larger then the "radius" of the OBB, then the OBB is outside the frustum. - f32 t0, t1, t2, t3, t4, t5; - bool mt0, mt1, mt2, mt3, mt4, mt5; - mt0 = (t0 = m_fp[0] | p) > 0.0f; - if (mt0) - { - if (t0 > (fabsf(m_fp[0].n | ax) + fabsf(m_fp[0].n | ay) + fabsf(m_fp[0].n | az))) - { - return CULL_EXCLUSION; - } - } - mt1 = (t1 = m_fp[1] | p) > 0.0f; - if (mt1) - { - if (t1 > (fabsf(m_fp[1].n | ax) + fabsf(m_fp[1].n | ay) + fabsf(m_fp[1].n | az))) - { - return CULL_EXCLUSION; - } - } - mt2 = (t2 = m_fp[2] | p) > 0.0f; - if (mt2) - { - if (t2 > (fabsf(m_fp[2].n | ax) + fabsf(m_fp[2].n | ay) + fabsf(m_fp[2].n | az))) - { - return CULL_EXCLUSION; - } - } - mt3 = (t3 = m_fp[3] | p) > 0.0f; - if (mt3) - { - if (t3 > (fabsf(m_fp[3].n | ax) + fabsf(m_fp[3].n | ay) + fabsf(m_fp[3].n | az))) - { - return CULL_EXCLUSION; - } - } - mt4 = (t4 = m_fp[4] | p) > 0.0f; - if (mt4) - { - if (t4 > (fabsf(m_fp[4].n | ax) + fabsf(m_fp[4].n | ay) + fabsf(m_fp[4].n | az))) - { - return CULL_EXCLUSION; - } - } - mt5 = (t5 = m_fp[5] | p) > 0.0f; - if (mt5) - { - if (t5 > (fabsf(m_fp[5].n | ax) + fabsf(m_fp[5].n | ay) + fabsf(m_fp[5].n | az))) - { - return CULL_EXCLUSION; - } - } - - //if obb-center is in view-frustum, then stop further calculation - if (!(mt0 | mt1 | mt2 | mt3 | mt4 | mt5)) - { - return CULL_OVERLAP; - } - - return AdditionalCheck(wpos, obb, uscale); -} - - -// Description: -// Improved approach to check if an OBB and the camera-frustum intersect, or if the OBB -// is totally inside the camera-frustum. The bounding-box of the OBB is assumed to be -// in world-space. This test can reject even such OBBs that intersect a frustum-plane far -// outside the view-frustum -// -// Example: -// int InOut=camera.IsOBBVisible_EH(obb); -// -// return values: -// CULL_EXCLUSION = OBB outside of frustum (very fast rejection-test) -// CULL_OVERLAP = OBB intersects the borders of the frustum, further checks necessary -// CULL_INCLUSION = OBB is complete inside the frustum, no further checks necessary -inline uint8 CCamera::IsOBBVisible_EH(const Vec3& wpos, const OBB& obb, f32 uscale = 1.0f) const -{ - assert(obb.m33.IsOrthonormalRH(0.001f)); - //transform the obb-center into world-space - Vec3 p = obb.m33 * obb.c * uscale + wpos; - - //extract the orientation-vectors from the columns of the 3x3 matrix - //and scale them by the half-lengths - Vec3 ax = obb.m33.GetColumn0() * obb.h.x * uscale; - Vec3 ay = obb.m33.GetColumn1() * obb.h.y * uscale; - Vec3 az = obb.m33.GetColumn2() * obb.h.z * uscale; - - //we project the axes of the OBB onto the normal of each of the 6 planes. - //If the absolute value of the distance from the center of the OBB to the plane - //is larger then the "radius" of the OBB, then the OBB is outside the frustum. - f32 t0, t1, t2, t3, t4, t5; - bool mt0, mt1, mt2, mt3, mt4, mt5; - if (mt0 = (t0 = m_fp[0] | p) > 0.0f) - { - if (t0 > (fabsf(m_fp[0].n | ax) + fabsf(m_fp[0].n | ay) + fabsf(m_fp[0].n | az))) - { - return CULL_EXCLUSION; - } - } - if (mt1 = (t1 = m_fp[1] | p) > 0.0f) - { - if (t1 > (fabsf(m_fp[1].n | ax) + fabsf(m_fp[1].n | ay) + fabsf(m_fp[1].n | az))) - { - return CULL_EXCLUSION; - } - } - if (mt2 = (t2 = m_fp[2] | p) > 0.0f) - { - if (t2 > (fabsf(m_fp[2].n | ax) + fabsf(m_fp[2].n | ay) + fabsf(m_fp[2].n | az))) - { - return CULL_EXCLUSION; - } - } - if (mt3 = (t3 = m_fp[3] | p) > 0.0f) - { - if (t3 > (fabsf(m_fp[3].n | ax) + fabsf(m_fp[3].n | ay) + fabsf(m_fp[3].n | az))) - { - return CULL_EXCLUSION; - } - } - if (mt4 = (t4 = m_fp[4] | p) > 0.0f) - { - if (t4 > (fabsf(m_fp[4].n | ax) + fabsf(m_fp[4].n | ay) + fabsf(m_fp[4].n | az))) - { - return CULL_EXCLUSION; - } - } - if (mt5 = (t5 = m_fp[5] | p) > 0.0f) - { - if (t5 > (fabsf(m_fp[5].n | ax) + fabsf(m_fp[5].n | ay) + fabsf(m_fp[5].n | az))) - { - return CULL_EXCLUSION; - } - } - - //check if obb-center is in view-frustum - if (!(mt0 | mt1 | mt2 | mt3 | mt4 | mt5)) - { - //yes, it is! - //and now check if OBB is totally included - if (-t0 < (fabsf(m_fp[0].n | ax) + fabsf(m_fp[0].n | ay) + fabsf(m_fp[0].n | az))) - { - return CULL_OVERLAP; - } - if (-t1 < (fabsf(m_fp[1].n | ax) + fabsf(m_fp[1].n | ay) + fabsf(m_fp[1].n | az))) - { - return CULL_OVERLAP; - } - if (-t2 < (fabsf(m_fp[2].n | ax) + fabsf(m_fp[2].n | ay) + fabsf(m_fp[2].n | az))) - { - return CULL_OVERLAP; - } - if (-t3 < (fabsf(m_fp[3].n | ax) + fabsf(m_fp[3].n | ay) + fabsf(m_fp[3].n | az))) - { - return CULL_OVERLAP; - } - if (-t4 < (fabsf(m_fp[4].n | ax) + fabsf(m_fp[4].n | ay) + fabsf(m_fp[4].n | az))) - { - return CULL_OVERLAP; - } - if (-t5 < (fabsf(m_fp[5].n | ax) + fabsf(m_fp[5].n | ay) + fabsf(m_fp[5].n | az))) - { - return CULL_OVERLAP; - } - return CULL_INCLUSION; - } - return AdditionalCheck(wpos, obb, uscale); -} - -//------------------------------------------------------------------------------ -//--- ADDITIONAL-TEST --- -//------------------------------------------------------------------------------ - -alignas(64) extern uint32 BoxSides[]; - -// Description: -// A box can easily straddle one of the view-frustum planes far -// outside the view-frustum and in this case the previous test would -// return CULL_OVERLAP. -// -// Note: With this check, we make sure the AABB is really not visble -NO_INLINE_WEAK bool CCamera::AdditionalCheck(const AABB& aabb) const -{ - Vec3d m = (aabb.min + aabb.max) * 0.5; - uint32 o = 1; //will be reset to 0 if center is outside - o &= isneg(m_fp[0] | m); - o &= isneg(m_fp[2] | m); - o &= isneg(m_fp[3] | m); - o &= isneg(m_fp[4] | m); - o &= isneg(m_fp[5] | m); - o &= isneg(m_fp[1] | m); - if (o) - { - return CULL_OVERLAP; //if obb-center is in view-frustum, then stop further calculation - } - Vec3d vmin(aabb.min - GetPosition()); //AABB in camera-space - Vec3d vmax(aabb.max - GetPosition()); //AABB in camera-space - - uint32 frontx8 = 0; // make the flags using the fact that the upper bit in f32 is its sign - - union f64_u - { - f64 floatVal; - int64 intVal; - }; - f64_u uminx, uminy, uminz, umaxx, umaxy, umaxz; - uminx.floatVal = vmin.x; - uminy.floatVal = vmin.y; - uminz.floatVal = vmin.z; - umaxx.floatVal = vmax.x; - umaxy.floatVal = vmax.y; - umaxz.floatVal = vmax.z; - - frontx8 |= (-uminx.intVal >> 0x3f) & 0x008; //if (AABB.min.x>0.0f) frontx8|=0x008; - frontx8 |= (umaxx.intVal >> 0x3f) & 0x010; //if (AABB.max.x<0.0f) frontx8|=0x010; - frontx8 |= (-uminy.intVal >> 0x3f) & 0x020; //if (AABB.min.y>0.0f) frontx8|=0x020; - frontx8 |= (umaxy.intVal >> 0x3f) & 0x040; //if (AABB.max.y<0.0f) frontx8|=0x040; - frontx8 |= (-uminz.intVal >> 0x3f) & 0x080; //if (AABB.min.z>0.0f) frontx8|=0x080; - frontx8 |= (umaxz.intVal >> 0x3f) & 0x100; //if (AABB.max.z<0.0f) frontx8|=0x100; - - //check if camera is inside the aabb - if (frontx8 == 0) - { - return CULL_OVERLAP; //AABB is patially visible - } - Vec3d v[8] = { - Vec3d(vmin.x, vmin.y, vmin.z), - Vec3d(vmax.x, vmin.y, vmin.z), - Vec3d(vmin.x, vmax.y, vmin.z), - Vec3d(vmax.x, vmax.y, vmin.z), - Vec3d(vmin.x, vmin.y, vmax.z), - Vec3d(vmax.x, vmin.y, vmax.z), - Vec3d(vmin.x, vmax.y, vmax.z), - Vec3d(vmax.x, vmax.y, vmax.z) - }; - - //--------------------------------------------------------------------- - //--- find the silhouette-vertices of the AABB --- - //--------------------------------------------------------------------- - uint32 p0 = BoxSides[frontx8 + 0]; - uint32 p1 = BoxSides[frontx8 + 1]; - uint32 p2 = BoxSides[frontx8 + 2]; - uint32 p3 = BoxSides[frontx8 + 3]; - uint32 p4 = BoxSides[frontx8 + 4]; - uint32 p5 = BoxSides[frontx8 + 5]; - uint32 sideamount = BoxSides[frontx8 + 7]; - - if (sideamount == 4) - { - //-------------------------------------------------------------------------- - //--- we take the 4 vertices of projection-plane in cam-space, --- - //----- and clip them against the 4 side-frustum-planes of the AABB - - //-------------------------------------------------------------------------- - Vec3d s0 = v[p0] % v[p1]; - if ((s0 | m_cltp) > 0 && (s0 | m_crtp) > 0 && (s0 | m_crbp) > 0 && (s0 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s1 = v[p1] % v[p2]; - if ((s1 | m_cltp) > 0 && (s1 | m_crtp) > 0 && (s1 | m_crbp) > 0 && (s1 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s2 = v[p2] % v[p3]; - if ((s2 | m_cltp) > 0 && (s2 | m_crtp) > 0 && (s2 | m_crbp) > 0 && (s2 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s3 = v[p3] % v[p0]; - if ((s3 | m_cltp) > 0 && (s3 | m_crtp) > 0 && (s3 | m_crbp) > 0 && (s3 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - } - - if (sideamount == 6) - { - //-------------------------------------------------------------------------- - //--- we take the 4 vertices of projection-plane in cam-space, --- - //--- and clip them against the 6 side-frustum-planes of the AABB --- - //-------------------------------------------------------------------------- - Vec3d s0 = v[p0] % v[p1]; - if ((s0 | m_cltp) > 0 && (s0 | m_crtp) > 0 && (s0 | m_crbp) > 0 && (s0 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s1 = v[p1] % v[p2]; - if ((s1 | m_cltp) > 0 && (s1 | m_crtp) > 0 && (s1 | m_crbp) > 0 && (s1 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s2 = v[p2] % v[p3]; - if ((s2 | m_cltp) > 0 && (s2 | m_crtp) > 0 && (s2 | m_crbp) > 0 && (s2 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s3 = v[p3] % v[p4]; - if ((s3 | m_cltp) > 0 && (s3 | m_crtp) > 0 && (s3 | m_crbp) > 0 && (s3 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s4 = v[p4] % v[p5]; - if ((s4 | m_cltp) > 0 && (s4 | m_crtp) > 0 && (s4 | m_crbp) > 0 && (s4 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - Vec3d s5 = v[p5] % v[p0]; - if ((s5 | m_cltp) > 0 && (s5 | m_crtp) > 0 && (s5 | m_crbp) > 0 && (s5 | m_clbp) > 0) - { - return CULL_EXCLUSION; - } - } - return CULL_OVERLAP; //AABB is patially visible -} - -//------------------------------------------------------------------------------ -//--- ADDITIONAL-TEST --- -//------------------------------------------------------------------------------ - -// Description: -// A box can easily straddle one of the view-frustum planes far -// outside the view-frustum and in this case the previous test would -// return CULL_OVERLAP. -// Note: -// With this check, we make sure the OBB is really not visible -NO_INLINE_WEAK bool CCamera::AdditionalCheck(const Vec3& wpos, const OBB& obb, f32 uscale) const -{ - Vec3 CamInOBBSpace = wpos - GetPosition(); - Vec3 iCamPos = -CamInOBBSpace * obb.m33; - uint32 front8 = 0; - AABB aabb = AABB((obb.c - obb.h) * uscale, (obb.c + obb.h) * uscale); - if (iCamPos.x < aabb.min.x) - { - front8 |= 0x008; - } - if (iCamPos.x > aabb.max.x) - { - front8 |= 0x010; - } - if (iCamPos.y < aabb.min.y) - { - front8 |= 0x020; - } - if (iCamPos.y > aabb.max.y) - { - front8 |= 0x040; - } - if (iCamPos.z < aabb.min.z) - { - front8 |= 0x080; - } - if (iCamPos.z > aabb.max.z) - { - front8 |= 0x100; - } - - if (front8 == 0) - { - return CULL_OVERLAP; - } - - //the transformed OBB-vertices in cam-space - Vec3 v[8] = { - obb.m33 * Vec3(aabb.min.x, aabb.min.y, aabb.min.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.max.x, aabb.min.y, aabb.min.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.min.x, aabb.max.y, aabb.min.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.max.x, aabb.max.y, aabb.min.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.min.x, aabb.min.y, aabb.max.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.max.x, aabb.min.y, aabb.max.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.min.x, aabb.max.y, aabb.max.z) + CamInOBBSpace, - obb.m33 * Vec3(aabb.max.x, aabb.max.y, aabb.max.z) + CamInOBBSpace - }; - - //--------------------------------------------------------------------- - //--- find the silhouette-vertices of the OBB --- - //--------------------------------------------------------------------- - uint32 p0 = BoxSides[front8 + 0]; - uint32 p1 = BoxSides[front8 + 1]; - uint32 p2 = BoxSides[front8 + 2]; - uint32 p3 = BoxSides[front8 + 3]; - uint32 p4 = BoxSides[front8 + 4]; - uint32 p5 = BoxSides[front8 + 5]; - uint32 sideamount = BoxSides[front8 + 7]; - - if (sideamount == 4) - { - //-------------------------------------------------------------------------- - //--- we take the 4 vertices of projection-plane in cam-space, --- - //----- and clip them against the 4 side-frustum-planes of the OBB - - //-------------------------------------------------------------------------- - Vec3 s0 = v[p0] % v[p1]; - if (((s0 | m_cltp) >= 0) && ((s0 | m_crtp) >= 0) && ((s0 | m_crbp) >= 0) && ((s0 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s1 = v[p1] % v[p2]; - if (((s1 | m_cltp) >= 0) && ((s1 | m_crtp) >= 0) && ((s1 | m_crbp) >= 0) && ((s1 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s2 = v[p2] % v[p3]; - if (((s2 | m_cltp) >= 0) && ((s2 | m_crtp) >= 0) && ((s2 | m_crbp) >= 0) && ((s2 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s3 = v[p3] % v[p0]; - if (((s3 | m_cltp) >= 0) && ((s3 | m_crtp) >= 0) && ((s3 | m_crbp) >= 0) && ((s3 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - } - - if (sideamount == 6) - { - //-------------------------------------------------------------------------- - //--- we take the 4 vertices of projection-plane in cam-space, --- - //--- and clip them against the 6 side-frustum-planes of the OBB --- - //-------------------------------------------------------------------------- - Vec3 s0 = v[p0] % v[p1]; - if (((s0 | m_cltp) >= 0) && ((s0 | m_crtp) >= 0) && ((s0 | m_crbp) >= 0) && ((s0 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s1 = v[p1] % v[p2]; - if (((s1 | m_cltp) >= 0) && ((s1 | m_crtp) >= 0) && ((s1 | m_crbp) >= 0) && ((s1 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s2 = v[p2] % v[p3]; - if (((s2 | m_cltp) >= 0) && ((s2 | m_crtp) >= 0) && ((s2 | m_crbp) >= 0) && ((s2 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s3 = v[p3] % v[p4]; - if (((s3 | m_cltp) >= 0) && ((s3 | m_crtp) >= 0) && ((s3 | m_crbp) >= 0) && ((s3 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s4 = v[p4] % v[p5]; - if (((s4 | m_cltp) >= 0) && ((s4 | m_crtp) >= 0) && ((s4 | m_crbp) >= 0) && ((s4 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - Vec3 s5 = v[p5] % v[p0]; - if (((s5 | m_cltp) >= 0) && ((s5 | m_crtp) >= 0) && ((s5 | m_crbp) >= 0) && ((s5 | m_clbp) >= 0)) - { - return CULL_EXCLUSION; - } - } - //now we are 100% sure that the OBB is visible on the screen - return CULL_OVERLAP; -} - -#endif // CRYINCLUDE_CRYCOMMON_CRY_CAMERA_H diff --git a/Code/Legacy/CryCommon/Cry_Color.h b/Code/Legacy/CryCommon/Cry_Color.h index 4f00f0c373..7fae67c284 100644 --- a/Code/Legacy/CryCommon/Cry_Color.h +++ b/Code/Legacy/CryCommon/Cry_Color.h @@ -8,21 +8,12 @@ // Description : 4D Color template. - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_COLOR_H -#define CRYINCLUDE_CRYCOMMON_CRY_COLOR_H #pragma once #include #include #include "Cry_Math.h" -ILINE float FClamp(float X, float Min, float Max) -{ - return X < Min ? Min : X < Max ? X : Max; -} - template struct Color_tpl; @@ -54,44 +45,6 @@ struct Color_tpl ILINE Color_tpl(const Vec3& c, float fAlpha); ILINE Color_tpl(const Vec4& c); - void Clamp(float Min = 0, float Max = 1.0f) - { - r = ::FClamp(r, Min, Max); - g = ::FClamp(g, Min, Max); - b = ::FClamp(b, Min, Max); - a = ::FClamp(a, Min, Max); - } - void ScaleCol (float f) - { - r = static_cast(r * f); - g = static_cast(g * f); - b = static_cast(b * f); - } - - float Luminance() const - { - return r * 0.30f + g * 0.59f + b * 0.11f; - } - - ILINE float Max() const - { - return max(r, max(b, g)); - } - - float NormalizeCol (ColorF& out) const - { - float max = Max(); - - if (max == 0) - { - return 0; - } - - out = *this / max; - - return max; - } - ILINE Color_tpl(const Vec3& vVec) { r = (T)vVec.x; @@ -114,20 +67,6 @@ struct Color_tpl a = static_cast(fA); } - ILINE void set(T _x, T _y = 0, T _z = 0, T _w = 0) - { - r = _x; - g = _y; - b = _z; - a = _w; - } - ILINE void set(T _x, T _y = 0, T _z = 0) - { - r = _x; - g = _y; - b = _z; - a = 1; - } ILINE Color_tpl operator + () const { return *this; @@ -227,117 +166,12 @@ struct Color_tpl return (r != v.r) || (g != v.g) || (b != v.b) || (a != v.a); } - ILINE unsigned char pack_rgb332() const; - ILINE unsigned short pack_argb4444() const; - ILINE unsigned short pack_rgb555() const; - ILINE unsigned short pack_rgb565() const; - ILINE unsigned int pack_bgr888() const; - ILINE unsigned int pack_rgb888() const; ILINE unsigned int pack_abgr8888() const; ILINE unsigned int pack_argb8888() const; - inline Vec4 toVec4() const { return Vec4(r, g, b, a); } inline Vec3 toVec3() const { return Vec3(r, g, b); } - inline void toFloat4(f32* out) const; - - inline void toHSV(f32& h, f32& s, f32& v) const; - inline void fromHSV(f32 h, f32 s, f32 v); inline void clamp(T bottom = 0.0f, T top = 1.0f); - inline void maximum(const Color_tpl& ca, const Color_tpl& cb); - inline void minimum(const Color_tpl& ca, const Color_tpl& cb); - inline void abs(); - - inline void adjust_contrast(T c); - inline void adjust_saturation(T s); - inline void adjust_luminance(float newLum); - - inline void lerpFloat(const Color_tpl& ca, const Color_tpl& cb, float s); - inline void negative(const Color_tpl& c); - inline void grey(const Color_tpl& c); - - // helper function - maybe we can improve the integration - static inline uint32 ComputeAvgCol_Fast(const uint32 dwCol0, const uint32 dwCol1) - { - uint32 dwHalfCol0 = (dwCol0 / 2) & 0x7f7f7f7f; // each component /2 - uint32 dwHalfCol1 = (dwCol1 / 2) & 0x7f7f7f7f; // each component /2 - - return dwHalfCol0 + dwHalfCol1; - } - - // mCIE: adjusted to compensate problems of DXT compression (extra bit in green channel causes green/purple artifacts) - // explained in CryEngine wiki: ColorSpaces - Color_tpl RGB2mCIE() const - { - Color_tpl in = *this; - - // to get grey chrominance for dark colors - in.r += 0.000001f; - in.g += 0.000001f; - in.b += 0.000001f; - - float RGBSum = in.r + in.g + in.b; - - float fInv = 1.0f / RGBSum; - - float RNorm = 3 * 10.0f / 31.0f * in.r * fInv; - float GNorm = 3 * 21.0f / 63.0f * in.g * fInv; - float Scale = RGBSum / 3.0f; - - // test grey - // out.r = 10.0f/31.0f; // 1/3 = 10/30 Red range 0..30, 31 unused - // out.g = 21.0f/63.0f; // 1/3 = 21/63 Green range 0..63 - - RNorm = max(0.0f, min(1.0f, RNorm)); - GNorm = max(0.0f, min(1.0f, GNorm)); - - return Color_tpl(RNorm, GNorm, Scale); - } - - // mCIE: adjusted to compensate problems of DXT compression (extra bit in green channel causes green/purple artefacts) - // explained in CryEngine wiki: ColorSpaces - Color_tpl mCIE2RGB() const - { - Color_tpl out = *this; - - float fScale = out.b; // Blue range 0..31 - - // test grey - // out.r = 10.0f/31.0f; // 1/3 = 10/30 Red range 0..30, 31 unused - // out.g = 21.0f/63.0f; // 1/3 = 21/63 Green range 0..63 - - out.r *= 31.0f / 30.0f; // - out.g *= 63.0f / 63.0f; // - out.b = 0.999f - out.r - out.g; - - float s = 3.0f * fScale; - - out.r *= s; - out.g *= s; - out.b *= s; - - out.Clamp(); - - return out; - } - - void rgb2srgb() - { - for (int i = 0; i < 3; i++) - { - T& c = (*this)[i]; - - if (c < 0.0031308f) - { - c = 12.92f * c; - } - else - { - c = 1.055f * pow(c, 1.0f / 2.4f) - 0.055f; - } - } - } - void srgb2rgb() { for (int i = 0; i < 3; i++) @@ -355,8 +189,6 @@ struct Color_tpl } } - void GetMemoryUsage([[maybe_unused]] class ICrySizer* pSizer) const { /*nothing*/} - AZStd::array GetAsArray() const { AZStd::array primitiveArray = { { r, g, b, a } }; @@ -512,35 +344,10 @@ ILINE Color_tpl::Color_tpl(const Vec4& c) a = (uint8)(c.w * 255); } -template<> -inline void Color_tpl::toFloat4(f32* out) const -{ - out[0] = r / 255.0f; - out[1] = g / 255.0f; - out[2] = b / 255.0f; - out[3] = a / 255.0f; -} - -template<> -inline void Color_tpl::toFloat4(f32* out) const -{ - out[0] = r; - out[1] = g; - out[2] = b; - out[3] = a; -} - ////////////////////////////////////////////////////////////////////////////////////////////// // functions implementation /////////////////////////////////////////////// -/////////////////////////////////////////////// -/*template -inline Color_tpl::Color_tpl(const T *p_elts) -{ -r = p_elts[0]; g = p_elts[1]; b = p_elts[2]; a = p_elts[3]; -}*/ - /////////////////////////////////////////////// /////////////////////////////////////////////// template @@ -549,178 +356,6 @@ ILINE Color_tpl operator * (T s, const Color_tpl& v) return Color_tpl(v.r * s, v.g * s, v.b * s, v.a * s); } -/////////////////////////////////////////////// -template -ILINE unsigned char Color_tpl::pack_rgb332() const -{ - unsigned char cr; - unsigned char cg; - unsigned char cb; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned char)r; - cg = (unsigned char)g; - cb = (unsigned char)b; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - } - else // float or double - { - cr = (unsigned char)(r * 255.0f); - cg = (unsigned char)(g * 255.0f); - cb = (unsigned char)(b * 255.0f); - } - return ((cr >> 5) << 5) | ((cg >> 5) << 2) | (cb >> 5); -} - -/////////////////////////////////////////////// -template -ILINE unsigned short Color_tpl::pack_argb4444() const -{ - unsigned char cr; - unsigned char cg; - unsigned char cb; - unsigned char ca; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned char)r; - cg = (unsigned char)g; - cb = (unsigned char)b; - ca = (unsigned char)a; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - ca = (unsigned short)(a) >> 8; - } - else // float or double - { - cr = (unsigned char)(r * 255.0f); - cg = (unsigned char)(g * 255.0f); - cb = (unsigned char)(b * 255.0f); - ca = (unsigned char)(a * 255.0f); - } - return ((ca >> 4) << 12) | ((cr >> 4) << 8) | ((cg >> 4) << 4) | (cb >> 4); -} - -/////////////////////////////////////////////// -template -ILINE unsigned short Color_tpl::pack_rgb555() const -{ - unsigned char cr; - unsigned char cg; - unsigned char cb; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned char)r; - cg = (unsigned char)g; - cb = (unsigned char)b; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - } - else // float or double - { - cr = (unsigned char)(r * 255.0f); - cg = (unsigned char)(g * 255.0f); - cb = (unsigned char)(b * 255.0f); - } - return ((cr >> 3) << 10) | ((cg >> 3) << 5) | (cb >> 3); -} - -/////////////////////////////////////////////// -template -ILINE unsigned short Color_tpl::pack_rgb565() const -{ - unsigned short cr; - unsigned short cg; - unsigned short cb; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned short)r; - cg = (unsigned short)g; - cb = (unsigned short)b; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - } - else // float or double - { - cr = (unsigned short)(r * 255.0f); - cg = (unsigned short)(g * 255.0f); - cb = (unsigned short)(b * 255.0f); - } - return ((cr >> 3) << 11) | ((cg >> 2) << 5) | (cb >> 3); -} - -/////////////////////////////////////////////// -template -ILINE unsigned int Color_tpl::pack_bgr888() const -{ - unsigned char cr; - unsigned char cg; - unsigned char cb; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned char)r; - cg = (unsigned char)g; - cb = (unsigned char)b; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - } - else // float or double - { - cr = (unsigned char)(r * 255.0f); - cg = (unsigned char)(g * 255.0f); - cb = (unsigned char)(b * 255.0f); - } - return (cb << 16) | (cg << 8) | cr; -} - -/////////////////////////////////////////////// -template -ILINE unsigned int Color_tpl::pack_rgb888() const -{ - unsigned char cr; - unsigned char cg; - unsigned char cb; - if constexpr (sizeof(r) == 1) // char and unsigned char - { - cr = (unsigned char)r; - cg = (unsigned char)g; - cb = (unsigned char)b; - } - else if constexpr (sizeof(r) == 2) // short and unsigned short - { - cr = (unsigned short)(r) >> 8; - cg = (unsigned short)(g) >> 8; - cb = (unsigned short)(b) >> 8; - } - else // float or double - { - cr = (unsigned char)(r * 255.0f); - cg = (unsigned char)(g * 255.0f); - cb = (unsigned char)(b * 255.0f); - } - return (cr << 16) | (cg << 8) | cb; -} - /////////////////////////////////////////////// template ILINE unsigned int Color_tpl::pack_abgr8888() const @@ -786,211 +421,6 @@ ILINE unsigned int Color_tpl::pack_argb8888() const return (ca << 24) | (cr << 16) | (cg << 8) | cb; } -/////////////////////////////////////////////// -template -inline void Color_tpl::toHSV(f32& h, f32& s, f32& v) const -{ - f32 red, green, blue; - if constexpr (sizeof(this->r) == 1) // 8bit integer - { - red = this->r * (1.0f / f32(0xff)); - green = this->g * (1.0f / f32(0xff)); - blue = this->b * (1.0f / f32(0xff)); - } - else if constexpr (sizeof(this->r) == 2) // 16bit integer - { - red = this->r * (1.0f / f32(0xffff)); - green = this->g * (1.0f / f32(0xffff)); - blue = this->b * (1.0f / f32(0xffff)); - } - else // floating point - { - red = this->r; - green = this->g; - blue = this->b; - } - - if ((blue > green) && (blue > red)) - { - if (!::iszero(v = blue)) - { - const f32 min = red < green ? red : green; - const f32 delta = v - min; - if (!::iszero(delta)) - { - s = delta / v; - h = (240.0f / 360.0f) + (red - green) / delta * (60.0f / 360.0f); - } - else - { - s = 0.0f; - h = (240.0f / 360.0f) + (red - green) * (60.0f / 360.0f); - } - if (h < 0.0f) - { - h += 1.0f; - } - } - else - { - s = 0.0f; - h = 0.0f; - } - } - else if (green > red) - { - if (!::iszero(v = green)) - { - const f32 min = red < blue ? red : blue; - const f32 delta = v - min; - if (!::iszero(delta)) - { - s = delta / v; - h = (120.0f / 360.0f) + (blue - red) / delta * (60.0f / 360.0f); - } - else - { - s = 0.0f; - h = (120.0f / 360.0f) + (blue - red) * (60.0f / 360.0f); - } - if (h < 0.0f) - { - h += 1.0f; - } - } - else - { - s = 0.0f; - h = 0.0f; - } - } - else - { - if (!::iszero(v = red)) - { - const f32 min = green < blue ? green : blue; - const f32 delta = v - min; - if (!::iszero(delta)) - { - s = delta / v; - h = (green - blue) / delta * (60.0f / 360.0f); - } - else - { - s = 0.0f; - h = (green - blue) * (60.0f / 360.0f); - } - if (h < 0.0f) - { - h += 1.0f; - } - } - else - { - s = 0.0f; - h = 0.0f; - } - } -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::fromHSV(f32 h, f32 s, f32 v) -{ - f32 red, green, blue; - if (::iszero(v)) - { - red = 0.0f; - green = 0.0f; - blue = 0.0f; - } - else if (::iszero(s)) - { - red = v; - green = v; - blue = v; - } - else - { - const f32 hi = h * 6.0f; - const int32 i = (int32)::floor(hi); - const f32 f = hi - i; - - const f32 v0 = v * (1.0f - s); - const f32 v1 = v * (1.0f - s * f); - const f32 v2 = v * (1.0f - s * (1.0f - f)); - - switch (i) - { - case 0: - red = v; - green = v2; - blue = v0; - break; - case 1: - red = v1; - green = v; - blue = v0; - break; - case 2: - red = v0; - green = v; - blue = v2; - break; - case 3: - red = v0; - green = v1; - blue = v; - break; - case 4: - red = v2; - green = v0; - blue = v; - break; - case 5: - red = v; - green = v0; - blue = v1; - break; - - case 6: - red = v; - green = v2; - blue = v0; - break; - case -1: - red = v; - green = v0; - blue = v1; - break; - default: - red = 0.0f; - green = 0.0f; - blue = 0.0f; - break; - } - } - - if constexpr (sizeof(this->r) == 1) // 8bit integer - { - this->r = red * f32(0xff); - this->g = green * f32(0xff); - this->b = blue * f32(0xff); - } - else if constexpr (sizeof(this->r) == 2) // 16bit integer - { - this->r = red * f32(0xffff); - this->g = green * f32(0xffff); - this->b = blue * f32(0xffff); - } - else // floating point - { - this->r = red; - this->g = green; - this->b = blue; - } -} - /////////////////////////////////////////////// template inline void Color_tpl::clamp(T bottom, T top) @@ -1001,214 +431,5 @@ inline void Color_tpl::clamp(T bottom, T top) a = min(top, max(bottom, a)); } -/////////////////////////////////////////////// -template -inline void Color_tpl::maximum(const Color_tpl& ca, const Color_tpl& cb) -{ - r = max(ca.r, cb.r); - g = max(ca.g, cb.g); - b = max(ca.b, cb.b); - a = max(ca.a, cb.a); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::minimum(const Color_tpl& ca, const Color_tpl& cb) -{ - r = min(ca.r, cb.r); - g = min(ca.g, cb.g); - b = min(ca.b, cb.b); - a = min(ca.a, cb.a); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::abs() -{ - r = fabs_tpl(r); - g = fabs_tpl(g); - b = fabs_tpl(b); - a = fabs_tpl(a); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::adjust_contrast(T c) -{ - r = 0.5f + c * (r - 0.5f); - g = 0.5f + c * (g - 0.5f); - b = 0.5f + c * (b - 0.5f); - a = 0.5f + c * (a - 0.5f); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::adjust_saturation(T s) -{ - // Approximate values for each component's contribution to luminance. - // Based upon the NTSC standard described in ITU-R Recommendation BT.709. - T grey = r * 0.2125f + g * 0.7154f + b * 0.0721f; - r = grey + s * (r - grey); - g = grey + s * (g - grey); - b = grey + s * (b - grey); - a = grey + s * (a - grey); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::adjust_luminance(float newLum) -{ - // Optimized yet equivalent version of replacing luminance in XYZ space. - // Color and luminance are expected to be linear. - - Color_tpl colF(r, g, b, a); - - float lum = colF.r * 0.212671f + colF.g * 0.715160f + colF.b * 0.072169f; - if (iszero(lum)) - { - return; - } - - *this = Color_tpl(colF * newLum / lum); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::lerpFloat(const Color_tpl& ca, const Color_tpl& cb, float s) -{ - r = (T)(ca.r + s * (cb.r - ca.r)); - g = (T)(ca.g + s * (cb.g - ca.g)); - b = (T)(ca.b + s * (cb.b - ca.b)); - a = (T)(ca.a + s * (cb.a - ca.a)); -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::negative([[maybe_unused]] const Color_tpl& c) -{ - r = T(1.0f) - r; - g = T(1.0f) - g; - b = T(1.0f) - b; - a = T(1.0f) - a; -} - -/////////////////////////////////////////////// -template -inline void Color_tpl::grey([[maybe_unused]] const Color_tpl& c) -{ - T m = (r + g + b) / T(3); - - r = m; - g = m; - b = m; -} - -////////////////////////////////////////////////////////////////////////////////////////////// -//#define RGBA8(r,g,b,a) (ColorB((uint8)(r),(uint8)(g),(uint8)(b),(uint8)(a))) -#if defined(NEED_ENDIAN_SWAP) - #define RGBA8(a, b, g, r) ((uint32)(((uint8)(r) | ((uint16)((uint8)(g)) << 8)) | (((uint32)(uint8)(b)) << 16)) | (((uint32)(uint8)(a)) << 24)) -#else - #define RGBA8(r, g, b, a) ((uint32)(((uint8)(r) | ((uint16)((uint8)(g)) << 8)) | (((uint32)(uint8)(b)) << 16)) | (((uint32)(uint8)(a)) << 24)) -#endif -#define Col_Black ColorF (0.000f, 0.000f, 0.000f) // 0xFF000000 RGB: 0, 0, 0 -#define Col_White ColorF (1.000f, 1.000f, 1.000f) // 0xFFFFFFFF RGB: 255, 255, 255 -#define Col_Aquamarine ColorF (0.498f, 1.000f, 0.831f) // 0xFF7FFFD4 RGB: 127, 255, 212 -#define Col_Azure ColorF (0.000f, 0.498f, 1.000f) // 0xFF007FFF RGB: 0, 127, 255 -#define Col_Blue ColorF (0.000f, 0.000f, 1.000f) // 0xFF0000FF RGB: 0, 0, 255 -#define Col_BlueViolet ColorF (0.541f, 0.169f, 0.886f) // 0xFF8A2BE2 RGB: 138, 43, 226 -#define Col_Brown ColorF (0.647f, 0.165f, 0.165f) // 0xFFA52A2A RGB: 165, 42, 42 -#define Col_CadetBlue ColorF (0.373f, 0.620f, 0.627f) // 0xFF5F9EA0 RGB: 95, 158, 160 -#define Col_Coral ColorF (1.000f, 0.498f, 0.314f) // 0xFFFF7F50 RGB: 255, 127, 80 -#define Col_CornflowerBlue ColorF (0.392f, 0.584f, 0.929f) // 0xFF6495ED RGB: 100, 149, 237 -#define Col_Cyan ColorF (0.000f, 1.000f, 1.000f) // 0xFF00FFFF RGB: 0, 255, 255 -#define Col_DarkGray ColorF (0.663f, 0.663f, 0.663f) // 0xFFA9A9A9 RGB: 169, 169, 169 -#define Col_DarkGrey ColorF (0.663f, 0.663f, 0.663f) // 0xFFA9A9A9 RGB: 169, 169, 169 -#define Col_DarkGreen ColorF (0.000f, 0.392f, 0.000f) // 0xFF006400 RGB: 0, 100, 0 -#define Col_DarkOliveGreen ColorF (0.333f, 0.420f, 0.184f) // 0xFF556B2F RGB: 85, 107, 47 -#define Col_DarkOrchid ColorF (0.600f, 0.196f, 0.800f) // 0xFF9932CC RGB: 153, 50, 204 -#define Col_DarkSlateBlue ColorF (0.282f, 0.239f, 0.545f) // 0xFF483D8B RGB: 72, 61, 139 -#define Col_DarkSlateGray ColorF (0.184f, 0.310f, 0.310f) // 0xFF2F4F4F RGB: 47, 79, 79 -#define Col_DarkSlateGrey ColorF (0.184f, 0.310f, 0.310f) // 0xFF2F4F4F RGB: 47, 79, 79 -#define Col_DarkTurquoise ColorF (0.000f, 0.808f, 0.820f) // 0xFF00CED1 RGB: 0, 206, 209 -#define Col_DarkWood ColorF (0.050f, 0.010f, 0.005f) // 0xFF0D0301 RGB: 13, 3, 1 -#define Col_DeepPink ColorF (1.000f, 0.078f, 0.576f) // 0xFFFF1493 RGB: 255, 20, 147 -#define Col_DimGray ColorF (0.412f, 0.412f, 0.412f) // 0xFF696969 RGB: 105, 105, 105 -#define Col_DimGrey ColorF (0.412f, 0.412f, 0.412f) // 0xFF696969 RGB: 105, 105, 105 -#define Col_FireBrick ColorF (0.698f, 0.133f, 0.133f) // 0xFFB22222 RGB: 178, 34, 34 -#define Col_ForestGreen ColorF (0.133f, 0.545f, 0.133f) // 0xFF228B22 RGB: 34, 139, 34 -#define Col_Gold ColorF (1.000f, 0.843f, 0.000f) // 0xFFFFD700 RGB: 255, 215, 0 -#define Col_Goldenrod ColorF (0.855f, 0.647f, 0.125f) // 0xFFDAA520 RGB: 218, 165, 32 -#define Col_Gray ColorF (0.502f, 0.502f, 0.502f) // 0xFF808080 RGB: 128, 128, 128 -#define Col_Grey ColorF (0.502f, 0.502f, 0.502f) // 0xFF808080 RGB: 128, 128, 128 -#define Col_Green ColorF (0.000f, 0.502f, 0.000f) // 0xFF008000 RGB: 0, 128, 0 -#define Col_GreenYellow ColorF (0.678f, 1.000f, 0.184f) // 0xFFADFF2F RGB: 173, 255, 47 -#define Col_IndianRed ColorF (0.804f, 0.361f, 0.361f) // 0xFFCD5C5C RGB: 205, 92, 92 -#define Col_Khaki ColorF (0.941f, 0.902f, 0.549f) // 0xFFF0E68C RGB: 240, 230, 140 -#define Col_LightBlue ColorF (0.678f, 0.847f, 0.902f) // 0xFFADD8E6 RGB: 173, 216, 230 -#define Col_LightGray ColorF (0.827f, 0.827f, 0.827f) // 0xFFD3D3D3 RGB: 211, 211, 211 -#define Col_LightGrey ColorF (0.827f, 0.827f, 0.827f) // 0xFFD3D3D3 RGB: 211, 211, 211 -#define Col_LightSteelBlue ColorF (0.690f, 0.769f, 0.871f) // 0xFFB0C4DE RGB: 176, 196, 222 -#define Col_LightWood ColorF (0.600f, 0.240f, 0.100f) // 0xFF993D1A RGB: 153, 61, 26 -#define Col_Lime ColorF (0.000f, 1.000f, 0.000f) // 0xFF00FF00 RGB: 0, 255, 0 -#define Col_LimeGreen ColorF (0.196f, 0.804f, 0.196f) // 0xFF32CD32 RGB: 50, 205, 50 -#define Col_Magenta ColorF (1.000f, 0.000f, 1.000f) // 0xFFFF00FF RGB: 255, 0, 255 -#define Col_Maroon ColorF (0.502f, 0.000f, 0.000f) // 0xFF800000 RGB: 128, 0, 0 -#define Col_MedianWood ColorF (0.300f, 0.120f, 0.030f) // 0xFF4D1F09 RGB: 77, 31, 9 -#define Col_MediumAquamarine ColorF (0.400f, 0.804f, 0.667f) // 0xFF66CDAA RGB: 102, 205, 170 -#define Col_MediumBlue ColorF (0.000f, 0.000f, 0.804f) // 0xFF0000CD RGB: 0, 0, 205 -#define Col_MediumForestGreen ColorF (0.420f, 0.557f, 0.137f) // 0xFF6B8E23 RGB: 107, 142, 35 -#define Col_MediumGoldenrod ColorF (0.918f, 0.918f, 0.678f) // 0xFFEAEAAD RGB: 234, 234, 173 -#define Col_MediumOrchid ColorF (0.729f, 0.333f, 0.827f) // 0xFFBA55D3 RGB: 186, 85, 211 -#define Col_MediumSeaGreen ColorF (0.235f, 0.702f, 0.443f) // 0xFF3CB371 RGB: 60, 179, 113 -#define Col_MediumSlateBlue ColorF (0.482f, 0.408f, 0.933f) // 0xFF7B68EE RGB: 123, 104, 238 -#define Col_MediumSpringGreen ColorF (0.000f, 0.980f, 0.604f) // 0xFF00FA9A RGB: 0, 250, 154 -#define Col_MediumTurquoise ColorF (0.282f, 0.820f, 0.800f) // 0xFF48D1CC RGB: 72, 209, 204 -#define Col_MediumVioletRed ColorF (0.780f, 0.082f, 0.522f) // 0xFFC71585 RGB: 199, 21, 133 -#define Col_MidnightBlue ColorF (0.098f, 0.098f, 0.439f) // 0xFF191970 RGB: 25, 25, 112 -#define Col_Navy ColorF (0.000f, 0.000f, 0.502f) // 0xFF000080 RGB: 0, 0, 128 -#define Col_NavyBlue ColorF (0.137f, 0.137f, 0.557f) // 0xFF23238E RGB: 35, 35, 142 -#define Col_Orange ColorF (1.000f, 0.647f, 0.000f) // 0xFFFFA500 RGB: 255, 165, 0 -#define Col_OrangeRed ColorF (1.000f, 0.271f, 0.000f) // 0xFFFF4500 RGB: 255, 69, 0 -#define Col_Orchid ColorF (0.855f, 0.439f, 0.839f) // 0xFFDA70D6 RGB: 218, 112, 214 -#define Col_PaleGreen ColorF (0.596f, 0.984f, 0.596f) // 0xFF98FB98 RGB: 152, 251, 152 -#define Col_Pink ColorF (1.000f, 0.753f, 0.796f) // 0xFFFFC0CB RGB: 255, 192, 203 -#define Col_Plum ColorF (0.867f, 0.627f, 0.867f) // 0xFFDDA0DD RGB: 221, 160, 221 -#define Col_Red ColorF (1.000f, 0.000f, 0.000f) // 0xFFFF0000 RGB: 255, 0, 0 -#define Col_Salmon ColorF (0.980f, 0.502f, 0.447f) // 0xFFFA8072 RGB: 250, 128, 114 -#define Col_SeaGreen ColorF (0.180f, 0.545f, 0.341f) // 0xFF2E8B57 RGB: 46, 139, 87 -#define Col_Sienna ColorF (0.627f, 0.322f, 0.176f) // 0xFFA0522D RGB: 160, 82, 45 -#define Col_SkyBlue ColorF (0.529f, 0.808f, 0.922f) // 0xFF87CEEB RGB: 135, 206, 235 -#define Col_SlateBlue ColorF (0.416f, 0.353f, 0.804f) // 0xFF6A5ACD RGB: 106, 90, 205 -#define Col_SpringGreen ColorF (0.000f, 1.000f, 0.498f) // 0xFF00FF7F RGB: 0, 255, 127 -#define Col_SteelBlue ColorF (0.275f, 0.510f, 0.706f) // 0xFF4682B4 RGB: 70, 130, 180 -#define Col_Tan ColorF (0.824f, 0.706f, 0.549f) // 0xFFD2B48C RGB: 210, 180, 140 -#define Col_Thistle ColorF (0.847f, 0.749f, 0.847f) // 0xFFD8BFD8 RGB: 216, 191, 216 -#define Col_Transparent ColorF (0.0f, 0.0f, 0.0f, 0.0f) // 0x00000000 RGB: 0, 0, 0 -#define Col_Turquoise ColorF (0.251f, 0.878f, 0.816f) // 0xFF40E0D0 RGB: 64, 224, 208 -#define Col_Violet ColorF (0.933f, 0.510f, 0.933f) // 0xFFEE82EE RGB: 238, 130, 238 -#define Col_VioletRed ColorF (0.800f, 0.196f, 0.600f) // 0xFFCC3299 RGB: 204, 50, 153 -#define Col_Wheat ColorF (0.961f, 0.871f, 0.702f) // 0xFFF5DEB3 RGB: 245, 222, 179 -#define Col_Yellow ColorF (1.000f, 1.000f, 0.000f) // 0xFFFFFF00 RGB: 255, 255, 0 -#define Col_YellowGreen ColorF (0.604f, 0.804f, 0.196f) // 0xFF9ACD32 RGB: 154, 205, 50 #define Col_TrackviewDefault ColorF (0.187820792f, 0.187820792f, 1.0f) - #define Clr_Empty ColorF(0.0f, 0.0f, 0.0f, 1.0f) -#define Clr_Dark ColorF(0.15f, 0.15f, 0.15f, 1.0f) -#define Clr_White ColorF(1.0f, 1.0f, 1.0f, 1.0f) -#define Clr_WhiteTrans ColorF(1.0f, 1.0f, 1.0f, 0.0f) -#define Clr_Full ColorF(1.0f, 1.0f, 1.0f, 1.0f) -#define Clr_Neutral ColorF(1.0f, 1.0f, 1.0f, 1.0f) -#define Clr_Transparent ColorF(0.0f, 0.0f, 0.0f, 0.0f) -#define Clr_FrontVector ColorF(0.0f, 0.0f, 0.5f, 1.0f) -#define Clr_Static ColorF(127.0f / 255.0f, 127.0f / 255.0f, 0.0f, 0.0f) -#define Clr_Median ColorF(0.5f, 0.5f, 0.5f, 0.0f) -#define Clr_MedianHalf ColorF(0.5f, 0.5f, 0.5f, 0.5f) -#define Clr_FarPlane ColorF(1.0f, 0.0f, 0.0f, 0.0f) -#define Clr_FarPlane_R ColorF(bReverseDepth ? 0.0f : 1.0f, 0.0f, 0.0f, 0.0f) -#define Clr_Unknown ColorF(0.0f, 0.0f, 0.0f, 0.0f) -#define Clr_Unused ColorF(0.0f, 0.0f, 0.0f, 0.0f) -#define Clr_Debug ColorF(1.0f, 0.0f, 0.0f, 1.0f) - -#endif // CRYINCLUDE_CRYCOMMON_CRY_COLOR_H - - diff --git a/Code/Legacy/CryCommon/Cry_Geo.h b/Code/Legacy/CryCommon/Cry_Geo.h index 95213c62dc..7c85b2bdf4 100644 --- a/Code/Legacy/CryCommon/Cry_Geo.h +++ b/Code/Legacy/CryCommon/Cry_Geo.h @@ -8,10 +8,6 @@ // Description : Common structures for geometry computations - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_GEO_H -#define CRYINCLUDE_CRYCOMMON_CRY_GEO_H #pragma once #include "Cry_Math.h" @@ -29,11 +25,6 @@ struct AABB; template struct OBB_tpl; -struct Sphere; -struct AAEllipsoid; -struct Ellipsoid; -struct Cone; - //----------------------------------------------------- @@ -41,127 +32,12 @@ struct Cone; // Definitions // /////////////////////////////////////////////////////////////////////////////// -// -// Random geometry generation functions. -// - -enum EGeomForm -{ - GeomForm_Vertices, - GeomForm_Edges, - GeomForm_Surface, - GeomForm_Volume, - - MaxGeomForm -}; - -enum EGeomType -{ - GeomType_None, - GeomType_BoundingBox, - GeomType_Physics, - GeomType_Render, -}; - struct PosNorm { Vec3 vPos; Vec3 vNorm; - - void zero() - { - vPos.zero(); - vNorm.zero(); - } - - // transform by matrix, etc - void operator <<= (Matrix34 const& mx) - { - vPos = mx * vPos; - vNorm = Matrix33(mx) * vNorm; - } - void operator <<= (QuatTS const& qts) - { - vPos = qts * vPos; - vNorm = qts.q * vNorm; - } - void operator <<= (DualQuat const& dq) - { - vPos = dq * vPos; - vNorm = dq.nq * vNorm; - } }; -struct RectF -{ - float x, y, w, h; - RectF() - : x(0) - , y(0) - , w(1) - , h(1) - { - } -}; - -struct RectI -{ - int x, y, w, h; - RectI() - : x(0) - , y(0) - , w(1) - , h(1) - { - } - RectI(int inX, int inY, int inW, int inH) - : x(inX) - , y(inY) - , w(inW) - , h(inH) - { - } - _inline void Add(RectI rcAdd) - { - int x2 = x + w; - int y2 = y + h; - int x22 = rcAdd.x + rcAdd.w; - int y22 = rcAdd.y + rcAdd.h; - x = min(x, rcAdd.x); - y = min(y, rcAdd.y); - x2 = max(x2, x22); - y2 = max(y2, y22); - w = x2 - x; - h = y2 - y; - } - _inline void Add(int inX, int inY, int inW, int inH) - { - Add(RectI(inX, inY, inW, inH)); - } -}; - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// struct Line -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -struct Line -{ - Vec3 pointonline; - Vec3 direction; //caution: the direction is important for any intersection test - - //default Line constructor (without initialisation) - inline Line(void) {} - inline Line(const Vec3& o, const Vec3& d) { pointonline = o; direction = d; } - inline void operator () (const Vec3& o, const Vec3& d) { pointonline = o; direction = d; } - - ~Line(void) {}; -}; - - - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -190,26 +66,18 @@ struct Ray /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -template -struct Lineseg_tpl +struct Lineseg { - Vec3_tpl start; - Vec3_tpl end; + Vec3_tpl start; + Vec3_tpl end; //default Lineseg constructor (without initialisation) - inline Lineseg_tpl(void) {} - inline Lineseg_tpl(const Vec3_tpl& s, const Vec3_tpl& e) { start = s; end = e; } - inline void operator () (const Vec3_tpl& s, const Vec3_tpl& e) { start = s; end = e; } + inline Lineseg(void) {} + inline Lineseg(const Vec3_tpl& s, const Vec3_tpl& e) { start = s; end = e; } - Vec3 GetPoint(F t) const {return t * end + (F(1.0) - t) * start; } - - ~Lineseg_tpl(void) {}; + ~Lineseg(void) {}; }; -typedef Lineseg_tpl Lineseg; -typedef Lineseg_tpl Linesegr; - - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -240,33 +108,6 @@ struct Triangle_tpl } }; - - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// struct Cone -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -struct Cone -{ - Vec3 mTip; - Vec3 mDir; - Vec3 mBase; - - float mHeight; - float mBaseRadius; - - Cone() {} - Cone(const Vec3& tip, const Vec3& dir, float height, float baseRadius) - : mTip(tip) - , mDir(dir) - , mBase(tip + dir * height) - , mHeight(height) - , mBaseRadius(baseRadius) {} -}; - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -343,12 +184,6 @@ struct AABB ILINE float GetRadius() const { return IsResetSel(0.0f, (max - min).GetLengthFloat() * 0.5f); } - ILINE float GetRadiusSqr() const - { return IsResetSel(0.0f, ((max - min) * 0.5f).GetLengthSquaredFloat()); } - - ILINE float GetVolume() const - { return IsResetSel(0.0f, (max.x - min.x) * (max.y - min.y) * (max.z - min.z)); } - ILINE void Add(const Vec3& v) { min.CheckMin(v); @@ -368,133 +203,6 @@ struct AABB max.CheckMax(bb.max); } - inline void Move(const Vec3& v) - { - const float moveMult = IsResetSel(0.0f, 1.0f); - const Vec3 vMove = v * moveMult; - min += vMove; - max += vMove; - } - - inline void Expand(Vec3 const& v) - { - if (!IsReset()) - { - min -= v; - max += v; - } - } - - // Augment the box on all sides by a box. - inline void Augment(AABB const& bb) - { - if (!IsReset() && !bb.IsReset()) - { - Add(min + bb.min); - Add(max + bb.max); - } - } - - void ClipToBox(AABB const& bb) - { - min.CheckMax(bb.min); - max.CheckMin(bb.max); - } - - void ClipMoveToBox(AABB const& bb) - { - for (int a = 0; a < 3; a++) - { - if (max[a] - min[a] > bb.max[a] - bb.min[a]) - { - min[a] = bb.min[a]; - max[a] = bb.max[a]; - } - else if (min[a] < bb.min[a]) - { - max[a] += bb.min[a] - min[a]; - min[a] = bb.min[a]; - } - else if (max[a] > bb.max[a]) - { - min[a] += bb.max[a] - max[a]; - max[a] = bb.max[a]; - } - } - } - - //! Check if this bounding box overlap with bounding box of sphere. - bool IsOverlapSphereBounds(const Vec3& pos, float radius) const - { - assert(min.IsValid()); - assert(max.IsValid()); - assert(pos.IsValid()); - - if (pos.x > min.x && pos.x < max.x && pos.y > min.y && pos.y < max.y && pos.z > min.z && pos.z < max.z) - { - return true; - } - - if (pos.x + radius < min.x) - { - return false; - } - if (pos.y + radius < min.y) - { - return false; - } - if (pos.z + radius < min.z) - { - return false; - } - if (pos.x - radius > max.x) - { - return false; - } - if (pos.y - radius > max.y) - { - return false; - } - if (pos.z - radius > max.z) - { - return false; - } - return true; - } - - //! Check if this bounding box contain sphere within itself. - bool IsContainSphere(const Vec3& pos, float radius) const - { - assert(min.IsValid()); - assert(max.IsValid()); - assert(pos.IsValid()); - if (pos.x - radius < min.x) - { - return false; - } - if (pos.y - radius < min.y) - { - return false; - } - if (pos.z - radius < min.z) - { - return false; - } - if (pos.x + radius > max.x) - { - return false; - } - if (pos.y + radius > max.y) - { - return false; - } - if (pos.z + radius > max.z) - { - return false; - } - return true; - } - //! Check if this bounding box contains a point within itself. bool IsContainPoint(const Vec3& pos) const { @@ -541,27 +249,6 @@ struct AABB return sqrt(GetDistanceSqr(v)); } - bool ContainsBox(AABB const& b) const - { - assert(min.IsValid()); - assert(max.IsValid()); - assert(b.min.IsValid()); - assert(b.max.IsValid()); - return min.x <= b.min.x && min.y <= b.min.y && min.z <= b.min.z - && max.x >= b.max.x && max.y >= b.max.y && max.z >= b.max.z; - } - - bool ContainsBox2D(AABB const& b) const - { - assert(min.IsValid()); - assert(max.IsValid()); - assert(b.min.IsValid()); - assert(b.max.IsValid()); - return min.x <= b.min.x && min.y <= b.min.y - && max.x >= b.max.x && max.y >= b.max.y; - } - - // Check two bounding boxes for intersection. inline bool IsIntersectBox(const AABB& b) const { @@ -622,86 +309,6 @@ struct AABB max = pos + sz; } } - ILINE static AABB CreateTransformedAABB(const Matrix34& m34, const AABB& aabb) - { AABB taabb; taabb.SetTransformedAABB(m34, aabb); return taabb; } - - - - ILINE void SetTransformedAABB(const QuatT& qt, const AABB& aabb) - { - if (aabb.IsReset()) - { - Reset(); - } - else - { - Matrix33 m33 = Matrix33(qt.q); - m33.m00 = fabs_tpl(m33.m00); - m33.m01 = fabs_tpl(m33.m01); - m33.m02 = fabs_tpl(m33.m02); - m33.m10 = fabs_tpl(m33.m10); - m33.m11 = fabs_tpl(m33.m11); - m33.m12 = fabs_tpl(m33.m12); - m33.m20 = fabs_tpl(m33.m20); - m33.m21 = fabs_tpl(m33.m21); - m33.m22 = fabs_tpl(m33.m22); - Vec3 sz = m33 * ((aabb.max - aabb.min) * 0.5f); - Vec3 pos = qt * ((aabb.max + aabb.min) * 0.5f); - min = pos - sz; - max = pos + sz; - } - } - ILINE static AABB CreateTransformedAABB(const QuatT& qt, const AABB& aabb) - { AABB taabb; taabb.SetTransformedAABB(qt, aabb); return taabb; } - - - //create an AABB using just the extensions of the OBB and ignore the orientation. - template - ILINE void SetAABBfromOBB(const OBB_tpl& obb) - { min = obb.c - obb.h; max = obb.c + obb.h; } - template - ILINE static AABB CreateAABBfromOBB(const OBB_tpl& obb) - { return AABB(obb.c - obb.h, obb.c + obb.h); } - - /*! - * converts an OBB into an tight fitting AABB - * - * Example: - * AABB aabb = AABB::CreateAABBfromOBB(wposition,obb,1.0f); - * - * return values: - * expanded AABB in world-space - */ - template - ILINE void SetAABBfromOBB(const Vec3& wpos, const OBB_tpl& obb, f32 scaling = 1.0f) - { - Vec3 pos = obb.m33 * obb.c * scaling + wpos; - Vec3 sz = obb.m33.GetFabs() * obb.h * scaling; - min = pos - sz; - max = pos + sz; - } - template - ILINE static AABB CreateAABBfromOBB(const Vec3& wpos, const OBB_tpl& obb, f32 scaling = 1.0f) - { AABB taabb; taabb.SetAABBfromOBB(wpos, obb, scaling); return taabb; } - - /* Converts a Cone into a tight fitting AABB */ - ILINE static AABB CreateAABBfromCone(const Cone& c) - { - // Construct AABB for cone base - Vec3 baseX = Vec3(1.f - c.mDir.x * c.mDir.x, c.mDir.x * c.mDir.y, c.mDir.x * c.mDir.z).GetNormalized() * c.mBaseRadius; - Vec3 baseY = Vec3(c.mDir.y * c.mDir.x, 1.f - c.mDir.y * c.mDir.y, c.mDir.y * c.mDir.z).GetNormalized() * c.mBaseRadius; - Vec3 baseZ = Vec3(c.mDir.z * c.mDir.x, c.mDir.z * c.mDir.y, 1.f - c.mDir.z * c.mDir.z).GetNormalized() * c.mBaseRadius; - - Vec3 aabbMax = Vec3(baseX.x, baseY.y, baseZ.z).abs(); - Vec3 aabbMin = -aabbMax; - - AABB result(aabbMin, aabbMax); - result.Move(c.mBase); - - // add tip - result.Add(c.mTip); - return result; - } }; ILINE bool IsEquivalent(const AABB& a, const AABB& b, float epsilon = VEC_EPSILON) @@ -710,9 +317,6 @@ ILINE bool IsEquivalent(const AABB& a, const AABB& b, float epsilon = VEC_EPSILO } - - - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -752,6 +356,7 @@ struct OBB_tpl ~OBB_tpl(void) {}; }; +typedef OBB_tpl OBB; @@ -774,392 +379,4 @@ struct Sphere void operator()(const Vec3& c, float r) { center = c; radius = r; } }; -struct HWVSphere -{ - hwvec3 center; - simdf radius; - - ILINE HWVSphere(const hwvec3& c, const simdf& r) - { - center = c; - radius = r; - } - - ILINE HWVSphere(const ::Sphere& sp) - { - center = HWVLoadVecUnaligned(&sp.center); - radius = SIMDFLoadFloat(sp.radius); - } -}; - - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// struct AAEllipsoid -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -struct AAEllipsoid -{ - Vec3 center; - Vec3 radius_vec; - - //default AAEllipsoid constructor (without initialisation) - inline AAEllipsoid(void) {} - inline AAEllipsoid(const Vec3& c, const Vec3& rv) { radius_vec = rv; center = c; } - inline void operator () (const Vec3& c, const Vec3& rv) { radius_vec = rv; center = c; } - - ~AAEllipsoid(void) {}; -}; - - - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// struct Ellipsoid -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -struct Ellipsoid -{ - Matrix34 ExtensionPos; - - //default Ellipsoid constructor (without initialisation) - inline Ellipsoid(void) {} - inline Ellipsoid(const Matrix34& ep) { ExtensionPos = ep; } - inline void operator () (const Matrix34& ep) { ExtensionPos = ep; } - - ~Ellipsoid(void) {}; -}; - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// struct TRect -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -template -struct TRect_tpl -{ - typedef Vec2_tpl Vec; - - Vec Min, Max; - - inline TRect_tpl() {} - inline TRect_tpl(Num x1, Num y1, Num x2, Num y2) - : Min(x1, y1) - , Max(x2, y2) {} - inline TRect_tpl(const TRect_tpl& rc) - : Min(rc.Min) - , Max(rc.Max) {} - inline TRect_tpl(const Vec& min, const Vec& max) - : Min(min) - , Max(max) {} - - inline TRect_tpl operator * (Num k) const - { - return TRect_tpl(Min.x * k, Min.y * k, Max.x * k, Max.y * k); - } - inline TRect_tpl operator / (Num k) const - { - return TRect_tpl(Min.x / k, Min.y / k, Max.x / k, Max.y / k); - } - - inline bool IsEmpty() const { return Max.x < Min.x && Max.y < Min.y; } - inline TRect_tpl& SetEmpty() { Max = Vec(-1, -1); Min = Vec(0, 0); return *this; } - - inline Vec GetDim() const { return Max - Min; } - inline Num GetWidth() const { return Max.x - Min.x; } - inline Num GetHeight() const { return Max.y - Min.y; } - - inline bool IsEqual(const TRect_tpl& rc) const { return Min.x == rc.Min.x && Min.y == rc.Min.y && Max.x == rc.Max.x && Max.y == rc.Max.y; } - - inline bool InRect(const TRect_tpl& rc) const { return rc.Min.x >= Min.x && rc.Max.x <= Max.x && rc.Min.y >= Min.y && rc.Max.y <= Max.y; } - inline bool InRect(Vec pt) const { return pt.x >= Min.x && pt.x <= Max.x && pt.y >= Min.y && pt.y <= Max.y; } - inline Vec& IntoRect(Vec& pt) const - { - if (pt.x < Min.x) - { - pt.x = Min.x; - } - else if (pt.x > Max.x) - { - pt.x = Max.x; - } - if (pt.y < Min.y) - { - pt.y = Min.y; - } - else if (pt.y > Max.y) - { - pt.y = Max.y; - } - return pt; - } - - inline bool Intersects(const TRect_tpl& rc) const - { - return !IsEmpty() && !rc.IsEmpty() && - !(Min.x > rc.Max.x || Max.x < rc.Min.x || - Min.y > rc.Max.y || Max.y < rc.Min.y); - } - - inline TRect_tpl& DoUnite(const TRect_tpl& rc) - { - if (IsEmpty()) - { - Min = rc.Min; - Max = rc.Max; - return *this; - } - if (rc.IsEmpty()) - { - return *this; - } - if (Min.x > rc.Min.x) - { - Min.x = rc.Min.x; - } - if (Min.y > rc.Min.y) - { - Min.y = rc.Min.y; - } - if (Max.x < rc.Max.x) - { - Max.x = rc.Max.x; - } - if (Max.y < rc.Max.y) - { - Max.y = rc.Max.y; - } - return *this; - } - - inline TRect_tpl& DoIntersect(const TRect_tpl& rc) - { - if (IsEmpty()) - { - return *this; - } - if (rc.IsEmpty()) - { - return SetEmpty(); - } - if (Min.x < rc.Min.x) - { - Min.x = rc.Min.x; - } - if (Min.y < rc.Min.y) - { - Min.y = rc.Min.y; - } - if (Max.x > rc.Max.x) - { - Max.x = rc.Max.x; - } - if (Max.y > rc.Max.y) - { - Max.y = rc.Max.y; - } - - if (Min.x == Max.x || Min.y == Max.y) - { - return SetEmpty(); - } - - return *this; - } - - inline TRect_tpl GetSubRect(const TRect_tpl& rc) const - { - if (IsEmpty()) - { - return *this; - } - if (rc.IsEmpty()) - { - return rc; - } - return TRect_tpl(Min.x + rc.Min.x * GetWidth(), - Min.y + rc.Min.y * GetHeight(), - Min.x + rc.Max.x * GetWidth(), - Min.y + rc.Max.y * GetHeight()); - } - - inline TRect_tpl GetSubRectInv(const TRect_tpl& rcSub) const - { - if (IsEmpty()) - { - return *this; - } - if (rcSub.IsEmpty()) - { - return rcSub; - } - return TRect_tpl((rcSub.Min.x - Min.x) / GetWidth(), - (rcSub.Min.y - Min.y) / GetHeight(), - (rcSub.Max.x - Min.x) / GetWidth(), - (rcSub.Max.y - Min.y) / GetHeight()); - } -}; - -typedef TRect_tpl Rectf; -typedef TRect_tpl Recti; - typedef Triangle_tpl Triangle; -typedef Triangle_tpl Triangle_f64; -typedef OBB_tpl OBB; - -////////////////////////////////////////////////////////////////////////// -// Manage linear and rotational 3D velocity in a class -class Velocity3 -{ -public: - Vec3 vLin, vRot; - - Velocity3() - {} - Velocity3(type_zero) - : vLin(ZERO) - , vRot(ZERO) {} - Velocity3(Vec3 const& lin) - : vLin(lin) - , vRot(ZERO) {} - Velocity3(Vec3 const& lin, Vec3 const& rot) - : vLin(lin) - , vRot(rot) {} - - void FromDelta(QuatT const& loc0, QuatT const& loc1, float fTime) - { - float fInvT = 1.f / fTime; - vLin = (loc1.t - loc0.t) * fInvT; - vRot = Quat::log(loc1.q * loc0.q.GetInverted()) * fInvT; - } - - Vec3 VelocityAt(Vec3 const& vPosRel) const - { return vLin + (vRot % vPosRel); } - - void operator += (Velocity3 const& vv) - { - vLin += vv.vLin; - vRot += vv.vRot; - } - void operator *= (float f) - { - vLin *= f; - vRot *= f; - } - void Interp(Velocity3 const& vv, float f) - { - vLin += (vv.vLin - vLin) * f; - vRot += (vv.vRot - vRot) * f; - } -}; - -///////////////////////////////////////////////////////////////////////// -//this is some special engine stuff, should be moved to a better location -///////////////////////////////////////////////////////////////////////// - -// for bbox's checks and calculations -#define MAX_BB +99999.0f -#define MIN_BB -99999.0f - -//! checks if this has been set to minBB -inline bool IsMinBB(const Vec3& v) -{ - if (v.x <= MIN_BB) - { - return (true); - } - if (v.y <= MIN_BB) - { - return (true); - } - if (v.z <= MIN_BB) - { - return (true); - } - return (false); -} - -//! checks if this has been set to maxBB -inline bool IsMaxBB(const Vec3& v) -{ - if (v.x >= MAX_BB) - { - return (true); - } - if (v.y >= MAX_BB) - { - return (true); - } - if (v.z >= MAX_BB) - { - return (true); - } - return (false); -} - -inline Vec3 SetMaxBB(void) { return Vec3(MAX_BB, MAX_BB, MAX_BB); } -inline Vec3 SetMinBB(void) { return Vec3(MIN_BB, MIN_BB, MIN_BB); } - -inline void AddToBounds (const Vec3& v, Vec3& mins, Vec3& maxs) -{ - if (v.x < mins.x) - { - mins.x = v.x; - } - if (v.x > maxs.x) - { - maxs.x = v.x; - } - if (v.y < mins.y) - { - mins.y = v.y; - } - if (v.y > maxs.y) - { - maxs.y = v.y; - } - if (v.z < mins.z) - { - mins.z = v.z; - } - if (v.z > maxs.z) - { - maxs.z = v.z; - } -} - - -//////////////////////////////////////////////////////////////// -//! calc the area of a polygon giving a list of vertices and normal -inline float CalcArea(const Vec3* vertices, int numvertices, const Vec3& normal) -{ - Vec3 csum(0, 0, 0); - - int n = numvertices; - for (int i = 0, j = 1; i <= n - 2; i++, j++) - { - csum.x += vertices[i].y * vertices[j].z - vertices[i].z * vertices[j].y; - csum.y += vertices[i].z * vertices[j].x - vertices[i].x * vertices[j].z; - csum.z += vertices[i].x * vertices[j].y - vertices[i].y * vertices[j].x; - } - - csum.x += vertices[n - 1].y * vertices[0].z - vertices[n - 1].z * vertices[0].y; - csum.y += vertices[n - 1].z * vertices[0].x - vertices[n - 1].x * vertices[0].z; - csum.z += vertices[n - 1].x * vertices[0].y - vertices[n - 1].y * vertices[0].x; - - float area = 0.5f * (float)fabs(normal | csum); - return (area); -} - - - -#endif // CRYINCLUDE_CRYCOMMON_CRY_GEO_H diff --git a/Code/Legacy/CryCommon/Cry_HWMatrix.h b/Code/Legacy/CryCommon/Cry_HWMatrix.h deleted file mode 100644 index 853dbcc2c2..0000000000 --- a/Code/Legacy/CryCommon/Cry_HWMatrix.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Scalar implementation of hardware vector based matrix - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H -#define CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H -#pragma once - -struct hwmtx33 -{ - hwvec3 m0, m1, m2; -}; - -ILINE void HWMtx33LoadAligned(hwmtx33& out, const Matrix34A& inMtx) -{ - out.m0 = HWVLoadVecAligned(reinterpret_cast(&inMtx.m00)); - out.m1 = HWVLoadVecAligned(reinterpret_cast(&inMtx.m10)); - out.m2 = HWVLoadVecAligned(reinterpret_cast(&inMtx.m20)); -} - -ILINE hwvec3 HWMtx33RotateVec(const hwmtx33& m, const hwvec3& v) -{ - return Vec3((m.m0[0] * v.x) + (m.m0[1] * v.y) + (m.m0[2] * v.z), - (m.m1[0] * v.x) + (m.m1[1] * v.y) + (m.m1[2] * v.z), - (m.m2[0] * v.x) + (m.m2[1] * v.y) + (m.m2[2] * v.z)); -} - -ILINE hwvec3 HWMtx33RotateVecOpt(const hwmtx33& m, const hwvec3& v) -{ - return HWMtx33RotateVec(m, v); -} - -ILINE hwmtx33 HWMtx33CreateRotationV0V1(const hwvec3& v0, const hwvec3& v1) -{ - assert((fabs_tpl(1 - (v0 | v0))) < 0.01); //check if unit-vector - assert((fabs_tpl(1 - (v1 | v1))) < 0.01); //check if unit-vector - hwmtx33 m; - float dot = v0 | v1; - if (dot < -0.9999f) - { - Vec3 axis = v0.GetOrthogonal().GetNormalized(); - m.m0[0] = (2.0f * axis.x * axis.x - 1); - m.m0[1] = (2.0f * axis.x * axis.y); - m.m0[2] = (2.0f * axis.x * axis.z); - m.m1[0] = (2.0f * axis.y * axis.x); - m.m1[1] = (2.0f * axis.y * axis.y - 1); - m.m1[2] = (2.0f * axis.y * axis.z); - m.m2[0] = (2.0f * axis.z * axis.x); - m.m2[1] = (2.0f * axis.z * axis.y); - m.m2[2] = (2.0f * axis.z * axis.z - 1); - } - else - { - Vec3 v = v0 % v1; - f32 h = 1.0f / (1.0f + dot); - m.m0[0] = (dot + h * v.x * v.x); - m.m0[1] = (h * v.x * v.y - v.z); - m.m0[2] = (h * v.x * v.z + v.y); - m.m1[0] = (h * v.x * v.y + v.z); - m.m1[1] = (dot + h * v.y * v.y); - m.m1[2] = (h * v.y * v.z - v.x); - m.m2[0] = (h * v.x * v.z - v.y); - m.m2[1] = (h * v.y * v.z + v.x); - m.m2[2] = (dot + h * v.z * v.z); - } - - return m; -} - -//Returns a matrix optimized for this platform's matrix ops, in this case, not doing a thing; -ILINE hwmtx33 HWMtx33GetOptimized(const hwmtx33& m) -{ - return (hwmtx33)m; -} - -#endif // CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H - diff --git a/Code/Legacy/CryCommon/Cry_HWVector3.h b/Code/Legacy/CryCommon/Cry_HWVector3.h deleted file mode 100644 index cf2beb9a01..0000000000 --- a/Code/Legacy/CryCommon/Cry_HWVector3.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description: Hardware vector class - scalar implementation - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H -#define CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H -#pragma once - - -#define HWV_PERMUTE_0X 0 -#define HWV_PERMUTE_0Y 1 -#define HWV_PERMUTE_0Z 2 -#define HWV_PERMUTE_0W 3 -#define HWV_PERMUTE_1X 4 -#define HWV_PERMUTE_1Y 5 -#define HWV_PERMUTE_1Z 6 -#define HWV_PERMUTE_1W 7 - -typedef Vec3 hwvec3; -typedef Vec4 hwvec4; -typedef float simdf; -typedef Vec4 hwvec4fconst; -typedef int hwvec4i[4]; - -#define HWV3Constant(name, f0, f1, f2) const Vec3 name(f0, f1, f2) -#define SIMDFConstant(name, f0) const simdf name = f0 -#define HWV4PermuteControl(name, i0, i1, i2, i3) static const hwvec4i name = {i0, i1, i2, i3}; -#define SIMDFAsVec3(a) (hwvec3)a -#define HWV3AsSIMDF(a) (simdf)a.x - -ILINE hwvec3 HWVLoadVecUnaligned(const Vec3* pLoadFrom) -{ - return *pLoadFrom; -} - -ILINE hwvec3 HWVLoadVecAligned(const Vec4A* pLoadFrom) -{ - return Vec3(pLoadFrom->x, pLoadFrom->y, pLoadFrom->z); -} - -ILINE void HWVSaveVecUnaligned(Vec3* pSaveTo, const hwvec3& pLoadFrom) -{ - *pSaveTo = pLoadFrom; -} - -ILINE void HWVSaveVecAligned(Vec4* pSaveTo, const hwvec4& pLoadFrom) -{ - *pSaveTo = pLoadFrom; -} - -ILINE hwvec3 HWVAdd(const hwvec3& a, const hwvec3& b) -{ - return hwvec3(a.x + b.x, a.y + b.y, a.z + b.z); -} - -ILINE hwvec3 HWVMultiply(const hwvec3& a, const hwvec3& b) -{ - return hwvec3(a.x * b.x, a.y * b.y, a.z * b.z); -} - -ILINE hwvec3 HWVMultiplySIMDF(const hwvec3& a, const simdf& b) -{ - return hwvec3(a.x * b, a.y * b, a.z * b); -} - -ILINE hwvec3 HWVMultiplyAdd(const hwvec3& a, const hwvec3& b, const hwvec3& c) -{ - return hwvec3((a.x * b.x) + c.x, (a.y * b.y) + c.y, (a.z * b.z) + c.z); -} - -ILINE hwvec3 HWVMultiplySIMDFAdd(const hwvec3& a, const simdf& b, const hwvec3& c) -{ - return hwvec3((a.x * b) + c.x, (a.y * b) + c.y, (a.z * b) + c.z); -} - -ILINE hwvec3 HWVSub(const hwvec3& a, const hwvec3& b) -{ - return (a - b); -} - -ILINE hwvec3 HWVCross(const hwvec3& a, const hwvec3& b) -{ - return hwvec3((a.y * b.z) - (a.z * b.y) - , (a.z * b.x) - (a.x * b.z) - , (a.x * b.y) - (a.y * b.x)); -} - -ILINE simdf HWV3Dot(const hwvec3& a, const hwvec3& b) -{ - return (a.x * b.x) + (a.y * b.y) + (a.z * b.z); -} - -ILINE hwvec3 HWVMax(const hwvec3& a, const hwvec3& b) -{ - return Vec3(a.x > b.x ? a.x : b.x, - a.y > b.y ? a.y : b.y, - a.z > b.z ? a.z : b.z); -} - -ILINE hwvec3 HWVMin(const hwvec3& a, const hwvec3& b) -{ - return Vec3(a.x < b.x ? a.x : b.x, - a.y < b.y ? a.y : b.y, - a.z < b.z ? a.z : b.z); -} - -ILINE hwvec3 HWVClamp(const hwvec3& a, const hwvec3& min, const hwvec3& max) -{ - return HWVMax(min, HWVMin(a, max)); -} - -ILINE hwvec3 HWV3Normalize(const hwvec3& a) -{ - float fInvLen = isqrt_safe_tpl((a.x * a.x) + (a.y * a.y) + (a.z * a.z)); - return Vec3(a.x * fInvLen, a.y * fInvLen, a.z * fInvLen); -} - -ILINE hwvec3 HWVGetOrthogonal(const hwvec3& a) -{ - hwvec3 result = a; - - //int i = isneg(square(0.9f)*a.GetLengthSquared()-(a.x*a.x)); - int i = isneg(square(0.9f) * a.GetLengthSquared() - a.x * a.x); - result[i] = 0; - result[incm3(i)] = a[decm3(i)]; - result[decm3(i)] = -a[incm3(i)]; - return result; -} - -ILINE simdf HWV3SplatXToSIMDF(const hwvec3& a) -{ - return a.x; -} - -ILINE simdf HWV3SplatYToSIMDF(const hwvec3& a) -{ - return a.y; -} - -ILINE hwvec3 HWV3PermuteWord(const hwvec3& a, const hwvec3& b, const hwvec4i& p) -{ - hwvec3 selection[2] = {a, b}; - float* fSelection = (float*)selection; - return Vec3(fSelection[p[0]], fSelection[p[1]], fSelection[p[2]]); -} - -ILINE hwvec3 HWV3Zero() -{ - return Vec3(0.0f, 0.0f, 0.0f); -} - -ILINE hwvec4 HWV4Zero() -{ - return Vec4(0.0f, 0.0f, 0.0f, 0.0f); -} - - -ILINE hwvec3 HWV3Negate(const hwvec3& a) -{ - return Vec3(-a.x, -a.y, -a.z); -} - -ILINE hwvec3 HWVSelect(const hwvec3& a, const hwvec3& b, const hwvec3& control) -{ - return Vec3(control[0] > 0.0f ? b[0] : a[0], - control[1] > 0.0f ? b[1] : a[1], - control[2] > 0.0f ? b[2] : a[2]); -} - -ILINE hwvec3 HWVSelectSIMDF(const hwvec3& a, const hwvec3& b, const bool& control) -{ - return control ? b : a; -} - -ILINE simdf HWV3LengthSq(const hwvec3& a) -{ - return a.len2(); -} - - -////////////////////////////////////////////////// -//SIMDF functions for float stored in HWVEC4 data -////////////////////////////////////////////////// - -ILINE simdf SIMDFLoadFloat(const float& f) -{ - return f; -} - -ILINE void SIMDFSaveFloat(float* f, const simdf& a) -{ - *f = a; -} - -ILINE bool SIMDFGreaterThan(const simdf& a, const simdf& b) -{ - return (a > b); -} - -ILINE bool SIMDFLessThanEqualB(const simdf& a, const simdf& b) -{ - return (a <= b); -} - -ILINE bool SIMDFLessThanEqual(const simdf& a, const simdf& b) -{ - return (a <= b); -} - -ILINE bool SIMDFLessThanB(const simdf& a, const simdf& b) -{ - return (a < b); -} - -ILINE bool SIMDFLessThan(const simdf& a, const simdf& b) -{ - return (a < b); -} - -ILINE simdf SIMDFAdd(const simdf& a, const simdf& b) -{ - return a + b; -} - -ILINE simdf SIMDFMult(const simdf& a, const simdf& b) -{ - return a * b; -} - -ILINE simdf SIMDFReciprocal(const simdf& a) -{ - return 1.0f / a; -} - -ILINE simdf SIMDFSqrt(const simdf& a) -{ - return sqrt_tpl(a); -} - -ILINE simdf SIMDFSqrtEst(const simdf& a) -{ - return sqrt_tpl(a); -} - -ILINE simdf SIMDFSqrtEstFast(const simdf& a) -{ - return sqrt_tpl(a); -} - -ILINE simdf SIMDFMax(const simdf& a, const simdf& b) -{ - return max(a, b); -} - -ILINE simdf SIMDFMin(const simdf& a, const simdf& b) -{ - return min(a, b); -} - -ILINE simdf SIMDFClamp(const simdf& a, const simdf& min, const simdf& max) -{ - return clamp_tpl(a, min, max); -} - -ILINE simdf SIMDFAbs(const simdf& a) -{ - return fabsf(a); -} - -#endif // CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H diff --git a/Code/Legacy/CryCommon/Cry_Math.h b/Code/Legacy/CryCommon/Cry_Math.h index 74a18e8910..a96b83a1bf 100644 --- a/Code/Legacy/CryCommon/Cry_Math.h +++ b/Code/Legacy/CryCommon/Cry_Math.h @@ -8,8 +8,6 @@ // Description : Common math class - - #pragma once //======================================================================================== @@ -18,7 +16,6 @@ #include "Cry_ValidNumber.h" #include // eLittleEndian #include -//#include #include /////////////////////////////////////////////////////////////////////////////// // Forward declarations // @@ -27,8 +24,7 @@ template struct Vec2_tpl; template struct Vec3_tpl; -template -struct Vec4_tpl; +struct Vec4; template struct Ang3_tpl; @@ -38,14 +34,6 @@ template struct AngleAxis_tpl; template struct Quat_tpl; -template -struct QuatT_tpl; -template -struct DualQuat_tpl; -template -struct QuatTS_tpl; -template -struct QuatTNS_tpl; template struct Diag33_tpl; @@ -94,14 +82,8 @@ const f32 gf_halfPI = f32(1.57079632679489661923132169163975144209858469968755); #define TANGENT30_2 0.57735026918962576450914878050196f * 2 // 2*tan(30) #define LN2 0.69314718055994530941723212145818f // ln(2) - - - - ILINE f32 fsel(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; } ILINE f64 fsel(const f64 _a, const f64 _b, const f64 _c) { return (_a < 0.0f) ? _c : _b; } -ILINE f32 fself(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; } -ILINE f32 fsels(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; } ILINE f32 fres(const f32 _a) { return 1.f / _a; } template ILINE T isel(int c, T a, T b) { return (c < 0) ? b : a; } @@ -319,13 +301,6 @@ ILINE int64 pos_round(f64 f) { return int64(f + 0.5); } ILINE int32 int_ceil(f32 f) { int32 i = int32(f); return (f > f32(i)) ? i + 1 : i; } ILINE int64 int_ceil(f64 f) { int64 i = int64(f); return (f > f64(i)) ? i + 1 : i; } -ILINE float ufrac8_to_float(float u) { return u * (1.f / 255.f); } -ILINE float ifrac8_to_float(float i) { return i * (1.f / 127.f); } -ILINE uint8 float_to_ufrac8(float f) { int i = pos_round(f * 255.f); assert(i >= 0 && i < 256); return uint8(i); } -ILINE int8 float_to_ifrac8(float f) { int i = int_round(f * 127.f); assert(abs(i) <= 127); return int8(i); } - - - template ILINE F sqr(const F& op) { return op * op; } template @@ -490,11 +465,8 @@ ILINE int64 iszero(long int x) { return -(x >> 63 ^ (x - 1) >> 63); } #endif ILINE float if_neg_else(float test, float val_neg, float val_nonneg) { return (float)fsel(test, val_nonneg, val_neg); } -ILINE float if_pos_else(float test, float val_pos, float val_nonpos) { return (float)fsel(-test, val_nonpos, val_pos); } template ILINE int32 inrange(F x, F end1, F end2) { return isneg(fabs_tpl(end1 + end2 - x * (F)2) - fabs_tpl(end1 - end2)); } -template -ILINE F cond_select(int32 bFirst, F op1, F op2) { F arg[2] = { op1, op2 }; return arg[bFirst ^ 1]; } template ILINE int32 idxmax3(const F* pdata) @@ -510,56 +482,6 @@ ILINE int32 idxmax3(const Vec3_tpl& vec) imax |= isneg(vec[imax] - vec.z) << 1; return imax & (2 | (imax >> 1 ^ 1)); } -template -ILINE int32 idxmin3(const F* pdata) -{ - int32 imin = isneg(pdata[1] - pdata[0]); - imin |= isneg(pdata[2] - pdata[imin]) << 1; - return imin & (2 | (imin >> 1 ^ 1)); -} -template -ILINE int32 idxmin3(const Vec3_tpl& vec) -{ - int32 imin = isneg(vec.y - vec.x); - imin |= isneg(vec.z - vec[imin]) << 1; - return imin & (2 | (imin >> 1 ^ 1)); -} -// Approximation of exp(-x) -ILINE float approxExp(float x) { return fres(1.f + x); } -// Approximation of 1.f - exp(-x) -ILINE float approxOneExp(float x) { return x * fres(1.f + x); } - - -ILINE int ilog2(uint64 x) // if x==1<> 23) - 127; -#endif -} - static int32 inc_mod3[] = {1, 2, 0}, dec_mod3[] = {2, 0, 1}; #ifdef PHYSICS_EXPORTS @@ -596,114 +518,6 @@ enum type_identity #include "Cry_Matrix34.h" #include "Cry_Matrix44.h" #include "Cry_Quat.h" -#include "Cry_HWVector3.h" -#include "Cry_HWMatrix.h" - -////////////////////////////////////////////////////////////////////////// - -/// This function relaxes a value (val) towards a desired value (to) whilst maintaining continuity -/// of val and its rate of change (valRate). timeDelta is the time between this call and the previous one. -/// The caller would normally keep val and valRate as working variables, and smoothTime is normally -/// a fixed parameter. The to/timeDelta values can change. -/// -/// Implementation details: -/// -/// This is a critically damped spring system. A linear spring is attached between "val" and "to" that -/// drags "val" to "to". At the same time a damper between the two removes oscillations; it's tweaked -/// so it doesn't dampen more than necessary. In combination this gives smooth ease-in and ease-out behavior. -/// -/// smoothTime can be interpreted in a couple of ways: -/// - it's the "expected time to reach the target when at maximum velocity" (the target will, however, not be reached -/// in that time because the speed will decrease the closer it gets to the target) -/// - it's the 'lag time', how many seconds "val" lags behind "to". If your -/// target has a certain speed, the lag distance is simply the smoothTime times that speed. -/// - it's 2/omega, where omega is the spring's natural frequency (or less formally a measure of the spring stiffness) -/// -/// The implementation is stable for varying timeDelta, but for performance reasons it uses a polynomial approximation -/// to the exponential function. The approximation works well (within 0.1% of accuracy) when smoothTime > 2*deltaTime, -/// which is usually the case. (but it might be troublesome when you want a stiff spring or have frame hikes!) -/// The implementation handles cases where smoothTime==0 separately and reliably. In that case the target will be -/// reached immediately, and valRate is updated appropriately. -/// -/// Based on "Critically Damped Ease-In/Ease-Out Smoothing", Thomas Lowe, Game Programming Gems IV -/// - - -template -ILINE void SmoothCD( - T& val, ///< in/out: value to be smoothed - T& valRate, ///< in/out: rate of change of the value - const float timeDelta, ///< in: time interval - const T& to, ///< in: the target value - const float smoothTime) ///< in: timescale for smoothing -{ - if (smoothTime > 0.0f) - { - const float omega = 2.0f / smoothTime; - const float x = omega * timeDelta; - const float exp = 1.0f / (1.0f + x + 0.48f * x * x + 0.235f * x * x * x); - const T change = (val - to); - const T temp = (T)((valRate + change * omega) * timeDelta); - valRate = (T)((valRate - temp * omega) * exp); - val = (T)(to + (change + temp) * exp); - } - else if (timeDelta > 0.0f) - { - valRate = (T)((to - val) / timeDelta); - val = to; - } - else - { - val = to; - T zeroizeAmount = valRate; - valRate -= zeroizeAmount; // zero it... - } -} - - -template -ILINE void SmoothCDWithMaxRate( - T& val, ///< in/out: value to be smoothed - T& valRate, ///< in/out: rate of change of the value - const float timeDelta, ///< in: time interval - const T& to, ///< in: the target value - const float smoothTime, ///< in: timescale for smoothing - const T& maxValRate) ///< in: maximum allowed rate of change -{ - if (smoothTime > 0.0f) - { - const float omega = 2.0f / smoothTime; - const float x = omega * timeDelta; - const float exp = 1.0f / (1.0f + x + 0.48f * x * x + 0.235f * x * x * x); - const T unclampedChange = val - to; - const T maxChange = maxValRate * smoothTime; - const T clampedChange = clamp_tpl(unclampedChange, -maxChange, maxChange); - const T clampedTo = val - clampedChange; - const T temp = (T)((valRate + clampedChange * omega) * timeDelta); - valRate = (T)((valRate - temp * omega) * exp); - val = (T)(clampedTo + (clampedChange + temp) * exp); - } - else if (timeDelta > 0.0f) - { - const T unclampedRate = (T)((to - val) / timeDelta); - valRate = clamp_tpl(unclampedRate, -maxValRate, maxValRate); - val += valRate * timeDelta; - } - else - { - val = to; - T zeroizeAmount = valRate; - valRate -= zeroizeAmount; // zero it... - } -} - -// Smoothes linear blending into cubic (b-spline) with 0-derivatives -// near 0 and 1 -inline f32 SmoothBlendValue (const f32 fBlend) -{ - const f32 fBlendAdj = fBlend - 0.5f; - return (f32)fsel(-fBlend, 0.f, fsel(fBlend - 1.f, 1.f, 0.5f - 2.f * (fBlendAdj * fBlendAdj * fBlendAdj) + 1.5f * fBlendAdj)); -} // function for safe comparsion of floating point values ILINE bool fcmp(f32 fA, f32 fB, f32 fEpsilon = FLT_EPSILON) diff --git a/Code/Legacy/CryCommon/Cry_Matrix33.h b/Code/Legacy/CryCommon/Cry_Matrix33.h index 9e0b12fafa..74004c15e0 100644 --- a/Code/Legacy/CryCommon/Cry_Matrix33.h +++ b/Code/Legacy/CryCommon/Cry_Matrix33.h @@ -8,10 +8,6 @@ // Description : Common matrix class - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H -#define CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H #pragma once @@ -64,7 +60,6 @@ struct Matrix33_tpl #else ILINE Matrix33_tpl(){}; #endif - //set matrix to Identity ILINE Matrix33_tpl(type_identity) { @@ -78,21 +73,6 @@ struct Matrix33_tpl m21 = 0; m22 = 1; } - //set matrix to Zero - ILINE Matrix33_tpl(type_zero) - { - m00 = 0; - m01 = 0; - m02 = 0; - m10 = 0; - m11 = 0; - m12 = 0; - m20 = 0; - m21 = 0; - m22 = 0; - } - - //ASSIGNMENT OPERATOR of identical Matrix33 types. //The assignment operator has precedence over assignment constructor //Matrix33 m; m=m33; @@ -118,7 +98,7 @@ struct Matrix33_tpl //CONSTRUCTOR for identical float-types. It initializes a Matrix33 with 9 floats. //Matrix33(0,1,2, 3,4,5, 6,7,8); - explicit ILINE Matrix33_tpl(F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22) + explicit ILINE Matrix33_tpl(F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22) { m00 = x00; m01 = x01; @@ -130,26 +110,11 @@ struct Matrix33_tpl m21 = x21; m22 = x22; } - //CONSTRUCTOR for different float-types. It initializes a Matrix33 with 9 floats. - //Matrix33(0.0,1.0,2.0, 3.0,4.0,5.0, 6.0,7.0,8.0); - template - explicit ILINE Matrix33_tpl(F1 x00, F1 x01, F1 x02, F1 x10, F1 x11, F1 x12, F1 x20, F1 x21, F1 x22) - { - m00 = F(x00); - m01 = F(x01); - m02 = F(x02); - m10 = F(x10); - m11 = F(x11); - m12 = F(x12); - m20 = F(x20); - m21 = F(x21); - m22 = F(x22); - } //CONSTRUCTOR for identical float-types. It initializes a Matrix33 with 3 vectors stored in the columns. //Matrix33(v0,v1,v2); - explicit ILINE Matrix33_tpl(const Vec3_tpl&vx, const Vec3_tpl&vy, const Vec3_tpl&vz) + explicit ILINE Matrix33_tpl(const Vec3_tpl&vx, const Vec3_tpl&vy, const Vec3_tpl&vz) { m00 = vx.x; m01 = vy.x; @@ -164,7 +129,7 @@ struct Matrix33_tpl //CONSTRUCTOR for different float-types. It initializes a Matrix33 with 3 vectors stored in the columns and converts between floats/doubles. //Matrix33r(v0,v1,v2); template - explicit ILINE Matrix33_tpl(const Vec3_tpl&vx, const Vec3_tpl&vy, const Vec3_tpl&vz) + explicit ILINE Matrix33_tpl(const Vec3_tpl&vx, const Vec3_tpl&vy, const Vec3_tpl&vz) { m00 = F(vx.x); m01 = F(vy.x); @@ -209,8 +174,6 @@ struct Matrix33_tpl m22 = F(m.m22); } - - //CONSTRUCTOR for identical float-types. It converts a Matrix34 into a Matrix33. //Needs to be 'explicit' because we loose the translation vector in the conversion process //Matrix33(m34); @@ -245,9 +208,6 @@ struct Matrix33_tpl m22 = F(m.m22); } - - - //CONSTRUCTOR for identical float-types. It converts a Matrix44 into a Matrix33. //Needs to be 'explicit' because we loose the translation vector and the 3rd row in the conversion process //Matrix33(m44); @@ -356,26 +316,6 @@ struct Matrix33_tpl SetRotationXYZ(Ang3_tpl(F(ang.x), F(ang.y), F(ang.z))); } - - - - //Bracket OPERATOR: initializes a Matrix33 with 9 floats. - //Matrix33 m; m(0,1,2, 3,4,5, 6,7,8); - ILINE void operator () (F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22) - { - m00 = x00; - m01 = x01; - m02 = x02; - m10 = x10; - m11 = x11; - m12 = x12; - m20 = x20; - m21 = x21; - m22 = x22; - assert(IsValid()); - } - - //--------------------------------------------------------------------------------------- ILINE void SetIdentity(void) @@ -391,27 +331,6 @@ struct Matrix33_tpl m22 = 1; } - ILINE static Matrix33_tpl CreateIdentity() - { - Matrix33_tpl m33; - m33.SetIdentity(); - return m33; - } - - ILINE void SetZero() - { - m00 = 0; - m01 = 0; - m02 = 0; - m10 = 0; - m11 = 0; - m12 = 0; - m20 = 0; - m21 = 0; - m22 = 0; - } - - /*! * Create a rotation matrix around an arbitrary axis (Eulers Theorem). * The axis is specified as a normalized Vec3. The angle is assumed to be in radians. @@ -597,7 +516,7 @@ struct Matrix33_tpl F dot = v0 | v1; if (dot < F(-0.9999f)) { - Vec3d axis = v0.GetOrthogonal().GetNormalized(); + Vec3_tpl axis = v0.GetOrthogonal().GetNormalized(); m00 = F(2 * axis.x * axis.x - 1); m01 = F(2 * axis.x * axis.y); m02 = F(2 * axis.x * axis.z); @@ -723,28 +642,6 @@ struct Matrix33_tpl return m33; } - - //! calculate 2 vector that form a orthogonal base with a given input vector (by M.M.) - //! /param invDirection input direction (has to be normalized) - //! /param outvA first output vector that is perpendicular to the input direction - //! /param outvB second output vector that is perpendicular the input vector and the first output vector - ILINE static Matrix33_tpl CreateOrthogonalBase(const Vec3& invDirection) - { - Vec3 outvA; - if (invDirection.z < -0.5f || invDirection.z > 0.5f) - { - outvA = Vec3(invDirection.z, invDirection.y, -invDirection.x); - } - else - { - outvA = Vec3(invDirection.y, -invDirection.x, invDirection.z); - } - Vec3 outvB = (invDirection % outvA).GetNormalized(); - outvA = (invDirection % outvB).GetNormalized(); - return CreateFromVectors(invDirection, outvA, outvB); - } - - ////////////////////////////////////////////////////////////////////////// ILINE static Matrix33_tpl CreateOrientation(const Vec3_tpl& dir, const Vec3_tpl& up, float rollAngle) { @@ -779,77 +676,6 @@ struct Matrix33_tpl return tm; } - - /*! - * Direct-Matrix-Slerp: for the sake of completeness, I have included the following expression - * for Spherical-Linear-Interpolation without using quaternions. This is much faster then converting - * both matrices into quaternions in order to do a quaternion slerp and then converting the slerped - * quaternion back into a matrix. - * This is a high-precision calculation. Given two orthonormal 3x3 matrices this function calculates - * the shortest possible interpolation-path between the two rotations. The interpolation curve forms - * a great arc on the rotation sphere (geodesic). Not only does Slerp follow a great arc it follows - * the shortest great arc. Furthermore Slerp has constant angular velocity. All in all Slerp is the - * optimal interpolation curve between two rotations. - * - * STABILITY PROBLEM: There are two singularities at angle=0 and angle=PI. At 0 the interpolation-axis - * is arbitrary, which means any axis will produce the same result because we have no rotation. Thats - * why I'm using (1,0,0). At PI the rotations point away from each other and the interpolation-axis - * is unpredictable. In this case I'm also using the axis (1,0,0). If the angle is ~0 or ~PI, then we - * have to normalize a very small vector and this can cause numerical instability. The quaternion-slerp - * has exactly the same problems. - * Ivo - * Example: - * Matrix33 slerp=Matrix33::CreateSlerp( m,n,0.333f ); - */ - ILINE void SetSlerp(const Matrix33_tpl& m, const Matrix33_tpl& n, F t) - { - assert(m.IsValid()); - assert(n.IsValid()); - //calculate delta-rotation between m and n (=39 flops) - Matrix33_tpl d, i; - d.m00 = m.m00 * n.m00 + m.m10 * n.m10 + m.m20 * n.m20; - d.m01 = m.m00 * n.m01 + m.m10 * n.m11 + m.m20 * n.m21; - d.m02 = m.m00 * n.m02 + m.m10 * n.m12 + m.m20 * n.m22; - d.m10 = m.m01 * n.m00 + m.m11 * n.m10 + m.m21 * n.m20; - d.m11 = m.m01 * n.m01 + m.m11 * n.m11 + m.m21 * n.m21; - d.m12 = m.m01 * n.m02 + m.m11 * n.m12 + m.m21 * n.m22; - d.m20 = d.m01 * d.m12 - d.m02 * d.m11; - d.m21 = d.m02 * d.m10 - d.m00 * d.m12; - d.m22 = d.m00 * d.m11 - d.m01 * d.m10; - assert(d.IsOrthonormalRH(0.0001f)); - - Vec3_tpl axis(d.m21 - d.m12, d.m02 - d.m20, d.m10 - d.m01); - F l = sqrt(axis | axis); - if (l > F(0.00001)) - { - axis /= l; - } - else - { - axis(1, 0, 0); - } - i.SetRotationAA(acos(clamp_tpl((d.m00 + d.m11 + d.m22 - 1) * 0.5f, F(-1), F(+1))) * t, axis); //angle interpolation and calculation of new delta-matrix (=26 flops) - - //final concatenation (=39 flops) - m00 = F(m.m00 * i.m00 + m.m01 * i.m10 + m.m02 * i.m20); - m01 = F(m.m00 * i.m01 + m.m01 * i.m11 + m.m02 * i.m21); - m02 = F(m.m00 * i.m02 + m.m01 * i.m12 + m.m02 * i.m22); - m10 = F(m.m10 * i.m00 + m.m11 * i.m10 + m.m12 * i.m20); - m11 = F(m.m10 * i.m01 + m.m11 * i.m11 + m.m12 * i.m21); - m12 = F(m.m10 * i.m02 + m.m11 * i.m12 + m.m12 * i.m22); - m20 = m01 * m12 - m02 * m11; - m21 = m02 * m10 - m00 * m12; - m22 = m00 * m11 - m01 * m10; - assert(this->IsOrthonormalRH(0.0001f)); - } - ILINE static Matrix33_tpl CreateSlerp(const Matrix33_tpl m, const Matrix33_tpl n, F t) - { - Matrix33_tpl m33; - m33.SetSlerp(m, n, t); - return m33; - } - - ILINE void SetScale(const Vec3_tpl& s) { m00 = s.x; @@ -880,9 +706,6 @@ struct Matrix33_tpl } ILINE static Matrix33_tpl CreateFromVectors(const Vec3_tpl& vx, const Vec3_tpl& vy, const Vec3_tpl& vz) { Matrix33_tpl dst; dst.SetFromVectors(vx, vy, vz); return dst; } - - - ILINE void Transpose() // in-place transposition { F t; @@ -896,56 +719,6 @@ struct Matrix33_tpl m12 = m21; m21 = t; } - ILINE Matrix33_tpl GetTransposed() const - { - Matrix33_tpl dst; - dst.m00 = m00; - dst.m01 = m10; - dst.m02 = m20; - dst.m10 = m01; - dst.m11 = m11; - dst.m12 = m21; - dst.m20 = m02; - dst.m21 = m12; - dst.m22 = m22; - return dst; - } - ILINE Matrix33_tpl T() const { return GetTransposed(); } - - ILINE Matrix33_tpl& Fabs() - { - m00 = fabs_tpl(m00); - m01 = fabs_tpl(m01); - m02 = fabs_tpl(m02); - m10 = fabs_tpl(m10); - m11 = fabs_tpl(m11); - m12 = fabs_tpl(m12); - m20 = fabs_tpl(m20); - m21 = fabs_tpl(m21); - m22 = fabs_tpl(m22); - return *this; - } - ILINE Matrix33_tpl GetFabs() const { Matrix33_tpl m = *this; m.Fabs(); return m; } - - - ILINE void Adjoint(void) - { - //rescue members - Matrix33_tpl m = *this; - //calculate the adjoint-matrix - m00 = m.m11 * m.m22 - m.m12 * m.m21; - m01 = m.m12 * m.m20 - m.m10 * m.m22; - m02 = m.m10 * m.m21 - m.m11 * m.m20; - m10 = m.m21 * m.m02 - m.m22 * m.m01; - m11 = m.m22 * m.m00 - m.m20 * m.m02; - m12 = m.m20 * m.m01 - m.m21 * m.m00; - m20 = m.m01 * m.m12 - m.m02 * m.m11; - m21 = m.m02 * m.m10 - m.m00 * m.m12; - m22 = m.m00 * m.m11 - m.m01 * m.m10; - } - ILINE Matrix33_tpl GetAdjoint() const { Matrix33_tpl dst = *this; dst.Adjoint(); return dst; } - - /*! * @@ -1201,8 +974,6 @@ struct Matrix33_tpl /////////////////////////////////////////////////////////////////////////////// typedef Matrix33_tpl Matrix33; //always 32 bit -typedef Matrix33_tpl Matrix33d; //always 64 bit -typedef Matrix33_tpl Matrix33r; //variable float precision. depending on the target system it can be between 32, 64 or 80 bit //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- @@ -1360,9 +1131,6 @@ ILINE Matrix33_tpl& operator+=(Matrix33_tpl& l, const Matrix33_tpl& return l; } - - - template ILINE Matrix33_tpl operator - (const Matrix33_tpl& l, const Matrix33_tpl& r) { @@ -1397,9 +1165,6 @@ ILINE Matrix33_tpl& operator-=(Matrix33_tpl& l, const Matrix33_tpl& return l; } - - - template ILINE Matrix33_tpl operator*(const Matrix33_tpl& m, F op) { @@ -1462,37 +1227,3 @@ ILINE Vec2_tpl operator*(const Vec2_tpl& v, const Matrix33_tpl& m) assert(v.IsValid()); return Vec2_tpl(v.x * m.m00 + v.y * m.m10, v.x * m.m01 + v.y * m.m11); } - -template -ILINE Matrix33_tpl& crossproduct_matrix(const Vec3_tpl& v, Matrix33_tpl& m) -{ - m.m00 = 0; - m.m01 = -v.z; - m.m02 = v.y; - m.m10 = v.z; - m.m11 = 0; - m.m12 = -v.x; - m.m20 = -v.y; - m.m21 = v.x; - m.m22 = 0; - return m; -} - -template -ILINE Matrix33_tpl& dotproduct_matrix(const Vec3_tpl& v, const Vec3_tpl& op, Matrix33_tpl& m) -{ - m.m00 = v.x * op.x; - m.m10 = v.y * op.x; - m.m20 = v.z * op.x; - m.m01 = v.x * op.y; - m.m11 = v.y * op.y; - m.m21 = v.z * op.y; - m.m02 = v.x * op.z; - m.m12 = v.y * op.z; - m.m22 = v.z * op.z; - return m; -} - - -#endif // CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H - diff --git a/Code/Legacy/CryCommon/Cry_Matrix34.h b/Code/Legacy/CryCommon/Cry_Matrix34.h index 0659d3bc47..8dcb48cf6a 100644 --- a/Code/Legacy/CryCommon/Cry_Matrix34.h +++ b/Code/Legacy/CryCommon/Cry_Matrix34.h @@ -8,16 +8,8 @@ // Description : Common matrix class - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_MATRIX34_H -#define CRYINCLUDE_CRYCOMMON_CRY_MATRIX34_H #pragma once - - - - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -347,220 +339,6 @@ struct Matrix34_tpl *this = Matrix33_tpl(q); } - - - //CONSTRUCTOR for identical float-types. It converts a QuatT into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - explicit ILINE Matrix34_tpl(const QuatT_tpl &q) - { - *this = Matrix34_tpl(Matrix33_tpl(q.q), q.t); - } - //CONSTRUCTOR for different float-types. It converts a QuatT into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - template - ILINE explicit Matrix34_tpl(const QuatT_tpl q) - { - *this = Matrix34_tpl(Matrix33_tpl(q.q), q.t); - } - - - - - //CONSTRUCTOR for identical float-types. It converts a QuatTS into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - explicit ILINE Matrix34_tpl(const QuatTS_tpl &q) - { - assert(q.q.IsValid()); - Vec3_tpl v2 = q.q.v + q.q.v; - F xx = 1 - v2.x * q.q.v.x; - F yy = v2.y * q.q.v.y; - F xw = v2.x * q.q.w; - F xy = v2.y * q.q.v.x; - F yz = v2.z * q.q.v.y; - F yw = v2.y * q.q.w; - F xz = v2.z * q.q.v.x; - F zz = v2.z * q.q.v.z; - F zw = v2.z * q.q.w; - m00 = (1 - yy - zz) * q.s; - m01 = (xy - zw) * q.s; - m02 = (xz + yw) * q.s; - m03 = q.t.x; - m10 = (xy + zw) * q.s; - m11 = (xx - zz) * q.s; - m12 = (yz - xw) * q.s; - m13 = q.t.y; - m20 = (xz - yw) * q.s; - m21 = (yz + xw) * q.s; - m22 = (xx - yy) * q.s; - m23 = q.t.z; - } - //CONSTRUCTOR for different float-types. It converts a QuatTS into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - template - ILINE explicit Matrix34_tpl(const QuatTS_tpl &q) - { - assert(q.q.IsValid()); - Vec3_tpl v2 = q.q.v + q.q.v; - F1 xx = 1 - v2.x * q.q.v.x; - F1 yy = v2.y * q.q.v.y; - F1 xw = v2.x * q.q.w; - F1 xy = v2.y * q.q.v.x; - F1 yz = v2.z * q.q.v.y; - F1 yw = v2.y * q.q.w; - F1 xz = v2.z * q.q.v.x; - F1 zz = v2.z * q.q.v.z; - F1 zw = v2.z * q.q.w; - m00 = F((1 - yy - zz) * q.s); - m01 = F((xy - zw) * q.s); - m02 = F((xz + yw) * q.s); - m03 = F(q.t.x); - m10 = F((xy + zw) * q.s); - m11 = F((xx - zz) * q.s); - m12 = F((yz - xw) * q.s); - m13 = F(q.t.y); - m20 = F((xz - yw) * q.s); - m21 = F((yz + xw) * q.s); - m22 = F((xx - yy) * q.s); - m23 = F(q.t.z); - } - - - - - //CONSTRUCTOR for identical float-types. It converts a QuatTNS into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - explicit ILINE Matrix34_tpl(const QuatTNS_tpl &q) - { - assert(q.q.IsValid()); - Vec3_tpl v2 = q.q.v + q.q.v; - F xx = 1 - v2.x * q.q.v.x; - F yy = v2.y * q.q.v.y; - F xw = v2.x * q.q.w; - F xy = v2.y * q.q.v.x; - F yz = v2.z * q.q.v.y; - F yw = v2.y * q.q.w; - F xz = v2.z * q.q.v.x; - F zz = v2.z * q.q.v.z; - F zw = v2.z * q.q.w; - m00 = (1 - yy - zz) * q.s.x; - m01 = (xy - zw) * q.s.y; - m02 = (xz + yw) * q.s.z; - m03 = q.t.x; - m10 = (xy + zw) * q.s.x; - m11 = (xx - zz) * q.s.y; - m12 = (yz - xw) * q.s.z; - m13 = q.t.y; - m20 = (xz - yw) * q.s.x; - m21 = (yz + xw) * q.s.y; - m22 = (xx - yy) * q.s.z; - m23 = q.t.z; - } - //CONSTRUCTOR for different float-types. It converts a QuatTNS into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - template - ILINE explicit Matrix34_tpl(const QuatTNS_tpl &q) - { - assert(q.q.IsValid()); - Vec3_tpl v2 = q.q.v + q.q.v; - F1 xx = 1 - v2.x * q.q.v.x; - F1 yy = v2.y * q.q.v.y; - F1 xw = v2.x * q.q.w; - F1 xy = v2.y * q.q.v.x; - F1 yz = v2.z * q.q.v.y; - F1 yw = v2.y * q.q.w; - F1 xz = v2.z * q.q.v.x; - F1 zz = v2.z * q.q.v.z; - F1 zw = v2.z * q.q.w; - m00 = F((1 - yy - zz) * q.s.x); - m01 = F((xy - zw) * q.s.y); - m02 = F((xz + yw) * q.s.z); - m03 = F(q.t.x); - m10 = F((xy + zw) * q.s.x); - m11 = F((xx - zz) * q.s.y); - m12 = F((yz - xw) * q.s.z); - m13 = F(q.t.y); - m20 = F((xz - yw) * q.s.x); - m21 = F((yz + xw) * q.s.y); - m22 = F((xx - yy) * q.s.z); - m23 = F(q.t.z); - } - - - - - //CONSTRUCTOR for identical float-types. It converts a DualQuat into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - ILINE explicit Matrix34_tpl(const DualQuat_tpl &q) - { - assert((fabs_tpl(1 - (q.nq | q.nq))) < 0.01); //check if unit-quaternion - Vec3_tpl t = (q.nq.w * q.dq.v - q.dq.w * q.nq.v + q.nq.v % q.dq.v); //perfect for HLSL - Vec3_tpl v2 = q.nq.v + q.nq.v; - F xx = 1 - v2.x * q.nq.v.x; - F yy = v2.y * q.nq.v.y; - F xw = v2.x * q.nq.w; - F xy = v2.y * q.nq.v.x; - F yz = v2.z * q.nq.v.y; - F yw = v2.y * q.nq.w; - F xz = v2.z * q.nq.v.x; - F zz = v2.z * q.nq.v.z; - F zw = v2.z * q.nq.w; - m00 = 1 - yy - zz; - m01 = xy - zw; - m02 = xz + yw; - m03 = t.x + t.x; - m10 = xy + zw; - m11 = xx - zz; - m12 = yz - xw; - m13 = t.y + t.y; - m20 = xz - yw; - m21 = yz + xw; - m22 = xx - yy; - m23 = t.z + t.z; - } - //CONSTRUCTOR for different float-types. It converts a DualQuat into a Matrix34. - //Needs to be 'explicit' because we loose float-precision in the conversion process - //Matrix34(QuatT); - template - ILINE explicit Matrix34_tpl(const DualQuat_tpl &q) - { - assert((fabs_tpl(1 - (q.nq | q.nq))) < 0.01); //check if unit-quaternion - Vec3_tpl t = (q.nq.w * q.dq.v - q.dq.w * q.nq.v + q.nq.v % q.dq.v); //perfect for HLSL - Vec3_tpl v2 = q.nq.v + q.nq.v; - F1 xx = 1 - v2.x * q.nq.v.x; - F1 yy = v2.y * q.nq.v.y; - F1 xw = v2.x * q.nq.w; - F1 xy = v2.y * q.nq.v.x; - F1 yz = v2.z * q.nq.v.y; - F1 yw = v2.y * q.nq.w; - F1 xz = v2.z * q.nq.v.x; - F1 zz = v2.z * q.nq.v.z; - F1 zw = v2.z * q.nq.w; - m00 = F(1 - yy - zz); - m01 = F(xy - zw); - m02 = F(xz + yw); - m03 = F(t.x + t.x); - m10 = F(xy + zw); - m11 = F(xx - zz); - m12 = F(yz - xw); - m13 = F(t.y + t.y); - m20 = F(xz - yw); - m21 = F(yz + xw); - m22 = F(xx - yy); - m23 = F(t.z + t.z); - } - - - - - - //apply scaling to the columns of the matrix. ILINE void ScaleColumn(const Vec3_tpl& s) { @@ -580,7 +358,7 @@ struct Matrix34_tpl * Initializes the Matrix34 with the identity. * */ - void SetIdentity(void) + void SetIdentity() { m00 = 1.0f; m01 = 0.0f; @@ -596,58 +374,12 @@ struct Matrix34_tpl m23 = 0.0f; } - ILINE static Matrix34_tpl CreateIdentity(void) + ILINE static Matrix34_tpl CreateIdentity() { Matrix34_tpl m; m.SetIdentity(); return m; } - - ILINE bool IsIdentity() const - { - return 0 == (fabs_tpl((F)1 - m00) + fabs_tpl(m01) + fabs_tpl(m02) + fabs_tpl(m03) + fabs_tpl(m10) + fabs_tpl((F)1 - m11) + fabs_tpl(m12) + fabs_tpl(m13) + fabs_tpl(m20) + fabs_tpl(m21) + fabs_tpl((F)1 - m22)) + fabs_tpl(m23); - } - - ILINE int IsZero() const - { - return 0 == (fabs_tpl(m00) + fabs_tpl(m01) + fabs_tpl(m02) + fabs_tpl(m03) + fabs_tpl(m10) + fabs_tpl(m11) + fabs_tpl(m12) + fabs_tpl(m13) + fabs_tpl(m20) + fabs_tpl(m21) + fabs_tpl(m22)) + fabs_tpl(m23); - } - - /*! - * Create a rotation matrix around an arbitrary axis (Eulers Theorem). - * The axis is specified as an normalized Vec3. The angle is assumed to be in radians. - * This function also assumes a translation-vector and stores it in the right column. - * - * Example: - * Matrix34 m34; - * Vec3 axis=GetNormalized( Vec3(-1.0f,-0.3f,0.0f) ); - * m34.SetRotationAA( 3.14314f, axis, Vec3(5,5,5) ); - */ - ILINE void SetRotationAA(const F rad, const Vec3_tpl& axis, const Vec3_tpl& t = Vec3(ZERO)) - { - *this = Matrix33_tpl::CreateRotationAA(rad, axis); - this->SetTranslation(t); - } - ILINE static Matrix34_tpl CreateRotationAA(const F rad, const Vec3_tpl& axis, const Vec3_tpl& t = Vec3(ZERO)) - { - Matrix34_tpl m34; - m34.SetRotationAA(rad, axis, t); - return m34; - } - - ILINE void SetRotationAA(const Vec3_tpl& rot, const Vec3_tpl& t = Vec3(ZERO)) - { - *this = Matrix33_tpl::CreateRotationAA(rot); - this->SetTranslation(t); - } - ILINE static Matrix34_tpl CreateRotationAA(const Vec3_tpl& rot, const Vec3_tpl& t = Vec3(ZERO)) - { - Matrix34_tpl m34; - m34.SetRotationAA(rot, t); - return m34; - } - - /*! * Create rotation-matrix about X axis using an angle. * The angle is assumed to be in radians. @@ -690,28 +422,6 @@ struct Matrix34_tpl return m34; } - /*! - * Create rotation-matrix about Z axis using an angle. - * The angle is assumed to be in radians. - * The translation-vector is set to zero. - * - * Example: - * Matrix34 m34; - * m34.SetRotationZ(0.5f); - */ - ILINE void SetRotationZ(const f32 rad, const Vec3_tpl& t = Vec3(ZERO)) - { - *this = Matrix33_tpl::CreateRotationZ(rad); - this->SetTranslation(t); - } - ILINE static Matrix34_tpl CreateRotationZ(const f32 rad, const Vec3_tpl& t = Vec3(ZERO)) - { - Matrix34_tpl m34; - m34.SetRotationZ(rad, t); - return m34; - } - - /*! * * Convert three Euler angle to mat33 (rotation order:XYZ) @@ -742,22 +452,6 @@ struct Matrix34_tpl } - ILINE void SetRotationAA(F c, F s, Vec3_tpl axis, const Vec3_tpl& t = Vec3(ZERO)) - { - assert(axis.IsValid()); - assert(t.IsValid()); - *this = Matrix33_tpl::CreateRotationAA(c, s, axis); - m03 = t.x; - m13 = t.y; - m23 = t.z; - } - ILINE static Matrix34_tpl CreateRotationAA(F c, F s, Vec3_tpl axis, const Vec3_tpl& t = Vec3(ZERO)) - { - Matrix34_tpl m34; - m34.SetRotationAA(c, s, axis, t); - return m34; - } - ILINE void SetTranslationMat(const Vec3_tpl& v) { m00 = 1.0f; @@ -804,25 +498,6 @@ struct Matrix34_tpl return m; } - void InvertFast() - { // in-place transposition - assert(IsOrthonormal()); - F t; - Vec3 v(m03, m13, m23); - t = m01; - m01 = m10; - m10 = t; - m03 = -v.x * m00 - v.y * m01 - v.z * m20; - t = m02; - m02 = m20; - m20 = t; - m13 = -v.x * m10 - v.y * m11 - v.z * m21; - t = m12; - m12 = m21; - m21 = t; - m23 = -v.x * m20 - v.y * m21 - v.z * m22; - } - Matrix34_tpl GetInvertedFast() const { assert(IsOrthonormal()); @@ -875,14 +550,6 @@ struct Matrix34_tpl m22 = z.z; } - - //determinant is ambiguous: only the upper-left-submatrix's determinant is calculated - ILINE f32 Determinant() const - { - return (m00 * m11 * m22) + (m01 * m12 * m20) + (m02 * m10 * m21) - (m02 * m11 * m20) - (m00 * m12 * m21) - (m01 * m10 * m22); - } - - //-------------------------------------------------------------------------------- //---- helper functions to access matrix-members ------------ //-------------------------------------------------------------------------------- @@ -896,10 +563,8 @@ struct Matrix34_tpl ILINE void SetRow(int i, const Vec3_tpl& v) { assert(i < 3); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; } ILINE const Vec3_tpl& GetRow(int i) const { assert(i < 3); return *(const Vec3_tpl*)(&m00 + 4 * i); } - ILINE const Vec4_tpl& GetRow4(int i) const { assert(i < 3); return *(const Vec4_tpl*)(&m00 + 4 * i); } + ILINE const Vec4& GetRow4(int i) const { assert(i < 3); return *(const Vec4*)(&m00 + 4 * i); } - ILINE void SetColumn(int i, const Vec3_tpl& v) { assert(i < 4); F* p = (F*)(&m00); p[i + 4 * 0] = v.x; p[i + 4 * 1] = v.y; p[i + 4 * 2] = v.z; } - ILINE Vec3_tpl GetColumn(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec3(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2]); } ILINE Vec3_tpl GetColumn0() const { return Vec3_tpl(m00, m10, m20); } ILINE Vec3_tpl GetColumn1() const { return Vec3_tpl(m01, m11, m21); } ILINE Vec3_tpl GetColumn2() const { return Vec3_tpl(m02, m12, m22); } @@ -908,8 +573,6 @@ struct Matrix34_tpl ILINE void SetTranslation(const Vec3_tpl& t) { m03 = t.x; m13 = t.y; m23 = t.z; } ILINE Vec3_tpl GetTranslation() const { return Vec3_tpl(m03, m13, m23); } - ILINE void ScaleTranslation (F s) { m03 *= s; m13 *= s; m23 *= s; } - ILINE Matrix34_tpl AddTranslation(const Vec3_tpl& t) { m03 += t.x; m13 += t.y; m23 += t.z; return *this; } ILINE void SetRotation33(const Matrix33_tpl& m33) { @@ -924,43 +587,6 @@ struct Matrix34_tpl m22 = m33.m22; } - ILINE void GetRotation33(Matrix33_tpl& m33) const - { - m33.m00 = m00; - m33.m01 = m01; - m33.m02 = m02; - m33.m10 = m10; - m33.m11 = m11; - m33.m12 = m12; - m33.m20 = m20; - m33.m21 = m21; - m33.m22 = m22; - } - - //check if we have an orthonormal-base (general case, works even with reflection matrices) - int IsOrthonormal(F threshold = 0.001) const - { - f32 d0 = fabs_tpl(GetColumn0() | GetColumn1()); - if (d0 > threshold) - { - return 0; - } - f32 d1 = fabs_tpl(GetColumn0() | GetColumn2()); - if (d1 > threshold) - { - return 0; - } - f32 d2 = fabs_tpl(GetColumn1() | GetColumn2()); - if (d2 > threshold) - { - return 0; - } - int a = (fabs_tpl(1 - (GetColumn0() | GetColumn0()))) < threshold; - int b = (fabs_tpl(1 - (GetColumn1() | GetColumn1()))) < threshold; - int c = (fabs_tpl(1 - (GetColumn2() | GetColumn2()))) < threshold; - return a & b & c; - } - //check if we have an orthonormal-base (assuming we are using a right-handed coordinate system) int IsOrthonormalRH(F threshold = 0.001) const { @@ -978,68 +604,6 @@ struct Matrix34_tpl ); } - bool IsValid() const - { - if (!NumberValid(m00)) - { - return false; - } - if (!NumberValid(m01)) - { - return false; - } - if (!NumberValid(m02)) - { - return false; - } - if (!NumberValid(m03)) - { - return false; - } - if (!NumberValid(m10)) - { - return false; - } - if (!NumberValid(m11)) - { - return false; - } - if (!NumberValid(m12)) - { - return false; - } - if (!NumberValid(m13)) - { - return false; - } - if (!NumberValid(m20)) - { - return false; - } - if (!NumberValid(m21)) - { - return false; - } - if (!NumberValid(m22)) - { - return false; - } - if (!NumberValid(m23)) - { - return false; - } - return true; - } - - - bool IsDegenerate(float epsilon = FLT_EPSILON) const - { - //check the basis vectors for 0 vector - return GetColumn0().len2() < epsilon - || GetColumn1().len2() < epsilon - || GetColumn2().len2() < epsilon; - } - /*! * Create a matrix with SCALING, ROTATION and TRANSLATION (in this order). * @@ -1093,43 +657,12 @@ struct Matrix34_tpl * Example 1: * Matrix m34; * m34.SetScale( Vec3(0.5f, 1.0f, 2.0f) ); - * Example 2: - * Matrix34 m34 = Matrix34::CreateScale( Vec3(0.5f, 1.0f, 2.0f) ); */ ILINE void SetScale(const Vec3_tpl& s, const Vec3_tpl& t = Vec3(ZERO)) { *this = Matrix33::CreateScale(s); this->SetTranslation(t); } - ILINE static Matrix34_tpl CreateScale(const Vec3_tpl& s, const Vec3_tpl& t = Vec3(ZERO)) - { - Matrix34_tpl m34; - m34.SetScale(s, t); - return m34; - } - - - ILINE Matrix44_tpl GetTransposed() const - { - Matrix44_tpl tmp; - tmp.m00 = m00; - tmp.m01 = m10; - tmp.m02 = m20; - tmp.m03 = 0; - tmp.m10 = m01; - tmp.m11 = m11; - tmp.m12 = m21; - tmp.m13 = 0; - tmp.m20 = m02; - tmp.m21 = m12; - tmp.m22 = m22; - tmp.m23 = 0; - tmp.m30 = m03; - tmp.m31 = m13; - tmp.m32 = m23; - tmp.m33 = 1; - return tmp; - } /*! * calculate a real inversion of a Matrix34 @@ -1141,7 +674,7 @@ struct Matrix34_tpl * Example 2: * Matrix34 im34 = m34.GetInverted(); */ - void Invert(void) + void Invert() { //rescue members Matrix34_tpl m = *this; @@ -1182,37 +715,6 @@ struct Matrix34_tpl dst.Invert(); return dst; } - - /*! - * Name: ReflectMat34 - * Description: reflect a rotation matrix with respect to a plane. - * - * Example: - * Vec3 normal( 0.0f,-1.0f, 0.0f); - * Vec3 pos(0,1000,0); - * Matrix34 m34=CreateReflectionMat( pos, normal ); - */ - ILINE static Matrix34_tpl CreateReflectionMat (const Vec3_tpl& p, const Vec3_tpl& n) - { - Matrix34_tpl m; - F vxy = -2.0f * n.x * n.y; - F vxz = -2.0f * n.x * n.z; - F vyz = -2.0f * n.y * n.z; - F pdotn = 2.0f * (p | n); - m.m00 = 1.0f - 2.0f * n.x * n.x; - m.m01 = vxy; - m.m02 = vxz; - m.m03 = pdotn * n.x; - m.m10 = vxy; - m.m11 = 1.0f - 2.0f * n.y * n.y; - m.m12 = vyz; - m.m13 = pdotn * n.y; - m.m20 = vxz; - m.m21 = vyz; - m.m22 = 1.0f - 2.0f * n.z * n.z; - m.m23 = pdotn * n.z; - return m; - } }; /////////////////////////////////////////////////////////////////////////////// @@ -1220,8 +722,6 @@ struct Matrix34_tpl /////////////////////////////////////////////////////////////////////////////// typedef Matrix34_tpl Matrix34; //always 32 bit -typedef Matrix34_tpl Matrix34d;//always 64 bit -typedef Matrix34_tpl Matrix34r;//variable float precision. depending on the target system it can be between 32, 64 or bit #if AZ_COMPILER_MSVC typedef __declspec(align(16)) Matrix34_tpl Matrix34A; #elif AZ_COMPILER_CLANG @@ -1423,6 +923,3 @@ ILINE Matrix44_tpl operator * (const Matrix34_tpl& l, const Matrix44_tpl& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; } - ILINE void SetRow4(int i, const Vec4_tpl& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; p[3 + 4 * i] = v.w; } + ILINE void SetRow4(int i, const Vec4& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; p[3 + 4 * i] = v.w; } ILINE const Vec3_tpl& GetRow(int i) const { assert(i < 4); return *(const Vec3_tpl*)(&m00 + 4 * i); } ILINE void SetColumn(int i, const Vec3_tpl& v) { assert(i < 4); F* p = (F*)(&m00); p[i + 4 * 0] = v.x; p[i + 4 * 1] = v.y; p[i + 4 * 2] = v.z; } ILINE Vec3_tpl GetColumn(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec3(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2]); } - ILINE Vec4_tpl GetColumn4(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec4(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2], p[i + 4 * 3]); } + ILINE Vec4 GetColumn4(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec4(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2], p[i + 4 * 3]); } ILINE Vec3 GetTranslation() const { return Vec3(m03, m13, m23); } ILINE void SetTranslation(const Vec3& t) { m03 = t.x; m13 = t.y; m23 = t.z; } @@ -792,24 +792,24 @@ ILINE Matrix44_tpl operator * (const Matrix44_tpl& l, const Matrix44_tpl } //post-multiply -template -ILINE Vec4_tpl operator*(const Matrix44_tpl& m, const Vec4_tpl& v) +template +ILINE Vec4 operator*(const Matrix44_tpl& m, const Vec4& v) { assert(m.IsValid()); assert(v.IsValid()); - return Vec4_tpl(v.x * m.m00 + v.y * m.m01 + v.z * m.m02 + v.w * m.m03, + return Vec4(v.x * m.m00 + v.y * m.m01 + v.z * m.m02 + v.w * m.m03, v.x * m.m10 + v.y * m.m11 + v.z * m.m12 + v.w * m.m13, v.x * m.m20 + v.y * m.m21 + v.z * m.m22 + v.w * m.m23, v.x * m.m30 + v.y * m.m31 + v.z * m.m32 + v.w * m.m33); } //pre-multiply -template -ILINE Vec4_tpl operator*(const Vec4_tpl& v, const Matrix44_tpl& m) +template +ILINE Vec4 operator*(const Vec4& v, const Matrix44_tpl& m) { assert(m.IsValid()); assert(v.IsValid()); - return Vec4_tpl(v.x * m.m00 + v.y * m.m10 + v.z * m.m20 + v.w * m.m30, + return Vec4(v.x * m.m00 + v.y * m.m10 + v.z * m.m20 + v.w * m.m30, v.x * m.m01 + v.y * m.m11 + v.z * m.m21 + v.w * m.m31, v.x * m.m02 + v.y * m.m12 + v.z * m.m22 + v.w * m.m32, v.x * m.m03 + v.y * m.m13 + v.z * m.m23 + v.w * m.m33); diff --git a/Code/Legacy/CryCommon/Cry_Quat.h b/Code/Legacy/CryCommon/Cry_Quat.h index a18d8a2ad9..115de36cdc 100644 --- a/Code/Legacy/CryCommon/Cry_Quat.h +++ b/Code/Legacy/CryCommon/Cry_Quat.h @@ -8,10 +8,6 @@ // Description : Common quaternion class - - -#ifndef CRYINCLUDE_CRYCOMMON_CRY_QUAT_H -#define CRYINCLUDE_CRYCOMMON_CRY_QUAT_H #pragma once #include @@ -751,41 +747,6 @@ struct Quat_tpl return d; } - - /*! - * linear-interpolation between quaternions (nlerp) - * in this case we convert the t-value into a 1d cubic spline to get closer to Slerp - * - * Example: - * Quat result,p,q; - * result.SetNlerpCubic( p, q, 0.5f ); - */ - ILINE void SetNlerpCubic(const Quat_tpl& p, const Quat_tpl& tq, F t) - { - Quat_tpl q = tq; - assert((fabs_tpl(1 - (p | p))) < 0.001); //check if unit-quaternion - assert((fabs_tpl(1 - (q | q))) < 0.001); //check if unit-quaternion - F cosine = (p | q); - if (cosine < 0) - { - q = -q; - } - F k = (1 - fabs_tpl(cosine)) * F(0.4669269); - F s = 2 * k * t * t * t - 3 * k * t * t + (1 + k) * t; - v.x = p.v.x * (1.0f - s) + q.v.x * s; - v.y = p.v.y * (1.0f - s) + q.v.y * s; - v.z = p.v.z * (1.0f - s) + q.v.z * s; - w = p.w * (1.0f - s) + q.w * s; - Normalize(); - } - ILINE static Quat_tpl CreateNlerpCubic(const Quat_tpl& p, const Quat_tpl& tq, F t) - { - Quat_tpl d; - d.SetNlerpCubic(p, tq, t); - return d; - } - - /*! * spherical-interpolation between quaternions (geometrical slerp) * @@ -836,39 +797,6 @@ struct Quat_tpl return d; } - /*! - * spherical-interpolation between quaternions (algebraic slerp_a) - * I have included this function just for the sake of completeness, because - * its the only useful application to check if exp & log really work. - * Both slerp-functions are returning the same result. - * - * Example: - * Quat result,p,q; - * result.SetExpSlerp( p,q,0.3345f ); - */ - ILINE void SetExpSlerp(const Quat_tpl& p, const Quat_tpl& tq, F t) - { - assert((fabs_tpl(1 - (p | p))) < 0.001); //check if unit-quaternion - assert((fabs_tpl(1 - (tq | tq))) < 0.001); //check if unit-quaternion - Quat_tpl q = tq; - if ((p | q) < 0) - { - q = -q; - } - *this = p * exp(log(!p * q) * t); //algebraic slerp (1) - //...and some more exp-slerp-functions producing all the same result - //*this = exp( log (p* !q) * (1-t)) * q; //algebraic slerp (2) - //*this = exp( log (q* !p) * t) * p; //algebraic slerp (3) - //*this = q * exp( log (!q*p) * (1-t)); //algebraic slerp (4) - } - ILINE static Quat_tpl CreateExpSlerp(const Quat_tpl& p, const Quat_tpl& q, F t) - { - Quat_tpl d; - d.SetExpSlerp(p, q, t); - return d; - } - - //! squad(p,a,b,q,t) = slerp( slerp(p,q,t),slerp(a,b,t), 2(1-t)t). ILINE void SetSquad(const Quat_tpl& p, const Quat_tpl& a, const Quat_tpl& b, const Quat_tpl& q, F t) { @@ -895,15 +823,7 @@ struct Quat_tpl // Typedefs // /////////////////////////////////////////////////////////////////////////////// -#ifndef MAX_API_NUM typedef Quat_tpl Quat; //always 32 bit -typedef Quat_tpl Quatd; //always 64 bit -typedef Quat_tpl Quatr; //variable float precision. depending on the target system it can be between 32, 64 or 80 bit -#endif - -typedef Quat_tpl CryQuat; -typedef Quat_tpl quaternionf; -typedef Quat_tpl quaternion; /*! * @@ -964,22 +884,6 @@ ILINE void operator *= (Quat_tpl& q, const Quat_tpl& p) q.v = p.v * s0 + q.v * p.w + (q.v % p.v); } -/*! -* Implements the multiplication operator: QuatT=Quat*Quatpos -* -* AxB = operation B followed by operation A. -* A multiplication takes 31 muls and 27 adds (=58 float operations). -* -* Example: -* Quat quat = Quat::CreateRotationX(1.94192f);; -* QuatT quatpos = QuatT::CreateRotationZ(3.14192f,Vec3(11,22,33)); -* QuatT qp = quat*quatpos; -*/ -template -ILINE QuatT_tpl operator * (const Quat_tpl& q, const QuatT_tpl& p) -{ - return QuatT_tpl(q * p.q, q * p.t); -} @@ -1154,1043 +1058,3 @@ ILINE void operator %= (Quat_tpl& q, const Quat_tpl& tp) } q = Quat_tpl(q.w + p.w, q.v + p.v); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//---------------------------------------------------------------------- -// Quaternion with translation vector -//---------------------------------------------------------------------- -template -struct QuatT_tpl -{ - Quat_tpl q; //this is the quaternion - Vec3_tpl t; //this is the translation vector and a scalar (for uniform scaling?) - - ILINE QuatT_tpl(){} - - //initialize with zeros - ILINE QuatT_tpl(type_zero) - { - q.w = 0, q.v.x = 0, q.v.y = 0, q.v.z = 0, t.x = 0, t.y = 0, t.z = 0; - } - ILINE QuatT_tpl(type_identity) - { - q.w = 1, q.v.x = 0, q.v.y = 0, q.v.z = 0, t.x = 0, t.y = 0, t.z = 0; - } - - ILINE QuatT_tpl(const Vec3_tpl& _t, const Quat_tpl& _q) { q = _q; t = _t; } - - //CONSTRUCTOR: implement the copy/casting/assignment constructor: - template - ILINE QuatT_tpl(const QuatT_tpl& qt) - : q(qt.q) - , t(qt.t) {} - - //convert unit DualQuat back to QuatT - ILINE QuatT_tpl(const DualQuat_tpl& qd) - { - //copy quaternion part - q = qd.nq; - //convert translation vector: - t = (qd.nq.w * qd.dq.v - qd.dq.w * qd.nq.v + qd.nq.v % qd.dq.v) * 2; //perfect for HLSL - } - - explicit ILINE QuatT_tpl(const QuatTS_tpl& qts) - : q(qts.q) - , t(qts.t) {} - - explicit ILINE QuatT_tpl(const Matrix34_tpl& m) - { - q = Quat_tpl(Matrix33(m)); - t = m.GetTranslation(); - } - - ILINE QuatT_tpl(const Quat_tpl& quat, const Vec3_tpl& trans) - { - q = quat; - t = trans; - } - - ILINE void SetIdentity() - { - q.w = 1; - q.v.x = 0; - q.v.y = 0; - q.v.z = 0; - t.x = 0; - t.y = 0; - t.z = 0; - } - - ILINE bool IsIdentity() const - { - return (q.IsIdentity() && t.IsZero()); - } - - /*! - * Convert three Euler angle to mat33 (rotation order:XYZ) - * The Euler angles are assumed to be in radians. - * The translation-vector is set to zero by default. - * - * Example 1: - * QuatT qp; - * qp.SetRotationXYZ( Ang3(0.5f,0.2f,0.9f), translation ); - * - * Example 2: - * QuatT qp=QuatT::CreateRotationXYZ( Ang3(0.5f,0.2f,0.9f), translation ); - */ - ILINE void SetRotationXYZ(const Ang3_tpl& rad, const Vec3_tpl& trans = Vec3(ZERO)) - { - assert(rad.IsValid()); - assert(trans.IsValid()); - q.SetRotationXYZ(rad); - t = trans; - } - ILINE static QuatT_tpl CreateRotationXYZ(const Ang3_tpl& rad, const Vec3_tpl& trans = Vec3(ZERO)) - { - assert(rad.IsValid()); - assert(trans.IsValid()); - QuatT_tpl qp; - qp.SetRotationXYZ(rad, trans); - return qp; - } - - - - ILINE void SetRotationAA(F cosha, F sinha, const Vec3_tpl axis, const Vec3_tpl& trans = Vec3(ZERO)) - { - q.SetRotationAA(cosha, sinha, axis); - t = trans; - } - ILINE static QuatT_tpl CreateRotationAA(F cosha, F sinha, const Vec3_tpl axis, const Vec3_tpl& trans = Vec3(ZERO)) - { - QuatT_tpl qt; - qt.SetRotationAA(cosha, sinha, axis, trans); - return qt; - } - - - ILINE void Invert() - { // in-place transposition - assert(q.IsValid()); - t = -t * q; - q = !q; - } - ILINE QuatT_tpl GetInverted() const - { - assert(q.IsValid()); - QuatT_tpl qpos; - qpos.q = !q; - qpos.t = -t * q; - return qpos; - } - - ILINE void SetTranslation(const Vec3_tpl& trans) { t = trans; } - - ILINE Vec3_tpl GetColumn0() const {return q.GetColumn0(); } - ILINE Vec3_tpl GetColumn1() const {return q.GetColumn1(); } - ILINE Vec3_tpl GetColumn2() const {return q.GetColumn2(); } - ILINE Vec3_tpl GetColumn3() const {return t; } - ILINE Vec3_tpl GetRow0() const { return q.GetRow0(); } - ILINE Vec3_tpl GetRow1() const { return q.GetRow1(); } - ILINE Vec3_tpl GetRow2() const { return q.GetRow2(); } - - ILINE static bool IsEquivalent(const QuatT_tpl& qt1, const QuatT_tpl& qt2, F qe = RAD_EPSILON, F ve = VEC_EPSILON) - { - real rad = acos(min(1.0f, fabs_tpl(qt1.q | qt2.q))); - bool qdif = rad <= qe; - bool vdif = fabs_tpl(qt1.t.x - qt2.t.x) <= ve && fabs_tpl(qt1.t.y - qt2.t.y) <= ve && fabs_tpl(qt1.t.z - qt2.t.z) <= ve; - return (qdif && vdif); - } - - ILINE bool IsValid() const - { - if (!t.IsValid()) - { - return false; - } - if (!q.IsValid()) - { - return false; - } - return true; - } - - /*! - * linear-interpolation between quaternions (lerp) - * - * Example: - * CQuaternion result,p,q; - * result=qlerp( p, q, 0.5f ); - */ - ILINE void SetNLerp(const QuatT_tpl& p, const QuatT_tpl& tq, F ti) - { - assert(p.q.IsValid()); - assert(tq.q.IsValid()); - Quat_tpl d = tq.q; - if ((p.q | d) < 0) - { - d = -d; - } - Vec3_tpl vDiff = d.v - p.q.v; - q.v = p.q.v + (vDiff * ti); - q.w = p.q.w + ((d.w - p.q.w) * ti); - q.Normalize(); - vDiff = tq.t - p.t; - t = p.t + (vDiff * ti); - } - ILINE static QuatT_tpl CreateNLerp(const QuatT_tpl& p, const QuatT_tpl& q, F t) - { - QuatT_tpl d; - d.SetNLerp(p, q, t); - return d; - } - - //NOTE: all vectors are stored in columns - ILINE void SetFromVectors(const Vec3& vx, const Vec3& vy, const Vec3& vz, const Vec3& pos) - { - Matrix34 m34; - m34.m00 = vx.x; - m34.m01 = vy.x; - m34.m02 = vz.x; - m34.m03 = pos.x; - m34.m10 = vx.y; - m34.m11 = vy.y; - m34.m12 = vz.y; - m34.m13 = pos.y; - m34.m20 = vx.z; - m34.m21 = vy.z; - m34.m22 = vz.z; - m34.m23 = pos.z; - *this = QuatT_tpl(m34); - } - ILINE static QuatT_tpl CreateFromVectors(const Vec3_tpl& vx, const Vec3_tpl& vy, const Vec3_tpl& vz, const Vec3_tpl& pos) - { - QuatT_tpl qt; - qt.SetFromVectors(vx, vy, vz, pos); - return qt; - } - - QuatT_tpl GetScaled(F scale) - { - return QuatT_tpl(t * scale, q.GetScaled(scale)); - } -}; - -typedef QuatT_tpl QuatT; //always 32 bit -typedef QuatT_tpl QuatTd;//always 64 bit -typedef QuatT_tpl QuatTr;//variable float precision. depending on the target system it can be between 32, 64 or bit - -/*! -* -* Implements the multiplication operator: QuatT=Quatpos*Quat -* -* AxB = operation B followed by operation A. -* A multiplication takes 16 muls and 12 adds (=28 float operations). -* -* Example: -* Quat quat = Quat::CreateRotationX(1.94192f);; -* QuatT quatpos = QuatT::CreateRotationZ(3.14192f,Vec3(11,22,33)); -* QuatT qp = quatpos*quat; -*/ -template -ILINE QuatT_tpl operator * (const QuatT_tpl& p, const Quat_tpl& q) -{ - assert(p.IsValid()); - assert(q.IsValid()); - return QuatT_tpl(p.q * q, p.t); -} - -/*! -* Implements the multiplication operator: QuatT=QuatposA*QuatposB -* -* AxB = operation B followed by operation A. -* A multiplication takes 31 muls and 30 adds (=61 float operations). -* -* Example: -* QuatT quatposA = QuatT::CreateRotationX(1.94192f,Vec3(77,55,44)); -* QuatT quatposB = QuatT::CreateRotationZ(3.14192f,Vec3(11,22,33)); -* QuatT qp = quatposA*quatposB; -*/ -template -ILINE QuatT_tpl operator * (const QuatT_tpl& q, const QuatT_tpl& p) -{ - assert(q.IsValid()); - assert(p.IsValid()); - return QuatT_tpl(q.q * p.q, q.q * p.t + q.t); -} - - - -/*! -* post-multiply of a QuatT and a Vec3 (3D rotations with quaternions) -* -* Example: -* Quat q(1,0,0,0); -* Vec3 v(33,44,55); -* Vec3 result = q*v; -*/ -template -Vec3_tpl operator * (const QuatT_tpl& q, const Vec3_tpl& v) -{ - assert(v.IsValid()); - assert(q.IsValid()); - //muls=15 / adds=15+3 - Vec3_tpl out, r2; - r2.x = (q.q.v.y * v.z - q.q.v.z * v.y) + q.q.w * v.x; - r2.y = (q.q.v.z * v.x - q.q.v.x * v.z) + q.q.w * v.y; - r2.z = (q.q.v.x * v.y - q.q.v.y * v.x) + q.q.w * v.z; - out.x = (r2.z * q.q.v.y - r2.y * q.q.v.z); - out.x += out.x + v.x + q.t.x; - out.y = (r2.x * q.q.v.z - r2.z * q.q.v.x); - out.y += out.y + v.y + q.t.y; - out.z = (r2.y * q.q.v.x - r2.x * q.q.v.y); - out.z += out.z + v.z + q.t.z; - return out; -} - - - - - - - - - - - - - - - - -//---------------------------------------------------------------------- -// Quaternion with translation vector and scale -// Similar to QuatT, but s is not ignored. -// Most functions then differ, so we don't inherit. -//---------------------------------------------------------------------- -template -struct QuatTS_tpl -{ - Quat_tpl q; - Vec3_tpl t; - F s; - - //constructors -#if defined(_DEBUG) - ILINE QuatTS_tpl() - { - if constexpr (sizeof(F) == 4) - { - uint32* p = alias_cast(&q.v.x); - p[0] = F32NAN; - p[1] = F32NAN; - p[2] = F32NAN; - p[3] = F32NAN; - p[4] = F32NAN; - p[5] = F32NAN; - p[6] = F32NAN; - p[7] = F32NAN; - } - if constexpr (sizeof(F) == 8) - { - uint64* p = alias_cast(&q.v.x); - p[0] = F64NAN; - p[1] = F64NAN; - p[2] = F64NAN; - p[3] = F64NAN; - p[4] = F64NAN; - p[5] = F64NAN; - p[6] = F64NAN; - p[7] = F64NAN; - } - } -#else - ILINE QuatTS_tpl(){} -#endif - - ILINE QuatTS_tpl(const Quat_tpl& quat, const Vec3_tpl& trans, F scale = 1) { q = quat; t = trans; s = scale; } - ILINE QuatTS_tpl(type_identity) { SetIdentity(); } - - //CONSTRUCTOR: implement the copy/casting/assignment constructor: - template - ILINE QuatTS_tpl(const QuatTS_tpl& qts) - : q(qts.q) - , t(qts.t) - , s(qts.s) {} - - ILINE QuatTS_tpl& operator = (const QuatT_tpl& qt) - { - q = qt.q; - t = qt.t; - s = 1.0f; - return *this; - } - ILINE QuatTS_tpl(const QuatT_tpl& qp) { q = qp.q; t = qp.t; s = 1.0f; } - - - ILINE void SetIdentity() - { - q.SetIdentity(); - t = Vec3(ZERO); - s = 1; - } - - explicit ILINE QuatTS_tpl(const Matrix34_tpl& m) - { - t = m.GetTranslation(); - - // The determinant of a matrix is the volume spanned by its base vectors. - // We need an approximate length scale, so we calculate the cube root of the determinant. - s = pow(m.Determinant(), F(1.0 / 3.0)); - - // Orthonormalize using X and Z as anchors. - const Vec3_tpl& r0 = m.GetRow(0); - const Vec3_tpl& r2 = m.GetRow(2); - - const Vec3_tpl v0 = r0.GetNormalized(); - const Vec3_tpl v1 = (r2 % r0).GetNormalized(); - const Vec3_tpl v2 = (v0 % v1); - - Matrix33_tpl m3; - m3.SetRow(0, v0); - m3.SetRow(1, v1); - m3.SetRow(2, v2); - - q = Quat_tpl(m3); - } - - void Invert() - { - s = 1 / s; - q = !q; - t = q * t * -s; - } - QuatTS_tpl GetInverted() const - { - QuatTS_tpl inv; - inv.s = 1 / s; - inv.q = !q; - inv.t = inv.q * t * -inv.s; - return inv; - } - - - /*! - * linear-interpolation between quaternions (nlerp) - * - * Example: - * CQuaternion result,p,q; - * result=qlerp( p, q, 0.5f ); - */ - ILINE void SetNLerp(const QuatTS_tpl& p, const QuatTS_tpl& tq, F ti) - { - assert(p.q.IsValid()); - assert(tq.q.IsValid()); - Quat_tpl d = tq.q; - if ((p.q | d) < 0) - { - d = -d; - } - Vec3_tpl vDiff = d.v - p.q.v; - q.v = p.q.v + (vDiff * ti); - q.w = p.q.w + ((d.w - p.q.w) * ti); - q.Normalize(); - - vDiff = tq.t - p.t; - t = p.t + (vDiff * ti); - - s = p.s + ((tq.s - p.s) * ti); - } - - ILINE static QuatTS_tpl CreateNLerp(const QuatTS_tpl& p, const QuatTS_tpl& q, F t) - { - QuatTS_tpl d; - d.SetNLerp(p, q, t); - return d; - } - - - - ILINE static bool IsEquivalent(const QuatTS_tpl& qts1, const QuatTS_tpl& qts2, F qe = RAD_EPSILON, F ve = VEC_EPSILON) - { - f64 rad = acos(min(1.0f, fabs_tpl(qts1.q | qts2.q))); - bool qdif = rad <= qe; - bool vdif = fabs_tpl(qts1.t.x - qts2.t.x) <= ve && fabs_tpl(qts1.t.y - qts2.t.y) <= ve && fabs_tpl(qts1.t.z - qts2.t.z) <= ve; - bool sdif = fabs_tpl(qts1.s - qts2.s) <= ve; - return (qdif && vdif && sdif); - } - - - bool IsValid(F e = VEC_EPSILON) const - { - if (!q.v.IsValid()) - { - return false; - } - if (!NumberValid(q.w)) - { - return false; - } - if (!q.IsUnit(e)) - { - return false; - } - if (!t.IsValid()) - { - return false; - } - if (!NumberValid(s)) - { - return false; - } - return true; - } - - ILINE Vec3_tpl GetColumn0() const {return q.GetColumn0(); } - ILINE Vec3_tpl GetColumn1() const {return q.GetColumn1(); } - ILINE Vec3_tpl GetColumn2() const {return q.GetColumn2(); } - ILINE Vec3_tpl GetColumn3() const {return t; } - ILINE Vec3_tpl GetRow0() const { return q.GetRow0(); } - ILINE Vec3_tpl GetRow1() const { return q.GetRow1(); } - ILINE Vec3_tpl GetRow2() const { return q.GetRow2(); } -}; - -typedef QuatTS_tpl QuatTS; //always 64 bit -typedef QuatTS_tpl QuatTSd;//always 64 bit -typedef QuatTS_tpl QuatTSr;//variable float precision. depending on the target system it can be between 32, 64 or 80 bit - -template -ILINE QuatTS_tpl operator * (const QuatTS_tpl& a, const Quat_tpl& b) -{ - return QuatTS_tpl(a.q * b, a.t, a.s); -} - - -template -ILINE QuatTS_tpl operator * (const QuatTS_tpl& a, const QuatT_tpl& b) -{ - return QuatTS_tpl(a.q * b.q, a.q * (b.t * a.s) + a.t, a.s); -} -template -ILINE QuatTS_tpl operator * (const QuatT_tpl& a, const QuatTS_tpl& b) -{ - return QuatTS_tpl(a.q * b.q, a.q * b.t + a.t, b.s); -} -template -ILINE QuatTS_tpl operator * (const Quat_tpl& a, const QuatTS_tpl& b) -{ - return QuatTS_tpl(a * b.q, a * b.t, b.s); -} - -/*! -* Implements the multiplication operator: QuatTS=QuatTS*QuatTS -*/ -template -ILINE QuatTS_tpl operator * (const QuatTS_tpl& a, const QuatTS_tpl& b) -{ - assert(a.IsValid()); - assert(b.IsValid()); - return QuatTS_tpl(a.q * b.q, a.q * (b.t * a.s) + a.t, a.s * b.s); -} - -/*! -* post-multiply of a QuatT and a Vec3 (3D rotations with quaternions) -*/ -template -ILINE Vec3_tpl operator * (const QuatTS_tpl& q, const Vec3_tpl& v) -{ - assert(q.IsValid()); - assert(v.IsValid()); - return q.q * v * q.s + q.t; -} - - -//---------------------------------------------------------------------- -// Quaternion with translation vector and non-uniform scale -//---------------------------------------------------------------------- -template -struct QuatTNS_tpl -{ - Quat_tpl q; - Vec3_tpl t; - Vec3_tpl s; - - //constructors -#if defined(_DEBUG) - ILINE QuatTNS_tpl() - { - if constexpr (sizeof(F) == 4) - { - uint32* p = alias_cast(&q.v.x); - p[0] = F32NAN; - p[1] = F32NAN; - p[2] = F32NAN; - p[3] = F32NAN; - p[4] = F32NAN; - p[5] = F32NAN; - p[6] = F32NAN; - p[7] = F32NAN; - p[8] = F32NAN; - p[9] = F32NAN; - } - if constexpr (sizeof(F) == 8) - { - uint64* p = alias_cast(&q.v.x); - p[0] = F64NAN; - p[1] = F64NAN; - p[2] = F64NAN; - p[3] = F64NAN; - p[4] = F64NAN; - p[5] = F64NAN; - p[6] = F64NAN; - p[7] = F64NAN; - p[8] = F64NAN; - p[9] = F64NAN; - } - } -#else - ILINE QuatTNS_tpl() {}; -#endif - - ILINE QuatTNS_tpl(const Quat_tpl& quat, const Vec3_tpl& trans, const Vec3_tpl& scale = Vec3_tpl(1)) { q = quat; t = trans; s = scale; } - ILINE QuatTNS_tpl(type_identity) { SetIdentity(); } - - //CONSTRUCTOR: implement the copy/casting/assignment constructor: - template - ILINE QuatTNS_tpl(const QuatTS_tpl& qts) - : q(qts.q) - , t(qts.t) - , s(qts.s) - { - } - - ILINE QuatTNS_tpl& operator = (const QuatT_tpl& qt) - { - q = qt.q; - t = qt.t; - s = Vec3_tpl(1); - return *this; - } - ILINE QuatTNS_tpl(const QuatT_tpl& qp) { q = qp.q; t = qp.t; s = Vec3_tpl(1); } - - - ILINE void SetIdentity() - { - q.SetIdentity(); - t = Vec3_tpl(ZERO); - s = Vec3_tpl(1); - } - - explicit ILINE QuatTNS_tpl(const Matrix34_tpl& m) - { - t = m.GetTranslation(); - - // Lengths of base vectors equates to scaling in matrix - s.x = m.GetColumn0().GetLength(); - s.y = m.GetColumn1().GetLength(); - s.z = m.GetColumn2().GetLength(); - - // Orthonormalize using X and Z as anchors. - const Vec3_tpl& r0 = m.GetRow(0); - const Vec3_tpl& r2 = m.GetRow(2); - - const Vec3_tpl v0 = r0.GetNormalized(); - const Vec3_tpl v1 = (r2 % r0).GetNormalized(); - const Vec3_tpl v2 = (v0 % v1); - - Matrix33_tpl m3; - m3.SetRow(0, v0); - m3.SetRow(1, v1); - m3.SetRow(2, v2); - - q = Quat_tpl(m3); - } - - void Invert() - { - s = Vec3_tpl(1) / s; - q = !q; - t = q * t * -s; - } - QuatTNS_tpl GetInverted() const - { - QuatTNS_tpl inv; - inv.s = Vec3_tpl(1) / s; - inv.q = !q; - inv.t = inv.q * t * -inv.s; - return inv; - } - - - /*! - * linear-interpolation between quaternions (nlerp) - * - * Example: - * CQuaternion result,p,q; - * result=qlerp( p, q, 0.5f ); - */ - ILINE void SetNLerp(const QuatTNS_tpl& p, const QuatTNS_tpl& tq, F ti) - { - assert(p.q.IsValid()); - assert(tq.q.IsValid()); - Quat_tpl d = tq.q; - if ((p.q | d) < 0) - { - d = -d; - } - Vec3_tpl vDiff = d.v - p.q.v; - q.v = p.q.v + (vDiff * ti); - q.w = p.q.w + ((d.w - p.q.w) * ti); - q.Normalize(); - - vDiff = tq.t - p.t; - t = p.t + (vDiff * ti); - - s = p.s + ((tq.s - p.s) * ti); - } - - ILINE static QuatTNS_tpl CreateNLerp(const QuatTNS_tpl& p, const QuatTNS_tpl& q, F t) - { - QuatTNS_tpl d; - d.SetNLerp(p, q, t); - return d; - } - - - - ILINE static bool IsEquivalent(const QuatTNS_tpl& qts1, const QuatTNS_tpl& qts2, F qe = RAD_EPSILON, F ve = VEC_EPSILON) - { - real rad = acos(min(1.0f, fabs_tpl(qts1.q | qts2.q))); - bool qdif = rad <= qe; - bool vdif = fabs_tpl(qts1.t.x - qts2.t.x) <= ve && fabs_tpl(qts1.t.y - qts2.t.y) <= ve && fabs_tpl(qts1.t.z - qts2.t.z) <= ve; - bool sdif = fabs_tpl(qts1.s.x - qts2.s.x) <= ve && fabs_tpl(qts1.s.y - qts2.s.y) <= ve && fabs_tpl(qts1.s.z - qts2.s.z) <= ve; - return (qdif && vdif && sdif); - } - - - bool IsValid(F e = VEC_EPSILON) const - { - if (!q.v.IsValid()) - { - return false; - } - if (!NumberValid(q.w)) - { - return false; - } - if (!q.IsUnit(e)) - { - return false; - } - if (!t.IsValid()) - { - return false; - } - if (!NumberValid(s.x)) - { - return false; - } - if (!NumberValid(s.y)) - { - return false; - } - if (!NumberValid(s.z)) - { - return false; - } - return true; - } - - ILINE Vec3_tpl GetColumn0() const {return q.GetColumn0(); } - ILINE Vec3_tpl GetColumn1() const {return q.GetColumn1(); } - ILINE Vec3_tpl GetColumn2() const {return q.GetColumn2(); } - ILINE Vec3_tpl GetColumn3() const {return t; } - ILINE Vec3_tpl GetRow0() const { return q.GetRow0(); } - ILINE Vec3_tpl GetRow1() const { return q.GetRow1(); } - ILINE Vec3_tpl GetRow2() const { return q.GetRow2(); } -}; - -typedef QuatTNS_tpl QuatTNS; -typedef QuatTNS_tpl QuatTNSr; -typedef QuatTNS_tpl QuatTNS_f64; - -template -ILINE QuatTNS_tpl operator * (const QuatTNS_tpl& a, const Quat_tpl& b) -{ - return QuatTNS_tpl(a.q * b, a.t, a.s); -} - -template -ILINE QuatTNS_tpl operator * (const Quat_tpl& a, const QuatTNS_tpl& b) -{ - return QuatTNS_tpl(a * b.q, a * b.t, b.s); -} - -template -ILINE QuatTNS_tpl operator * (const QuatTNS_tpl& a, const QuatT_tpl& b) -{ - return QuatTNS_tpl(a.q * b.q, a.q * Vec3_tpl(b.x * a.s.x, b.y * a.s.y, b.z * a.s.z) + a.t, a.s); -} - -template -ILINE QuatTNS_tpl operator * (const QuatT_tpl& a, const QuatTNS_tpl& b) -{ - return QuatTNS_tpl(a.q * b.q, a.q * b.t + a.t, b.s); -} - -/*! -* Implements the multiplication operator: QuatTNS=QuatTNS*QuatTNS -*/ -template -ILINE QuatTNS_tpl operator * (const QuatTNS_tpl& a, const QuatTNS_tpl& b) -{ - assert(a.IsValid()); - assert(b.IsValid()); - return QuatTNS_tpl( - a.q * b.q, - a.q * Vec3_tpl(b.t.x * a.s.x, b.t.y * a.s.y, b.t.z * a.s.z) + a.t, - Vec3_tpl(a.s.x * b.s.x, a.s.y * b.s.y, a.s.z * b.s.z) - ); -} - -/*! -* post-multiply of a QuatTNS and a Vec3 (3D rotations with quaternions) -*/ -template -ILINE Vec3_tpl operator * (const QuatTNS_tpl& q, const Vec3_tpl& v) -{ - assert(q.IsValid()); - assert(v.IsValid()); - return q.q * Vec3_tpl(v.x * q.s.x, v.y * q.s.y, v.z * q.s.z) + q.t; -} - -//---------------------------------------------------------------------- -// Dual Quaternion -//---------------------------------------------------------------------- -template -struct DualQuat_tpl -{ - Quat_tpl nq; - Quat_tpl dq; - - ILINE DualQuat_tpl() {} - - ILINE DualQuat_tpl(const Quat_tpl& q, const Vec3_tpl& t) - { - //copy the quaternion part - nq = q; - //convert the translation into a dual quaternion part - dq.w = -0.5f * (t.x * q.v.x + t.y * q.v.y + t.z * q.v.z); - dq.v.x = 0.5f * (t.x * q.w + t.y * q.v.z - t.z * q.v.y); - dq.v.y = 0.5f * (-t.x * q.v.z + t.y * q.w + t.z * q.v.x); - dq.v.z = 0.5f * (t.x * q.v.y - t.y * q.v.x + t.z * q.w); - } - - ILINE DualQuat_tpl(const QuatT_tpl& qt) - { - //copy the quaternion part - nq = qt.q; - //convert the translation into a dual quaternion part - dq.w = -0.5f * (qt.t.x * qt.q.v.x + qt.t.y * qt.q.v.y + qt.t.z * qt.q.v.z); - dq.v.x = 0.5f * (qt.t.x * qt.q.w - qt.t.z * qt.q.v.y + qt.t.y * qt.q.v.z); - dq.v.y = 0.5f * (qt.t.y * qt.q.w - qt.t.x * qt.q.v.z + qt.t.z * qt.q.v.x); - dq.v.z = 0.5f * (qt.t.x * qt.q.v.y - qt.t.y * qt.q.v.x + qt.t.z * qt.q.w); - } - - explicit ILINE DualQuat_tpl( const Matrix34_tpl& m34 ) - { - // non-dual part (just copy q0): - nq = Quat_tpl(m34); - f32 tx = m34.m03; - f32 ty = m34.m13; - f32 tz = m34.m23; - - // dual part: - dq.w = -0.5f * (tx * nq.v.x + ty * nq.v.y + tz * nq.v.z); - dq.v.x = 0.5f * (tx * nq.w + ty * nq.v.z - tz * nq.v.y); - dq.v.y = 0.5f * (-tx * nq.v.z + ty * nq.w + tz * nq.v.x); - dq.v.z = 0.5f * (tx * nq.v.y - ty * nq.v.x + tz * nq.w); - } - - - ILINE DualQuat_tpl(type_identity) - { - SetIdentity(); - } - - ILINE DualQuat_tpl(type_zero) - { - SetZero(); - } - - template - ILINE DualQuat_tpl(const DualQuat_tpl& QDual) - : nq(QDual.nq) - , dq(QDual.dq) {} - - ILINE void SetIdentity() - { - nq.SetIdentity(); - dq.w = 0.0f; - dq.v.x = 0.0f; - dq.v.y = 0.0f; - dq.v.z = 0.0f; - } - - ILINE void SetZero() - { - nq.w = 0.0f; - nq.v.x = 0.0f; - nq.v.y = 0.0f; - nq.v.z = 0.0f; - dq.w = 0.0f; - dq.v.x = 0.0f; - dq.v.y = 0.0f; - dq.v.z = 0.0f; - } - - ILINE void Normalize() - { - // Normalize both components so that nq is unit - F norm = isqrt_safe_tpl(nq.v.len2() + sqr(nq.w)); - nq *= norm; - dq *= norm; - } -}; - -#ifndef MAX_API_NUM -typedef DualQuat_tpl DualQuat; //always 32 bit -typedef DualQuat_tpl DualQuatd;//always 64 bit -typedef DualQuat_tpl DualQuatr;//variable float precision. depending on the target system it can be between 32, 64 or 80 bit -#else -typedef DualQuat_tpl CryDualQuat; -#endif - -template -ILINE DualQuat_tpl operator*(const DualQuat_tpl& l, const F2 r) -{ - DualQuat_tpl dual; - dual.nq.w = l.nq.w * r; - dual.nq.v.x = l.nq.v.x * r; - dual.nq.v.y = l.nq.v.y * r; - dual.nq.v.z = l.nq.v.z * r; - - dual.dq.w = l.dq.w * r; - dual.dq.v.x = l.dq.v.x * r; - dual.dq.v.y = l.dq.v.y * r; - dual.dq.v.z = l.dq.v.z * r; - return dual; -} - -template -ILINE DualQuat_tpl operator+(const DualQuat_tpl& l, const DualQuat_tpl& r) -{ - DualQuat_tpl dual; - dual.nq.w = l.nq.w + r.nq.w; - dual.nq.v.x = l.nq.v.x + r.nq.v.x; - dual.nq.v.y = l.nq.v.y + r.nq.v.y; - dual.nq.v.z = l.nq.v.z + r.nq.v.z; - - dual.dq.w = l.dq.w + r.dq.w; - dual.dq.v.x = l.dq.v.x + r.dq.v.x; - dual.dq.v.y = l.dq.v.y + r.dq.v.y; - dual.dq.v.z = l.dq.v.z + r.dq.v.z; - return dual; -} - -template -ILINE void operator += (DualQuat_tpl& l, const DualQuat_tpl& r) -{ - l.nq.w += r.nq.w; - l.nq.v.x += r.nq.v.x; - l.nq.v.y += r.nq.v.y; - l.nq.v.z += r.nq.v.z; - - l.dq.w += r.dq.w; - l.dq.v.x += r.dq.v.x; - l.dq.v.y += r.dq.v.y; - l.dq.v.z += r.dq.v.z; -} - -template -ILINE Vec3_tpl operator*(const DualQuat_tpl& dq, const Vec3_tpl& v) -{ - F2 t; - const F2 ax = dq.nq.v.y * v.z - dq.nq.v.z * v.y + dq.nq.w * v.x; - const F2 ay = dq.nq.v.z * v.x - dq.nq.v.x * v.z + dq.nq.w * v.y; - const F2 az = dq.nq.v.x * v.y - dq.nq.v.y * v.x + dq.nq.w * v.z; - F2 x = dq.dq.v.x * dq.nq.w - dq.nq.v.x * dq.dq.w + dq.nq.v.y * dq.dq.v.z - dq.nq.v.z * dq.dq.v.y; - x += x; - t = (az * dq.nq.v.y - ay * dq.nq.v.z); - x += t + t + v.x; - F2 y = dq.dq.v.y * dq.nq.w - dq.nq.v.y * dq.dq.w + dq.nq.v.z * dq.dq.v.x - dq.nq.v.x * dq.dq.v.z; - y += y; - t = (ax * dq.nq.v.z - az * dq.nq.v.x); - y += t + t + v.y; - F2 z = dq.dq.v.z * dq.nq.w - dq.nq.v.z * dq.dq.w + dq.nq.v.x * dq.dq.v.y - dq.nq.v.y * dq.dq.v.x; - z += z; - t = (ay * dq.nq.v.x - ax * dq.nq.v.y); - z += t + t + v.z; - return Vec3_tpl(x, y, z); -} - -template -ILINE DualQuat_tpl operator*(const DualQuat_tpl& a, const DualQuat_tpl& b) -{ - DualQuat_tpl dual; - - dual.nq.v.x = a.nq.v.y * b.nq.v.z - a.nq.v.z * b.nq.v.y + a.nq.w * b.nq.v.x + a.nq.v.x * b.nq.w; - dual.nq.v.y = a.nq.v.z * b.nq.v.x - a.nq.v.x * b.nq.v.z + a.nq.w * b.nq.v.y + a.nq.v.y * b.nq.w; - dual.nq.v.z = a.nq.v.x * b.nq.v.y - a.nq.v.y * b.nq.v.x + a.nq.w * b.nq.v.z + a.nq.v.z * b.nq.w; - dual.nq.w = a.nq.w * b.nq.w - (a.nq.v.x * b.nq.v.x + a.nq.v.y * b.nq.v.y + a.nq.v.z * b.nq.v.z); - - //dual.dq = a.nq*b.dq + a.dq*b.nq; - dual.dq.v.x = a.nq.v.y * b.dq.v.z - a.nq.v.z * b.dq.v.y + a.nq.w * b.dq.v.x + a.nq.v.x * b.dq.w; - dual.dq.v.y = a.nq.v.z * b.dq.v.x - a.nq.v.x * b.dq.v.z + a.nq.w * b.dq.v.y + a.nq.v.y * b.dq.w; - dual.dq.v.z = a.nq.v.x * b.dq.v.y - a.nq.v.y * b.dq.v.x + a.nq.w * b.dq.v.z + a.nq.v.z * b.dq.w; - dual.dq.w = a.nq.w * b.dq.w - (a.nq.v.x * b.dq.v.x + a.nq.v.y * b.dq.v.y + a.nq.v.z * b.dq.v.z); - - dual.dq.v.x += a.dq.v.y * b.nq.v.z - a.dq.v.z * b.nq.v.y + a.dq.w * b.nq.v.x + a.dq.v.x * b.nq.w; - dual.dq.v.y += a.dq.v.z * b.nq.v.x - a.dq.v.x * b.nq.v.z + a.dq.w * b.nq.v.y + a.dq.v.y * b.nq.w; - dual.dq.v.z += a.dq.v.x * b.nq.v.y - a.dq.v.y * b.nq.v.x + a.dq.w * b.nq.v.z + a.dq.v.z * b.nq.w; - dual.dq.w += a.dq.w * b.nq.w - (a.dq.v.x * b.nq.v.x + a.dq.v.y * b.nq.v.y + a.dq.v.z * b.nq.v.z); - - return dual; -} - - -#endif // CRYINCLUDE_CRYCOMMON_CRY_QUAT_H - - diff --git a/Code/Legacy/CryCommon/Cry_Vector2.h b/Code/Legacy/CryCommon/Cry_Vector2.h index a8722c1b02..81a8c10e49 100644 --- a/Code/Legacy/CryCommon/Cry_Vector2.h +++ b/Code/Legacy/CryCommon/Cry_Vector2.h @@ -302,21 +302,13 @@ struct Vec2_tpl /////////////////////////////////////////////////////////////////////////////// typedef Vec2_tpl Vec2; // always 32 bit -typedef Vec2_tpl Vec2d; // always 64 bit typedef Vec2_tpl Vec2i; -typedef Vec2_tpl Vec2ui; -typedef Vec2_tpl Vec2r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit -typedef Vec2_tpl vector2f; #if defined(LINUX64) typedef Vec2_tpl vector2l; #else typedef Vec2_tpl vector2l; #endif -typedef Vec2_tpl vector2df; -typedef Vec2_tpl vector2d; -typedef Vec2_tpl vector2di; -typedef Vec2_tpl vector2dui; template Vec2_tpl operator*(F op1, const Vec2_tpl& op2) {return Vec2_tpl(op1 * op2.x, op1 * op2.y); } diff --git a/Code/Legacy/CryCommon/Cry_Vector3.h b/Code/Legacy/CryCommon/Cry_Vector3.h index bd1cc11430..f627c788f6 100644 --- a/Code/Legacy/CryCommon/Cry_Vector3.h +++ b/Code/Legacy/CryCommon/Cry_Vector3.h @@ -178,21 +178,6 @@ struct Vec3_tpl assert(IsValid()); } - explicit ILINE Vec3_tpl(const Vec4_tpl &v) { - x = F(v.x); - y = F(v.y); - z = F(v.z); - } - template - explicit ILINE Vec3_tpl(const Vec4_tpl &v) { - x = F(v.x); - y = F(v.y); - z = F(v.z); - } - - - - /*! * overloaded arithmetic operator * @@ -847,6 +832,8 @@ struct Vec3_tpl } }; +using Vec3i = Vec3_tpl; + // dot product (2 versions) template ILINE F1 operator * (const Vec3_tpl& v0, const Vec3_tpl& v1) @@ -943,15 +930,6 @@ ILINE bool IsEquivalent(const Vec3_tpl& v0, const Vec3_tpl& v1, f32 epsilo /////////////////////////////////////////////////////////////////////////////// typedef Vec3_tpl Vec3; // always 32 bit -typedef Vec3_tpl Vec3d; // always 64 bit -typedef Vec3_tpl Vec3i; -typedef Vec3_tpl Vec3ui; -typedef Vec3_tpl Vec3r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit - -template<> -inline Vec3_tpl::Vec3_tpl(type_min) { x = y = z = -1.7E308; } -template<> -inline Vec3_tpl::Vec3_tpl(type_max) { x = y = z = 1.7E308; } template<> inline Vec3_tpl::Vec3_tpl(type_min) { x = y = z = -3.3E38f; } template<> @@ -1176,8 +1154,6 @@ struct Ang3_tpl }; typedef Ang3_tpl Ang3; -typedef Ang3_tpl Ang3r; -typedef Ang3_tpl Ang3_f64; //--------------------------------------- @@ -1251,7 +1227,6 @@ struct AngleAxis_tpl }; typedef AngleAxis_tpl AngleAxis; -typedef AngleAxis_tpl AngleAxis_f64; template ILINE const Vec3_tpl AngleAxis_tpl::operator * (const Vec3_tpl& v) const @@ -1260,22 +1235,6 @@ ILINE const Vec3_tpl AngleAxis_tpl::operator * (const Vec3_tpl& v) cons return origin + (v - origin) * cos_tpl(angle) + (axis % v) * sin_tpl(angle); } - - - - - - - - - - - - - - - - ////////////////////////////////////////////////////////////////////// template struct Plane_tpl @@ -1405,8 +1364,6 @@ struct Plane_tpl }; typedef Plane_tpl Plane; //always 32 bit -typedef Plane_tpl Planed;//always 64 bit -typedef Plane_tpl Planer;//variable float precision. depending on the target system it can be between 32, 64 or 80 bit // declare common constants. Must be done after the class for compiler conformance diff --git a/Code/Legacy/CryCommon/Cry_Vector4.h b/Code/Legacy/CryCommon/Cry_Vector4.h index bbb3395fb3..2b1af84c54 100644 --- a/Code/Legacy/CryCommon/Cry_Vector4.h +++ b/Code/Legacy/CryCommon/Cry_Vector4.h @@ -5,37 +5,31 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - - // Description : Common vector class - - #pragma once - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// class Vec4_tpl +// class Vec4 /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -template -struct Vec4_tpl +struct Vec4 { - typedef F value_type; + using value_type = f32; enum { component_count = 4 }; - F x, y, z, w; + f32 x, y, z, w; #if defined(_DEBUG) ILINE Vec4_tpl() { - if constexpr (sizeof(F) == 4) + if constexpr (sizeof(f32) == 4) { uint32* p = alias_cast(&x); p[0] = F32NAN; @@ -43,49 +37,25 @@ struct Vec4_tpl p[2] = F32NAN; p[3] = F32NAN; } - if constexpr (sizeof(F) == 8) - { - uint64* p = alias_cast(&x); - p[0] = F64NAN; - p[1] = F64NAN; - p[2] = F64NAN; - p[3] = F64NAN; - } } #else - ILINE Vec4_tpl() {} + ILINE Vec4() {} #endif - template - ILINE Vec4_tpl& operator = (const Vec4_tpl& v1) - { - x = F(v1.x); - y = F(v1.y); - z = F(v1.z); - w = F(v1.w); - return (*this); - } + ILINE Vec4(f32 vx, f32 vy, f32 vz, f32 vw) { x = vx; y = vy; z = vz; w = vw; } + ILINE Vec4(const Vec3_tpl& v, f32 vw) { x = v.x; y = v.y; z = v.z; w = vw; } + explicit ILINE Vec4(f32 m) { x = y = z = w = m; } + ILINE Vec4(type_zero) { x = y = z = w = f32(0); } - ILINE Vec4_tpl(F vx, F vy, F vz, F vw) { x = vx; y = vy; z = vz; w = vw; } - ILINE Vec4_tpl(const Vec3_tpl& v, F vw) { x = v.x; y = v.y; z = v.z; w = vw; } - explicit ILINE Vec4_tpl(F m) { x = y = z = w = m; } - ILINE Vec4_tpl(type_zero) { x = y = z = w = F(0); } + ILINE void operator () (f32 vx, f32 vy, f32 vz, f32 vw) { x = vx; y = vy; z = vz; w = vw; } + ILINE void operator () (const Vec3_tpl& v, f32 vw) { x = v.x; y = v.y; z = v.z; w = vw; } - ILINE void operator () (F vx, F vy, F vz, F vw) { x = vx; y = vy; z = vz; w = vw; } - ILINE void operator () (const Vec3_tpl& v, F vw) { x = v.x; y = v.y; z = v.z; w = vw; } + ILINE f32& operator [] (int index) { assert(index >= 0 && index <= 3); return ((f32*)this)[index]; } + ILINE f32 operator [] (int index) const { assert(index >= 0 && index <= 3); return ((f32*)this)[index]; } - ILINE F& operator [] (int index) { assert(index >= 0 && index <= 3); return ((F*)this)[index]; } - ILINE F operator [] (int index) const { assert(index >= 0 && index <= 3); return ((F*)this)[index]; } - template - ILINE Vec4_tpl(const Vec4_tpl& v) - : x((F)v.x) - , y((F)v.y) - , z((F)v.z) - , w((F)v.w) { assert(this->IsValid()); } + ILINE Vec4& zero() { x = y = z = w = 0; return *this; } - ILINE Vec4_tpl& zero() { x = y = z = w = 0; return *this; } - - ILINE bool IsEquivalent(const Vec4_tpl& v1, F epsilon = VEC_EPSILON) const + ILINE bool IsEquivalent(const Vec4& v1, f32 epsilon = VEC_EPSILON) const { assert(v1.IsValid()); assert(this->IsValid()); @@ -93,7 +63,7 @@ struct Vec4_tpl } - ILINE Vec4_tpl& operator=(const Vec4_tpl& src) + ILINE Vec4& operator=(const Vec4& src) { x = src.x; y = src.y; @@ -102,17 +72,17 @@ struct Vec4_tpl return *this; } - ILINE Vec4_tpl operator * (F k) const + ILINE Vec4 operator * (f32 k) const { - return Vec4_tpl(x * k, y * k, z * k, w * k); + return Vec4(x * k, y * k, z * k, w * k); } - ILINE Vec4_tpl operator / (F k) const + ILINE Vec4 operator / (f32 k) const { - k = (F)1.0 / k; - return Vec4_tpl(x * k, y * k, z * k, w * k); + k = (f32)1.0 / k; + return Vec4(x * k, y * k, z * k, w * k); } - ILINE Vec4_tpl& operator *= (F k) + ILINE Vec4& operator *= (f32 k) { x *= k; y *= k; @@ -120,9 +90,9 @@ struct Vec4_tpl w *= k; return *this; } - ILINE Vec4_tpl& operator /= (F k) + ILINE Vec4& operator /= (f32 k) { - k = (F)1.0 / k; + k = (f32)1.0 / k; x *= k; y *= k; z *= k; @@ -130,7 +100,7 @@ struct Vec4_tpl return *this; } - ILINE void operator += (const Vec4_tpl& v) + ILINE void operator += (const Vec4& v) { x += v.x; y += v.y; @@ -138,7 +108,7 @@ struct Vec4_tpl w += v.w; } - ILINE void operator -= (const Vec4_tpl& v) + ILINE void operator -= (const Vec4& v) { x -= v.x; y -= v.y; @@ -147,17 +117,17 @@ struct Vec4_tpl } - ILINE F Dot (const Vec4_tpl& vec2) const + ILINE f32 Dot (const Vec4& vec2) const { return x * vec2.x + y * vec2.y + z * vec2.z + w * vec2.w; } - ILINE F GetLength() const + ILINE f32 GetLength() const { return sqrt_tpl(Dot(*this)); } - ILINE F GetLengthSquared() const + ILINE f32 GetLengthSquared() const { return Dot(*this); } @@ -190,24 +160,24 @@ struct Vec4_tpl * Example: * if (v0==v1) dosomething; */ - ILINE bool operator==(const Vec4_tpl& vec) + ILINE bool operator==(const Vec4& vec) { return x == vec.x && y == vec.y && z == vec.z && w == vec.w; } - ILINE bool operator!=(const Vec4_tpl& vec) { return !(*this == vec); } + ILINE bool operator!=(const Vec4& vec) { return !(*this == vec); } - ILINE friend bool operator ==(const Vec4_tpl& v0, const Vec4_tpl& v1) + ILINE friend bool operator ==(const Vec4& v0, const Vec4& v1) { return ((v0.x == v1.x) && (v0.y == v1.y) && (v0.z == v1.z) && (v0.w == v1.w)); } - ILINE friend bool operator !=(const Vec4_tpl& v0, const Vec4_tpl& v1) { return !(v0 == v1); } + ILINE friend bool operator !=(const Vec4& v0, const Vec4& v1) { return !(v0 == v1); } //! normalize the vector // The default Normalize function is in fact "safe". 0 vectors remain unchanged. ILINE void Normalize() { assert(this->IsValid()); - F fInvLen = isqrt_safe_tpl(x * x + y * y + z * z + w * w); + f32 fInvLen = isqrt_safe_tpl(x * x + y * y + z * z + w * w); x *= fInvLen; y *= fInvLen; z *= fInvLen; @@ -218,61 +188,21 @@ struct Vec4_tpl ILINE void NormalizeFast() { assert(this->IsValid()); - F fInvLen = isqrt_fast_tpl(x * x + y * y + z * z + w * w); + f32 fInvLen = isqrt_fast_tpl(x * x + y * y + z * z + w * w); x *= fInvLen; y *= fInvLen; z *= fInvLen; w *= fInvLen; } - - ILINE void SetLerp(const Vec4_tpl& p, const Vec4_tpl& q, F t) { *this = p * (1.0f - t) + q * t; } - ILINE static Vec4_tpl CreateLerp(const Vec4_tpl& p, const Vec4_tpl& q, F t) { return p * (1.0f - t) + q * t; } }; - -typedef Vec4_tpl Vec4; // always 32 bit -typedef Vec4_tpl Vec4d; // always 64 bit -typedef Vec4_tpl Vec4i; -typedef Vec4_tpl Vec4ui; -typedef Vec4_tpl Vec4r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit - -#if defined(WIN32) || defined(WIN64) || defined(LINUX) || defined(APPLE) -typedef Vec4_tpl Vec4A; -#elif defined(AZ_RESTRICTED_PLATFORM) - #include AZ_RESTRICTED_FILE(Cry_Vector4_h) -#endif - -//vector self-addition -template -ILINE Vec4_tpl& operator += (Vec4_tpl& v0, const Vec4_tpl& v1) -{ - v0 = v0 + v1; - return v0; -} - //vector addition -template -ILINE Vec4_tpl operator + (const Vec4_tpl& v0, const Vec4_tpl& v1) +ILINE Vec4 operator + (const Vec4& v0, const Vec4& v1) { - return Vec4_tpl(v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w); + return Vec4(v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w); } //vector subtraction -template -ILINE Vec4_tpl operator - (const Vec4_tpl& v0, const Vec4_tpl& v1) +ILINE Vec4 operator - (const Vec4& v0, const Vec4& v1) { - return Vec4_tpl(v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w); -} - -//vector multiplication -template -ILINE Vec4_tpl operator * (const Vec4_tpl v0, const Vec4_tpl& v1) -{ - return Vec4_tpl(v0.x * v1.x, v0.y * v1.y, v0.z * v1.z, v0.w * v1.w); -} - -//vector division -template -ILINE Vec4_tpl operator / (const Vec4_tpl& v0, const Vec4_tpl& v1) -{ - return Vec4_tpl(v0.x / v1.x, v0.y / v1.y, v0.z / v1.z, v0.w / v1.w); + return Vec4(v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w); } diff --git a/Code/Legacy/CryCommon/FunctorBaseFunction.h b/Code/Legacy/CryCommon/FunctorBaseFunction.h deleted file mode 100644 index 6fbb6dc5e2..0000000000 --- a/Code/Legacy/CryCommon/FunctorBaseFunction.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Implementation of the common function template specializations. - - -#ifndef CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H -#define CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H -#pragma once - - -#include "IFunctorBase.h" - -////////////////////////////////////////////////////////////////////////// -// Return type void -// No arguments. -template<> -class TFunctor - : public IFunctorBase -{ -public: - typedef void (* TFunctionType)(); - - TFunctor(TFunctionType pFunction) - : m_pfnFunction(pFunction){} - - virtual void Call() - { - m_pfnFunction(); - } -private: - TFunctionType m_pfnFunction; -}; -////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////// -// Return type void -// 1 argument. -template -class TFunctor - : public IFunctorBase -{ -public: - typedef void (* TFunctionType)(tArgument1); - - TFunctor(TFunctionType pFunction, tArgument1 Argument1) - : m_pfnFunction(pFunction) - , m_tArgument1(Argument1){} - - virtual void Call() - { - m_pfnFunction(m_tArgument1); - } -private: - TFunctionType m_pfnFunction; - tArgument1 m_tArgument1; -}; -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -// Return type void -// 2 arguments. -template -class TFunctor - : public IFunctorBase -{ -public: - typedef void (* TFunctionType)(tArgument1, tArgument2); - - TFunctor(TFunctionType pFunction, const tArgument1& Argument1, const tArgument2& Argument2) - : m_pfnFunction(pFunction) - , m_tArgument1(Argument1) - , m_tArgument2(Argument2){} - - virtual void Call() - { - m_pfnFunction(m_tArgument1, m_tArgument2); - } -private: - TFunctionType m_pfnFunction; - tArgument1 m_tArgument1; - tArgument2 m_tArgument2; -}; -////////////////////////////////////////////////////////////////////////// - -#endif // CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H diff --git a/Code/Legacy/CryCommon/FunctorBaseMember.h b/Code/Legacy/CryCommon/FunctorBaseMember.h deleted file mode 100644 index d2e75a8752..0000000000 --- a/Code/Legacy/CryCommon/FunctorBaseMember.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Implementation of the member function template specializations. - -#ifndef CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H -#define CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H -#pragma once - - -#include "IFunctorBase.h" - -////////////////////////////////////////////////////////////////////////// -// Return type void -// No Arguments -template -class TFunctor - : public IFunctorBase -{ -public: - typedef void (tCalleeType::* TMemberFunctionType)(); - - TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction) - : m_pCalee(pCallee) - , m_pfnMemberFunction(pMemberFunction){} - - virtual void Call() - { - (m_pCalee->*m_pfnMemberFunction)(); - } -private: - tCalleeType* m_pCalee; - TMemberFunctionType m_pfnMemberFunction; -}; -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -// Return type void -// 1 argument. -template -class TFunctor - : public IFunctorBase -{ -public: - typedef void (tCalleeType::* TMemberFunctionType)(tArgument1); - - TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction, const tArgument1& Argument1) - : m_pCalee(pCallee) - , m_pfnMemberFunction(pMemberFunction) - , m_tArgument1(Argument1){} - - virtual void Call() - { - (m_pCalee->*m_pfnMemberFunction)(m_tArgument1); - } -private: - tCalleeType* m_pCalee; - TMemberFunctionType m_pfnMemberFunction; - tArgument1 m_tArgument1; -}; -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -// Return type void -// 2 arguments. -template -class TFunctor - : public IFunctorBase -{ -public: - typedef void (tCalleeType::* TMemberFunctionType)(tArgument1, tArgument2); - - TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction, const tArgument1& Argument1, const tArgument2& Argument2) - : m_pCalee(pCallee) - , m_pfnMemberFunction(pMemberFunction) - , m_tArgument1(Argument1) - , m_tArgument2(Argument2){} - - virtual void Call() - { - (m_pCalee->*m_pfnMemberFunction)(m_tArgument1, m_tArgument2); - } -private: - tCalleeType* m_pCalee; - TMemberFunctionType m_pfnMemberFunction; - tArgument1 m_tArgument1; - tArgument2 m_tArgument2; -}; -////////////////////////////////////////////////////////////////////////// - -#endif // CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H diff --git a/Code/Legacy/CryCommon/IConsole.h b/Code/Legacy/CryCommon/IConsole.h index f68a82f9dc..f77237f1af 100644 --- a/Code/Legacy/CryCommon/IConsole.h +++ b/Code/Legacy/CryCommon/IConsole.h @@ -10,15 +10,13 @@ #include #include +#include #include -struct SFunctor; - struct ConsoleBind; struct ICVar; class ITexture; -class ICrySizer; struct ISystem; #define CVAR_INT 1 @@ -192,15 +190,6 @@ struct IConsole // Return: // pointer to the interface ICVar virtual ICVar* RegisterInt(const char* sName, int iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) = 0; - // Create a new console variable that store the value in a int64 - // Arguments: - // sName - console variable name - // iValue - default value - // nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data) - // help - help text that is shown when you use ? in the console - // Return: - // pointer to the interface ICVar - virtual ICVar* RegisterInt64(const char* sName, int64 iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) = 0; // Create a new console variable that store the value in a float // Arguments: // sName - console variable name @@ -243,14 +232,6 @@ struct IConsole // pointer to the interface ICVar virtual ICVar* Register(const char* name, const char** src, const char* defaultvalue, int nFlags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true) = 0; - // Registers an existing console variable - // Should only be used with static duration objects, object is never freed - // Arguments: - // pVar - the existing console variable - // Return: - // pointer to the interface ICVar (that was passed in) - virtual ICVar* Register(ICVar* pVar) = 0; - // ! Remove a variable from the console // @param sVarName console variable name // @param bDelete if true the variable is deleted @@ -431,9 +412,6 @@ struct IConsole virtual void ResetAutoCompletion() = 0; ////////////////////////////////////////////////////////////////////////// - // Calculation of the memory used by the whole console system - virtual void GetMemoryUsage (ICrySizer* pSizer) const = 0; - // Function related to progress bar virtual void ResetProgressBar(int nProgressRange) = 0; // Function related to progress bar @@ -619,16 +597,12 @@ struct ICVar // Adds a new on change functor to the list. // It will add from index 1 on (0 is reserved). // Returns an ID to use when getting or removing the functor - virtual uint64 AddOnChangeFunctor(const SFunctor& pChangeFunctor) = 0; + virtual uint64 AddOnChangeFunctor(const AZStd::function& pChangeFunctor) = 0; ////////////////////////////////////////////////////////////////////////// // Get the current callback function. virtual ConsoleVarFunc GetOnChangeCallback() const = 0; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - virtual void GetMemoryUsage(class ICrySizer* pSizer) const = 0; - ////////////////////////////////////////////////////////////////////////// // only useful for CVarGroups, other types return GetIVal() // CVarGroups set multiple other CVars and this function returns diff --git a/Code/Legacy/CryCommon/IEntityRenderState.h b/Code/Legacy/CryCommon/IEntityRenderState.h index b459a6acaa..42e485cd1e 100644 --- a/Code/Legacy/CryCommon/IEntityRenderState.h +++ b/Code/Legacy/CryCommon/IEntityRenderState.h @@ -7,33 +7,14 @@ */ #pragma once +#include -#include "IStatObj.h" - -#include -#include -#include -#include - - -namespace AZ -{ - class Vector2; -} - -struct IMaterial; -struct IRenderNode; -struct IVisArea; -struct SRenderingPassInfo; -struct SRendItemSorter; -struct SFrameLodInfo; -struct pe_params_area; -struct pe_articgeomparams; +struct IStatObj; struct IRenderNode { // Gives access to object components. - struct IStatObj* GetEntityStatObj(unsigned int = 0, unsigned int = 0, Matrix34A* = NULL, bool = false) { + IStatObj* GetEntityStatObj(unsigned int = 0, unsigned int = 0, Matrix34* = nullptr, bool = false) { return nullptr; } diff --git a/Code/Legacy/CryCommon/IFont.h b/Code/Legacy/CryCommon/IFont.h index 15cc6568bf..01ffb6d206 100644 --- a/Code/Legacy/CryCommon/IFont.h +++ b/Code/Legacy/CryCommon/IFont.h @@ -23,7 +23,6 @@ #include struct ISystem; -class ICrySizer; struct ICryFont; struct IFFont; @@ -94,9 +93,6 @@ struct ICryFont //! \param glyphSizeY Height (in pixels) of the characters to be rendered at in the font texture. virtual void AddCharsToFontTextures(FontFamilyPtr pFontFamily, const char* pChars, int glyphSizeX = defaultGlyphSizeX, int glyphSizeY = defaultGlyphSizeY) = 0; - // Summary: - // Puts the objects used in this module into the sizer interface - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; // Summary: // All font names separated by , // Example: @@ -266,10 +262,6 @@ struct IFFont // Wraps text based on specified maximum line width (UTF-8) virtual void WrapText(AZStd::string& result, float maxWidth, const char* pStr, const STextDrawContext& ctx) = 0; - // Description: - // Puts the memory used by this font into the given sizer. - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - // Description: // useful for special feature rendering interleaved with fonts (e.g. box behind the text) virtual void GetGradientTextureCoord(float& minU, float& minV, float& maxU, float& maxV) const = 0; diff --git a/Code/Legacy/CryCommon/IIndexedMesh.h b/Code/Legacy/CryCommon/IIndexedMesh.h index a84cebacb3..8d3ee64c71 100644 --- a/Code/Legacy/CryCommon/IIndexedMesh.h +++ b/Code/Legacy/CryCommon/IIndexedMesh.h @@ -10,13 +10,8 @@ #pragma once #include "Cry_Color.h" -#include "StlUtils.h" -#include "CryEndian.h" - -#include // for AABB #include #include -#include // Description: // 2D Texture coordinates used by CMesh. @@ -28,32 +23,6 @@ private: float s, t; public: - explicit SMeshTexCoord(float x, float y) - { - s = x; - t = y; - } - - explicit SMeshTexCoord(const Vec2f16& other) - { - const Vec2 uv = other.ToVec2(); - - s = uv.x; - t = uv.y; - } - - explicit SMeshTexCoord(const Vec2& other) - { - s = other.x; - t = other.y; - } - - explicit SMeshTexCoord(const Vec4& other) - { - s = other.x; - t = other.y; - } - bool IsEquivalent(const SMeshTexCoord& other, float epsilon = 0.00005f) const { return @@ -113,16 +82,6 @@ public: }; - -struct SMeshBoneMapping_uint8 -{ - typedef uint8 BoneId; - typedef uint8 Weight; - - BoneId boneIds[4]; - Weight weights[4]; -}; - // Subset of mesh is a continuous range of vertices and indices that share same material. struct SMeshSubset { @@ -181,7 +140,6 @@ struct IIndexedMesh int m_nIndexCount; // number of elements in m_pIndices array }; - // virtual ~IIndexedMesh() {} // Release indexed mesh. @@ -190,15 +148,9 @@ struct IIndexedMesh //! Gives read-only access to mesh data virtual void GetMeshDescription(SMeshDescription& meshDesc) const = 0; - /*! Frees vertex and face streams. Calling this function invalidates SMeshDescription pointers */ - virtual void FreeStreams() = 0; - //! Return number of allocated faces virtual int GetFaceCount() const = 0; - /*! Reallocates faces. Calling this function invalidates SMeshDescription pointers */ - virtual void SetFaceCount(int nNewCount) = 0; - //! Return number of allocated vertices, normals and colors virtual int GetVertexCount() const = 0; @@ -216,6 +168,4 @@ struct IIndexedMesh ////////////////////////////////////////////////////////////////////////// virtual int GetSubSetCount() const = 0; virtual const SMeshSubset& GetSubSet(int nIndex) const = 0; - - // }; diff --git a/Code/Legacy/CryCommon/ILevelSystem.h b/Code/Legacy/CryCommon/ILevelSystem.h index 1a022ccc55..edcd8615aa 100644 --- a/Code/Legacy/CryCommon/ILevelSystem.h +++ b/Code/Legacy/CryCommon/ILevelSystem.h @@ -8,13 +8,8 @@ // Description : Gathers level information. Loads a level. - - -#ifndef CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H -#define CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H #pragma once -#include #include #include @@ -56,8 +51,6 @@ struct ILevelSystemListener virtual void OnLoadingProgress([[maybe_unused]] const char* levelName, [[maybe_unused]] int progressAmount) {} //! Called after a level is unloaded, before the data is freed. virtual void OnUnloadComplete([[maybe_unused]] const char* levelName) {} - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { } }; struct ILevelSystem @@ -95,5 +88,3 @@ protected: static constexpr const char* LevelsDirectoryName = "levels"; }; - -#endif // CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H diff --git a/Code/Legacy/CryCommon/ILocalizationManager.h b/Code/Legacy/CryCommon/ILocalizationManager.h index 0f0ba88250..0b5d76fc24 100644 --- a/Code/Legacy/CryCommon/ILocalizationManager.h +++ b/Code/Legacy/CryCommon/ILocalizationManager.h @@ -43,10 +43,6 @@ struct SLocalizedAdvancesSoundEntry { AZStd::string sName; float fValue; - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(sName); - } }; // Localization Sound Info structure, containing sound related parameters. diff --git a/Code/Legacy/CryCommon/ILog.h b/Code/Legacy/CryCommon/ILog.h index 23257ea59b..8a9c6cc5a2 100644 --- a/Code/Legacy/CryCommon/ILog.h +++ b/Code/Legacy/CryCommon/ILog.h @@ -16,9 +16,6 @@ // this code is disable by default due it's runtime cost //#define SUPPORT_LOG_IDENTER -// forward declarations -class ICrySizer; - // Summary: // Callback interface to the ILog. struct ILogCallback @@ -121,10 +118,6 @@ struct ILog virtual const char* GetModuleFilter() = 0; - // Notes: - // Collect memory statistics in CrySizer - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - // Asset scope strings help to figure out asset dependencies in case of asset loading errors. // Should not be used directly, only by using define CRY_DEFINE_ASSET_SCOPE // @see CRY_DEFINE_ASSET_SCOPE diff --git a/Code/Legacy/CryCommon/IMaterial.h b/Code/Legacy/CryCommon/IMaterial.h index 1b3ef258ce..d4a36caf77 100644 --- a/Code/Legacy/CryCommon/IMaterial.h +++ b/Code/Legacy/CryCommon/IMaterial.h @@ -14,7 +14,6 @@ #include struct IShader; -struct ISurfaceType; struct SShaderItem; namespace AZ @@ -38,12 +37,7 @@ namespace AZ struct IMaterial { // TODO: Remove it! - virtual ~IMaterial() {} - virtual void AddRef() = 0; - virtual void Release() = 0; - virtual SShaderItem& GetShaderItem() = 0; virtual const SShaderItem& GetShaderItem() const = 0; - }; diff --git a/Code/Legacy/CryCommon/IMovieSystem.h b/Code/Legacy/CryCommon/IMovieSystem.h index b5302b58f5..6cc5a06c8f 100644 --- a/Code/Legacy/CryCommon/IMovieSystem.h +++ b/Code/Legacy/CryCommon/IMovieSystem.h @@ -6,9 +6,6 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H -#define CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H #pragma once #include @@ -255,8 +252,6 @@ struct SAnimContext // TODO: Mask should be stored with dynamic length uint32 trackMask; //!< To update certain types of tracks only float startTime; //!< The start time of this playing sequence - - void Serialize(XmlNodeRef& xmlNode, bool loading); }; /** Parameters for cut-scene cameras @@ -891,7 +886,6 @@ struct ITrackEventListener // event - Track event added // pUserData - Data to accompany reason virtual void OnTrackEvent(IAnimSequence* sequence, int reason, const char* event, void* pUserData) = 0; - virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}; // }; @@ -1152,8 +1146,6 @@ struct IMovieListener //! callback on movie events virtual void OnMovieEvent(EMovieEvent movieEvent, IAnimSequence* pAnimSequence) = 0; // - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{} }; /** Movie System interface. @@ -1326,7 +1318,6 @@ struct IMovieSystem virtual bool IsRecording() const = 0; virtual void EnableCameraShake(bool bEnabled) = 0; - virtual bool IsCameraShakeEnabled() const = 0; // Pause any playing sequences. virtual void Pause() = 0; @@ -1381,8 +1372,6 @@ struct IMovieSystem virtual void EnableBatchRenderMode(bool bOn) = 0; virtual bool IsInBatchRenderMode() const = 0; - virtual ILightAnimWrapper* CreateLightAnimWrapper(const char* name) const = 0; - virtual void LoadParamTypeFromXml(CAnimParamType& animParamType, const XmlNodeRef& xmlNode, const uint version) = 0; virtual void SaveParamTypeToXml(const CAnimParamType& animParamType, XmlNodeRef& xmlNode) = 0; @@ -1408,40 +1397,6 @@ struct IMovieSystem // }; -inline void SAnimContext::Serialize(XmlNodeRef& xmlNode, bool bLoading) -{ - if (bLoading) - { - XmlString name; - if (xmlNode->getAttr("sequence", name)) - { - sequence = gEnv->pMovieSystem->FindLegacySequenceByName(name.c_str()); - } - xmlNode->getAttr("dt", dt); - xmlNode->getAttr("fps", fps); - xmlNode->getAttr("time", time); - xmlNode->getAttr("bSingleFrame", singleFrame); - xmlNode->getAttr("bResetting", resetting); - xmlNode->getAttr("trackMask", trackMask); - xmlNode->getAttr("startTime", startTime); - } - else - { - if (sequence) - { - AZStd::string fullname = sequence->GetName(); - xmlNode->setAttr("sequence", fullname.c_str()); - } - xmlNode->setAttr("dt", dt); - xmlNode->setAttr("fps", fps); - xmlNode->setAttr("time", time); - xmlNode->setAttr("bSingleFrame", singleFrame); - xmlNode->setAttr("bResetting", resetting); - xmlNode->setAttr("trackMask", trackMask); - xmlNode->setAttr("startTime", startTime); - } -} - inline void CAnimParamType::SaveToXml(XmlNodeRef& xmlNode) const { gEnv->pMovieSystem->SaveParamTypeToXml(*this, xmlNode); @@ -1456,5 +1411,3 @@ inline void CAnimParamType::Serialize(XmlNodeRef& xmlNode, bool bLoading, const { gEnv->pMovieSystem->SerializeParamType(*this, xmlNode, bLoading, version); } - -#endif // CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H diff --git a/Code/Legacy/CryCommon/IPathfinder.h b/Code/Legacy/CryCommon/IPathfinder.h index 7a05321c99..d81bc97d49 100644 --- a/Code/Legacy/CryCommon/IPathfinder.h +++ b/Code/Legacy/CryCommon/IPathfinder.h @@ -23,6 +23,7 @@ struct IAIPathAgent; #include #include #include +#include // Hacks to deal with windows header inclusion. #ifdef GetObject diff --git a/Code/Legacy/CryCommon/IReadWriteXMLSink.h b/Code/Legacy/CryCommon/IReadWriteXMLSink.h deleted file mode 100644 index 0f8356bab7..0000000000 --- a/Code/Legacy/CryCommon/IReadWriteXMLSink.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Moved Craig's ReadWriteXMLSink from CryAction to CrySystem - - -#ifndef CRYINCLUDE_CRYCOMMON_IREADWRITEXMLSINK_H -#define CRYINCLUDE_CRYCOMMON_IREADWRITEXMLSINK_H -#pragma once - -#include -#include - -struct IReadXMLSink; -struct IWriteXMLSource; - -struct IReadWriteXMLSink -{ - // - virtual ~IReadWriteXMLSink(){} - virtual bool ReadXML(const char* definitionFile, const char* dataFile, IReadXMLSink* pSink) = 0; - virtual bool ReadXML(const char* definitionFile, XmlNodeRef node, IReadXMLSink* pSink) = 0; - virtual bool ReadXML(XmlNodeRef definition, const char* dataFile, IReadXMLSink* pSink) = 0; - virtual bool ReadXML(XmlNodeRef definition, XmlNodeRef node, IReadXMLSink* pSink) = 0; - - virtual XmlNodeRef CreateXMLFromSource(const char* definitionFile, IWriteXMLSource* pSource) = 0; - virtual bool WriteXML(const char* definitionFile, const char* dataFile, IWriteXMLSource* pSource) = 0; - // -}; - - -struct SReadWriteXMLCommon -{ - typedef AZStd::variant TValue; -}; - - -TYPEDEF_AUTOPTR(IReadXMLSink); -typedef IReadXMLSink_AutoPtr IReadXMLSinkPtr; - -// this interface allows customization of the data read routines -struct IReadXMLSink - : public SReadWriteXMLCommon -{ - // - virtual ~IReadXMLSink(){} - // reference counting - virtual void AddRef() = 0; - virtual void Release() = 0; - - virtual IReadXMLSinkPtr BeginTable(const char* name, const XmlNodeRef& definition) = 0; - virtual IReadXMLSinkPtr BeginTableAt(int elem, const XmlNodeRef& definition) = 0; - virtual bool SetValue(const char* name, const TValue& value, const XmlNodeRef& definition) = 0; - virtual bool EndTableAt(int elem) = 0; - virtual bool EndTable(const char* name) = 0; - - virtual IReadXMLSinkPtr BeginArray(const char* name, const XmlNodeRef& definition) = 0; - virtual bool SetAt(int elem, const TValue& value, const XmlNodeRef& definition) = 0; - virtual bool EndArray(const char* name) = 0; - - virtual bool Complete() = 0; - - virtual bool IsCreationMode() = 0; - virtual XmlNodeRef GetCreationNode() = 0; - virtual void SetCreationNode(XmlNodeRef definition) = 0; - // -}; - - -TYPEDEF_AUTOPTR(IWriteXMLSource); -typedef IWriteXMLSource_AutoPtr IWriteXMLSourcePtr; - -// this interface allows customization of the data write routines -struct IWriteXMLSource - : public SReadWriteXMLCommon -{ - // - virtual ~IWriteXMLSource(){} - // reference counting - virtual void AddRef() = 0; - virtual void Release() = 0; - - virtual IWriteXMLSourcePtr BeginTable(const char* name) = 0; - virtual IWriteXMLSourcePtr BeginTableAt(int elem) = 0; - virtual bool HaveValue(const char* name) = 0; - virtual bool GetValue(const char* name, TValue& value, const XmlNodeRef& definition) = 0; - virtual bool EndTableAt(int elem) = 0; - virtual bool EndTable(const char* name) = 0; - - virtual IWriteXMLSourcePtr BeginArray(const char* name, size_t* numElems, const XmlNodeRef& definition) = 0; - virtual bool HaveElemAt(int elem) = 0; - virtual bool GetAt(int elem, TValue& value, const XmlNodeRef& definition) = 0; - virtual bool EndArray(const char* name) = 0; - - virtual bool Complete() = 0; - // -}; - -#endif // CRYINCLUDE_CRYCOMMON_IREADWRITEXMLSINK_H diff --git a/Code/Legacy/CryCommon/IRenderAuxGeom.h b/Code/Legacy/CryCommon/IRenderAuxGeom.h index d487cb483f..6627c41530 100644 --- a/Code/Legacy/CryCommon/IRenderAuxGeom.h +++ b/Code/Legacy/CryCommon/IRenderAuxGeom.h @@ -455,7 +455,7 @@ enum EAuxGeomPublicRenderflags_DepthWrite // EAuxGeomPublicRenderflagBitMasks enum EAuxGeomPublicRenderflags_DepthTest { - e_DepthTestOn = 0x0 << e_DepthTestShift, + e_DepthTestOn = 0x0 << e_DepthTestShift, e_DepthTestOff = 0x1 << e_DepthTestShift, }; @@ -465,10 +465,6 @@ enum EAuxGeomPublicRenderflags_Defaults // Default render flags for 3d primitives. e_Def3DPublicRenderflags = e_Mode3D | e_AlphaNone | e_DrawInFrontOff | e_FillModeSolid | e_CullModeBack | e_DepthWriteOn | e_DepthTestOn, - - // Default render flags for 2d primitives. - e_Def2DPublicRenderflags = e_Mode2D | e_AlphaNone | e_DrawInFrontOff | e_FillModeSolid | - e_CullModeBack | e_DepthWriteOn | e_DepthTestOn }; @@ -487,48 +483,15 @@ struct SAuxGeomRenderFlags bool operator !=(const SAuxGeomRenderFlags& rhs) const; bool operator !=(uint32 rhs) const; - // Summary: - // Gets the flags for 2D/3D rendering mode. - EAuxGeomPublicRenderflags_Mode2D3D GetMode2D3DFlag() const; - // Summary: - // Sets the flags for 2D/3D rendering mode. - void SetMode2D3DFlag(const EAuxGeomPublicRenderflags_Mode2D3D& state); - - // Summary: - // Gets the flags for alpha blend mode. - EAuxGeomPublicRenderflags_AlphaBlendMode GetAlphaBlendMode() const; - // Summary: - // Sets the flags for the alpha blend mode. - void SetAlphaBlendMode(const EAuxGeomPublicRenderflags_AlphaBlendMode& state); - - - EAuxGeomPublicRenderflags_DrawInFrontMode GetDrawInFrontMode() const; void SetDrawInFrontMode(const EAuxGeomPublicRenderflags_DrawInFrontMode& state); - // Summary: - // Gets the flags for the filling mode. - EAuxGeomPublicRenderflags_FillMode GetFillMode() const; // Summary: // Sets the flags for the filling mode. void SetFillMode(const EAuxGeomPublicRenderflags_FillMode& state); - // Summary: - // Gets the flags for the culling mode. - EAuxGeomPublicRenderflags_CullMode GetCullMode() const; // Summary: // Sets the flags for the culling mode. void SetCullMode(const EAuxGeomPublicRenderflags_CullMode& state); - - - EAuxGeomPublicRenderflags_DepthWrite GetDepthWriteFlag() const; - void SetDepthWriteFlag(const EAuxGeomPublicRenderflags_DepthWrite& state); - - // Summary: - // Gets the flags for the depth test. - EAuxGeomPublicRenderflags_DepthTest GetDepthTestFlag() const; - // Summary: - // Sets the flags for the depth test. - void SetDepthTestFlag(const EAuxGeomPublicRenderflags_DepthTest& state); }; @@ -596,86 +559,6 @@ SAuxGeomRenderFlags::operator !=(uint32 rhs) const } -inline EAuxGeomPublicRenderflags_Mode2D3D -SAuxGeomRenderFlags::GetMode2D3DFlag() const -{ - int mode2D3D((int)(m_renderFlags & (uint32)e_Mode2D3DMask)); - switch (mode2D3D) - { - case e_Mode2D: - { - return(e_Mode2D); - } - case e_Mode3D: - default: - { - assert(e_Mode3D == mode2D3D); - return(e_Mode3D); - } - } -} - - -inline void -SAuxGeomRenderFlags::SetMode2D3DFlag(const EAuxGeomPublicRenderflags_Mode2D3D& state) -{ - m_renderFlags &= ~e_Mode2D3DMask; - m_renderFlags |= state; -} - - -inline EAuxGeomPublicRenderflags_AlphaBlendMode -SAuxGeomRenderFlags::GetAlphaBlendMode() const -{ - uint32 alphaBlendMode(m_renderFlags & e_AlphaBlendingMask); - switch (alphaBlendMode) - { - case e_AlphaAdditive: - { - return(e_AlphaAdditive); - } - case e_AlphaBlended: - { - return(e_AlphaBlended); - } - case e_AlphaNone: - default: - { - assert(e_AlphaNone == alphaBlendMode); - return(e_AlphaNone); - } - } -} - - -inline void -SAuxGeomRenderFlags::SetAlphaBlendMode(const EAuxGeomPublicRenderflags_AlphaBlendMode& state) -{ - m_renderFlags &= ~e_AlphaBlendingMask; - m_renderFlags |= state; -} - - -inline EAuxGeomPublicRenderflags_DrawInFrontMode -SAuxGeomRenderFlags::GetDrawInFrontMode() const -{ - uint32 drawInFrontMode(m_renderFlags & e_DrawInFrontMask); - switch (drawInFrontMode) - { - case e_DrawInFrontOff: - { - return(e_DrawInFrontOff); - } - case e_DrawInFrontOn: - default: - { - assert(e_DrawInFrontOn == drawInFrontMode); - return(e_DrawInFrontOn); - } - } -} - - inline void SAuxGeomRenderFlags::SetDrawInFrontMode(const EAuxGeomPublicRenderflags_DrawInFrontMode& state) { @@ -683,31 +566,6 @@ SAuxGeomRenderFlags::SetDrawInFrontMode(const EAuxGeomPublicRenderflags_DrawInFr m_renderFlags |= state; } - -inline EAuxGeomPublicRenderflags_FillMode -SAuxGeomRenderFlags::GetFillMode() const -{ - uint32 fillMode(m_renderFlags & e_FillModeMask); - switch (fillMode) - { - case e_FillModePoint: - { - return(e_FillModePoint); - } - case e_FillModeWireframe: - { - return(e_FillModeWireframe); - } - case e_FillModeSolid: - default: - { - assert(e_FillModeSolid == fillMode); - return(e_FillModeSolid); - } - } -} - - inline void SAuxGeomRenderFlags::SetFillMode(const EAuxGeomPublicRenderflags_FillMode& state) { @@ -715,117 +573,9 @@ SAuxGeomRenderFlags::SetFillMode(const EAuxGeomPublicRenderflags_FillMode& state m_renderFlags |= state; } - -inline EAuxGeomPublicRenderflags_CullMode -SAuxGeomRenderFlags::GetCullMode() const -{ - uint32 cullMode(m_renderFlags & e_CullModeMask); - switch (cullMode) - { - case e_CullModeNone: - { - return(e_CullModeNone); - } - case e_CullModeFront: - { - return(e_CullModeFront); - } - case e_CullModeBack: - default: - { - assert(e_CullModeBack == cullMode); - return(e_CullModeBack); - } - } -} - - inline void SAuxGeomRenderFlags::SetCullMode(const EAuxGeomPublicRenderflags_CullMode& state) { m_renderFlags &= ~e_CullModeMask; m_renderFlags |= state; } - - -inline EAuxGeomPublicRenderflags_DepthWrite -SAuxGeomRenderFlags::GetDepthWriteFlag() const -{ - uint32 depthWriteFlag(m_renderFlags & e_DepthWriteMask); - switch (depthWriteFlag) - { - case e_DepthWriteOff: - { - return(e_DepthWriteOff); - } - case e_DepthWriteOn: - default: - { - assert(e_DepthWriteOn == depthWriteFlag); - return(e_DepthWriteOn); - } - } -} - - -inline void -SAuxGeomRenderFlags::SetDepthWriteFlag(const EAuxGeomPublicRenderflags_DepthWrite& state) -{ - m_renderFlags &= ~e_DepthWriteMask; - m_renderFlags |= state; -} - - -inline EAuxGeomPublicRenderflags_DepthTest -SAuxGeomRenderFlags::GetDepthTestFlag() const -{ - uint32 depthTestFlag(m_renderFlags & e_DepthTestMask); - switch (depthTestFlag) - { - case e_DepthTestOff: - { - return(e_DepthTestOff); - } - case e_DepthTestOn: - default: - { - assert(e_DepthTestOn == depthTestFlag); - return(e_DepthTestOn); - } - } -} - - -inline void -SAuxGeomRenderFlags::SetDepthTestFlag(const EAuxGeomPublicRenderflags_DepthTest& state) -{ - m_renderFlags &= ~e_DepthTestMask; - m_renderFlags |= state; -} - - -class CRenderAuxGeomRenderFlagsRestore -{ -public: - explicit CRenderAuxGeomRenderFlagsRestore(IRenderAuxGeom* pRender); - ~CRenderAuxGeomRenderFlagsRestore(); - -private: - IRenderAuxGeom* m_pRender; - SAuxGeomRenderFlags m_backuppedRenderFlags; - - // copy-construction not supported - CRenderAuxGeomRenderFlagsRestore(const CRenderAuxGeomRenderFlagsRestore&); - CRenderAuxGeomRenderFlagsRestore& operator=(const CRenderAuxGeomRenderFlagsRestore&); -}; - -inline CRenderAuxGeomRenderFlagsRestore::CRenderAuxGeomRenderFlagsRestore(IRenderAuxGeom* pRender) -{ - m_pRender = pRender; - m_backuppedRenderFlags = m_pRender->GetRenderFlags(); -} - -inline CRenderAuxGeomRenderFlagsRestore::~CRenderAuxGeomRenderFlagsRestore() -{ - m_pRender->SetRenderFlags(m_backuppedRenderFlags); -} diff --git a/Code/Legacy/CryCommon/IRenderer.h b/Code/Legacy/CryCommon/IRenderer.h index ab185b3bbc..495c885e44 100644 --- a/Code/Legacy/CryCommon/IRenderer.h +++ b/Code/Legacy/CryCommon/IRenderer.h @@ -193,32 +193,3 @@ struct DynUiPrimitive : public AZStd::intrusive_slist_node int m_numIndices = 0; }; using DynUiPrimitiveList = AZStd::intrusive_slist>; - -class CLodValue -{ -public: - CLodValue() = default; - - CLodValue(int nLodA) - { - m_nLodA = aznumeric_caster(nLodA); - } - - CLodValue(int nLodA, uint8 nDissolveRef, int nLodB) - { - m_nLodA = aznumeric_caster(nLodA); - m_nLodB = aznumeric_caster(nLodB); - m_nDissolveRef = nDissolveRef; - } - - int LodA() const { return m_nLodA; } - int LodB() const { return m_nLodB; } - - uint8 DissolveRefA() const { return m_nDissolveRef; } - uint8 DissolveRefB() const { return 255 - m_nDissolveRef; } - -private: - int16 m_nLodA = -1; - int16 m_nLodB = -1; - uint8 m_nDissolveRef = 0; -}; diff --git a/Code/Legacy/CryCommon/ISerialize.h b/Code/Legacy/CryCommon/ISerialize.h index 82ba9aef0d..c253796109 100644 --- a/Code/Legacy/CryCommon/ISerialize.h +++ b/Code/Legacy/CryCommon/ISerialize.h @@ -6,144 +6,24 @@ * */ - // Description : main header file - - -#ifndef CRYINCLUDE_CRYCOMMON_ISERIALIZE_H -#define CRYINCLUDE_CRYCOMMON_ISERIALIZE_H #pragma once +#include #include #include -#include "MiniQueue.h" -#include #include -#include -#include +// Forward declarations class CTimeValue; -// Forward template declaration -template -class InterpolatedValue_tpl; - -// Unfortunately this needs to be here - should be in CryNetwork somewhere. -struct SNetObjectID -{ - static const uint16 InvalidId = std::numeric_limits::max(); - - SNetObjectID() - : id(InvalidId) - , salt(0) {} - SNetObjectID(uint16 i, uint16 s) - : id(i) - , salt(s) {} - - uint16 id; - uint16 salt; - - ILINE bool operator!() const - { - return id == InvalidId; - } - typedef uint16 (SNetObjectID::* unknown_bool_type); - ILINE operator unknown_bool_type() const - { - return !!(*this) ? &SNetObjectID::id : NULL; - } - ILINE bool operator!=(const SNetObjectID& rhs) const - { - return !(*this == rhs); - } - ILINE bool operator==(const SNetObjectID& rhs) const - { - return id == rhs.id && salt == rhs.salt; - } - ILINE bool operator<(const SNetObjectID& rhs) const - { - return id < rhs.id || (id == rhs.id && salt < rhs.salt); - } - ILINE bool operator>(const SNetObjectID& rhs) const - { - return id > rhs.id || (id == rhs.id && salt > rhs.salt); - } - - bool IsLegal() const - { - return salt != 0; - } - - const char* GetText(char* tmpBuf = nullptr, size_t bufferSize = 0) const - { - static char singlebuf[64]; - if (!tmpBuf) - { - tmpBuf = singlebuf; - bufferSize = sizeof(singlebuf); - } - - if (id == InvalidId) - { - sprintf_s(tmpBuf, bufferSize, ""); - } - else if (!salt) - { - sprintf_s(tmpBuf, bufferSize, "illegal:%d:%d", id, salt); - } - else - { - sprintf_s(tmpBuf, bufferSize, "%d:%d", id, salt); - } - - return tmpBuf; - } - - uint32 GetAsUint32() const - { - return (uint32(salt) << 16) | id; - } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { /*nothing*/} -}; // this enumeration details what "kind" of serialization we are // performing, so that classes that want to, for instance, tailor // the data they present depending on where data is being written // to can do so -enum ESerializationTarget +enum class ESerializationTarget { eST_SaveGame, - eST_Network, - eST_Script -}; - -// this inner class defines an interface so that OnUpdate -// functions can be passed abstractly through to concrete -// serialization classes -struct ISerializeUpdateFunction -{ - // - virtual ~ISerializeUpdateFunction(){} - virtual void Execute() = 0; - // -}; - -// concrete implementation of IUpdateFunction for a general functor class -template -class CSerializeUpdateFunction - : public ISerializeUpdateFunction -{ -public: - CSerializeUpdateFunction(F_Update& update) - : m_rUpdate(update) {} - - virtual void Execute() - { - m_rUpdate(); - } - -private: - F_Update m_rUpdate; }; ////////////////////////////////////////////////////////////////////////// @@ -151,34 +31,68 @@ private: ////////////////////////////////////////////////////////////////////////// struct SSerializeString { - SSerializeString() {}; - SSerializeString(const SSerializeString& src) { m_str.assign(src.c_str()); }; + SSerializeString(){}; + SSerializeString(const SSerializeString& src) + { + m_str.assign(src.c_str()); + }; explicit SSerializeString(const char* sbegin, const char* send) - : m_str(sbegin, send) {}; - ~SSerializeString() {} + : m_str(sbegin, send){}; + ~SSerializeString() + { + } // Casting to const char* SSerializeString(const char* s) - : m_str(s) { }; - //operator const char* () const { return m_str; } + : m_str(s){}; - SSerializeString& operator =(const SSerializeString& src) { m_str.assign(src.c_str()); return *this; } - SSerializeString& operator =(const char* src) { m_str.assign(src); return *this; } + SSerializeString& operator=(const SSerializeString& src) + { + m_str.assign(src.c_str()); + return *this; + } + SSerializeString& operator=(const char* src) + { + m_str.assign(src); + return *this; + } - bool operator != (const SSerializeString& src) { return m_str != src.m_str; } + bool operator!=(const SSerializeString& src) + { + return m_str != src.m_str; + } - size_t size() const { return m_str.size(); } - size_t length() const { return m_str.length(); } - const char* c_str() const { return m_str.c_str(); }; - bool empty() const { return m_str.empty(); } - void resize(int sz) { m_str.resize(sz); } - void reserve(int sz) { m_str.reserve(sz); } + size_t size() const + { + return m_str.size(); + } + size_t length() const + { + return m_str.length(); + } + const char* c_str() const + { + return m_str.c_str(); + }; + bool empty() const + { + return m_str.empty(); + } + void resize(int sz) + { + m_str.resize(sz); + } + void reserve(int sz) + { + m_str.reserve(sz); + } void set_string(const AZStd::string& s) { m_str.assign(s.begin(), s.size()); } - operator const AZStd::string() const { + operator const AZStd::string() const + { return m_str; } @@ -195,21 +109,17 @@ struct ISerialize { static const int ENUM_POLICY_TAG = 0xe0000000; - ILINE ISerialize() {} + ISerialize() + { + } - // - virtual ~ISerialize(){} + virtual ~ISerialize() + { + } // this is for string values -- they need special support - virtual void ReadStringValue(const char* name, SSerializeString& curValue, uint32 policy = 0) = 0; - virtual void WriteStringValue(const char* name, SSerializeString& buffer, uint32 policy = 0) = 0; - // this function should be implemented to call the passed in interface - // if we are reading, and to not call it if we are writing - virtual void Update(ISerializeUpdateFunction* pUpdate) = 0; - - // for network updates: notify the network engine that this value was only partially read and we - // should re-request an update from the server soon - virtual void FlagPartialRead() = 0; + virtual void ReadStringValue(const char* name, SSerializeString& curValue) = 0; + virtual void WriteStringValue(const char* name, SSerializeString& buffer) = 0; ////////////////////////////////////////////////////////////////////////// // these functions should be implemented to deal with groups @@ -224,43 +134,18 @@ struct ISerialize ////////////////////////////////////////////////////////////////////////// virtual bool IsReading() const = 0; - virtual bool ShouldCommitValues() const = 0; - virtual ESerializationTarget GetSerializationTarget() const = 0; - virtual bool Ok() const = 0; - // // declare all primitive Value() implementations #define SERIALIZATION_TYPE(T) \ - virtual void Value(const char* name, T & x, uint32 policy) = 0; + virtual void Value(const char* name, T& x) = 0; #include "SerializationTypes.h" #undef SERIALIZATION_TYPE - - // declare all primitive Value() implementations -#define SERIALIZATION_TYPE(T) \ - virtual void ValueWithDefault(const char* name, T & x, const T&defaultValue) = 0; -#include "SerializationTypes.h" - SERIALIZATION_TYPE(SSerializeString) -#undef SERIALIZATION_TYPE - void Value([[maybe_unused]] const char* name, [[maybe_unused]] AZ::Vector3& x) - { - } - template - void Value(const char* name, B& x) - { - Value(name, x, 0); - } - - template - void Value(const char* name, B& x, uint32 policy); - - template - void ValueWithDefault(const char* name, B& x, const B& defaultValue); }; // this class provides a wrapper so that ISerialize can be used much more // easily; it is a template so that if we need to wrap a more specific // ISerialize implementation we can do so easily -template +template class CSerializeWrapper { public: @@ -276,507 +161,42 @@ public: // have been made to follow the trend. // the value function allows us to declare that a value needs - // to be serialized/deserialized; we can pass a serialization policy - // in order to compress the value, and an update function to allow - // us to be informed of when this value is changed - template - ILINE void Value(const char* szName, T_Value& value, int policy) - { - m_pSerialize->Value(szName, value, policy); - } + // to be serialized/deserialized; - template + template ILINE void Value(const char* szName, T_Value& value) { m_pSerialize->Value(szName, value); } - void Value(const char* szName, AZStd::string& value, int policy) + void Value(const char* szName, AZStd::string& value) { if (IsWriting()) { SSerializeString& serializeString = SetSharedSerializeString(value); - m_pSerialize->WriteStringValue(szName, serializeString, policy); + m_pSerialize->WriteStringValue(szName, serializeString); } else { - if (GetSerializationTarget() != eST_Script) - { - value = ""; - } - + value = ""; SSerializeString& serializeString = SetSharedSerializeString(value); - m_pSerialize->ReadStringValue(szName, serializeString, policy); + m_pSerialize->ReadStringValue(szName, serializeString); value = serializeString.c_str(); } } - ILINE void Value(const char* szName, AZStd::string& value) - { - Value(szName, value, 0); - } - void Value(const char* szName, const AZStd::string& value, int policy) + void Value(const char* szName, const AZStd::string& value) { if (IsWriting()) { SSerializeString& serializeString = SetSharedSerializeString(value); - m_pSerialize->WriteStringValue(szName, serializeString, policy); + m_pSerialize->WriteStringValue(szName, serializeString); } else { assert(0 && "This function can only be used for Writing"); } } - ILINE void Value(const char* szName, const AZStd::string& value) - { - Value(szName, value, 0); - } - template - void Value(const char* szName, T_Class* pInst, T_Value (T_Class::* get)() const, void (T_Class::* set)(T_Value)) - { - if (IsWriting()) - { - T_Value temp = (pInst->*get)(); - Value(szName, temp); - } - else - { - T_Value temp; - Value(szName, temp); - (pInst->*set)(temp); - } - } - template - void Value(const char* name, InterpolatedValue_tpl& val) - { - if (IsWriting()) - { - T a = val.Get(); - Value(name, a); - } - - if (IsReading()) - { - T a; - Value(name, a); - val.SetGoal(a); - } - } - - template - void Value(const char* name, InterpolatedValue_tpl& val, int policy) - { - if (IsWriting()) - { - T a = val.Get(); - Value(name, a, policy); - } - - if (IsReading()) - { - T a; - Value(name, a, policy); - val.SetGoal(a); - } - } - - bool ValueChar(const char* name, char* buffer, int len) - { - AZStd::string temp; - if (IsReading()) - { - Value(name, temp); - if ((int)temp.length() > len - 1) - { - return false; // truncated read - } - memcpy(buffer, temp.data(), temp.length() + 1); - buffer[len - 1] = 0; - } - else - { - temp = AZStd::string(buffer, buffer + len); - Value(name, temp); - } - return true; - } - - template - void ValueWithDefault(const char* name, T& x, const T& defaultValue) - { - m_pSerialize->ValueWithDefault(name, x, defaultValue); - } - - void ValueWithDefault(const char* szName, AZStd::string& value, const AZStd::string& defaultValue) - { - static SSerializeString defaultSerializeString; - - { - defaultSerializeString.set_string(defaultValue); - } - - SSerializeString& serializeString = SetSharedSerializeString(value); - m_pSerialize->ValueWithDefault(szName, serializeString, defaultSerializeString); - if (IsReading()) - { - value = serializeString.c_str(); - } - } - - template - void Value(const char* szName, T_Class* pInst, T_Value (T_Class::* get)() const, void (T_Class::* set)(T_Value), - const T_SerializationPolicy& policy) - { - if (IsWriting()) - { - T_Value temp = (pInst->*get)(); - Value(szName, temp, policy); - } - else - { - T_Value temp = static_cast(0); - Value(szName, temp, policy); - (pInst->*set)(temp); - } - } - - // a value that is written by referring to a map of key/value pairs - we receive the key, and write the value - template - void MappedValue(const char* szName, T_Key& value, const T_Map& mapper) - { - typedef typename T_Map::ValueType T_Value; - - if (IsWriting()) - { - T_Value write = mapper.KeyToValue(value); - Value(szName, write); - } - else - { - T_Value read; - Value(szName, read); - value = mapper.ValueToKey(read); - } - } - -#define CONTAINER_VALUE(container_type, insert_function) \ - template \ - void Value(const char* name, container_type&cont) \ - { \ - if (!BeginOptionalGroup(name, true)) {return; } \ - if (IsWriting()) \ - { \ - uint32 count = cont.size(); \ - Value("Size", count); \ - for (typename container_type::iterator iter = cont.begin(); iter != cont.end(); ++iter) \ - { \ - BeginGroup("i"); \ - T_Value value = *iter; \ - Value("v", value); \ - EndGroup(); \ - } \ - } \ - else \ - { \ - cont.clear(); \ - uint32 count = 0; \ - Value("Size", count); \ - while (count--) \ - { \ - BeginGroup("i"); \ - T_Value temp; \ - Value("v", temp); \ - cont.insert_function(temp); \ - EndGroup(); \ - } \ - } \ - EndGroup(); \ - } \ - template \ - void MappedValue(const char* name, container_type&cont, const T_Map&mapper) \ - { \ - if (!BeginOptionalGroup(name, true)) {return; } \ - if (IsWriting()) \ - { \ - uint32 count = cont.size(); \ - Value("Size", count); \ - for (typename container_type::iterator iter = cont.begin(); iter != cont.end(); ++iter) \ - { \ - BeginGroup("i"); \ - MappedValue("v", *iter, mapper); \ - EndGroup(); \ - } \ - } \ - else \ - { \ - cont.clear(); \ - uint32 count = 0; \ - Value("Size", count); \ - while (count--) \ - { \ - BeginGroup("i"); \ - T_Value temp; \ - MappedValue("v", temp, mapper); \ - cont.insert_function(temp); \ - EndGroup(); \ - } \ - } \ - EndGroup(); \ - } - -#define PAIR_CONTAINER_VALUE(container_type, insert_function) \ - template \ - void Value(const char* name, container_type, Allocator>&cont) \ - { \ - if (!BeginOptionalGroup(name, true)) {return; } \ - if (IsWriting()) \ - { \ - uint32 count = cont.size(); \ - Value("Size", count); \ - for (typename container_type, Allocator>::iterator iter = cont.begin(); iter != cont.end(); ++iter) \ - { \ - BeginGroup("i"); \ - T_Value1 value1 = iter->first; \ - T_Value2 value2 = iter->second; \ - Value("v1", value1); \ - Value("v2", value2); \ - EndGroup(); \ - } \ - } \ - else \ - { \ - cont.clear(); \ - uint32 count = 0; \ - Value("Size", count); \ - while (count--) \ - { \ - BeginGroup("i"); \ - T_Value1 temp1; \ - T_Value2 temp2; \ - Value("v1", temp1); \ - Value("v2", temp2); \ - cont.insert_function(std::pair(temp1, temp2)); \ - EndGroup(); \ - } \ - } \ - EndGroup(); \ - } \ - - CONTAINER_VALUE(std::vector, push_back); - CONTAINER_VALUE(std::list, push_back); - CONTAINER_VALUE(std::set, insert); - CONTAINER_VALUE(std::deque, push_back); - - PAIR_CONTAINER_VALUE(std::list, push_back); - PAIR_CONTAINER_VALUE(std::vector, push_back); - - template - void DummyValues(uint32 numDummyValues) - { - T_Value dummyValue; - for (uint32 i = 0; i < numDummyValues; ++i) - { - Value("Value", dummyValue); - } - } - - template - void Value(const char* name, MiniQueue& cont) - { - if (!BeginOptionalGroup(name, true)) - { - return; - } - if (IsWriting()) - { - uint32 count = cont.Size(); - Value("Size", count); - for (typename MiniQueue::SIterator iter = cont.Begin(); iter != cont.End(); ++iter) - { - T_Value value = *iter; - Value("Value", value); - } - } - else - { - cont.Clear(); - uint32 count = 0; - Value("Size", count); - while (count--) - { - T_Value temp; - Value("Value", temp); - cont.Push(temp); - } - } - DummyValues(cont.Capacity() - cont.Size()); - EndGroup(); - } - template - void MappedValue(const char* name, MiniQueue& cont, const T_Map& mapper) - { - if (!BeginOptionalGroup(name, true)) - { - return; - } - if (IsWriting()) - { - uint8 count = cont.Size(); - Value("Size", count); - for (typename MiniQueue::SIterator iter = cont.Begin(); iter != cont.End(); ++iter) - { - BeginGroup("i"); - MappedValue("Value", *iter, mapper); - EndGroup(); - } - } - else - { - cont.Clear(); - uint8 count = 0; - Value("Size", count); - while (count--) - { - BeginGroup("i"); - T_Value temp; - MappedValue("Value", temp, mapper); - cont.Push(temp); - EndGroup(); - } - } - EndGroup(); - } - -#define MAP_CONTAINER_VALUE(container_type) \ - template \ - void Value(const char* name, container_type&cont) \ - { \ - if (!BeginOptionalGroup(name, true)) {return; } \ - if (IsWriting()) \ - { \ - uint32 count = (uint32)cont.size(); \ - Value("Size", count); \ - for (typename container_type::iterator iter = cont.begin(); iter != cont.end(); ++iter) \ - { \ - T_Key tempKey = iter->first; \ - BeginGroup("pair"); \ - Value("k", tempKey); \ - Value("v", iter->second); \ - EndGroup(); \ - } \ - } \ - else \ - { \ - cont.clear(); \ - uint32 count; \ - Value("Size", count); \ - while (count--) \ - { \ - std::pair temp; \ - BeginGroup("pair"); \ - Value("k", temp.first); \ - Value("v", temp.second); \ - EndGroup(); \ - cont.insert(temp); \ - } \ - } \ - EndGroup(); \ - } - -#define HASH_CONTAINER_VALUE(container_type) \ - template \ - void Value(const char* name, container_type&cont) \ - { \ - if (!BeginOptionalGroup(name, true)) {return; } \ - if (IsWriting()) \ - { \ - uint32 count = (uint32)cont.size(); \ - Value("Size", count); \ - for (typename container_type::iterator iter = cont.begin(); iter != cont.end(); ++iter) \ - { \ - T_Key tempKey = iter->first; \ - BeginGroup("pair"); \ - Value("k", tempKey); \ - Value("v", iter->second); \ - EndGroup(); \ - } \ - } \ - else \ - { \ - cont.clear(); \ - uint32 count; \ - Value("Size", count); \ - while (count--) \ - { \ - AZStd::pair temp; \ - BeginGroup("pair"); \ - Value("k", temp.first); \ - Value("v", temp.second); \ - EndGroup(); \ - cont.insert(temp); \ - } \ - } \ - EndGroup(); \ - } - MAP_CONTAINER_VALUE(std::map); - MAP_CONTAINER_VALUE(std::multimap); - MAP_CONTAINER_VALUE(VectorMap); - - HASH_CONTAINER_VALUE(AZStd::unordered_map); - - template - ILINE void EnumValue(const char* szName, T_Value& value, - T_Value first, T_Value last) - { - int32 nValue = int32(value) - first; - Value(szName, nValue, ISerialize::ENUM_POLICY_TAG | (last - first)); - value = T_Value(nValue + first); - } - template - ILINE void EnumValue(const char* szName, - T_Class* pClass, T_Value (T_Class::* GetValue)() const, void (T_Class::* SetValue)(T_Value), - T_Value first, T_Value last) - { - bool w = IsWriting(); - int nValue; - if (w) - { - nValue = int32((pClass->*GetValue)()) - first; - } - Value(szName, nValue, ISerialize::ENUM_POLICY_TAG | (last - first)); - if (!w) - { - (pClass->*SetValue)(T_Value(nValue + first)); - } - } - /* - // we can request that a functor be called whenever our values - // are being updated by calling this function - template - ILINE void OnUpdate( F_Update& update ) - { - CUpdateFunction func(update); - m_pSerialize->Update( &func ); - } - template - ILINE void OnUpdate( T * pCls, void (T::*func)() ) - { - class CFunc : public IUpdateFunction - { - public: - CFunc( T * pCls, void (T::*func)() ) : m_pCls(pCls), m_func(func) {} - virtual void Execute() - { - (m_pCls->*m_func)(); - } - private: - T * m_pCls; - void (T::*m_func)(); - }; - CFunc ifunc( pCls, func ); - m_pSerialize->Update( &ifunc ); - } - */ // groups help us find common data ILINE void BeginGroup(const char* szName) { @@ -791,12 +211,6 @@ public: m_pSerialize->EndGroup(); } - // fetch the serialization target - ILINE ESerializationTarget GetSerializationTarget() const - { - return m_pSerialize->GetSerializationTarget(); - } - ILINE bool IsWriting() const { return !m_pSerialize->IsReading(); @@ -805,27 +219,12 @@ public: { return m_pSerialize->IsReading(); } - ILINE bool ShouldCommitValues() const - { - assert(m_pSerialize->IsReading()); - return m_pSerialize->ShouldCommitValues(); - } - - ILINE bool Ok() const - { - return m_pSerialize->Ok(); - } friend ILINE TISerialize* GetImpl(CSerializeWrapper ser) { return ser.m_pSerialize; } - ILINE void FlagPartialRead() - { - m_pSerialize->FlagPartialRead(); - } - operator CSerializeWrapper() { return CSerializeWrapper(m_pSerialize); @@ -844,65 +243,3 @@ private: // default serialize class to use!! typedef CSerializeWrapper TSerialize; - -// simple struct to declare something serializable... useful for -// exposition -struct ISerializable -{ - virtual ~ISerializable(){} - virtual void SerializeWith(TSerialize) = 0; -}; - -template -void ISerialize::Value(const char* name, B& x, uint32 policy) -{ - if (!BeginOptionalGroup(name, true)) - { - return; - } - TSerialize ser(this); - x.Serialize(ser); - EndGroup(); -} -// -//template <> -//void ISerialize::Value(const char * name, AZ::Vector3& x, uint32 policy) -//{ -// -//} - -// Based off ValueWithDefault in SimpleSerialize.h -template -void ISerialize::ValueWithDefault(const char* name, B& x, const B& defaultValue) -{ - if (BeginOptionalGroup(name, x != defaultValue)) - { - TSerialize ser(this); - x.Serialize(ser); - EndGroup(); - } - else if (IsReading()) - { - x = defaultValue; - } -} - -////////////////////////////////////////////////////////////////////////// -// Used to automatically Begin/End group in serialization stream -////////////////////////////////////////////////////////////////////////// -struct SSerializeScopedBeginGroup -{ - SSerializeScopedBeginGroup(TSerialize& ser, const char* sGroupName) - { - m_pSer = &ser; - m_pSer->BeginGroup(sGroupName); - } - ~SSerializeScopedBeginGroup() - { - m_pSer->EndGroup(); - } -private: - TSerialize* m_pSer; -}; - -#endif // CRYINCLUDE_CRYCOMMON_ISERIALIZE_H diff --git a/Code/Legacy/CryCommon/IShader.h b/Code/Legacy/CryCommon/IShader.h index e9a00d3b76..208af79ece 100644 --- a/Code/Legacy/CryCommon/IShader.h +++ b/Code/Legacy/CryCommon/IShader.h @@ -41,7 +41,6 @@ enum EEfResTextures : int // This needs a fixed size so the enum can be forward enum EParamType { eType_UNKNOWN, - eType_BYTE, eType_BOOL, eType_SHORT, eType_INT, @@ -90,10 +89,6 @@ struct SShaderItem IRenderShaderResources* m_pShaderResources; int32 m_nTechnique; uint32 m_nPreprocessFlags; - - bool Update(); - bool RefreshResourceConstants(); - inline struct SShaderTechnique* GetTechnique() const; }; struct IAnimNode; diff --git a/Code/Legacy/CryCommon/ISplines.h b/Code/Legacy/CryCommon/ISplines.h index a1c5c674b0..5104e80bc0 100644 --- a/Code/Legacy/CryCommon/ISplines.h +++ b/Code/Legacy/CryCommon/ISplines.h @@ -347,8 +347,6 @@ namespace spline m_c[3] = T((2.0f * v0 - 2.0f * v1 + s0 + s1) * idt * idt * idt); } } - - void GetMemoryUsage(ICrySizer* pSizer) const {} }; inline float fast_fmod(float x, float y) @@ -410,7 +408,7 @@ namespace spline //! TCB spline key used in quaternion spline with angle axis as input. struct TCBAngAxisKey - : public TCBSplineKey + : public TCBSplineKey { float angle; Vec3 axis; diff --git a/Code/Legacy/CryCommon/IStatObj.h b/Code/Legacy/CryCommon/IStatObj.h index b2cde275c5..a809064bcc 100644 --- a/Code/Legacy/CryCommon/IStatObj.h +++ b/Code/Legacy/CryCommon/IStatObj.h @@ -5,43 +5,14 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - - #pragma once -#include "smartptr.h" // TYPEDEF_AUTOPTR -#include "IMaterial.h" - -// forward declarations -////////////////////////////////////////////////////////////////////// -struct ShadowMapFrustum; -struct SRenderingPassInfo; -struct SRendItemSorter; -struct ITetrLattice; -struct SPhysGeomArray; -struct CStatObj; - -class CRenderObject; -class CDLight; -class IReadStream; -class CLodValue; - - -TYPEDEF_AUTOPTR(IReadStream); - -//! Interface to non animated object -struct phys_geometry; -struct IChunkFile; - -// General forward declaration. -struct SMeshLodInfo; - -#include "Cry_Color.h" #include "Cry_Math.h" #include "Cry_Geo.h" -#include "CrySizer.h" +#include "IMaterial.h" -#define MAX_STATOBJ_LODS_NUM 6 +// General forward declaration. +struct SRenderingPassInfo; ////////////////////////////////////////////////////////////////////////// // Type of static sub object. @@ -50,184 +21,46 @@ enum EStaticSubObjectType { STATIC_SUB_OBJECT_MESH, // This simple geometry part of the multi-sub object geometry. STATIC_SUB_OBJECT_HELPER_MESH, // Special helper mesh, not rendered usually, used for broken pieces. - STATIC_SUB_OBJECT_POINT, - STATIC_SUB_OBJECT_DUMMY, - STATIC_SUB_OBJECT_XREF, - STATIC_SUB_OBJECT_CAMERA, - STATIC_SUB_OBJECT_LIGHT, }; -////////////////////////////////////////////////////////////////////////// -// Flags that can be set on static object. -////////////////////////////////////////////////////////////////////////// -enum EStaticObjectFlags -{ - STATIC_OBJECT_HIDDEN = BIT(0), // When set static object will not be displayed. - STATIC_OBJECT_CLONE = BIT(1), // specifies whether this object was cloned for modification - STATIC_OBJECT_GENERATED = BIT(2), // tells that the object was generated procedurally (breakable obj., f.i.) - STATIC_OBJECT_CANT_BREAK = BIT(3), // StatObj has geometry unsuitable for procedural breaking - STATIC_OBJECT_DEFORMABLE = BIT(4), // StatObj can be procedurally smeared (using SmearStatObj) - STATIC_OBJECT_COMPOUND = BIT(5), // StatObj has subobject meshes - STATIC_OBJECT_MULTIPLE_PARENTS = BIT(6), // Child StatObj referenced by several parents - - // Collisions - STATIC_OBJECT_NO_PLAYER_COLLIDE = BIT(10), - - // Special flags. - STATIC_OBJECT_SPAWN_ENTITY = BIT(20), // StatObj spawns entity when broken. - STATIC_OBJECT_NO_AUTO_HIDEPOINTS = BIT(22), // Do not generate AI auto hide points around object if it's dynamic - STATIC_OBJECT_DYNAMIC = BIT(23), // mesh data should be kept in system memory (and yes, the name *is* an oxymoron) -}; - -#define HIT_NO_HIT (-1) -#define HIT_UNKNOWN (-2) - -#define HIT_OBJ_TYPE_BRUSH 0 -#define HIT_OBJ_TYPE_TERRAIN 1 -#define HIT_OBJ_TYPE_VISAREA 2 - // used for on-CPU voxelization -struct SRayHitTriangle -{ - SRayHitTriangle() { ZeroStruct(*this); } - Vec3 v[3]; - Vec2 t[3]; - ColorB c[3]; - Vec3 n; - _smart_ptr pMat; - uint8 nTriArea; - uint8 nOpacity; - uint8 nHitObjType; -}; - struct SRayHitInfo { SRayHitInfo() { memset(this, 0, sizeof(*this)); - nHitTriID = HIT_UNKNOWN; } ////////////////////////////////////////////////////////////////////////// // Input parameters. Vec3 inReferencePoint; Ray inRay; - bool bInFirstHit; - bool inRetTriangle; - bool bUseCache; - bool bOnlyZWrite; - bool bGetVertColorAndTC; - float fMaxHitDistance; // When not 0, only hits with closer distance will be registered. - Vec3 vTri0; - Vec3 vTri1; - Vec3 vTri2; - float fMinHitOpacity; ////////////////////////////////////////////////////////////////////////// // Output parameters. - float fDistance; // Distance from reference point. Vec3 vHitPos; Vec3 vHitNormal; - int nHitMatID; // Material Id that was hit. - int nHitTriID; // Triangle Id that was hit. - int nHitSurfaceID; // Material Id that was hit. - struct IRenderMesh* pRenderMesh; - struct IStatObj* pStatObj; - Vec2 vHitTC; - Vec4 vHitColor; - Vec4 vHitTangent; - Vec4 vHitBitangent; - PodArray* pHitTris; -}; -enum EFileStreamingStatus -{ - ecss_NotLoaded, - ecss_InProgress, - ecss_Ready + // More inputs + bool bInFirstHit; + bool bUseCache; }; -struct SMeshBoneMapping_uint8; -struct SSpine; -struct SMeshColor; - // Summary: // Interface to hold static object data struct IStatObj { - //! Loading flags - enum ELoadingFlags - { - ELoadingFlagsPreviewMode = BIT(0), - ELoadingFlagsForceBreakable = BIT(1), - ELoadingFlagsIgnoreLoDs = BIT(2), - ELoadingFlagsTessellate = BIT(3), // if e_StatObjTessellation enabled - ELoadingFlagsJustGeometry = BIT(4), // for streaming, to avoid parsing all chunks - }; - ////////////////////////////////////////////////////////////////////////// // SubObject ////////////////////////////////////////////////////////////////////////// struct SSubObject { - SSubObject() { bShadowProxy = 0; } - EStaticSubObjectType nType; - AZStd::string name; - AZStd::string properties; - int nParent; // Index of the parent sub object, if there`s hierarchy between them. - Matrix34 tm; // Transformation matrix. Matrix34 localTM; // Local transformation matrix, relative to parent. IStatObj* pStatObj; // Static object for sub part of CGF. - Vec3 helperSize; // Size of the helper (if helper). - struct IRenderMesh* pWeights; // render mesh with a single deformation weights stream - unsigned int bIdentityMatrix : 1; // True if sub object matrix is identity. - unsigned int bHidden : 1; // True if sub object is hidden - unsigned int bShadowProxy : 1; // Child StatObj has 'shadowproxy' in name - unsigned int nBreakerJoints : 8; // number of joints that can switch this part to a broken state - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(name); - pSizer->AddObject(properties); - } }; ////////////////////////////////////////////////////////////////////////// - // - // Description: - // Increase the reference count of the object. - // Summary: - // Notifies that the object is being used - virtual int AddRef() = 0; - - // Description: - // Decrease the reference count of the object. If the reference count - // reaches zero, the object will be deleted from memory. - // Summary: - // Notifies that the object is no longer needed - virtual int Release() = 0; - - // Description: - // Set static object flags. - // Arguments: - // nFlags - flags to set, a combination of EStaticObjectFlags values. - virtual void SetFlags(int nFlags) = 0; - - // Description: - // Retrieve flags set on the static object. - virtual int GetFlags() const = 0; - - // Sets the default object indicator - virtual void SetDefaultObject(bool state) = 0; - - // Description: - // Retrieves the internal flag m_nVehicleOnlyPhysics. - virtual unsigned int GetVehicleOnlyPhysics() = 0; - - // Description: - // Retrieves the internal flag m_bBreakableByGame. - virtual unsigned int GetBreakableByGame() = 0; - + virtual ~IStatObj() {} // Description: // Provide access to the faces, vertices, texture coordinates, normals and // colors of the object used later for CRenderMesh construction. @@ -237,86 +70,6 @@ struct IStatObj // Get the object source geometry virtual struct IIndexedMesh* GetIndexedMesh(bool bCreateIfNone = false) = 0; - // Description: - // Create an empty indexed mesh ready to be filled with data - // If an indexed mesh already exists it is returned - // Return Value: - // An empty indexed mesh or the existing indexed mesh - virtual struct IIndexedMesh* CreateIndexedMesh() = 0; - - //! Access to rendering geometry for indoor engine ( optimized vert arrays, lists of shader pointers ) - virtual struct IRenderMesh* GetRenderMesh() = 0; - - // Description: - // Sets and replaces the physical representation of the object. - // Arguments: - // pPhysGeom - A pointer to a phys_geometry class. - // nType - Pass 0 to set the physic geometry or pass 1 to set the obstruct geometry - // Summary: - // Set the physic representation - virtual void SetPhysGeom(phys_geometry* pPhysGeom, int nType = 0) = 0; - - virtual float GetAIVegetationRadius() const = 0; - virtual void SetAIVegetationRadius(float radius) = 0; - - // Description: - // Set default material for the geometry. - // Arguments: - // pMaterial - A valid pointer to the material. - virtual void SetMaterial(_smart_ptr pMaterial) = 0; - - // Description: - // Returns default material of the geometry. - // Arguments: - // nType - Pass 0 to get the physic geometry or pass 1 to get the obstruct geometry - // Return Value: - // A pointer to a phys_geometry class. - virtual _smart_ptr GetMaterial() = 0; - virtual const _smart_ptr GetMaterial() const = 0; - - // Return Value: - // A Vec3 object containing the bounding box. - // Summary: - // Get the minimal bounding box component - virtual Vec3 GetBoxMin() = 0; - - // Return Value: - // A Vec3 object containing the bounding box. - // Summary: - // Get the minimal bounding box component - virtual Vec3 GetBoxMax() = 0; - - // Arguments: - // Minimum bounding box component - // Summary: - // Set the minimum bounding box component - virtual void SetBBoxMax(const Vec3& vBBoxMax) = 0; - - // Summary: - // Get the object radius - // Return Value: - // A float containing the radius - virtual float GetRadius() = 0; - - // Description: - // Reloads one or more component of the object. The possible flags - // are FRO_SHADERS, FRO_TEXTURES and FRO_GEOMETRY. - // Arguments: - // nFlags - One or more flag which indicate which element of the object - // to reload - // Summary: - // Reloads the object - virtual void Refresh(int nFlags) = 0; - - // Description: - // Registers the object elements into the renderer. - // Arguments: - // rParams - Render parameters - // nLogLevel - Level of the LOD - // Summary: - // Renders the object - virtual void Render(const struct SRendParams& rParams, const SRenderingPassInfo& passInfo) = 0; - // Summary: // Get the bounding box // Arguments: @@ -324,13 +77,6 @@ struct IStatObj // Maxs - Position of the top right far corner of the bounding box virtual AABB GetAABB() = 0; - // Summary: - // Generate a random point in object. - // Arguments: - // eForm - Object aspect to generate on (surface, volume, etc) - virtual float GetExtent(EGeomForm eForm) = 0; - virtual void GetRandomPos(PosNorm& ran, EGeomForm eForm) const = 0; - // Description: // Returns the LOD object, if present. // Arguments: @@ -341,64 +87,6 @@ struct IStatObj // Summary: // Get the LOD object virtual IStatObj* GetLodObject(int nLodLevel, bool bReturnNearest = false) = 0; - virtual IStatObj* GetLowestLod() = 0; - virtual int FindNearesLoadedLOD(int nLodIn, bool bSearchUp = false) = 0; - virtual int FindHighestLOD(int nBias) = 0; - - virtual AZStd::string& GetFileName() = 0; - virtual const AZStd::string& GetFileName() const = 0; - - // Summary: - // Returns the filename of the object - // Return Value: - // A null terminated string which contain the filename of the object. - virtual const char* GetFilePath() const = 0; - - // Summary: - // Set the filename of the object - // Arguments: - // szFileName - New filename of the object - // Return Value: - // None - virtual void SetFilePath(const char* szFileName) = 0; - - // Description: - // Will return the position of the helper named in the argument. The - // helper should have been specified during the exporting process of - // the cgf file. - // Arguments: - // szHelperName - A null terminated string holding the name of the helper - // Return Value: - // A Vec3 object which contains the position. - // Summary: - // Gets the position of a specified helper - virtual Vec3 GetHelperPos(const char* szHelperName) = 0; - - // Summary: - // Gets the transformation matrix of a specified helper, see GetHelperPos - virtual const Matrix34& GetHelperTM(const char* szHelperName) = 0; - - //! Tell us if the object is not found - virtual bool IsDefaultObject() = 0; - - // Summary: - // Free the geometry data - virtual void FreeIndexedMesh() = 0; - - // Pushes the underlying tree of objects into the given Sizer object for statistics gathering - virtual void GetMemoryUsage(class ICrySizer* pSizer) const = 0; - - //DOC-IGNORE-BEGIN - //! used for sprites - virtual float& GetRadiusVert() = 0; - - //! used for sprites - virtual float& GetRadiusHors() = 0; - //DOC-IGNORE-END - - // Summary: - // Determines if the object has physics capabilities - virtual bool IsPhysicsExist() = 0; // Summary: // Returns a pointer to the object @@ -406,12 +94,6 @@ struct IStatObj // A pointer to the current object, which is simply done like this "return this;" virtual struct IStatObj* GetIStatObj() { return this; } - // Summary: - // Invalidates geometry inside IStatObj, will mark hosted IIndexedMesh as invalid. - // Arguments: - // bPhysics - if true will also recreate physics for indexed mesh. - virtual void Invalidate(bool bPhysics = false, float tolerance = 0.05f) = 0; - ////////////////////////////////////////////////////////////////////////// // Interface to the Sub Objects. ////////////////////////////////////////////////////////////////////////// @@ -419,174 +101,10 @@ struct IStatObj // Retrieve number of sub-objects. virtual int GetSubObjectCount() const = 0; // Summary: - // Sets number of sub-objects. - virtual void SetSubObjectCount(int nCount) = 0; - // Summary: // Retrieve sub object by index, where 0 <= nIndex < GetSubObjectCount() - virtual IStatObj::SSubObject* GetSubObject(int nIndex) = 0; - // Summary: - // Check if this object is sub object of another IStatObj. - virtual bool IsSubObject() const = 0; - // Summary: - // Retrieve parent static object, only relevant when this IStatObj is Sub-object. - virtual IStatObj* GetParentObject() const = 0; - // Summary: - // Retrieve the static object, from which this one was cloned (if that is the case) - virtual IStatObj* GetCloneSourceObject() const = 0; - // Summary: - // Find sub-pbject by name. - virtual IStatObj::SSubObject* FindSubObject(const char* sNodeName) = 0; - // Find sub-object by name (including spaces, comma and semi-colon. - virtual IStatObj::SSubObject* FindSubObject_CGA(const char* sNodeName) = 0; - - // Summary: - // Find object by full name (use all the characters) - virtual IStatObj::SSubObject* FindSubObject_StrStr(const char* sNodeName) = 0; - // Remove Sub-Object. - virtual bool RemoveSubObject(int nIndex) = 0; - // Copy Sub-Object. - virtual bool CopySubObject(int nToIndex, IStatObj* pFromObj, int nFromIndex) = 0; - // adds a new sub object - virtual IStatObj::SSubObject& AddSubObject(IStatObj* pStatObj) = 0; - - virtual bool IsDeformable() = 0; - - ////////////////////////////////////////////////////////////////////////// - // Save contents of static object to the CGF file. - ////////////////////////////////////////////////////////////////////////// - // Save object to the CGF file. - // Arguments: - // sFilename - // Filename of the CGF file. - // Note that the function fails if pOutChunkFile is NULL and the path - // to the file does not exist on the drive. You can call - // CFileUtil::CreatePath() before SaveToCGF() call to create all - // folders that do not exist yet. - // pOutChunkFile - // Optional output parameter. If it is specified then the file will not be written to - // the drive but instead the function returns a pointer to the IChunkFile interface with - // filled CGF chunks. Caller of the function is responsible to call Release method - // of IChunkFile to release it later. - virtual bool SaveToCGF(const char* sFilename, IChunkFile** pOutChunkFile = NULL, bool bHavePhysicalProxy = false) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Summary: - // Clones static geometry, Makes an exact copy of the Static object and the contained geometry. - //virtual IStatObj* Clone(bool bCloneChildren=true, bool nDynamic=false) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Summary: - // Clones static geometry, Makes an exact copy of the Static object and the contained geometry. - virtual IStatObj* Clone(bool bCloneGeometry, bool bCloneChildren, bool bMeshesOnly) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Summary: - // makes sure that both objects have one-to-one vertex correspondance - // sets MorphBuddy for this object's render mesh - // returns 0 if failed (due to objects having no vertex maps most likely) - virtual int SetDeformationMorphTarget(IStatObj* pDeformed) = 0; - - // chages the weights of the deformation morphing according to point, radius, and strength - // (radius==0 updates all weights of all vertices) - // if the object is a compound object, updates the weights of its subobjects that have deformation morphs; clones the object if necessary - // otherwise, updates the weights passed as a pWeights param - virtual IStatObj* DeformMorph(const Vec3& pt, float r, float strength, IRenderMesh* pWeights = 0) = 0; - - // hides all non-physicalized geometry, clones the object if necessary - virtual IStatObj* HideFoliage() = 0; - - // Get object properties as loaded from CGF. - virtual const char* GetProperties() = 0; - - // Get physical properties specified for object. - virtual bool GetPhysicalProperties(float& mass, float& density) = 0; - - // Returns the last B operand for this object as A, along with its relative scale - virtual IStatObj* GetLastBooleanOp(float& scale) = 0; + virtual SSubObject* GetSubObject(int nIndex) = 0; // Intersect ray with static object. // Ray must be in object local space. - virtual bool RayIntersection(SRayHitInfo& hitInfo, _smart_ptr pCustomMtl = 0) = 0; - - // Intersect lineseg with static object. Works on dedi server as well. - // Lineseg must be in object local space. Returns the hit position and the surface type id of the point hit. - virtual bool LineSegIntersection(const Lineseg& lineSeg, Vec3& hitPos, int& surfaceTypeId) = 0; - - // Debug Draw this static object. - virtual void DebugDraw(const struct SGeometryDebugDrawInfo& info, float fExtrdueScale = 0.01f) = 0; - - // Returns initial hide mask - virtual uint64 GetInitialHideMask() = 0; - - // Updates hide mask as new mask = (mask & maskAND) | maskOR - virtual uint64 UpdateInitialHideMask(uint64 maskAND = 0ul - 1ul, uint64 maskOR = 0) = 0; - - // Set the filename of the mesh of the next state (for example damaged version) - virtual void SetStreamingDependencyFilePath(const char* szFileName) = 0; - - virtual void ComputeGeometricMean(SMeshLodInfo& lodInfo) = 0; - - // Returns the distance for the first LOD switch. Used for brushes and vegetation. - virtual float GetLodDistance() const = 0; - - // Returns true if the mesh has been stripped - virtual bool IsMeshStrippedCGF() const = 0; - - virtual void LoadLowLODs(bool bUseStreaming, unsigned long nLoadingFlags) = 0; - - // Indicates if lods have been loaded - virtual bool AreLodsLoaded() const = 0; - - // Indicates if a garbage check should be done - virtual bool CheckGarbage() const = 0; - - // Sets state of check garbage flags - virtual void SetCheckGarbage(bool val) = 0; - - // Returns the number of child references - virtual int CountChildReferences() const = 0; - - // Returns the user count - virtual int GetUserCount() const = 0; - - // Shutdown - virtual void ShutDown() = 0; - - virtual int GetMaxUsableLod() const = 0; - virtual int GetMinUsableLod() const = 0; - - virtual SMeshBoneMapping_uint8* GetBoneMapping() const = 0; - - virtual int GetSpineCount() const = 0; - virtual SSpine* GetSpines() const = 0; - - virtual IStatObj* GetLodLevel0() = 0; - virtual void SetLodLevel0(IStatObj* lod) = 0; - virtual _smart_ptr* GetLods() = 0; - virtual int GetLoadedLodsNum() = 0; - - virtual bool UpdateStreamableComponents(float fImportance, const Matrix34A& objMatrix, bool bFullUpdate, int nNewLod) = 0; - - virtual SPhysGeomArray& GetArrPhysGeomInfo() = 0; - virtual bool IsLodsAreLoadedFromSeparateFile() = 0; - - virtual void StartStreaming(bool bFinishNow, IReadStream_AutoPtr* ppStream) = 0; - virtual void UpdateStreamingPrioriryInternal(const Matrix34A& objMatrix, float fDistance, bool bFullUpdate) = 0; - - virtual void SetMerged(bool state) = 0; - - virtual int GetRenderMeshMemoryUsage() const = 0; - virtual void SetLodObject(int nLod, IStatObj* pLod) = 0; - virtual int GetLoadedTrisCount() const = 0; - virtual int GetRenderTrisCount() const = 0; - virtual int GetRenderMatIds() const = 0; - - virtual bool IsUnmergable() const = 0; - virtual void SetUnmergable(bool state) = 0; - - virtual int GetSubObjectMeshCount() const = 0; - virtual void SetSubObjectMeshCount(int count) = 0; - virtual void CleanUnusedLods() = 0; - - virtual AZStd::vector& GetClothData() = 0; + virtual bool RayIntersection(SRayHitInfo& hitInfo, IMaterial* pCustomMtl = nullptr) = 0; }; diff --git a/Code/Legacy/CryCommon/ISurfaceType.h b/Code/Legacy/CryCommon/ISurfaceType.h deleted file mode 100644 index 10bddbbe6c..0000000000 --- a/Code/Legacy/CryCommon/ISurfaceType.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Defines interfaces to access Surface Types. - - -#ifndef CRYINCLUDE_CRYCOMMON_ISURFACETYPE_H -#define CRYINCLUDE_CRYCOMMON_ISURFACETYPE_H -#pragma once - -////////////////////////////////////////////////////////////////////////// -// Flags that ISurfaceType::GetFlags() can return. -////////////////////////////////////////////////////////////////////////// -enum ESurfaceTypeFlags -{ - SURFACE_TYPE_NO_PHYSICALIZE = BIT(1), // This surface should not be physicalized. - SURFACE_TYPE_NO_COLLIDE = BIT(2), // Should only be set for vegetation canopy mats - SURFACE_TYPE_VEHICLE_ONLY_COLLISION = BIT(3), - SURFACE_TYPE_CAN_SHATTER = BIT(4), // This surface type can shatter - SURFACE_TYPE_BULLET_PIERCEABLE = BIT(5), // This surface is pierceable by bullets (used by MFX system to spawn front/back FX) -}; - -// Parameter structure passed to ISurfaceType::Execute -struct SSurfaceTypeExecuteParams -{ - Vec3 hitPoint; - Vec3 hitNormal; - int hitType; -}; - -#define SURFACE_BREAKAGE_TYPE(x) x - -////////////////////////////////////////////////////////////////////////// -// Surface definition. -////////////////////////////////////////////////////////////////////////// -struct ISurfaceType -{ - ////////////////////////////////////////////////////////////////////////// - struct SSurfaceTypeAIParams - { - float fImpactRadius; - float fImpactSoundRadius; - float fFootStepRadius; - float proneMult; - float crouchMult; - float movingMult; - - SSurfaceTypeAIParams() - { - fImpactRadius = 2.5f; - fImpactSoundRadius = 20.0f; - fFootStepRadius = 20.0f; - proneMult = 0.2f; - crouchMult = 0.5f; - movingMult = 2.5f; - } - }; - struct SPhysicalParams - { - int breakable_id; - int break_energy; - float hole_size; - float hole_size_explosion; - float hit_radius; - float hit_points; - float hit_points_secondary; - float hit_maxdmg; - float hit_lifetime; - int pierceability; - float damage_reduction; - float ric_angle; - float ric_dam_reduction; - float ric_vel_reduction; - float friction; - float bouncyness; - int iBreakability; - int collType; - float sound_obstruction; - }; - struct SBreakable2DParams - { - AZStd::string particle_effect; - float blast_radius; - float blast_radius_first; - float vert_size_spread; - int rigid_body; - float life_time; - float cell_size; - int max_patch_tris; - float filter_angle; - float shard_density; - int use_edge_alpha; - float crack_decal_scale; - AZStd::string crack_decal_mtl; - float max_fracture; - AZStd::string full_fracture_fx; - AZStd::string fracture_fx; - int no_procedural_full_fracture; - AZStd::string broken_mtl; - float destroy_timeout; - float destroy_timeout_spread; - - SBreakable2DParams() - : blast_radius(0) - , rigid_body(0) - , life_time(0) - , cell_size(0) - , max_patch_tris(0) - , shard_density(0) - , crack_decal_scale(0) - , max_fracture(1.0f) - , vert_size_spread(0) - , filter_angle(0) - , use_edge_alpha(0) - , blast_radius_first(0) - , no_procedural_full_fracture(0) - , destroy_timeout(0) - , destroy_timeout_spread(0) {} - }; - struct SBreakageParticles - { - AZStd::string type; - AZStd::string particle_effect; - int count_per_unit; - float count_scale; - float scale; - SBreakageParticles() - : count_per_unit(1) - , count_scale(1) - , scale(1) {} - }; - - // - virtual ~ISurfaceType(){} - - // Releases surface type. - virtual void Release() = 0; - - // Return unique Id of this surface type. - // Maximum of 65535 simultanious surface types can exist. - virtual uint16 GetId() const = 0; - - // Unique name of the surface type. - virtual const char* GetName() const = 0; - - // Typename of this surface type. - virtual const char* GetType() const = 0; - - // Flags of the surface type. - // Return: - // A combination of ESurfaceTypeFlags flags. - virtual int GetFlags() const = 0; - - // Execute material. - virtual void Execute(SSurfaceTypeExecuteParams& params) = 0; - - // returns a some cached properties for faster access - virtual int GetBreakability() const = 0; - virtual float GetBreakEnergy() const = 0; - virtual int GetHitpoints() const = 0; - - ////////////////////////////////////////////////////////////////////////// - virtual const SPhysicalParams& GetPhyscalParams() = 0; - - // Optional AI Params. - virtual const SSurfaceTypeAIParams* GetAIParams() = 0; - - // Optional params for 2D breakable plane. - virtual SBreakable2DParams* GetBreakable2DParams() = 0; - virtual SBreakageParticles* GetBreakageParticles(const char* sType, bool bLookInDefault = true) = 0; - - ////////////////////////////////////////////////////////////////////////// - // Called by Surface manager. - ////////////////////////////////////////////////////////////////////////// - // Loads surface, (do not use directly). - virtual bool Load(int nId) = 0; - // -}; - -////////////////////////////////////////////////////////////////////////// -// Description: -// This interface is used to enumerate all items registered to the surface type manager. -////////////////////////////////////////////////////////////////////////// -struct ISurfaceTypeEnumerator -{ - // - virtual ~ISurfaceTypeEnumerator(){} - virtual void Release() = 0; - virtual ISurfaceType* GetFirst() = 0; - virtual ISurfaceType* GetNext() = 0; - // -}; - -// Description: -// Manages loading and mapping of physical surface materials to Ids and materials scripts. -// Behaviour: -// At start will enumerate all material names. -// When the surface is first time requested by name it will be loaded and cached -// and new unique id will be generated for it. -struct ISurfaceTypeManager -{ - // - virtual ~ISurfaceTypeManager(){} - - - // Description: - // Load Surface types - virtual void LoadSurfaceTypes() = 0; - - // Description: - // Return surface type by name. - // If surface is not yet loaded it will be loaded and and cached. - // Arguments: - // sName - Name of the surface type ("mat_metal","mat_wood", etc..) - // warn - print warning message if surface not found - virtual ISurfaceType* GetSurfaceTypeByName(const char* sName, const char* sWhy = NULL, bool warn = true) = 0; - - // Description: - // Return surface type by id. - // If surface is not yet loaded it will be loaded and and cached. - // Arguments: - // sName - Name of the surface type ("mat_metal","mat_wood", etc..) - virtual ISurfaceType* GetSurfaceType(int nSurfaceId, const char* sWhy = NULL) = 0; - - // Description: - // Retrieve an interface to the enumerator class that allow to iterate over all surface types. - virtual ISurfaceTypeEnumerator* GetEnumerator() = 0; - - // Register a new surface type. - virtual bool RegisterSurfaceType(ISurfaceType* pSurfaceType, bool bDefault = false) = 0; - virtual void UnregisterSurfaceType(ISurfaceType* pSurfaceType) = 0; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - // -}; - -#endif // CRYINCLUDE_CRYCOMMON_ISURFACETYPE_H - diff --git a/Code/Legacy/CryCommon/ISystem.h b/Code/Legacy/CryCommon/ISystem.h index 722e73c774..948977d02a 100644 --- a/Code/Legacy/CryCommon/ISystem.h +++ b/Code/Legacy/CryCommon/ISystem.h @@ -6,8 +6,6 @@ * */ -#ifndef CRYINCLUDE_CRYCOMMON_ISYSTEM_H -#define CRYINCLUDE_CRYCOMMON_ISYSTEM_H #pragma once #ifdef CRYSYSTEM_EXPORTS @@ -15,10 +13,10 @@ #else #define CRYSYSTEM_API DLL_IMPORT #endif +#include #include "CryAssert.h" - -#include +#include #if defined(AZ_RESTRICTED_PLATFORM) #undef AZ_RESTRICTED_SECTION @@ -33,7 +31,6 @@ // Forward declarations //////////////////////////////////////////////////////////////////////////////////////////////// #include // <> required for Interfuscator -#include "IValidator.h" // <> required for Interfuscator #include // <> required for Interfuscator #include "CryVersion.h" #include "smartptr.h" @@ -61,9 +58,7 @@ struct SFileVersion; struct INameTable; struct ILevelSystem; struct IViewSystem; -class ICrySizer; class IXMLBinarySerializer; -struct IReadWriteXMLSink; struct IAVI_Reader; class CPNoise3; struct ILocalizationManager; @@ -84,9 +79,11 @@ class CCamera; struct CLoadingTimeProfiler; class ICmdLine; - class ILyShine; +enum EValidatorModule : int; +enum EValidatorSeverity : int; + enum ESystemUpdateFlags { // Summary: @@ -435,9 +432,6 @@ struct ISystemUserCallback // Show message by provider. virtual int ShowMessage(const char* text, const char* caption, unsigned int uType) { return CryMessageBox(text, caption, uType); } - // Description: - // Collects the memory information in the user program/application. - virtual void GetMemoryUsage(ICrySizer* pSizer) = 0; // // Post console load, for cvar setting @@ -1313,9 +1307,8 @@ namespace Detail const char* GetHelp() { return NULL; } bool IsConstCVar() const { return true; } void SetOnChangeCallback(ConsoleVarFunc pChangeFunc) { (void)pChangeFunc; } - uint64 AddOnChangeFunctor(const SFunctor& pChangeFunctor) { (void)pChangeFunctor; return 0; } + uint64 AddOnChangeFunctor(const AZStd::function& pChangeFunctor) { (void)pChangeFunctor; return 0; } ConsoleVarFunc GetOnChangeCallback() const { InvalidAccess(); return NULL; } - void GetMemoryUsage([[maybe_unused]] class ICrySizer* pSizer) const {} int GetRealIVal() const { return GetIVal(); } void SetLimits([[maybe_unused]] float min, [[maybe_unused]] float max) { return; } void GetLimits([[maybe_unused]] float& min, [[maybe_unused]] float& max) { return; } @@ -1411,18 +1404,9 @@ static void AssertConsoleExists(void) // Preferred way to register an int CVar with a callback #define REGISTER_INT_CB(_name, _def_val, _flags, _comment, _onchangefunction) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->RegisterInt(_name, (_def_val), (_flags), CVARHELP(_comment), _onchangefunction)) // Summary: -// Preferred way to register an int64 CVar -#define REGISTER_INT64(_name, _def_val, _flags, _comment) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->RegisterInt64(_name, (_def_val), (_flags), CVARHELP(_comment))) -// Summary: -// Preferred way to register an int64 CVar with a callback -#define REGISTER_INT64_CB(_name, _def_val, _flags, _comment, _onchangefunction) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->RegisterInt64(_name, (_def_val), (_flags), CVARHELP(_comment), _onchangefunction)) -// Summary: // Preferred way to register a float CVar #define REGISTER_FLOAT(_name, _def_val, _flags, _comment) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->RegisterFloat(_name, (_def_val), (_flags), CVARHELP(_comment))) // Summary: -// Preferred way to register a float CVar with a callback -#define REGISTER_FLOAT_CB(_name, _def_val, _flags, _comment, _onchangefunction) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->RegisterFloat(_name, (_def_val), (_flags), CVARHELP(_comment), _onchangefunction)) -// Summary: // Offers more flexibility but more code is required #define REGISTER_CVAR2(_name, _var, _def_val, _flags, _comment) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->Register(_name, _var, (_def_val), (_flags), CVARHELP(_comment))) // Summary: @@ -1432,9 +1416,6 @@ static void AssertConsoleExists(void) // Offers more flexibility but more code is required, explicit address taking of destination variable #define REGISTER_CVAR3(_name, _var, _def_val, _flags, _comment) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->Register(_name, &(_var), (_def_val), (_flags), CVARHELP(_comment))) // Summary: -// Offers more flexibility but more code is required, explicit address taking of destination variable -#define REGISTER_CVAR3_CB(_name, _var, _def_val, _flags, _comment, _onchangefunction) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? 0 : gEnv->pConsole->Register(_name, &(_var), (_def_val), (_flags), CVARHELP(_comment), _onchangefunction)) -// Summary: // Preferred way to register a console command #define REGISTER_COMMAND(_name, _func, _flags, _comment) (ASSERT_CONSOLE_EXISTS, gEnv->pConsole == 0 ? false : gEnv->pConsole->AddCommand(_name, _func, (_flags), CVARHELP(_comment))) // Summary: @@ -1465,12 +1446,10 @@ static void AssertConsoleExists(void) #define REGISTER_STRING_CB_DEV_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) /* consumed; pure cvar not available */ #define REGISTER_INT_DEV_ONLY(_name, _def_val, _flags, _comment) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) /* consumed; pure cvar not available */ #define REGISTER_INT_CB_DEV_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) /* consumed; pure cvar not available */ -#define REGISTER_INT64_DEV_ONLY(_name, _def_val, _flags, _comment) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) /* consumed; pure cvar not available */ #define REGISTER_FLOAT_DEV_ONLY(_name, _def_val, _flags, _comment) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) /* consumed; pure cvar not available */ #define REGISTER_CVAR2_DEV_ONLY(_name, _var, _def_val, _flags, _comment) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0); *(_var) = _def_val #define REGISTER_CVAR2_CB_DEV_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0); *(_var) = _def_val #define REGISTER_CVAR3_DEV_ONLY(_name, _var, _def_val, _flags, _comment) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0); _var = _def_val -#define REGISTER_CVAR3_CB_DEV_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) NULL; static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0); _var = _def_val #define REGISTER_COMMAND_DEV_ONLY(_name, _func, _flags, _comment) /* consumed; command not available */ #else #define REGISTER_CVAR_DEV_ONLY(_var, _def_val, _flags, _comment) REGISTER_CVAR(_var, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) @@ -1479,12 +1458,10 @@ static void AssertConsoleExists(void) #define REGISTER_STRING_CB_DEV_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_STRING_CB(_name, _def_val, ((_flags) | VF_DEV_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_INT_DEV_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT(_name, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_INT_CB_DEV_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_INT_CB(_name, _def_val, ((_flags) | VF_DEV_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) -#define REGISTER_INT64_DEV_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT64(_name, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_FLOAT_DEV_ONLY(_name, _def_val, _flags, _comment) REGISTER_FLOAT(_name, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_CVAR2_DEV_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR2(_name, _var, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_CVAR2_CB_DEV_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR2_CB(_name, _var, _def_val, ((_flags) | VF_DEV_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_CVAR3_DEV_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR3(_name, _var, _def_val, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) -#define REGISTER_CVAR3_CB_DEV_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR3_CB(_name, _var, _def_val, ((_flags) | VF_DEV_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_COMMAND_DEV_ONLY(_name, _func, _flags, _comment) REGISTER_COMMAND(_name, _func, ((_flags) | VF_DEV_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #endif // defined(_RELEASE) // @@ -1508,12 +1485,9 @@ static void AssertConsoleExists(void) #define REGISTER_STRING_CB_DEDI_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_STRING_CB(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_INT_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_INT_CB_DEDI_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_INT_CB(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) -#define REGISTER_INT64_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT64(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_FLOAT_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_FLOAT(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_CVAR2_DEDI_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR2(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_CVAR2_CB_DEDI_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR2_CB(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) -#define REGISTER_CVAR3_DEDI_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR3(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) -#define REGISTER_CVAR3_CB_DEDI_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR3_CB(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #define REGISTER_COMMAND_DEDI_ONLY(_name, _func, _flags, _comment) REGISTER_COMMAND(_name, _func, ((_flags) | VF_DEDI_ONLY), _comment); static_assert(((_flags) & ILLEGAL_DEV_FLAGS) == 0) #else #define REGISTER_CVAR_DEDI_ONLY(_var, _def_val, _flags, _comment) REGISTER_CVAR_DEV_ONLY(_var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) @@ -1522,12 +1496,9 @@ static void AssertConsoleExists(void) #define REGISTER_STRING_CB_DEDI_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_STRING_CB_DEV_ONLY(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction) #define REGISTER_INT_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT_DEV_ONLY(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) #define REGISTER_INT_CB_DEDI_ONLY(_name, _def_val, _flags, _comment, _onchangefunction) REGISTER_INT_CB_DEV_ONLY(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction) -#define REGISTER_INT64_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_INT64_DEV_ONLY(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) #define REGISTER_FLOAT_DEDI_ONLY(_name, _def_val, _flags, _comment) REGISTER_FLOAT_DEV_ONLY(_name, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) #define REGISTER_CVAR2_DEDI_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR2_DEV_ONLY(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) #define REGISTER_CVAR2_CB_DEDI_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR2_CB_DEV_ONLY(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction) -#define REGISTER_CVAR3_DEDI_ONLY(_name, _var, _def_val, _flags, _comment) REGISTER_CVAR3_DEV_ONLY(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment) -#define REGISTER_CVAR3_CB_DEDI_ONLY(_name, _var, _def_val, _flags, _comment, _onchangefunction) REGISTER_CVAR3_CB_DEV_ONLY(_name, _var, _def_val, ((_flags) | VF_DEDI_ONLY), _comment, _onchangefunction) #define REGISTER_COMMAND_DEDI_ONLY(_name, _func, _flags, _comment) REGISTER_COMMAND_DEV_ONLY(_name, _func, ((_flags) | VF_DEDI_ONLY), _comment) #endif // defined(_RELEASE) // @@ -1592,4 +1563,3 @@ inline void CryLogAlways(const char* format, ...) } #endif // EXCLUDE_NORMAL_LOG -#endif // CRYINCLUDE_CRYCOMMON_ISYSTEM_H diff --git a/Code/Legacy/CryCommon/ITexture.h b/Code/Legacy/CryCommon/ITexture.h index b370005f83..2655810fb0 100644 --- a/Code/Legacy/CryCommon/ITexture.h +++ b/Code/Legacy/CryCommon/ITexture.h @@ -13,7 +13,6 @@ enum ETEX_Format : AZ::u8 { eTF_Unknown = 0, - eTF_R8G8B8A8S, eTF_R8G8B8A8 = 2, // may be saved into file eTF_A8 = 4, @@ -25,76 +24,6 @@ enum ETEX_Format : AZ::u8 eTF_R8G8, eTF_R8G8S, eTF_R16G16, - eTF_R16G16S, - eTF_R16G16F, - eTF_R11G11B10F, - eTF_R10G10B10A2, - eTF_R16G16B16A16, - eTF_R16G16B16A16S, - eTF_R16G16B16A16F, - eTF_R32G32B32A32F, - - eTF_CTX1, - eTF_BC1 = 22, // may be saved into file - eTF_BC2 = 23, // may be saved into file - eTF_BC3 = 24, // may be saved into file - eTF_BC4U, // 3Dc+ - eTF_BC4S, - eTF_BC5U, // 3Dc - eTF_BC5S, - eTF_BC6UH, - eTF_BC6SH, - eTF_BC7, - eTF_R9G9B9E5, - - // hardware depth buffers - eTF_D16, - eTF_D24S8, - eTF_D32F, - eTF_D32FS8, - - // only available as hardware format under DX11.1 with DXGI 1.2 - eTF_B5G6R5, - eTF_B5G5R5, - eTF_B4G4R4A4, - - // only available as hardware format under OpenGL - eTF_EAC_R11, - eTF_EAC_RG11, - eTF_ETC2, - eTF_ETC2A, - - // only available as hardware format under DX9 - eTF_A8L8, - eTF_L8, - eTF_L8V8U8, - eTF_B8G8R8, - eTF_L8V8U8X8, - eTF_B8G8R8X8, - eTF_B8G8R8A8, - - eTF_PVRTC2, - eTF_PVRTC4, - - eTF_ASTC_4x4, - eTF_ASTC_5x4, - eTF_ASTC_5x5, - eTF_ASTC_6x5, - eTF_ASTC_6x6, - eTF_ASTC_8x5, - eTF_ASTC_8x6, - eTF_ASTC_8x8, - eTF_ASTC_10x5, - eTF_ASTC_10x6, - eTF_ASTC_10x8, - eTF_ASTC_10x10, - eTF_ASTC_12x10, - eTF_ASTC_12x12, - - // add R16 unsigned int format for hardware that do not support float point rendering - eTF_R16U, - eTF_R16G16U, - eTF_R10G10B10A2UI, eTF_MaxFormat // unused, must be always the last in the list }; diff --git a/Code/Legacy/CryCommon/IValidator.h b/Code/Legacy/CryCommon/IValidator.h index 8e6b6eaa5c..724e564154 100644 --- a/Code/Legacy/CryCommon/IValidator.h +++ b/Code/Legacy/CryCommon/IValidator.h @@ -9,21 +9,15 @@ // Description : IValidator interface used to check objects for warnings and errors // Report missing resources or invalid files. - - -#ifndef CRYINCLUDE_CRYCOMMON_IVALIDATOR_H -#define CRYINCLUDE_CRYCOMMON_IVALIDATOR_H #pragma once # define MAX_WARNING_LENGTH 4096 -#if MAX_WARNING_LENGTH < 33 -#error "MAX_WARNING_LENGTH should be bigger than 32" -#endif +static_assert(MAX_WARNING_LENGTH>32,"MAX_WARNING_LENGTH should be bigger than 32"); #define ERROR_CANT_FIND_CENTRAL_DIRECTORY "Cannot find Central Directory Record in pak. This is either not a pak file, or a pak file without Central Directory. It does not mean that the data is permanently lost, but it may be severely damaged. Please repair the file with external tools, there may be enough information left to recover the file completely." -enum EValidatorSeverity +enum EValidatorSeverity : int { VALIDATOR_ERROR, VALIDATOR_ERROR_DBGBRK, // will __debugbreak() if sys_error_debugbreak is 1 @@ -31,7 +25,7 @@ enum EValidatorSeverity VALIDATOR_COMMENT }; -enum EValidatorModule +enum EValidatorModule : int { VALIDATOR_MODULE_UNKNOWN, VALIDATOR_MODULE_RENDERER, @@ -61,45 +55,3 @@ enum EValidatorFlags VALIDATOR_FLAG_IGNORE_IN_EDITOR = 0x0040, // Do not log this with the editor VALIDATOR_FLAG_SKIP_VALIDATOR = 0x0080, // Do not call validator's Report() }; - -struct SValidatorRecord -{ - //! Severity of this error. - EValidatorSeverity severity; - //! In which module error occured. - EValidatorModule module; - //! Error Text. - const char* text; - //! File which is missing or causing problem. - const char* file; - //! Additional description for this error. - const char* description; - //! Asset scope sring - const char* assetScope; - //! Flags that suggest kind of error. - int flags; - - ////////////////////////////////////////////////////////////////////////// - SValidatorRecord() - { - module = VALIDATOR_MODULE_UNKNOWN; - text = NULL; - file = NULL; - assetScope = NULL; - description = NULL; - severity = VALIDATOR_WARNING; - flags = 0; - } -}; - -/*! This interface will be given to Validate methods of engine, for resources and objects validation. - */ -struct IValidator -{ - // - virtual ~IValidator(){} - virtual void Report(SValidatorRecord& record) = 0; - // -}; - -#endif // CRYINCLUDE_CRYCOMMON_IVALIDATOR_H diff --git a/Code/Legacy/CryCommon/IXml.h b/Code/Legacy/CryCommon/IXml.h index 2434b44664..be2bdcd5ab 100644 --- a/Code/Legacy/CryCommon/IXml.h +++ b/Code/Legacy/CryCommon/IXml.h @@ -5,18 +5,12 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - - -#ifndef CRYINCLUDE_CRYCOMMON_IXML_H -#define CRYINCLUDE_CRYCOMMON_IXML_H #pragma once #include #include #include -class ICrySizer; - template struct Color_tpl; typedef Color_tpl ColorB; @@ -24,17 +18,12 @@ typedef Color_tpl ColorB; template struct Vec2_tpl; typedef Vec2_tpl Vec2; -typedef Vec2_tpl Vec2d; template struct Vec3_tpl; typedef Vec3_tpl Vec3; -typedef Vec3_tpl Vec3d; -template -struct Vec4_tpl; -typedef Vec4_tpl Vec4; -typedef Vec4_tpl Vec4d; +struct Vec4; template struct Quat_tpl; @@ -59,7 +48,6 @@ class QColor; class QString; class IXMLBinarySerializer; -struct IReadWriteXMLSink; struct ISerialize; /* @@ -329,11 +317,9 @@ public: virtual void setAttr(const char* key, float value) = 0; virtual void setAttr(const char* key, double value) = 0; virtual void setAttr(const char* key, const Vec2& value) = 0; - virtual void setAttr(const char* key, const Vec2d& value) = 0; virtual void setAttr(const char* key, const Ang3& value) = 0; virtual void setAttr(const char* key, const Vec3& value) = 0; virtual void setAttr(const char* key, const Vec4& value) = 0; - virtual void setAttr(const char* key, const Vec3d& value) = 0; virtual void setAttr(const char* key, const Quat& value) = 0; #if defined(LINUX64) || defined(APPLE) // Compatibility functions, on Linux and Mac long int is the default int64_t @@ -378,11 +364,9 @@ public: virtual bool getAttr(const char* key, float& value) const = 0; virtual bool getAttr(const char* key, double& value) const = 0; virtual bool getAttr(const char* key, Vec2& value) const = 0; - virtual bool getAttr(const char* key, Vec2d& value) const = 0; virtual bool getAttr(const char* key, Ang3& value) const = 0; virtual bool getAttr(const char* key, Vec3& value) const = 0; virtual bool getAttr(const char* key, Vec4& value) const = 0; - virtual bool getAttr(const char* key, Vec3d& value) const = 0; virtual bool getAttr(const char* key, Quat& value) const = 0; virtual bool getAttr(const char* key, bool& value) const = 0; virtual bool getAttr(const char* key, XmlString& value) const = 0; @@ -401,13 +385,6 @@ public: } #endif - // - - // - // Summary: - // Collect all allocated memory - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - // Summary: // Copies children to this node from a given node. // Children are reference copied (shallow copy) and the children's parent is NOT set to this @@ -700,7 +677,7 @@ public: XmlNodeRefIterator& operator=(const XmlNodeRefIterator& other) = default; - XmlNodeRefIterator& operator++() + XmlNodeRefIterator& operator++() { ++m_index; Update(); @@ -714,7 +691,7 @@ public: return ret; } - IXmlNode* operator*() const + IXmlNode* operator*() const { return m_currentChildNode; } @@ -794,7 +771,6 @@ struct IXmlSerializer virtual ISerialize* GetWriter(XmlNodeRef& node) = 0; virtual ISerialize* GetReader(XmlNodeRef& node) = 0; // - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; }; ////////////////////////////////////////////////////////////////////////// @@ -802,7 +778,6 @@ struct IXmlSerializer // XML Parser interface. struct IXmlParser { - // virtual ~IXmlParser(){} virtual void AddRef() = 0; virtual void Release() = 0; @@ -814,9 +789,6 @@ struct IXmlParser // Summary: // Parses xml from memory buffer. virtual XmlNodeRef ParseBuffer(const char* buffer, int nBufLen, bool bCleanPools, bool bSuppressWarnings = false) = 0; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - // }; ////////////////////////////////////////////////////////////////////////// @@ -863,7 +835,6 @@ struct IXmlTableReader // to know absolute cell index (i.e. column). // Returns false if no cells left in the row. virtual bool ReadCell(int& columnIndex, const char*& pContent, size_t& contentSize) = 0; - virtual float GetCurrentRowHeight() = 0; // }; @@ -877,28 +848,17 @@ struct IXmlUtils // Summary: // Loads xml file, returns 0 if load failed. - virtual XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false, bool bEnablePatching = true) = 0; + virtual XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false) = 0; // Summary: // Loads xml from memory buffer, returns 0 if load failed. virtual XmlNodeRef LoadXmlFromBuffer(const char* buffer, size_t size, bool bReuseStrings = false, bool bSuppressWarnings = false) = 0; - // Summary: - // Creates an MD5 hash of an XML file - virtual const char* HashXml(XmlNodeRef node) = 0; - - // Summary: - // Gets an object that can read a xml into a IReadXMLSink - // and writes a xml from a IWriteXMLSource - virtual IReadWriteXMLSink* GetIReadWriteXMLSink() = 0; - // Summary: // Creates XML Writer for ISerialize interface. // See also: // IXmlSerializer virtual IXmlSerializer* CreateXmlSerializer() = 0; - // - // // Summary: // Creates XML Parser. // Notes: @@ -908,40 +868,9 @@ struct IXmlUtils // After use it must be released with call to Release method. virtual IXmlParser* CreateXmlParser() = 0; - // Summary: - // Creates XML to file in the binary form. - virtual bool SaveBinaryXmlFile(const char* sFilename, XmlNodeRef root) = 0; - // Summary: - // Reads XML data from file in the binary form. - virtual XmlNodeRef LoadBinaryXmlFile(const char* sFilename, bool bEnablePatching = true) = 0; - - // Summary: - // Enables or disables checking for binary xml files. - // Return Value: - // The previous status. - virtual bool EnableBinaryXmlLoading(bool bEnable) = 0; - // Summary: // Creates XML Table reader. // Notes: // After use it must be released with call to Release method. virtual IXmlTableReader* CreateXmlTableReader() = 0; - - // Init xml stats nodes pool - virtual void InitStatsXmlNodePool(uint32 nPoolSize) = 0; - - // Creates new xml node for statistics. - virtual XmlNodeRef CreateStatsXmlNode(const char* sNodeName) = 0; - // Set owner thread - virtual void SetStatsOwnerThread(threadID threadId) = 0; - - // Free memory held on to by xml pool if empty - virtual void FlushStatsXmlNodePool() = 0; - - // Sets the patch which is used to transform loaded XML files. the patch itself is encoded into XML - // Set to NULL to clear an existing transform and disable further patching - virtual void SetXMLPatcher(XmlNodeRef* pPatcher) = 0; - // }; - -#endif // CRYINCLUDE_CRYCOMMON_IXML_H diff --git a/Code/Legacy/CryCommon/Linux_Win32Wrapper.h b/Code/Legacy/CryCommon/Linux_Win32Wrapper.h index ffdf3fe998..7157bc4a78 100644 --- a/Code/Legacy/CryCommon/Linux_Win32Wrapper.h +++ b/Code/Legacy/CryCommon/Linux_Win32Wrapper.h @@ -429,7 +429,6 @@ extern DWORD GetCurrentProcessId(void); //helper function extern void adaptFilenameToLinux(char* rAdjustedFilename); -extern const int comparePathNames(const char* cpFirst, const char* cpSecond, unsigned int len);//returns 0 if identical extern void replaceDoublePathFilename(char* szFileName);//removes "\.\" to "\" and "/./" to "/" ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Legacy/CryCommon/LocalizationManagerBus.h b/Code/Legacy/CryCommon/LocalizationManagerBus.h index 1d818de111..fadda76e3f 100644 --- a/Code/Legacy/CryCommon/LocalizationManagerBus.h +++ b/Code/Legacy/CryCommon/LocalizationManagerBus.h @@ -8,7 +8,6 @@ #pragma once -#include #include #include #include diff --git a/Code/Legacy/CryCommon/LyShine/Bus/UiTransform2dBus.h b/Code/Legacy/CryCommon/LyShine/Bus/UiTransform2dBus.h index fb30a78aac..4a242d9d25 100644 --- a/Code/Legacy/CryCommon/LyShine/Bus/UiTransform2dBus.h +++ b/Code/Legacy/CryCommon/LyShine/Bus/UiTransform2dBus.h @@ -42,10 +42,10 @@ public: // types void UnitClamp() { - m_left = FClamp(m_left, 0.0f, 1.0f); - m_top = FClamp(m_top, 0.0f, 1.0f); - m_right = FClamp(m_right, 0.0f, 1.0f); - m_bottom = FClamp(m_bottom, 0.0f, 1.0f); + m_left = AZStd::clamp(m_left, 0.0f, 1.0f); + m_top = AZStd::clamp(m_top, 0.0f, 1.0f); + m_right = AZStd::clamp(m_right, 0.0f, 1.0f); + m_bottom = AZStd::clamp(m_bottom, 0.0f, 1.0f); } bool operator==(const Anchors& rhs) const diff --git a/Code/Legacy/CryCommon/MTPseudoRandom.cpp b/Code/Legacy/CryCommon/MTPseudoRandom.cpp deleted file mode 100644 index f8a3950ff0..0000000000 --- a/Code/Legacy/CryCommon/MTPseudoRandom.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : Marsenne Twister PRNG. See MT.h for more info. - -#include "MTPseudoRandom.h" -// non-inline function definitions and static member definitions cannot -// reside in header file because of the risk of multiple declarations - -void CMTRand_int32::gen_state() // generate new m_nState vector -{ - for (int i = 0; i < (n - m); ++i) - { - m_nState[i] = m_nState[i + m] ^ twiddle(m_nState[i], m_nState[i + 1]); - } - for (int i = n - m; i < (n - 1); ++i) - { - m_nState[i] = m_nState[i + m - n] ^ twiddle(m_nState[i], m_nState[i + 1]); - } - m_nState[n - 1] = m_nState[m - 1] ^ twiddle(m_nState[n - 1], m_nState[0]); - p = 0; // reset position -} - -void CMTRand_int32::seed(uint32 s) // init by 32 bit seed -{ //if (s == 0) - //m_nRandom = 1; - for (int i = 0; i < n; ++i) - { - m_nState[i] = 0x0UL; - } - m_nState[0] = s; - for (int i = 1; i < n; ++i) - { - m_nState[i] = 1812433253UL * (m_nState[i - 1] ^ (m_nState[i - 1] >> 30)) + i; - // see Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier - // in the previous versions, MSBs of the seed affect only MSBs of the array m_nState - // 2002/01/09 modified by Makoto Matsumoto - } - p = n; // force gen_state() to be called for next random number -} - -void CMTRand_int32::seed(const uint32* array, int size) // init by array -{ - seed(19650218UL); - int i = 1, j = 0; - for (int k = ((n > size) ? n : size); k; --k) - { - m_nState[i] = (m_nState[i] ^ ((m_nState[i - 1] ^ (m_nState[i - 1] >> 30)) * 1664525UL)) - + array[j] + j; // non linear - ++j; - j %= size; - if ((++i) == n) - { - m_nState[0] = m_nState[n - 1]; - i = 1; - } - } - for (int k = n - 1; k; --k) - { - m_nState[i] = (m_nState[i] ^ ((m_nState[i - 1] ^ (m_nState[i - 1] >> 30)) * 1566083941UL)) - i; - if ((++i) == n) - { - m_nState[0] = m_nState[n - 1]; - i = 1; - } - } - m_nState[0] = 0x80000000UL; // MSB is 1; assuring non-zero initial array - p = n; // force gen_state() to be called for next random number -} diff --git a/Code/Legacy/CryCommon/MTPseudoRandom.h b/Code/Legacy/CryCommon/MTPseudoRandom.h deleted file mode 100644 index c1ed7694a5..0000000000 --- a/Code/Legacy/CryCommon/MTPseudoRandom.h +++ /dev/null @@ -1,166 +0,0 @@ -// mtrand.h -// C++ include file for MT19937, with initialization improved 2002/1/26. -// Coded by Takuji Nishimura and Makoto Matsumoto. -// Ported to C++ by Jasper Bedaux 2003/1/1 (see http://www.bedaux.net/mtrand/). -// The generators returning floating point numbers are based on -// a version by Isaku Wada, 2002/01/09 -// Static shared data converted to per-instance, 2008-11-13 by JSP. -// -// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The names of its contributors may not be used to endorse or promote -// products derived from this software without specific prior written -// permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Any feedback is very welcome. -// http://www.math.keio.ac.jp/matumoto/emt.html -// email: matumoto@math.keio.ac.jp -// -// Feedback about the C++ port should be sent to Jasper Bedaux, -// see http://www.bedaux.net/mtrand/ for e-mail address and info. - -//------------------------------------------------------------------------- -// History: -// - 28:7:2005: File created and minor changes by Marco Corbetta -// -//*************************************************************************/ -// Modified from original - -#ifndef CRYINCLUDE_CRYCOMMON_MTPSEUDORANDOM_H -#define CRYINCLUDE_CRYCOMMON_MTPSEUDORANDOM_H -#pragma once - -#include - -////////////////////////////////////////////////////////////////////////// -class CMTRand_int32 -{ - // Mersenne Twister random number generator - -public: - // default constructor - CMTRand_int32() { seed(5489UL); } - // constructor with 32 bit int as seed - CMTRand_int32(uint32 seed_value) { seed(seed_value); } - // constructor with array of 32 bit integers as seed - CMTRand_int32(const uint32* array, int size) { seed(array, size); } - // seeds with 32 bit integer - void seed(uint32 seed_value); - // seeds with array - void seed(const uint32*, int size); - // overloaded operator() to make this a generator (functor) - //uint32 operator()() { return rand_int32(); } - - ~CMTRand_int32() {} - - // Functions with PascalCase names were added for - // interchangeability with CRndGen (see LCGRandom.h). - - void Seed(uint32 seed_value) - { - seed(seed_value); - } - - uint32 GenerateUint32() - { - return rand_int32(); - } - - uint64 GenerateUint64() - { - const uint32 a = GenerateUint32(); - const uint32 b = GenerateUint32(); - return ((uint64)b << 32) | (uint64)a; - } - - float GenerateFloat() - { - return (float)GenerateUint32() * (1.0f / 4294967295.0f); - } - - // Ranged function returns random value within the *inclusive* range - // between minValue and maxValue. - // Any orderings work correctly: minValue <= maxValue and - // minValue >= minValue. - template - T GetRandom(const T minValue, const T maxValue) - { - return CryRandom_Internal::BoundedRandom::Get(*this, minValue, maxValue); - } - - // Vector (Vec2, Vec3, Vec4) ranged function returns vector with - // every component within the *inclusive* ranges between minValue.component - // and maxValue.component. - // All orderings work correctly: minValue.component <= maxValue.component and - // minValue.component >= maxValue.component. - template - T GetRandomComponentwise(const T& minValue, const T& maxValue) - { - return CryRandom_Internal::BoundedRandomComponentwise::Get(*this, minValue, maxValue); - } - - // The function returns a random unit vector (Vec2, Vec3, Vec4). - template - T GetRandomUnitVector() - { - return CryRandom_Internal::GetRandomUnitVector(*this); - } - -protected: // used by derived classes, otherwise not accessible; use the ()-operator - // generates 32 bit random int - uint32 rand_int32() - { - if (p >= n) gen_state(); // new m_nState vector needed - // gen_state() is split off to be non-inline, because it is only called once - // in every 624 calls and otherwise irand() would become too big to get inlined - uint32 x = m_nState[p++]; - x ^= (x >> 11); - x ^= (x << 7) & 0x9D2C5680UL; - x ^= (x << 15) & 0xEFC60000UL; - return x ^ (x >> 18); - } - -private: - static const int n = 624, m = 397; // compile time constants - - // the variables below are static (no duplicates can exist) - uint32 m_nState[n+1]; // m_nState vector array - int p; // position in m_nState array - // private functions used to generate the pseudo random numbers - uint32 twiddle(uint32 u, uint32 v) - { - return (((u & 0x80000000UL) | (v & 0x7FFFFFFFUL)) >> 1) - ^ ((v & 1UL) ? 0x9908B0DFUL : 0x0UL); - } - void gen_state(); // generate new m_nState - // make copy constructor and assignment operator unavailable, they don't make sense - CMTRand_int32(const CMTRand_int32&); // copy constructor not defined - void operator=(const CMTRand_int32&); // assignment operator not defined -}; - - -#endif // CRYINCLUDE_CRYCOMMON_MTPSEUDORANDOM_H diff --git a/Code/Legacy/CryCommon/MathConversion.h b/Code/Legacy/CryCommon/MathConversion.h index 69d5244b63..9ac09173cb 100644 --- a/Code/Legacy/CryCommon/MathConversion.h +++ b/Code/Legacy/CryCommon/MathConversion.h @@ -153,35 +153,6 @@ inline AZ::Matrix3x4 LYTransformToAZMatrix3x4(const Matrix34& source) return AZ::Matrix3x4::CreateFromRowMajorFloat12(source.GetData()); } -inline AZ::Transform LYQuatTToAZTransform(const QuatT& source) -{ - return AZ::Transform::CreateFromQuaternionAndTranslation( - LYQuaternionToAZQuaternion(source.q), - LYVec3ToAZVec3(source.t)); -} - -inline QuatT AZTransformToLYQuatT(const AZ::Transform& source) -{ - return QuatT( - AZQuaternionToLYQuaternion(source.GetRotation()), - AZVec3ToLYVec3(source.GetTranslation())); -} - -inline QuatT AZMatrix3x4ToLYQuatT(const AZ::Matrix3x4& source) -{ - AZ::Matrix3x4 sourceNoScale(source); - sourceNoScale.ExtractScale(); - - return QuatT( - AZQuaternionToLYQuaternion(AZ::Quaternion::CreateFromMatrix3x4(sourceNoScale)), - AZVec3ToLYVec3(source.GetTranslation())); -} - -inline DualQuat AZMatrix3x4ToLYDualQuat(const AZ::Matrix3x4& matrix3x4) -{ - return DualQuat(AZMatrix3x4ToLYMatrix3x4(matrix3x4)); -} - inline AABB AZAabbToLyAABB(const AZ::Aabb& source) { return AABB(AZVec3ToLYVec3(source.GetMin()), AZVec3ToLYVec3(source.GetMax())); diff --git a/Code/Legacy/CryCommon/MetaUtils.h b/Code/Legacy/CryCommon/MetaUtils.h deleted file mode 100644 index 9d62f115d3..0000000000 --- a/Code/Legacy/CryCommon/MetaUtils.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_CRYCOMMON_METAUTILS_H -#define CRYINCLUDE_CRYCOMMON_METAUTILS_H -#pragma once - - - -namespace metautils -{ - // select - - template - struct select; - - template - struct select - { - typedef Ty1 type; - }; - - template - struct select - { - typedef Ty2 type; - }; - - // is_same - // Identifies whether types Ty1 and Ty2 are the same including const & volatile. - - template - struct is_same; - - template - struct is_same - { - enum - { - value = true, - }; - }; - - template - struct is_same - { - enum - { - value = false, - }; - }; - - // remove_const - // Removes top level const qualifier. - - template - struct remove_const - { - typedef Ty type; - }; - - template - struct remove_const - { - typedef Ty type; - }; - - template - struct remove_const - { - typedef Ty type[]; - }; - - template - struct remove_const - { - typedef Ty type[N]; - }; - - // is_const - // Determines whether type Ty is const qualified. - - template - struct is_const - { - enum - { - value = false - }; - }; - - template - struct is_const - { - enum - { - value = true - }; - }; - - template - struct is_const - { - enum - { - value = false - }; - }; - - template - struct is_const - { - enum - { - value = true - }; - }; - - template - struct is_const - { - enum - { - value = false - }; - }; -}; - -#endif // CRYINCLUDE_CRYCOMMON_METAUTILS_H diff --git a/Code/Legacy/CryCommon/Mocks/ICVarMock.h b/Code/Legacy/CryCommon/Mocks/ICVarMock.h index 08f4471ad1..d8131c3552 100644 --- a/Code/Legacy/CryCommon/Mocks/ICVarMock.h +++ b/Code/Legacy/CryCommon/Mocks/ICVarMock.h @@ -11,7 +11,7 @@ #include #include -#include +#include class CVarMock : public ICVar @@ -35,9 +35,8 @@ public: MOCK_METHOD0(GetHelp, const char*()); MOCK_CONST_METHOD0(IsConstCVar, bool()); MOCK_METHOD1(SetOnChangeCallback, void(ConsoleVarFunc)); - MOCK_METHOD1(AddOnChangeFunctor, uint64(const SFunctor& pChangeFunctor)); + MOCK_METHOD1(AddOnChangeFunctor, uint64(const AZStd::function& pChangeFunctor)); MOCK_CONST_METHOD0(GetOnChangeCallback, ConsoleVarFunc()); - MOCK_CONST_METHOD1(GetMemoryUsage, void(class ICrySizer* pSizer)); MOCK_CONST_METHOD0(GetRealIVal, int()); MOCK_METHOD2(SetLimits, void(float, float)); MOCK_METHOD2(GetLimits, void(float&, float&)); diff --git a/Code/Legacy/CryCommon/Mocks/IConsoleMock.h b/Code/Legacy/CryCommon/Mocks/IConsoleMock.h index 9c947b9c0f..24ae70cba4 100644 --- a/Code/Legacy/CryCommon/Mocks/IConsoleMock.h +++ b/Code/Legacy/CryCommon/Mocks/IConsoleMock.h @@ -21,12 +21,10 @@ public: MOCK_METHOD1(Init, void(ISystem * pSystem)); MOCK_METHOD5(RegisterString, ICVar * (const char* sName, const char* sValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc)); MOCK_METHOD5(RegisterInt, ICVar * (const char* sName, int iValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc)); - MOCK_METHOD5(RegisterInt64, ICVar * (const char* sName, int64 iValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc)); MOCK_METHOD5(RegisterFloat, ICVar * (const char* sName, float fValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc)); MOCK_METHOD7(Register, ICVar * (const char* name, float* src, float defaultvalue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc, bool allowModify)); MOCK_METHOD7(Register, ICVar * (const char* name, int* src, int defaultvalue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc, bool allowModify)); MOCK_METHOD7(Register, ICVar * (const char* name, const char** src, const char* defaultvalue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc, bool allowModify)); - MOCK_METHOD1(Register, ICVar * (ICVar * pVar)); MOCK_METHOD2(UnregisterVariable, void(const char* sVarName, bool bDelete )); MOCK_METHOD1(SetScrollMax, void(int value)); MOCK_METHOD1(AddOutputPrintSink, void(IOutputPrintSink * inpSink)); @@ -63,7 +61,6 @@ public: MOCK_METHOD2(RegisterAutoComplete, void (const char* sVarOrCommand, IConsoleArgumentAutoComplete * pArgAutoComplete)); MOCK_METHOD1(UnRegisterAutoComplete, void (const char* sVarOrCommand)); MOCK_METHOD0(ResetAutoCompletion, void ()); - MOCK_CONST_METHOD1(GetMemoryUsage, void (ICrySizer * pSizer)); MOCK_METHOD1(ResetProgressBar, void (int nProgressRange)); MOCK_METHOD0(TickProgressBar, void ()); MOCK_METHOD1(SetInputLine, void (const char* szLine)); diff --git a/Code/Legacy/CryCommon/Mocks/ILogMock.h b/Code/Legacy/CryCommon/Mocks/ILogMock.h index c3a45b4d6f..ac2ba7f32c 100644 --- a/Code/Legacy/CryCommon/Mocks/ILogMock.h +++ b/Code/Legacy/CryCommon/Mocks/ILogMock.h @@ -48,8 +48,6 @@ public: void()); MOCK_METHOD0(GetModuleFilter, const char*()); - MOCK_CONST_METHOD1(GetMemoryUsage, - void(ICrySizer * pSizer)); MOCK_METHOD1(Indent, void(class CLogIndenter * indenter)); MOCK_METHOD1(Unindent, diff --git a/Code/Legacy/CryCommon/MultiThread_Containers.h b/Code/Legacy/CryCommon/MultiThread_Containers.h index 8a60adfa6b..168ebf28cf 100644 --- a/Code/Legacy/CryCommon/MultiThread_Containers.h +++ b/Code/Legacy/CryCommon/MultiThread_Containers.h @@ -6,13 +6,9 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_MULTITHREAD_CONTAINERS_H -#define CRYINCLUDE_CRYCOMMON_MULTITHREAD_CONTAINERS_H #pragma once #include "StlUtils.h" -#include "BitFiddling.h" #include #include @@ -43,8 +39,6 @@ namespace CryMT const T& back() const { AutoLock lock(m_cs); return v.back(); } void push(const T& x) { AutoLock lock(m_cs); return v.push_back(x); }; void reserve(const size_t n) { AutoLock lock(m_cs); v.reserve(n); }; - // classic pop function of queue should not be used for thread safety, use try_pop instead - //void pop() { AutoLock lock(m_cs); return v.erase(v.begin()); }; AZStd::recursive_mutex& get_lock() const { return m_cs; } @@ -69,27 +63,6 @@ namespace CryMT return false; }; - ////////////////////////////////////////////////////////////////////////// - bool try_remove(const T& value) - { - AutoLock lock(m_cs); - if (!v.empty()) - { - typename container_type::iterator it = std::find(v.begin(), v.end(), value); - if (it != v.end()) - { - v.erase(it); - return true; - } - } - return false; - }; - - template - void GetMemoryUsage(Sizer* pSizer) const - { - pSizer->AddObject(v); - } private: container_type v; mutable AZStd::recursive_mutex m_cs; @@ -104,6 +77,3 @@ namespace stl v.free_memory(); } } - - -#endif // CRYINCLUDE_CRYCOMMON_MULTITHREAD_CONTAINERS_H diff --git a/Code/Legacy/CryCommon/Random.h b/Code/Legacy/CryCommon/Random.h index c0d06f458c..6ffb38f736 100644 --- a/Code/Legacy/CryCommon/Random.h +++ b/Code/Legacy/CryCommon/Random.h @@ -6,9 +6,6 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_RANDOM_H -#define CRYINCLUDE_CRYCOMMON_RANDOM_H #pragma once #include "BaseTypes.h" @@ -21,22 +18,11 @@ namespace CryRandom_Internal } -// Seed the global random number generator. -inline void cry_random_seed(const uint32 nSeed) -{ - CryRandom_Internal::g_random_generator.Seed(nSeed); -} - inline uint32 cry_random_uint32() { return CryRandom_Internal::g_random_generator.GenerateUint32(); } -inline float cry_frand() -{ - return CryRandom_Internal::g_random_generator.GenerateFloat(); -} - // Ranged function returns random value within the *inclusive* range // between minValue and maxValue. // Any orderings work correctly: minValue <= maxValue and @@ -46,24 +32,3 @@ inline T cry_random(const T minValue, const T maxValue) { return CryRandom_Internal::g_random_generator.GetRandom(minValue, maxValue); } - -// Vector (Vec2, Vec3, Vec4) ranged function returns vector with -// every component within the *inclusive* ranges between minValue.component -// and maxValue.component. -// All orderings work correctly: minValue.component <= maxValue.component and -// minValue.component >= maxValue.component. -template -inline T cry_random_componentwise(const T& minValue, const T& maxValue) -{ - return CryRandom_Internal::g_random_generator.GetRandomComponentwise(minValue, maxValue); -} - -// The function returns a random unit vector (Vec2, Vec3, Vec4). -template -inline T cry_random_unit_vector() -{ - return CryRandom_Internal::g_random_generator.GetRandomUnitVector(); -} - -// eof -#endif // CRYINCLUDE_CRYCOMMON_RANDOM_H diff --git a/Code/Legacy/CryCommon/RenderBus.h b/Code/Legacy/CryCommon/RenderBus.h deleted file mode 100644 index 84259882a2..0000000000 --- a/Code/Legacy/CryCommon/RenderBus.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -#include - -namespace AZ -{ - /** - * This bus serves as a way for non-rendering systems to react to events - * that occur inside the renderer. For now these events will probably be implemented by - * things like CSystem and CryAction. In the future the idea is that these can be implemented - * by a user's GameComponent. - */ - class RenderNotifications - : public AZ::EBusTraits - { - public: - virtual ~RenderNotifications() = default; - - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - ////////////////////////////////////////////////////////////////////////// - - /** - * This event gets posted at the beginning of CD3D9Renderer's FreeResources method, before the resources have been freed. - */ - virtual void OnRendererFreeResources([[maybe_unused]] int flags) {}; - }; - - using RenderNotificationsBus = AZ::EBus; - - /** - * This bus is used for renderer notifications that occur directly from the render thread - * while scene rendering is occurring. (In contrast, the RenderNotificationsBus above runs on the - * main thread while the renderer is preparing the scene.) - */ - class RenderThreadEvents - : public AZ::EBusTraits - { - public: - virtual ~RenderThreadEvents() = default; - - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - ////////////////////////////////////////////////////////////////////////// - - /* - * This hook enables per-frame render work at the beginning of the frame. - * - * This event is triggered when RT_RenderScene is called at the beginning of a frame. - * The event will only be triggered on the render thread, if multithreaded rendering - * is enabled. And, it will only be triggered on a non-recursive scene render. - */ - virtual void OnRenderThreadRenderSceneBegin() {} - }; - - using RenderThreadEventsBus = AZ::EBus; - - /** - * This bus is used for firing screenshot request to any rendering system. - * The rendering system should implement its own screenshot function. - */ - class RenderScreenshotRequests - : public AZ::EBusTraits - { - public: - static const EBusHandlerPolicy HandlerPolicy = EBusHandlerPolicy::Single; ///< EBusTraits overrides - static const EBusAddressPolicy AddressPolicy = EBusAddressPolicy::Single; ///< EBusTraits overrides - - /** Take a screenshot and save it to a file. - @param filepath the path where a the screenshot is saved. - */ - virtual void WriteScreenshotToFile(const char* filepath) = 0; - - /** Take a screenshot and preserve it within a buffer - */ - virtual void WriteScreenshotToBuffer() = 0; - - /** Fill a provided buffer with the render buffer - @param imageBuffer The provided buffer to be filled - */ - virtual bool CopyScreenshotToBuffer(unsigned char* imageBuffer, unsigned int width, unsigned int height) = 0; - - }; - - using RenderScreenshotRequestBus = AZ::EBus; - - class RenderScreenshotNotifications - : public AZ::EBusTraits - { - public: - virtual ~RenderScreenshotNotifications() = default; - - static const EBusAddressPolicy AddressPolicy = EBusAddressPolicy::Single; ///< EBusTraits overrides - - /** Notify waiting components that the requested screenshot is ready - */ - virtual void OnScreenshotReady() = 0; - }; - - using RenderScreenshotNotificationBus = AZ::EBus; -} diff --git a/Code/Legacy/CryCommon/SFunctor.h b/Code/Legacy/CryCommon/SFunctor.h deleted file mode 100644 index d3075c9fae..0000000000 --- a/Code/Legacy/CryCommon/SFunctor.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -// Description : User header for multi DLL functors. - - -#ifndef CRYINCLUDE_CRYCOMMON_SFUNCTOR_H -#define CRYINCLUDE_CRYCOMMON_SFUNCTOR_H -#pragma once - - -#include "FunctorBaseFunction.h" -#include "FunctorBaseMember.h" - -// Needed for CryFont to compile. -// Maybe for others too. -#include "smartptr.h" - - -struct SFunctor -{ -public: - // Calls the functor method. - // returns true, if a functor is registered, false otherwise. - bool Call() - { - if (!m_pFunctor) - { - return false; - } - - m_pFunctor->Call(); - - return true; - } - - // Sets a new functor, common function, void return type, no arguments. - // Parameters: the function pointer. - template - void Set(tCallback pCallback) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallback); - } - - // Sets a new functor, common function, void return type, 1 argument. - // Parameters: the function pointer, the argument to be passed to the function. - template - void Set(tCallback pCallback, const tArgument1& Argument1) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallback, Argument1); - } - - // Sets a new functor, common function, void return type, 2 arguments. - // Parameters: the function pointer, the 2 arguments to be passed to the function. - template - void Set(tCallback pCallback, const tArgument1& Argument1, const tArgument2& Argument2) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallback, Argument1, Argument2); - } - - // Sets a new functor, common function, void return type, no arguments. - // Parameters: the function pointer, the 2 arguments to be passed to the function. - template - void Set(tCallee* pCallee, void (tCallee::* pCallback)()) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallee, pCallback); - } - - // Sets a new functor, common function, void return type, 1 argument. - // Parameters: the function pointer, the 2 arguments to be passed to the function, the argument. - template - void Set(tCallee* pCallee, void (tCallee::* pCallback)(tArgument1), const tArgument1& Argument1) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallee, pCallback, Argument1); - } - - // Sets a new functor, common function, void return type, 2 arguments. - // Parameters: the function pointer, the 2 arguments to be passed to the function, the 2 arguments. - template - void Set(tCallee* pCallee, void (tCallee::* pCallback)(tArgument1, tArgument2), const tArgument1& Argument1, const tArgument2& Argument2) - { - typedef TFunctor TType; - m_pFunctor = new TType(pCallee, pCallback, Argument1, Argument2); - } - - // Used to compare equality between 2 IFunctors. - bool operator==(const SFunctor& rOther) - { - return m_pFunctor == rOther.m_pFunctor; - } - - // Used order to IFunctors (needed for some containers, like map). - bool operator<(const SFunctor& rOther) - { - return m_pFunctor < rOther.m_pFunctor; - } -protected: - _smart_ptr m_pFunctor; -}; - -#endif // CRYINCLUDE_CRYCOMMON_SFUNCTOR_H diff --git a/Code/Legacy/CryCommon/SerializationTypes.h b/Code/Legacy/CryCommon/SerializationTypes.h index 6dbbe53f50..a041f0a836 100644 --- a/Code/Legacy/CryCommon/SerializationTypes.h +++ b/Code/Legacy/CryCommon/SerializationTypes.h @@ -10,7 +10,6 @@ SERIALIZATION_TYPE(bool) SERIALIZATION_TYPE(float) -SERIALIZATION_TYPE(double) SERIALIZATION_TYPE(Vec2) SERIALIZATION_TYPE(Vec3) SERIALIZATION_TYPE(Quat) @@ -24,5 +23,3 @@ SERIALIZATION_TYPE(uint16) SERIALIZATION_TYPE(uint32) SERIALIZATION_TYPE(uint64) SERIALIZATION_TYPE(CTimeValue) -SERIALIZATION_TYPE(SNetObjectID) -SERIALIZATION_TYPE(XmlNodeRef) // not for network - only for save games diff --git a/Code/Legacy/CryCommon/SerializeFwd.h b/Code/Legacy/CryCommon/SerializeFwd.h index e6cac372de..2b8a18b797 100644 --- a/Code/Legacy/CryCommon/SerializeFwd.h +++ b/Code/Legacy/CryCommon/SerializeFwd.h @@ -6,18 +6,10 @@ * */ - // Description : forward declaration of TSerialize - -#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZEFWD_H -#define CRYINCLUDE_CRYCOMMON_SERIALIZEFWD_H #pragma once - - template class CSerializeWrapper; struct ISerialize; typedef CSerializeWrapper TSerialize; - -#endif // CRYINCLUDE_CRYCOMMON_SERIALIZEFWD_H diff --git a/Code/Legacy/CryCommon/SimpleSerialize.h b/Code/Legacy/CryCommon/SimpleSerialize.h index 7ce2c1c5dd..2fd57b7bc3 100644 --- a/Code/Legacy/CryCommon/SimpleSerialize.h +++ b/Code/Legacy/CryCommon/SimpleSerialize.h @@ -6,78 +6,29 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_SIMPLESERIALIZE_H -#define CRYINCLUDE_CRYCOMMON_SIMPLESERIALIZE_H #pragma once - -#include // <> required for Interfuscator #include "TimeValue.h" +#include // <> required for Interfuscator -template -class CSimpleSerializeImpl_Reading; - -template <> -class CSimpleSerializeImpl_Reading -{ -public: - CSimpleSerializeImpl_Reading() - : m_bCommit(true) {} - ILINE bool IsReading() const - { - return true; - } - ILINE bool ShouldCommitValues() const - { - return m_bCommit; - } - ILINE void Update(ISerializeUpdateFunction* pFunc) - { - if (m_bCommit) - { - pFunc->Execute(); - } - } -protected: - bool m_bCommit; -}; - -template <> -class CSimpleSerializeImpl_Reading -{ -public: - ILINE bool IsReading() const - { - return false; - } - ILINE bool ShouldCommitValues() const - { - return true; - } - ILINE void Update(ISerializeUpdateFunction*) - { - } -}; - -template +template class CSimpleSerializeImpl - : public CSimpleSerializeImpl_Reading { public: CSimpleSerializeImpl() - : m_failed(false) {} + : m_failed(false) + { + } + ILINE bool IsReading() const + { + return READING; + } ILINE void BeginGroup(const char* szName) { } ILINE void EndGroup() { } - ILINE ESerializationTarget GetSerializationTarget() const - { - return TARGET; - } - ILINE void FlagPartialRead() {} ILINE bool Ok() const { @@ -94,9 +45,8 @@ private: bool m_failed; }; -template -class CSimpleSerialize - : public ISerialize +template +class CSimpleSerialize : public ISerialize { public: ILINE CSimpleSerialize(Impl& impl) @@ -104,11 +54,6 @@ public: { } - void Update(ISerializeUpdateFunction* pFunc) - { - m_impl.Update(pFunc); - } - void BeginGroup(const char* szName) { m_impl.BeginGroup(szName); @@ -129,47 +74,25 @@ public: return m_impl.IsReading(); } - bool ShouldCommitValues() const + void WriteStringValue(const char* name, SSerializeString& value) { - return m_impl.ShouldCommitValues(); + m_impl.Value(name, value); + } + void ReadStringValue(const char* name, SSerializeString& curValue) + { + m_impl.Value(name, curValue); } - ESerializationTarget GetSerializationTarget() const - { - return m_impl.GetSerializationTarget(); +#define SERIALIZATION_TYPE(T) \ + void Value(const char* name, T& x) override \ + { \ + m_impl.Value(name, x); \ } - - void WriteStringValue(const char* name, SSerializeString& value, uint32 policy) - { - m_impl.Value(name, value, policy); - } - void ReadStringValue(const char* name, SSerializeString& curValue, uint32 policy) - { - m_impl.Value(name, curValue, policy); - } - - bool Ok() const - { - return m_impl.Ok(); - } - - void FlagPartialRead() - { - m_impl.FlagPartialRead(); - } - -#define SERIALIZATION_TYPE(T) \ - virtual void Value(const char* name, T & x, uint32 policy) { m_impl.Value(name, x, policy); } #include "SerializationTypes.h" #undef SERIALIZATION_TYPE -#define SERIALIZATION_TYPE(T) \ - virtual void ValueWithDefault([[maybe_unused]] const char* name, [[maybe_unused]] T & x, [[maybe_unused]] const T&defaultValue) { assert(0); } -#include "SerializationTypes.h" - SERIALIZATION_TYPE(SSerializeString) -#undef SERIALIZATION_TYPE - - Impl * GetInnerImpl() { + Impl* GetInnerImpl() + { return &m_impl; } @@ -181,26 +104,5 @@ protected: // Support serialization with default values, // Require Implementation serialization stub to have Value() method returning boolean. ////////////////////////////////////////////////////////////////////////// -template -class CSimpleSerializeWithDefaults - : public CSimpleSerialize -{ -public: - ILINE CSimpleSerializeWithDefaults(Impl& impl) - : CSimpleSerialize(impl) {} - -#define SERIALIZATION_TYPE(T) \ - virtual void ValueWithDefault(const char* name, T & x, const T&defaultValue) { \ - if (CSimpleSerialize::m_impl.IsReading()) { \ - if (!CSimpleSerialize::m_impl.Value(name, x, 0)) { \ - x = defaultValue; } \ - } \ - else if (x != defaultValue) { \ - CSimpleSerialize::m_impl.Value(name, x, 0); } \ - } -#include "SerializationTypes.h" - SERIALIZATION_TYPE(SSerializeString) -#undef SERIALIZATION_TYPE -}; - -#endif // CRYINCLUDE_CRYCOMMON_SIMPLESERIALIZE_H +template +using CSimpleSerializeWithDefaults = CSimpleSerialize; diff --git a/Code/Legacy/CryCommon/StatObjBus.h b/Code/Legacy/CryCommon/StatObjBus.h index b9a47f976d..5a05440cb0 100644 --- a/Code/Legacy/CryCommon/StatObjBus.h +++ b/Code/Legacy/CryCommon/StatObjBus.h @@ -5,47 +5,15 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ - -#ifndef CRYINCLUDE_CRYCOMMON_STATOBJBUS_H -#define CRYINCLUDE_CRYCOMMON_STATOBJBUS_H +#pragma once #include #include -struct IStatObj; - -////////////////////////////////////////////////////////////////////////// -// -// Ebus support for handling unique IDs between IStatInstGroup instances. -// -////////////////////////////////////////////////////////////////////////// -using StatInstGroupId = int; - -class StatInstGroupEvents - : public AZ::EBusTraits -{ -public: - const static StatInstGroupId s_InvalidStatInstGroupId = -1; - - virtual ~StatInstGroupEvents() = default; - - // AZ::EBusTraits - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - using MutexType = AZStd::recursive_mutex; - - virtual StatInstGroupId GenerateStatInstGroupId() = 0; - virtual void ReleaseStatInstGroupId(StatInstGroupId statInstGroupId) = 0; - virtual void ReleaseStatInstGroupIdSet(const AZStd::unordered_set& statInstGroupIdSet) = 0; - virtual void ReserveStatInstGroupIdRange(StatInstGroupId from, StatInstGroupId to) = 0; -}; - -using StatInstGroupEventBus = AZ::EBus; - ////////////////////////////////////////////////////////////////////////// // // EBUS support for triggering necessary updates when IStatObj instances -// caches should be updated when 3D Engine events happen during level loads, +// caches should be updated when 3D Engine events happen during level loads, // shutting down the application, and so forth // ////////////////////////////////////////////////////////////////////////// @@ -66,6 +34,3 @@ public: }; using InstanceStatObjEventBus = AZ::EBus; - -#endif // CRYINCLUDE_CRYCOMMON_STATOBJBUS_H -#pragma once diff --git a/Code/Legacy/CryCommon/Synchronization.h b/Code/Legacy/CryCommon/Synchronization.h index d38160c967..ddd020ffde 100644 --- a/Code/Legacy/CryCommon/Synchronization.h +++ b/Code/Legacy/CryCommon/Synchronization.h @@ -6,9 +6,6 @@ * */ - -#ifndef CRYINCLUDE_CRYCOMMON_SYNCHRONIZATION_H -#define CRYINCLUDE_CRYCOMMON_SYNCHRONIZATION_H #pragma once @@ -25,46 +22,4 @@ namespace stl { - template - struct AutoLock - { - ILINE AutoLock(Sync& sync) - : _sync(sync) - { - sync.Lock(); - } - ILINE ~AutoLock() - { - _sync.Unlock(); - } - - private: - Sync& _sync; - }; - - - struct PSyncNone - { - void Lock() {} - void Unlock() {} - }; - - struct PSyncMultiThread - { - PSyncMultiThread() {} - - void Lock() - { - m_lock.lock(); - } - void Unlock() - { - m_lock.unlock(); - } - - private: - AZStd::spin_mutex m_lock; - }; }; - -#endif // CRYINCLUDE_CRYCOMMON_SYNCHRONIZATION_H diff --git a/Code/Legacy/CryCommon/TimeValue.h b/Code/Legacy/CryCommon/TimeValue.h index 14f402eb3d..a3da02ef62 100644 --- a/Code/Legacy/CryCommon/TimeValue.h +++ b/Code/Legacy/CryCommon/TimeValue.h @@ -21,8 +21,6 @@ public: static const int64 TIMEVALUE_PRECISION = 100000; // one second public: - void GetMemoryUsage(class ICrySizer*) const { /*nothing*/} - // Default constructor. ILINE CTimeValue() { @@ -164,8 +162,6 @@ public: ILINE bool operator==(const CTimeValue& inRhs) const { return m_lValue == inRhs.m_lValue; }; ILINE bool operator!=(const CTimeValue& inRhs) const { return m_lValue != inRhs.m_lValue; }; - void GetMemoryStatistics(class ICrySizer*) const { /*nothing*/} - private: // ---------------------------------------------------------- int64 m_lValue; // absolute or relative value in 1/TIMEVALUE_PRECISION, might be negative diff --git a/Code/Legacy/CryCommon/VertexFormats.h b/Code/Legacy/CryCommon/VertexFormats.h index 8f5d0f0923..97e0c20935 100644 --- a/Code/Legacy/CryCommon/VertexFormats.h +++ b/Code/Legacy/CryCommon/VertexFormats.h @@ -6,12 +6,9 @@ * */ - #pragma once #include -// Stream Configuration options -#define ENABLE_NORMALSTREAM_SUPPORT 1 enum EVertexFormat : uint8 { @@ -32,9 +29,6 @@ enum EVertexFormat : uint8 eVF_Max, }; - -typedef Vec4_tpl Vec4sf; // Used for tangents only. - struct UCol { union @@ -90,7 +84,7 @@ struct Vec3f16 w = CryConvertFloatToHalf(1.0f); return *this; } - _inline Vec3f16& operator = (const Vec4A& sl) + _inline Vec3f16& operator = (const Vec4& sl) { x = CryConvertFloatToHalf(sl.x); y = CryConvertFloatToHalf(sl.y); @@ -108,44 +102,6 @@ struct Vec3f16 } }; -struct Vec2f16 - : public CryHalf2 -{ - _inline Vec2f16() - { - } - _inline Vec2f16(f32 _x, f32 _y) - { - x = CryConvertFloatToHalf(_x); - y = CryConvertFloatToHalf(_y); - } - Vec2f16& operator = (const Vec2f16& sl) - { - x = sl.x; - y = sl.y; - return *this; - } - Vec2f16& operator = (const Vec2& sl) - { - x = CryConvertFloatToHalf(sl.x); - y = CryConvertFloatToHalf(sl.y); - return *this; - } - float operator[](int i) const - { - assert(i <= 1); - return CryConvertHalfToFloat(((CryHalf*)this)[i]); - } - _inline Vec2 ToVec2() const - { - Vec2 v; - v.x = CryConvertHalfToFloat(x); - v.y = CryConvertHalfToFloat(y); - return v; - } -}; - - struct SVF_P3F_C4B { Vec3 xyz; @@ -170,381 +126,7 @@ struct SVF_P2F_C4B_T2F_F4B uint8 pad; }; -struct SVF_P3S_C4B_T2S -{ - Vec3f16 xyz; - UCol color; - Vec2f16 st; -}; - -struct SVF_W4B_I4S -{ - UCol weights; - uint16 indices[4]; -}; - struct SVF_P3F { Vec3 xyz; }; - -//============================================================= -// Signed norm value packing [-1,+1] - -namespace PackingSNorm -{ - ILINE int16 tPackF2B(const float f) - { - return (int16)(f * 32767.0f); - } - - ILINE int16 tPackS2B(const int16 s) - { - return (int16)(s * 32767); - } - - ILINE float tPackB2F(const int16 i) - { - return (float)((float)i / 32767.0f); - } - - ILINE int16 tPackB2S(const int16 s) - { - // OPT: "(s >> 15) + !(s >> 15)" works as well - return (int16)(s / 32767); - } - - ILINE Vec4sf tPackF2Bv(const Vec4& v) - { - Vec4sf vs; - - vs.x = tPackF2B(v.x); - vs.y = tPackF2B(v.y); - vs.z = tPackF2B(v.z); - vs.w = tPackF2B(v.w); - - return vs; - } - - ILINE Vec4sf tPackF2Bv(const Vec3& v) - { - Vec4sf vs; - - vs.x = tPackF2B(v.x); - vs.y = tPackF2B(v.y); - vs.z = tPackF2B(v.z); - vs.w = tPackF2B(1.0f); - - return vs; - } - - ILINE Vec4 tPackB2F(const Vec4sf& v) - { - Vec4 vs; - - vs.x = tPackB2F(v.x); - vs.y = tPackB2F(v.y); - vs.z = tPackB2F(v.z); - vs.w = tPackB2F(v.w); - - return vs; - } - - ILINE void tPackB2F(const Vec4sf& v, Vec4& vDst) - { - vDst.x = tPackB2F(v.x); - vDst.y = tPackB2F(v.y); - vDst.z = tPackB2F(v.z); - vDst.w = 1.0f; - } - - ILINE void tPackB2FScale(const Vec4sf& v, Vec4& vDst, const Vec3& vScale) - { - vDst.x = (float)v.x * vScale.x; - vDst.y = (float)v.y * vScale.y; - vDst.z = (float)v.z * vScale.z; - vDst.w = 1.0f; - } - - ILINE void tPackB2FScale(const Vec4sf& v, Vec3& vDst, const Vec3& vScale) - { - vDst.x = (float)v.x * vScale.x; - vDst.y = (float)v.y * vScale.y; - vDst.z = (float)v.z * vScale.z; - } - - ILINE void tPackB2F(const Vec4sf& v, Vec3& vDst) - { - vDst.x = tPackB2F(v.x); - vDst.y = tPackB2F(v.y); - vDst.z = tPackB2F(v.z); - } -}; - -//============================================================= -// Pip => Graphics Pipeline structures, used for inputs for the GPU's Input Assembler -// These structures are optimized for fast decoding (ALU and bandwidth) and -// might be slow to encode on-the-fly - -struct SPipTangents -{ - SPipTangents() {} - -private: - Vec4sf Tangent; - Vec4sf Bitangent; - -public: - explicit SPipTangents(const Vec4sf& othert, const Vec4sf& otherb, const int16& othersign) - { - using namespace PackingSNorm; - Tangent = othert; - Tangent.w = PackingSNorm::tPackS2B(othersign); - Bitangent = otherb; - Bitangent.w = PackingSNorm::tPackS2B(othersign); - } - - explicit SPipTangents(const Vec4sf& othert, const Vec4sf& otherb, const SPipTangents& othersign) - { - Tangent = othert; - Tangent.w = othersign.Tangent.w; - Bitangent = otherb; - Bitangent.w = othersign.Bitangent.w; - } - - explicit SPipTangents(const Vec4sf& othert, const Vec4sf& otherb) - { - Tangent = othert; - Bitangent = otherb; - } - - explicit SPipTangents(const Vec3& othert, const Vec3& otherb, const int16& othersign) - { - Tangent = Vec4sf(PackingSNorm::tPackF2B(othert.x), PackingSNorm::tPackF2B(othert.y), PackingSNorm::tPackF2B(othert.z), PackingSNorm::tPackS2B(othersign)); - Bitangent = Vec4sf(PackingSNorm::tPackF2B(otherb.x), PackingSNorm::tPackF2B(otherb.y), PackingSNorm::tPackF2B(otherb.z), PackingSNorm::tPackS2B(othersign)); - } - - explicit SPipTangents(const Vec3& othert, const Vec3& otherb, const SPipTangents& othersign) - { - Tangent = Vec4sf(PackingSNorm::tPackF2B(othert.x), PackingSNorm::tPackF2B(othert.y), PackingSNorm::tPackF2B(othert.z), othersign.Tangent.w); - Bitangent = Vec4sf(PackingSNorm::tPackF2B(otherb.x), PackingSNorm::tPackF2B(otherb.y), PackingSNorm::tPackF2B(otherb.z), othersign.Bitangent.w); - } - - explicit SPipTangents(const Quat& other, const int16& othersign) - { - Vec3 othert = other.GetColumn0(); - Vec3 otherb = other.GetColumn1(); - - Tangent = Vec4sf(PackingSNorm::tPackF2B(othert.x), PackingSNorm::tPackF2B(othert.y), PackingSNorm::tPackF2B(othert.z), PackingSNorm::tPackS2B(othersign)); - Bitangent = Vec4sf(PackingSNorm::tPackF2B(otherb.x), PackingSNorm::tPackF2B(otherb.y), PackingSNorm::tPackF2B(otherb.z), PackingSNorm::tPackS2B(othersign)); - } - - void ExportTo(Vec4sf& othert, Vec4sf& otherb) const - { - othert = Tangent; - otherb = Bitangent; - } - - // get normal tangent and bitangent vectors - void GetTB(Vec4& othert, Vec4& otherb) const - { - othert = PackingSNorm::tPackB2F(Tangent); - otherb = PackingSNorm::tPackB2F(Bitangent); - } - - // get normal vector (perpendicular to tangent and bitangent plane) - ILINE Vec3 GetN() const - { - Vec4 tng, btg; - GetTB(tng, btg); - - Vec3 tng3(tng.x, tng.y, tng.z), - btg3(btg.x, btg.y, btg.z); - - // assumes w 1 or -1 - return tng3.Cross(btg3) * tng.w; - } - - // get normal vector (perpendicular to tangent and bitangent plane) - void GetN(Vec3& othern) const - { - othern = GetN(); - } - - // get the tangent-space basis as individual normal vectors (tangent, bitangent and normal) - void GetTBN(Vec3& othert, Vec3& otherb, Vec3& othern) const - { - Vec4 tng, btg; - GetTB(tng, btg); - - Vec3 tng3(tng.x, tng.y, tng.z), - btg3(btg.x, btg.y, btg.z); - - // assumes w 1 or -1 - othert = tng3; - otherb = btg3; - othern = tng3.Cross(btg3) * tng.w; - } - - // get normal vector sign (reflection) - ILINE int16 GetR() const - { - return PackingSNorm::tPackB2S(Tangent.w); - } - - // get normal vector sign (reflection) - void GetR(int16& sign) const - { - sign = GetR(); - } - - void TransformBy(const Matrix34& trn) - { - Vec4 tng, btg; - GetTB(tng, btg); - - Vec3 tng3(tng.x, tng.y, tng.z), - btg3(btg.x, btg.y, btg.z); - - tng3 = trn.TransformVector(tng3); - btg3 = trn.TransformVector(btg3); - - *this = SPipTangents(tng3, btg3, PackingSNorm::tPackB2S(Tangent.w)); - } - - void TransformSafelyBy(const Matrix34& trn) - { - Vec4 tng, btg; - GetTB(tng, btg); - - Vec3 tng3(tng.x, tng.y, tng.z), - btg3(btg.x, btg.y, btg.z); - - tng3 = trn.TransformVector(tng3); - btg3 = trn.TransformVector(btg3); - - // normalize in case "trn" wasn't length-preserving - tng3.Normalize(); - btg3.Normalize(); - - *this = SPipTangents(tng3, btg3, PackingSNorm::tPackB2S(Tangent.w)); - } -}; - -struct SPipQTangents -{ - SPipQTangents() {} - -private: - Vec4sf QTangent; - -public: - explicit SPipQTangents(const Vec4sf& other) - { - QTangent = other; - } - - bool operator ==(const SPipQTangents& other) const - { - return - QTangent[0] == other.QTangent[0] || - QTangent[1] == other.QTangent[1] || - QTangent[2] == other.QTangent[2] || - QTangent[3] == other.QTangent[3]; - } - - bool operator !=(const SPipQTangents& other) const - { - return !(*this == other); - } - - // get quaternion - ILINE Quat GetQ() const - { - Quat q; - - q.v.x = PackingSNorm::tPackB2F(QTangent.x); - q.v.y = PackingSNorm::tPackB2F(QTangent.y); - q.v.z = PackingSNorm::tPackB2F(QTangent.z); - q.w = PackingSNorm::tPackB2F(QTangent.w); - - return q; - } - - // get normal vector from quaternion - ILINE Vec3 GetN() const - { - const Quat q = GetQ(); - return q.GetColumn2() * (q.w < 0.0f ? -1.0f : +1.0f); - } -}; - -struct SPipNormal - : public Vec3 -{ - SPipNormal() {} - - explicit SPipNormal(const Vec3& othern) - { - x = othern.x; - y = othern.y; - z = othern.z; - } - - // get normal vector - ILINE Vec3 GetN() const - { - return *this; - } - - // get normal vector - void GetN(Vec3& othern) const - { - othern = GetN(); - } - - void TransformBy(const Matrix34& trn) - { - *this = SPipNormal(trn.TransformVector(*this)); - } - - void TransformSafelyBy(const Matrix34& trn) - { - // normalize in case "trn" wasn't length-preserving - *this = SPipNormal(trn.TransformVector(*this).normalize()); - } -}; - -//================================================================================================== - -typedef SVF_P3F_C4B_T2F SAuxVertex; - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Vertex Sizes -//extern const int m_VertexSize[]; - -//============================================================================ -// Custom vertex streams definitions -// NOTE: If you add new stream ID also include vertex declarations creating in -// CD3D9Renderer::EF_InitD3DVertexDeclarations (D3DRendPipeline.cpp) - -// Stream IDs -enum EStreamIDs -{ - VSF_GENERAL, // General vertex buffer - VSF_TANGENTS, // Tangents buffer - VSF_QTANGENTS, // Tangents buffer - VSF_HWSKIN_INFO, // HW skinning buffer - VSF_VERTEX_VELOCITY, // Velocity buffer -# if ENABLE_NORMALSTREAM_SUPPORT - VSF_NORMALS, // Normals, used for skinning -#endif - // <- Insert new stream IDs here - VSF_NUM, // Number of vertex streams - - VSF_MORPHBUDDY = 8, // Morphing (from m_pMorphBuddy) - VSF_INSTANCED = 9, // Data is for instance stream - VSF_MORPHBUDDY_WEIGHTS = 15, // Morphing weights -}; - -//================================================================================================================== diff --git a/Code/Legacy/CryCommon/WinBase.cpp b/Code/Legacy/CryCommon/WinBase.cpp index 8473417d4a..71bec78f69 100644 --- a/Code/Legacy/CryCommon/WinBase.cpp +++ b/Code/Legacy/CryCommon/WinBase.cpp @@ -810,21 +810,6 @@ void replaceDoublePathFilename(char* szFileName) azstrcpy((char*)szFileName, AZ_MAX_PATH_LEN, s.c_str()); } -const int comparePathNames(const char* cpFirst, const char* cpSecond, unsigned int len) -{ - //create two strings and replace the \\ by / and /./ by / - AZStd::string first(cpFirst); - AZStd::string second(cpSecond); - adaptFilenameToLinux(first); - adaptFilenameToLinux(second); - if (strlen(cpFirst) < len || strlen(cpSecond) < len) - { - return -1; - } - unsigned int length = std::min(std::min(first.size(), second.size()), (size_t)len); //make sure not to access invalid memory - return memicmp(first.c_str(), second.c_str(), length); -} - #if FIX_FILENAME_CASE static bool FixOnePathElement(char* path) { diff --git a/Code/Legacy/CryCommon/crycommon_files.cmake b/Code/Legacy/CryCommon/crycommon_files.cmake index 2f5030ccc4..c1cdcf094a 100644 --- a/Code/Legacy/CryCommon/crycommon_files.cmake +++ b/Code/Legacy/CryCommon/crycommon_files.cmake @@ -25,7 +25,6 @@ set(FILES IMiniLog.h IMovieSystem.h IProcess.h - IReadWriteXMLSink.h IRenderAuxGeom.h IRenderer.h ISerialize.h @@ -33,7 +32,6 @@ set(FILES ISplines.h IStatObj.h StatObjBus.h - ISurfaceType.h ISystem.h ITexture.h ITimer.h @@ -46,9 +44,6 @@ set(FILES VRCommon.h INavigationSystem.h IMNM.h - SFunctor.h - FunctorBaseFunction.h - FunctorBaseMember.h SerializationTypes.h CryEndian.h CryRandomInternal.h @@ -56,21 +51,15 @@ set(FILES LCGRandom.h BaseTypes.h AnimKey.h - BitFiddling.h - Common_TypeInfo.cpp CryAssert.h - CryCrc32.h CryFile.h CryListenerSet.h CryLegacyAllocator.h CryPath.h - CryPodArray.h - CrySizer.h CrySystemBus.h CryVersion.h LegacyAllocator.cpp LegacyAllocator.h - MetaUtils.h MiniQueue.h MultiThread_Containers.h NullAudioSystem.h @@ -82,13 +71,11 @@ set(FILES SimpleSerialize.h smartptr.h StlUtils.h - Synchronization.h Timer.h TimeValue.h VectorMap.h VertexFormats.h XMLBinaryHeaders.h - RenderBus.h MainThreadRenderRequestBus.h Cry_Matrix33.h Cry_Matrix34.h @@ -106,8 +93,6 @@ set(FILES Cry_Vector3.h CryHalf.inl MathConversion.h - Cry_HWMatrix.h - Cry_HWVector3.h AndroidSpecific.h AppleSpecific.h CryAssert_Android.h diff --git a/Code/Legacy/CryCommon/platform_impl.cpp b/Code/Legacy/CryCommon/platform_impl.cpp index d61bfe6ee4..323d3daf65 100644 --- a/Code/Legacy/CryCommon/platform_impl.cpp +++ b/Code/Legacy/CryCommon/platform_impl.cpp @@ -340,73 +340,6 @@ inline void CryDebugStr([[maybe_unused]] const char* format, ...) */ } -alignas(64) uint32 BoxSides[0x40 * 8] = { - 0, 0, 0, 0, 0, 0, 0, 0, //00 - 0, 4, 6, 2, 0, 0, 0, 4, //01 - 7, 5, 1, 3, 0, 0, 0, 4, //02 - 0, 0, 0, 0, 0, 0, 0, 0, //03 - 0, 1, 5, 4, 0, 0, 0, 4, //04 - 0, 1, 5, 4, 6, 2, 0, 6, //05 - 7, 5, 4, 0, 1, 3, 0, 6, //06 - 0, 0, 0, 0, 0, 0, 0, 0, //07 - 7, 3, 2, 6, 0, 0, 0, 4, //08 - 0, 4, 6, 7, 3, 2, 0, 6, //09 - 7, 5, 1, 3, 2, 6, 0, 6, //0a - 0, 0, 0, 0, 0, 0, 0, 0, //0b - 0, 0, 0, 0, 0, 0, 0, 0, //0c - 0, 0, 0, 0, 0, 0, 0, 0, //0d - 0, 0, 0, 0, 0, 0, 0, 0, //0e - 0, 0, 0, 0, 0, 0, 0, 0, //0f - 0, 2, 3, 1, 0, 0, 0, 4, //10 - 0, 4, 6, 2, 3, 1, 0, 6, //11 - 7, 5, 1, 0, 2, 3, 0, 6, //12 - 0, 0, 0, 0, 0, 0, 0, 0, //13 - 0, 2, 3, 1, 5, 4, 0, 6, //14 - 1, 5, 4, 6, 2, 3, 0, 6, //15 - 7, 5, 4, 0, 2, 3, 0, 6, //16 - 0, 0, 0, 0, 0, 0, 0, 0, //17 - 0, 2, 6, 7, 3, 1, 0, 6, //18 - 0, 4, 6, 7, 3, 1, 0, 6, //19 - 7, 5, 1, 0, 2, 6, 0, 6, //1a - 0, 0, 0, 0, 0, 0, 0, 0, //1b - 0, 0, 0, 0, 0, 0, 0, 0, //1c - 0, 0, 0, 0, 0, 0, 0, 0, //1d - 0, 0, 0, 0, 0, 0, 0, 0, //1e - 0, 0, 0, 0, 0, 0, 0, 0, //1f - 7, 6, 4, 5, 0, 0, 0, 4, //20 - 0, 4, 5, 7, 6, 2, 0, 6, //21 - 7, 6, 4, 5, 1, 3, 0, 6, //22 - 0, 0, 0, 0, 0, 0, 0, 0, //23 - 7, 6, 4, 0, 1, 5, 0, 6, //24 - 0, 1, 5, 7, 6, 2, 0, 6, //25 - 7, 6, 4, 0, 1, 3, 0, 6, //26 - 0, 0, 0, 0, 0, 0, 0, 0, //27 - 7, 3, 2, 6, 4, 5, 0, 6, //28 - 0, 4, 5, 7, 3, 2, 0, 6, //29 - 6, 4, 5, 1, 3, 2, 0, 6, //2a - 0, 0, 0, 0, 0, 0, 0, 0, //2b - 0, 0, 0, 0, 0, 0, 0, 0, //2c - 0, 0, 0, 0, 0, 0, 0, 0, //2d - 0, 0, 0, 0, 0, 0, 0, 0, //2e - 0, 0, 0, 0, 0, 0, 0, 0, //2f - 0, 0, 0, 0, 0, 0, 0, 0, //30 - 0, 0, 0, 0, 0, 0, 0, 0, //31 - 0, 0, 0, 0, 0, 0, 0, 0, //32 - 0, 0, 0, 0, 0, 0, 0, 0, //33 - 0, 0, 0, 0, 0, 0, 0, 0, //34 - 0, 0, 0, 0, 0, 0, 0, 0, //35 - 0, 0, 0, 0, 0, 0, 0, 0, //36 - 0, 0, 0, 0, 0, 0, 0, 0, //37 - 0, 0, 0, 0, 0, 0, 0, 0, //38 - 0, 0, 0, 0, 0, 0, 0, 0, //39 - 0, 0, 0, 0, 0, 0, 0, 0, //3a - 0, 0, 0, 0, 0, 0, 0, 0, //3b - 0, 0, 0, 0, 0, 0, 0, 0, //3c - 0, 0, 0, 0, 0, 0, 0, 0, //3d - 0, 0, 0, 0, 0, 0, 0, 0, //3e - 0, 0, 0, 0, 0, 0, 0, 0, //3f -}; - //////////////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(AZ_RESTRICTED_PLATFORM) #define AZ_RESTRICTED_SECTION PLATFORM_IMPL_H_SECTION_VIRTUAL_ALLOCATORS diff --git a/Code/Legacy/CrySystem/CrySystem_precompiled.h b/Code/Legacy/CrySystem/CrySystem_precompiled.h index 79fbbd92be..faa924931f 100644 --- a/Code/Legacy/CrySystem/CrySystem_precompiled.h +++ b/Code/Legacy/CrySystem/CrySystem_precompiled.h @@ -81,7 +81,6 @@ #include #include #include -#include #include diff --git a/Code/Legacy/CrySystem/Huffman.h b/Code/Legacy/CrySystem/Huffman.h index 942663095e..33f77a2829 100644 --- a/Code/Legacy/CrySystem/Huffman.h +++ b/Code/Legacy/CrySystem/Huffman.h @@ -122,24 +122,6 @@ public: void CompressInput(const uint8* const pInput, const size_t numBytes, uint8* const pOutput, size_t* const outputSize); size_t UncompressInput(const uint8* const pInput, const size_t numBytes, uint8* const pOutput, const size_t maxOutputSize); - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - - if (m_Counts != NULL) - { - pSizer->AddObject(m_Counts, sizeof(uint32), MAX_NUM_SYMBOLS); - } - if (m_TreeNodes != NULL) - { - pSizer->AddObject(m_TreeNodes, sizeof(HuffmanTreeNode), MAX_NUM_NODES); - } - if (m_Codes != NULL) - { - pSizer->AddObject(m_Codes, sizeof(HuffmanSymbolCode), MAX_NUM_CODES); - } - } - private: void ScaleCountsAndUpdateNodes(); int BuildTree(); diff --git a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp index fe87c3f784..a9e0c3d677 100644 --- a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp +++ b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.cpp @@ -37,12 +37,6 @@ namespace LegacyLevelSystem { static constexpr const char* ArchiveExtension = ".pak"; -void CLevelInfo::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(m_levelName); - pSizer->AddObject(m_levelPath); -} - ////////////////////////////////////////////////////////////////////////// bool CLevelInfo::OpenLevelPak() { @@ -829,14 +823,6 @@ void CLevelSystem::LogLoadingTime() gEnv->pLog->Log(text.c_str()); } -void CLevelSystem::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_levelInfos); - pSizer->AddObject(m_levelsFolder); - pSizer->AddObject(m_listeners); -} - ////////////////////////////////////////////////////////////////////////// void CLevelSystem::UnloadLevel() { diff --git a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.h b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.h index f77f818b84..836d2c2484 100644 --- a/Code/Legacy/CrySystem/LevelSystem/LevelSystem.h +++ b/Code/Legacy/CrySystem/LevelSystem/LevelSystem.h @@ -31,8 +31,6 @@ public: // ~ILevelInfo - void GetMemoryUsage(ICrySizer*) const; - private: bool ReadInfo(); @@ -114,8 +112,6 @@ public: // ~ILevelSystem - void GetMemoryUsage(ICrySizer* s) const; - private: float GetLastLevelLoadTime() { return m_fLastLevelLoadTime; } diff --git a/Code/Legacy/CrySystem/LocalizedStringManager.cpp b/Code/Legacy/CrySystem/LocalizedStringManager.cpp index 365c71252c..a87800899d 100644 --- a/Code/Legacy/CrySystem/LocalizedStringManager.cpp +++ b/Code/Legacy/CrySystem/LocalizedStringManager.cpp @@ -802,16 +802,6 @@ bool CLocalizedStringsManager::ReleaseLocalizationDataByTag( m_pLanguage->m_vLocalizedStrings.clear(); m_pLanguage->m_vLocalizedStrings = newVec; } - - /*LARGE_INTEGER liEnd, liFreq; - QueryPerformanceCounter(&liEnd); - QueryPerformanceFrequency(&liFreq); - - CTimeValue lockTime = CTimeValue((liEnd.QuadPart - liStart.QuadPart) * CTimeValue::TIMEVALUE_PRECISION / liFreq.QuadPart); - if (m_cvarLocalizationDebug >= 2) - { - CryLog(" ReleaseLocalizationDataByTag %s lock time %fMS", sTag, lockTime.GetMilliSeconds()); - }*/ } if (m_cvarLocalizationDebug >= 2) @@ -2418,16 +2408,6 @@ void CLocalizedStringsManager::FormatStringMessage(AZStd::string& outString, con } ////////////////////////////////////////////////////////////////////////// -int CLocalizedStringsManager::GetMemoryUsage(ICrySizer* pSizer) -{ - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_languages); - pSizer->AddObject(m_prototypeEvents); - pSizer->AddObject(m_characterNameSet); - pSizer->AddObject(m_pLanguage); - - return 0; -} #if defined (WIN32) || defined(WIN64) namespace diff --git a/Code/Legacy/CrySystem/LocalizedStringManager.h b/Code/Legacy/CrySystem/LocalizedStringManager.h index 1fba05f9ac..b1cb5b2067 100644 --- a/Code/Legacy/CrySystem/LocalizedStringManager.h +++ b/Code/Legacy/CrySystem/LocalizedStringManager.h @@ -89,8 +89,6 @@ public: void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam); // ~ISystemEventManager - int GetMemoryUsage(ICrySizer* pSizer); - void GetLoadedTags(TLocalizationTagVec& tagVec); void FreeLocalizationData(); @@ -113,17 +111,6 @@ private: AZStd::string sOriginalCharacterName; // english character name speaking via XML asset unsigned int nRow; // Number of row in XML file - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - - pSizer->AddObject(sKey); - pSizer->AddObject(sOriginalActorLine); - pSizer->AddObject(sUtf8TranslatedActorLine); - pSizer->AddObject(sOriginalText); - pSizer->AddObject(sOriginalCharacterName); - } }; struct SLanguage; @@ -194,28 +181,6 @@ private: }; AZStd::string GetTranslatedText(const SLanguage* pLanguage) const; - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - - pSizer->AddObject(sCharacterName); - - if ((flags & IS_COMPRESSED) == 0 && TranslatedText.psUtf8Uncompressed != NULL) //Number of bytes stored for compressed text is unknown, which throws this GetMemoryUsage off - { - pSizer->AddObject(*TranslatedText.psUtf8Uncompressed); - } - - pSizer->AddObject(sPrototypeSoundEvent); - - pSizer->AddObject(SoundMoods); - pSizer->AddObject(EventParameters); - - if (pEditorExtension != NULL) - { - pEditorExtension->GetMemoryUsage(pSizer); - } - } }; //Keys as CRC32. Strings previously, but these proved too large @@ -230,15 +195,6 @@ private: StringsKeyMap m_keysMap; TLocalizedStringEntries m_vLocalizedStrings; THuffmanCoders m_vEncoders; - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(sLanguage); - pSizer->AddObject(m_vLocalizedStrings); - pSizer->AddObject(m_keysMap); - pSizer->AddObject(m_vEncoders); - } }; struct SFileInfo diff --git a/Code/Legacy/CrySystem/Log.h b/Code/Legacy/CrySystem/Log.h index f3bee44283..fb683e66ef 100644 --- a/Code/Legacy/CrySystem/Log.h +++ b/Code/Legacy/CrySystem/Log.h @@ -11,6 +11,13 @@ #include #include +#include +#include +#include + +struct IConsole; +struct ICVar; +struct ISystem; ////////////////////////////////////////////////////////////////////// #if defined(ANDROID) || defined(AZ_PLATFORM_MAC) @@ -105,7 +112,6 @@ private: // ------------------------------------------------------------------- ELogType logType; bool bAdd; Destination destination; - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} }; void CheckAndPruneBackupLogs() const; @@ -193,17 +199,6 @@ private: // ------------------------------------------------------------------- #endif public: // ------------------------------------------------------------------- - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_pLogVerbosity); - pSizer->AddObject(m_pLogWriteToFile); - pSizer->AddObject(m_pLogWriteToFileVerbosity); - pSizer->AddObject(m_pLogVerbosityOverridesWriteToFile); - pSizer->AddObject(m_pLogSpamDelay); - pSizer->AddObject(m_threadSafeMsgQueue); - } // checks the verbosity of the message and returns NULL if the message must NOT be // logged, or the pointer to the part of the message that should be logged const char* CheckAgainstVerbosity(const char* pText, bool& logtofile, bool& logtoconsole, const uint8 DefaultVerbosity = 2); diff --git a/Code/Legacy/CrySystem/System.cpp b/Code/Legacy/CrySystem/System.cpp index 0f0a62f8c6..71775dbb6c 100644 --- a/Code/Legacy/CrySystem/System.cpp +++ b/Code/Legacy/CrySystem/System.cpp @@ -125,7 +125,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include "Log.h" #include "XML/xml.h" -#include "XML/ReadWriteXMLSink.h" #include "LocalizedStringManager.h" #include "XML/XmlUtils.h" @@ -340,9 +339,6 @@ CSystem::~CSystem() ////////////////////////////////////////////////////////////////////////// void CSystem::Release() { - //Disconnect the render bus - AZ::RenderNotificationsBus::Handler::BusDisconnect(); - delete this; } diff --git a/Code/Legacy/CrySystem/System.h b/Code/Legacy/CrySystem/System.h index 738ffd4bfb..9023171ea3 100644 --- a/Code/Legacy/CrySystem/System.h +++ b/Code/Legacy/CrySystem/System.h @@ -18,19 +18,22 @@ #include "CmdLine.h" #include -#include "RenderBus.h" - #include #include #include +#include +#include + namespace AzFramework { class MissingAssetLogger; } struct IConsoleCmdArgs; +struct ICVar; +struct IFFont; class CWatchdogThread; #if defined(AZ_RESTRICTED_PLATFORM) @@ -48,48 +51,11 @@ class CWatchdogThread; #if defined(WIN32) || defined(LINUX) || defined(APPLE) #define AZ_LEGACY_CRYSYSTEM_TRAIT_ALLOW_CREATE_BACKUP_LOG_FILE 1 #endif -#if defined(WIN32) || (defined(LINUX) && !defined(ANDROID)) || defined(MAC) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_DEFINE_DETECT_PROCESSOR 1 -#endif ////////////////////////////////////////////////////////////////////////// #if defined(WIN32) || defined(APPLE) || defined(LINUX) #define AZ_LEGACY_CRYSYSTEM_TRAIT_DO_PREASSERT 1 #endif -#if defined(MAC) || (defined(LINUX) && !defined(ANDROID)) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_ASM_VOLATILE_CPUID 1 -#endif -#if (defined(WIN32) && !defined(WIN64)) || (defined(LINUX) && !defined(ANDROID) && !defined(LINUX64)) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_HAS64BITEXT 1 -#endif -#if defined(WIN32) || (defined(LINUX) && !defined(ANDROID)) || defined(MAC) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_HTSUPPORTED 1 -#endif -#if defined(WIN32) || (defined(LINUX) && !defined(ANDROID)) || defined(MAC) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_HASCPUID 1 -#endif -#if defined(WIN32) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_HASAFFINITYMASK 1 -#endif - -#if defined(LINUX) || defined(APPLE) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_CRYPAK_POSIX 1 -#endif - -#if defined(WIN64) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 1 -#endif - -#if defined(WIN32) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_PACKED_PEHEADER 1 -#endif -#if defined(WIN32) || defined(LINUX) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_RENDERMEMORY_INFO 1 -#endif - -#if defined(WIN32) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_HANDLER_SYNC_AFFINITY 1 -#endif #if defined(LINUX) || defined(APPLE) #define AZ_LEGACY_CRYSYSTEM_TRAIT_FORWARD_EXCEPTION_POINTERS 1 @@ -105,18 +71,6 @@ class CWatchdogThread; #define AZ_LEGACY_CRYSYSTEM_TRAIT_DEBUGCALLSTACK_APPEND_MODULENAME 1 #endif -#if !(defined(ANDROID) || defined(IOS) || defined(LINUX)) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_IMAGEHANDLER_TIFFIO 1 -#endif - -#if 1 -#define AZ_LEGACY_CRYSYSTEM_TRAIT_JOBMANAGER_SIXWORKERTHREADS 0 -#endif - -#if defined(WIN32) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_MEMADDRESSRANGE_WINDOWS_STYLE 1 -#endif - #if 1 #define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_EXCLUDEUPDATE_ON_CONSOLE 0 #endif @@ -127,31 +81,8 @@ class CWatchdogThread; #define AZ_LEGACY_CRYSYSTEM_TRAIT_CAPTURESTACK 1 #endif -#if !defined(LINUX) && !defined(APPLE) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_SYSTEMCFG_MODULENAME 1 -#endif - -#if defined(WIN32) || defined(WIN64) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_THREADINFO_WINDOWS_STYLE 1 -#endif - -#if defined(WIN32) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_THREADTASK_EXCEPTIONS 1 -#endif ////////////////////////////////////////////////////////////////////////// -#if defined(APPLE) || defined(LINUX) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_FACTORY_REGISTRY_USE_PRINTF_FOR_FATAL 1 -#endif - -#if defined(LINUX) || defined(APPLE) -#define AZ_LEGACY_CRYSYSTEM_TRAIT_USE_FTELL_NOT_FTELLI64 1 -#endif - -#endif - -#if defined(USE_UNIXCONSOLE) || defined(USE_ANDROIDCONSOLE) || defined(USE_WINDOWSCONSOLE) || defined(USE_IOSCONSOLE) || defined(USE_NULLCONSOLE) -#define USE_DEDICATED_SERVER_CONSOLE #endif #if defined(LINUX) @@ -269,7 +200,6 @@ class CSystem , public ILoadConfigurationEntrySink , public ISystemEventListener , public IWindowMessageHandler - , public AZ::RenderNotificationsBus::Handler , public CrySystemRequestBus::Handler { public: diff --git a/Code/Legacy/CrySystem/SystemCFG.cpp b/Code/Legacy/CrySystem/SystemCFG.cpp index 0f67fdc2e1..7633a62f04 100644 --- a/Code/Legacy/CrySystem/SystemCFG.cpp +++ b/Code/Legacy/CrySystem/SystemCFG.cpp @@ -22,8 +22,6 @@ #include #include -#include "SystemCFG.h" - #if defined(AZ_RESTRICTED_PLATFORM) #undef AZ_RESTRICTED_SECTION #define SYSTEMCFG_CPP_SECTION_1 1 @@ -180,7 +178,7 @@ void CSystem::LogVersion() strftime(s, 128, "%d %b %y (%H %M %S)", today); #endif - [[maybe_unused]] const SFileVersion& ver = GetFileVersion(); + const SFileVersion& ver = GetFileVersion(); CryLogAlways("BackupNameAttachment=\" Build(%d) %s\" -- used by backup system\n", ver.v[0], s); // read by CreateBackupFile() @@ -251,122 +249,21 @@ void CSystem::LogVersion() ////////////////////////////////////////////////////////////////////////// void CSystem::LogBuildInfo() { - [[maybe_unused]] auto projectName = AZ::Utils::GetProjectName(); + auto projectName = AZ::Utils::GetProjectName(); CryLogAlways("GameName: %s", projectName.c_str()); CryLogAlways("BuildTime: " __DATE__ " " __TIME__); } - - -////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////// -class CCVarSaveDump - : public ICVarDumpSink -{ -public: - - CCVarSaveDump(FILE* pFile) - { - m_pFile = pFile; - } - - virtual void OnElementFound(ICVar* pCVar) - { - if (!pCVar) - { - return; - } - int nFlags = pCVar->GetFlags(); - if (((nFlags & VF_DUMPTODISK) && (nFlags & VF_MODIFIED)) || (nFlags & VF_WASINCONFIG)) - { - AZStd::string szValue = pCVar->GetString(); - int pos; - - pos = 1; - for (;; ) - { - pos = static_cast(szValue.find_first_of("\\", pos)); - - if (pos == AZStd::string::npos) - { - break; - } - - szValue.replace(pos, 1, "\\\\", 2); - pos += 2; - } - - // replace " with \" - pos = 1; - for (;; ) - { - pos = static_cast(szValue.find_first_of("\"", pos)); - - if (pos == AZStd::string::npos) - { - break; - } - - szValue.replace(pos, 1, "\\\"", 2); - pos += 2; - } - - AZStd::string szLine = pCVar->GetName(); - - if (pCVar->GetType() == CVAR_STRING) - { - szLine += " = \"" + szValue + "\"\r\n"; - } - else - { - szLine += " = " + szValue + "\r\n"; - } - - if (pCVar->GetFlags() & VF_WARNING_NOTUSED) - { - fputs("-- REMARK: the following was not assigned to a console variable\r\n", m_pFile); - } - - fputs(szLine.c_str(), m_pFile); - } - } - -private: // -------------------------------------------------------- - - FILE* m_pFile; // -}; - ////////////////////////////////////////////////////////////////////////// void CSystem::SaveConfiguration() { } ////////////////////////////////////////////////////////////////////////// -// system cfg -////////////////////////////////////////////////////////////////////////// -CSystemConfiguration::CSystemConfiguration(const AZStd::string& strSysConfigFilePath, CSystem* pSystem, ILoadConfigurationEntrySink* pSink, bool warnIfMissing) - : m_strSysConfigFilePath(strSysConfigFilePath) - , m_bError(false) - , m_pSink(pSink) - , m_warnIfMissing(warnIfMissing) +static bool ParseSystemConfig(const AZStd::string& strSysConfigFilePath, ILoadConfigurationEntrySink* pSink, bool warnIfMissing) { assert(pSink); - - m_pSystem = pSystem; - m_bError = !ParseSystemConfig(); -} - -////////////////////////////////////////////////////////////////////////// -CSystemConfiguration::~CSystemConfiguration() -{ -} - -////////////////////////////////////////////////////////////////////////// -bool CSystemConfiguration::ParseSystemConfig() -{ - AZStd::string filename = m_strSysConfigFilePath; + AZStd::string filename = strSysConfigFilePath; if (strlen(PathUtil::GetExt(filename.c_str())) == 0) { filename = PathUtil::ReplaceExtension(filename, "cfg"); @@ -384,7 +281,7 @@ bool CSystemConfiguration::ParseSystemConfig() // if the file is missing and its already prefixed with an alias, there is no need to look any further. if (!(file.Open(filename.c_str(), "rb", flags))) { - if (m_warnIfMissing) + if (warnIfMissing) { CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Config file %s not found!", filename.c_str()); } @@ -403,7 +300,7 @@ bool CSystemConfiguration::ParseSystemConfig() !(file.Open((AZStd::string("@assets@/config/spec/") + filename).c_str(), "rb", flags)) ) { - if (m_warnIfMissing) + if (warnIfMissing) { CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Config file %s not found!", filename.c_str()); } @@ -518,7 +415,7 @@ bool CSystemConfiguration::ParseSystemConfig() AZ::StringFunc::Replace(strValue, "\\\\", "\\"); AZ::StringFunc::Replace(strValue, "\\\"", "\""); - m_pSink->OnLoadConfigurationEntry(strKey.c_str(), strValue.c_str(), strGroup.c_str()); + pSink->OnLoadConfigurationEntry(strKey.c_str(), strValue.c_str(), strGroup.c_str()); } } } @@ -532,7 +429,7 @@ bool CSystemConfiguration::ParseSystemConfig() CryLog("Loading Config file %s (%s)", filename.c_str(), filenameLog.c_str()); - m_pSink->OnLoadConfigurationEntry_End(); + pSink->OnLoadConfigurationEntry_End(); return true; } @@ -574,7 +471,7 @@ void CSystem::LoadConfiguration(const char* sFilename, ILoadConfigurationEntrySi pSink = this; } - CSystemConfiguration tempConfig(sFilename, this, pSink, warnIfMissing); + ParseSystemConfig(sFilename, pSink, warnIfMissing); } } diff --git a/Code/Legacy/CrySystem/SystemCFG.h b/Code/Legacy/CrySystem/SystemCFG.h deleted file mode 100644 index 7ec6f1231b..0000000000 --- a/Code/Legacy/CrySystem/SystemCFG.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_CRYSYSTEM_SYSTEMCFG_H -#define CRYINCLUDE_CRYSYSTEM_SYSTEMCFG_H - -#pragma once - -#include -#include - -typedef AZStd::string SysConfigKey; -typedef AZStd::string SysConfigValue; - -////////////////////////////////////////////////////////////////////////// -class CSystemConfiguration -{ -public: - CSystemConfiguration(const AZStd::string& strSysConfigFilePath, CSystem* pSystem, ILoadConfigurationEntrySink* pSink, bool warnIfMissing = true); - ~CSystemConfiguration(); - - bool IsError() const { return m_bError; } - -private: // ---------------------------------------- - - // Returns: - // success - bool ParseSystemConfig(); - - CSystem* m_pSystem; - AZStd::string m_strSysConfigFilePath; - bool m_bError; - ILoadConfigurationEntrySink* m_pSink; // never 0 - bool m_warnIfMissing; -}; - - -#endif // CRYINCLUDE_CRYSYSTEM_SYSTEMCFG_H diff --git a/Code/Legacy/CrySystem/SystemInit.cpp b/Code/Legacy/CrySystem/SystemInit.cpp index a335dae112..85983975ce 100644 --- a/Code/Legacy/CrySystem/SystemInit.cpp +++ b/Code/Legacy/CrySystem/SystemInit.cpp @@ -1598,9 +1598,6 @@ AZ_POP_DISABLE_WARNING LoadConfiguration("client.cfg", &CVarsClientConfigSink); } - //Connect to the render bus - AZ::RenderNotificationsBus::Handler::BusConnect(); - // Send out EBus event EBUS_EVENT(CrySystemEventBus, OnCrySystemInitialized, *this, startupParams); diff --git a/Code/Legacy/CrySystem/ViewSystem/View.cpp b/Code/Legacy/CrySystem/ViewSystem/View.cpp index 36cd891e3e..ca5ef3892b 100644 --- a/Code/Legacy/CrySystem/ViewSystem/View.cpp +++ b/Code/Legacy/CrySystem/ViewSystem/View.cpp @@ -534,20 +534,6 @@ void CView::SetFrameAdditiveCameraAngles(const Ang3& addFrameAngles) m_frameAdditiveAngles = addFrameAngles; } -void CView::GetMemoryUsage(ICrySizer* s) const -{ - s->AddObject(this, sizeof(*this)); - s->AddObject(m_shakes); -} - -//void CView::Serialize(TSerialize ser) -//{ -// if (ser.IsReading()) -// { -// ResetShaking(); -// } -//} - void CView::PostSerialize() { } diff --git a/Code/Legacy/CrySystem/ViewSystem/View.h b/Code/Legacy/CrySystem/ViewSystem/View.h index 689c254897..237a2d0fa6 100644 --- a/Code/Legacy/CrySystem/ViewSystem/View.h +++ b/Code/Legacy/CrySystem/ViewSystem/View.h @@ -81,8 +81,6 @@ public: ID = shakeID; } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { /*nothing*/} }; @@ -111,8 +109,6 @@ public: CCamera& GetCamera() override { return m_camera; } const CCamera& GetCamera() const override { return m_camera; } - void GetMemoryUsage(ICrySizer* s) const; - protected: void ProcessShakeNormal(SShake* pShake, float frameTime); diff --git a/Code/Legacy/CrySystem/ViewSystem/ViewSystem.cpp b/Code/Legacy/CrySystem/ViewSystem/ViewSystem.cpp index 1d141a5e13..e83676827f 100644 --- a/Code/Legacy/CrySystem/ViewSystem/ViewSystem.cpp +++ b/Code/Legacy/CrySystem/ViewSystem/ViewSystem.cpp @@ -610,24 +610,6 @@ void CViewSystem::DebugDraw() } ////////////////////////////////////////////////////////////////////////// -void CViewSystem::GetMemoryUsage(ICrySizer* s) const -{ - SIZER_SUBCOMPONENT_NAME(s, "ViewSystem"); - s->Add(*this); - s->AddContainer(m_views); -} - -//void CViewSystem::Serialize(TSerialize ser) -//{ -// TViewMap::iterator iter = m_views.begin(); -// TViewMap::iterator iterEnd = m_views.end(); -// while (iter != iterEnd) -// { -// iter->second->Serialize(ser); -// ++iter; -// } -//} - void CViewSystem::PostSerialize() { TViewMap::iterator iter = m_views.begin(); diff --git a/Code/Legacy/CrySystem/ViewSystem/ViewSystem.h b/Code/Legacy/CrySystem/ViewSystem/ViewSystem.h index dd49e09e04..e0e4a67e9e 100644 --- a/Code/Legacy/CrySystem/ViewSystem/ViewSystem.h +++ b/Code/Legacy/CrySystem/ViewSystem/ViewSystem.h @@ -105,8 +105,6 @@ public: return stl::find_and_erase(m_listeners, pListener); } - void GetMemoryUsage(ICrySizer* s) const; - void ClearAllViews(); private: diff --git a/Code/Legacy/CrySystem/XConsole.cpp b/Code/Legacy/CrySystem/XConsole.cpp index 1cc9696a06..68cec01cc4 100644 --- a/Code/Legacy/CrySystem/XConsole.cpp +++ b/Code/Legacy/CrySystem/XConsole.cpp @@ -32,6 +32,19 @@ #include //#define DEFENCE_CVAR_HASH_LOGGING +// s should point to a buffer at least 65 chars long +inline void BitsAlpha64(uint64 n, char* s) +{ + for (int i = 0; n != 0; n >>= 1, i++) + { + if (n & 1) + { + *s++ = i < 32 ? static_cast(i + 'z' - 31) : static_cast(i + 'Z' - 63); + } + } + *s++ = '\0'; +} + static inline void AssertName([[maybe_unused]] const char* szName) { #ifdef _DEBUG @@ -567,35 +580,6 @@ ICVar* CXConsole::Register(const char* sName, int* src, int iValue, int nFlags, } -////////////////////////////////////////////////////////////////////////// -ICVar* CXConsole::RegisterCVarGroup(const char* szName, const char* szFileName) -{ - AssertName(szName); - assert(szFileName); - - // suppress cvars not starting with sys_spec_ as - // cheaters might create cvars before we created ours - if (_strnicmp(szName, "sys_spec_", 9) != 0) - { - return 0; - } - - ICVar* pCVar = stl::find_in_map(m_mapVariables, szName, NULL); - if (pCVar) - { - AZ_Error("System", false, "CVar groups should only be registered once"); - return pCVar; - } - - CXConsoleVariableCVarGroup* pCVarGroup = new CXConsoleVariableCVarGroup(this, szName, szFileName, VF_COPYNAME); - - pCVar = pCVarGroup; - - RegisterVar(pCVar, CXConsoleVariableCVarGroup::OnCVarChangeFunc); - - return pCVar; -} - ////////////////////////////////////////////////////////////////////////// ICVar* CXConsole::Register(const char* sName, float* src, float fValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc, bool allowModify) { @@ -620,7 +604,6 @@ ICVar* CXConsole::Register(const char* sName, float* src, float fValue, int nFla return pCVar; } - ////////////////////////////////////////////////////////////////////////// ICVar* CXConsole::Register(const char* sName, const char** src, const char* defaultValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc, bool allowModify) { @@ -644,7 +627,6 @@ ICVar* CXConsole::Register(const char* sName, const char** src, const char* defa return pCVar; } - ////////////////////////////////////////////////////////////////////////// ICVar* CXConsole::RegisterString(const char* sName, const char* sValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc) { @@ -705,30 +687,6 @@ ICVar* CXConsole::RegisterInt(const char* sName, int iValue, int nFlags, const c return pCVar; } - - -////////////////////////////////////////////////////////////////////////// -ICVar* CXConsole::RegisterInt64(const char* sName, int64 iValue, int nFlags, const char* help, ConsoleVarFunc pChangeFunc) -{ - AssertName(sName); - - ICVar* pCVar = stl::find_in_map(m_mapVariables, sName, NULL); - if (pCVar) - { - gEnv->pLog->Log("[CVARS]: [DUPLICATE] CXConsole::RegisterInt64(): variable [%s] is already registered", pCVar->GetName()); -#if LOG_CVAR_INFRACTIONS_CALLSTACK - gEnv->pSystem->debug_LogCallStack(); -#endif // LOG_CVAR_INFRACTIONS_CALLSTACK - return pCVar; - } - - pCVar = new CXConsoleVariableInt64(this, sName, iValue, nFlags, help); - RegisterVar(pCVar, pChangeFunc); - return pCVar; -} - - - ////////////////////////////////////////////////////////////////////////// void CXConsole::UnregisterVariable(const char* sVarName, [[maybe_unused]] bool bDelete) { @@ -2891,20 +2849,6 @@ int CXConsole::GetNumVisibleVars() return numVars; } -void CXConsole::AddCVarsToHash(ConsoleVariablesVector::const_iterator begin, ConsoleVariablesVector::const_iterator end, CCrc32& runningNameCrc32, CCrc32& runningNameValueCrc32) -{ - for (ConsoleVariablesVector::const_iterator it = begin; it <= end; ++it) - { - // add name & variable to string. We add both since adding only the value could cause - // many collisions with variables all having value 0 or all 1. - AZStd::string hashStr = it->first; - - runningNameCrc32.Add(hashStr.c_str(), hashStr.length()); - hashStr += it->second->GetDataProbeString(); - runningNameValueCrc32.Add(hashStr.c_str(), hashStr.length()); - } -} - ////////////////////////////////////////////////////////////////////////// size_t CXConsole::GetSortedVars(AZStd::vector& pszArray, const char* szPrefix) { @@ -3089,18 +3033,6 @@ inline size_t sizeOf (const char* sz) return sz ? strlen(sz) + 1 : 0; } -////////////////////////////////////////////////////////////////////////// -void CXConsole::GetMemoryUsage (class ICrySizer* pSizer) const -{ - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_sInputBuffer); - pSizer->AddObject(m_sPrevTab); - pSizer->AddObject(m_dqConsoleBuffer); - pSizer->AddObject(m_dqHistory); - pSizer->AddObject(m_mapCommands); - pSizer->AddObject(m_mapBinds); -} - ////////////////////////////////////////////////////////////////////////// void CXConsole::ConsoleLogInputResponse(const char* format, ...) { diff --git a/Code/Legacy/CrySystem/XConsole.h b/Code/Legacy/CrySystem/XConsole.h index 3ff9824e6f..200ddd85b3 100644 --- a/Code/Legacy/CrySystem/XConsole.h +++ b/Code/Legacy/CrySystem/XConsole.h @@ -13,8 +13,8 @@ #pragma once #include -#include #include "Timer.h" +#include #include #include @@ -22,10 +22,12 @@ #include #include +#include +#include //forward declaration struct INetwork; class CSystem; - +struct IFFont; #define MAX_HISTORY_ENTRIES 50 #define LINE_BORDER 10 @@ -53,12 +55,6 @@ struct CConsoleCommand : m_func(0) , m_nFlags(0) {} size_t sizeofThis () const {return sizeof(*this) + m_sName.capacity() + 1 + m_sCommand.capacity() + 1; } - void GetMemoryUsage (class ICrySizer* pSizer) const - { - pSizer->AddObject(m_sName); - pSizer->AddObject(m_sCommand); - pSizer->AddObject(m_sHelp); - } }; ////////////////////////////////////////////////////////////////////////// @@ -136,71 +132,68 @@ public: void Paste(); // interface IConsole --------------------------------------------------------- - virtual void Release(); + void Release() override; - virtual void Init(ISystem* pSystem); - virtual ICVar* RegisterString(const char* sName, const char* sValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0); - virtual ICVar* RegisterInt(const char* sName, int iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0); - virtual ICVar* RegisterInt64(const char* sName, int64 iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0); - virtual ICVar* RegisterFloat(const char* sName, float fValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0); - virtual ICVar* Register(const char* name, float* src, float defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true); - virtual ICVar* Register(const char* name, int* src, int defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true); - virtual ICVar* Register(const char* name, const char** src, const char* defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true); - virtual ICVar* Register(ICVar* pVar) { RegisterVar(pVar); return pVar; } + void Init(ISystem* pSystem) override; + ICVar* RegisterString(const char* sName, const char* sValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) override; + ICVar* RegisterInt(const char* sName, int iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) override; + ICVar* RegisterFloat(const char* sName, float fValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) override; + ICVar* Register(const char* name, float* src, float defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true) override; + ICVar* Register(const char* name, int* src, int defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true) override; + ICVar* Register(const char* name, const char** src, const char* defaultvalue, int flags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true) override; - virtual void UnregisterVariable(const char* sVarName, bool bDelete = false); - virtual void SetScrollMax(int value); - virtual void AddOutputPrintSink(IOutputPrintSink* inpSink); - virtual void RemoveOutputPrintSink(IOutputPrintSink* inpSink); - virtual void ShowConsole(bool show, int iRequestScrollMax = -1); - virtual void DumpCVars(ICVarDumpSink* pCallback, unsigned int nFlagsFilter = 0); - virtual void DumpKeyBinds(IKeyBindDumpSink* pCallback); - virtual void CreateKeyBind(const char* sCmd, const char* sRes); - virtual const char* FindKeyBind(const char* sCmd) const; - virtual void SetImage(ITexture* pImage, bool bDeleteCurrent); - virtual inline ITexture* GetImage() { return m_pImage; } - virtual void StaticBackground(bool bStatic) { m_bStaticBackground = bStatic; } - virtual bool GetLineNo(int indwLineNo, char* outszBuffer, int indwBufferSize) const; - virtual int GetLineCount() const; - virtual ICVar* GetCVar(const char* name); - virtual char* GetVariable(const char* szVarName, const char* szFileName, const char* def_val); - virtual float GetVariable(const char* szVarName, const char* szFileName, float def_val); - virtual void PrintLine(const char* s); - virtual void PrintLinePlus(const char* s); - virtual bool GetStatus(); - virtual void Clear(); - virtual void Update(); - virtual void Draw(); - virtual bool AddCommand(const char* sCommand, ConsoleCommandFunc func, int nFlags = 0, const char* sHelp = NULL); - virtual bool AddCommand(const char* sName, const char* sScriptFunc, int nFlags = 0, const char* sHelp = NULL); - virtual void RemoveCommand(const char* sName); - virtual void ExecuteString(const char* command, bool bSilentMode, bool bDeferExecution = false); - virtual void ExecuteConsoleCommand(const char* command) override; - virtual void ResetCVarsToDefaults() override; - virtual void Exit(const char* command, ...) PRINTF_PARAMS(2, 3); - virtual bool IsOpened(); - virtual int GetNumVars(); - virtual int GetNumVisibleVars(); - virtual size_t GetSortedVars(AZStd::vector& pszArray, const char* szPrefix = 0); - virtual void FindVar(const char* substr); - virtual const char* AutoComplete(const char* substr); - virtual const char* AutoCompletePrev(const char* substr); - virtual const char* ProcessCompletion(const char* szInputBuffer); - virtual void RegisterAutoComplete(const char* sVarOrCommand, IConsoleArgumentAutoComplete* pArgAutoComplete); - virtual void UnRegisterAutoComplete(const char* sVarOrCommand); - virtual void ResetAutoCompletion(); - virtual void GetMemoryUsage (ICrySizer* pSizer) const; - virtual void ResetProgressBar(int nProgressRange); - virtual void TickProgressBar(); - virtual void SetLoadingImage(const char* szFilename); - virtual void AddConsoleVarSink(IConsoleVarSink* pSink); - virtual void RemoveConsoleVarSink(IConsoleVarSink* pSink); - virtual const char* GetHistoryElement(bool bUpOrDown); - virtual void AddCommandToHistory(const char* szCommand); - virtual void SetInputLine(const char* szLine); - virtual void LoadConfigVar(const char* sVariable, const char* sValue); - virtual void EnableActivationKey(bool bEnable); - virtual void SetClientDataProbeString(const char* pName, const char* pValue); + void UnregisterVariable(const char* sVarName, bool bDelete = false) override; + void SetScrollMax(int value) override; + void AddOutputPrintSink(IOutputPrintSink* inpSink) override; + void RemoveOutputPrintSink(IOutputPrintSink* inpSink) override; + void ShowConsole(bool show, int iRequestScrollMax = -1) override; + void DumpCVars(ICVarDumpSink* pCallback, unsigned int nFlagsFilter = 0) override; + void DumpKeyBinds(IKeyBindDumpSink* pCallback) override; + void CreateKeyBind(const char* sCmd, const char* sRes) override; + const char* FindKeyBind(const char* sCmd) const override; + void SetImage(ITexture* pImage, bool bDeleteCurrent) override; + inline ITexture* GetImage() override { return m_pImage; } + void StaticBackground(bool bStatic) override { m_bStaticBackground = bStatic; } + bool GetLineNo(int indwLineNo, char* outszBuffer, int indwBufferSize) const override; + int GetLineCount() const override; + ICVar* GetCVar(const char* name) override; + char* GetVariable(const char* szVarName, const char* szFileName, const char* def_val) override; + float GetVariable(const char* szVarName, const char* szFileName, float def_val) override; + void PrintLine(const char* s) override; + void PrintLinePlus(const char* s) override; + bool GetStatus() override; + void Clear() override; + void Update() override; + void Draw() override; + bool AddCommand(const char* sCommand, ConsoleCommandFunc func, int nFlags = 0, const char* sHelp = NULL) override; + bool AddCommand(const char* sName, const char* sScriptFunc, int nFlags = 0, const char* sHelp = NULL) override; + void RemoveCommand(const char* sName) override; + void ExecuteString(const char* command, bool bSilentMode, bool bDeferExecution = false) override; + void ExecuteConsoleCommand(const char* command) override; + void ResetCVarsToDefaults() override; + void Exit(const char* command, ...) override PRINTF_PARAMS(2, 3); + bool IsOpened() override; + int GetNumVars() override; + int GetNumVisibleVars() override; + size_t GetSortedVars(AZStd::vector& pszArray, const char* szPrefix = 0) override; + void FindVar(const char* substr); + const char* AutoComplete(const char* substr) override; + const char* AutoCompletePrev(const char* substr) override; + const char* ProcessCompletion(const char* szInputBuffer) override; + void RegisterAutoComplete(const char* sVarOrCommand, IConsoleArgumentAutoComplete* pArgAutoComplete) override; + void UnRegisterAutoComplete(const char* sVarOrCommand) override; + void ResetAutoCompletion() override; + void ResetProgressBar(int nProgressRange) override; + void TickProgressBar() override; + void SetLoadingImage(const char* szFilename) override; + void AddConsoleVarSink(IConsoleVarSink* pSink) override; + void RemoveConsoleVarSink(IConsoleVarSink* pSink) override; + const char* GetHistoryElement(bool bUpOrDown) override; + void AddCommandToHistory(const char* szCommand) override; + void SetInputLine(const char* szLine) override; + void LoadConfigVar(const char* sVariable, const char* sValue) override; + void EnableActivationKey(bool bEnable) override; + void SetClientDataProbeString(const char* pName, const char* pValue) override; // InputChannelEventListener / InputTextEventListener bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override; @@ -208,7 +201,7 @@ public: // interface IRemoteConsoleListener ------------------------------------------------------------------ - virtual void OnConsoleCommand(const char* cmd); + void OnConsoleCommand(const char* cmd) override; // interface IConsoleVarSink ---------------------------------------------------------------------- @@ -222,10 +215,6 @@ public: ////////////////////////////////////////////////////////////////////////// - // Returns - // 0 if the operation failed - ICVar* RegisterCVarGroup(const char* sName, const char* szFileName); - void SetProcessingGroup(bool isGroup) { m_bIsProcessingGroup = isGroup; } bool GetIsProcessingGroup(void) const { return m_bIsProcessingGroup; } @@ -290,7 +279,6 @@ private: // ---------------------------------------------------------- void AddCheckedCVar(ConsoleVariablesVector& vector, const ConsoleVariablesVector::value_type& value); void RemoveCheckedCVar(ConsoleVariablesVector& vector, const ConsoleVariablesVector::value_type& value); - static void AddCVarsToHash(ConsoleVariablesVector::const_iterator begin, ConsoleVariablesVector::const_iterator end, CCrc32& runningNameCrc32, CCrc32& runningNameValueCrc32); static bool CVarNameLess(const std::pair& lhs, const std::pair& rhs); void PostLine(const char* lineOfText, size_t len); diff --git a/Code/Legacy/CrySystem/XConsoleVariable.cpp b/Code/Legacy/CrySystem/XConsoleVariable.cpp index efd5ecd495..31fea250f6 100644 --- a/Code/Legacy/CrySystem/XConsoleVariable.cpp +++ b/Code/Legacy/CrySystem/XConsoleVariable.cpp @@ -6,10 +6,8 @@ * */ - // Description : implementation of the CXConsoleVariable class. - #include "CrySystem_precompiled.h" #include "XConsole.h" #include "XConsoleVariable.h" @@ -19,6 +17,87 @@ #include +namespace +{ + using stack_string = AZStd::fixed_string<512>; + + uint64 AlphaBit64(char c) + { + return (c >= 'a' && c <= 'z' ? 1U << (c - 'z' + 31) : 0) | + (c >= 'A' && c <= 'Z' ? 1LL << (c - 'Z' + 63) : 0); + } + + int64 TextToInt64(const char* s, int64 nCurrent, bool bBitfield) + { + int64 nValue = 0; + if (s) + { + char* e; + if (bBitfield) + { + // Bit manipulation. + if (*s == '^') + // Bit number +#if defined(_MSC_VER) + { + nValue = 1LL << _strtoi64(++s, &e, 10); + } +#else + { + nValue = 1LL << strtoll(++s, &e, 10); + } +#endif + else + // Full number +#if defined(_MSC_VER) + { + nValue = _strtoi64(s, &e, 10); + } +#else + { + nValue = strtoll(s, &e, 10); + } +#endif + // Check letter codes. + for (; (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z'); e++) + { + nValue |= AlphaBit64(*e); + } + + if (*e == '+') + { + nValue = nCurrent | nValue; + } + else if (*e == '-') + { + nValue = nCurrent & ~nValue; + } + else if (*e == '^') + { + nValue = nCurrent ^ nValue; + } + } + else +#if defined(_MSC_VER) + { + nValue = _strtoi64(s, &e, 10); + } +#else + { + nValue = strtoll(s, &e, 10); + } +#endif + } + return nValue; + } + + int TextToInt(const char* s, int nCurrent, bool bBitfield) + { + return (int)TextToInt64(s, nCurrent, bBitfield); + } + +} // namespace + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -53,7 +132,6 @@ CXConsoleVariableBase::CXConsoleVariableBase(CXConsole* pConsole, const char* sN } } - ////////////////////////////////////////////////////////////////////////// CXConsoleVariableBase::~CXConsoleVariableBase() { @@ -78,10 +156,8 @@ void CXConsoleVariableBase::ForceSet(const char* s) m_nFlags |= oldFlags; } - - ////////////////////////////////////////////////////////////////////////// -void CXConsoleVariableBase::ClearFlags (int flags) +void CXConsoleVariableBase::ClearFlags(int flags) { m_nFlags &= ~flags; } @@ -121,7 +197,7 @@ void CXConsoleVariableBase::SetOnChangeCallback(ConsoleVarFunc pChangeFunc) m_pChangeFunc = pChangeFunc; } -uint64 CXConsoleVariableBase::AddOnChangeFunctor(const SFunctor& pChangeFunctor) +uint64 CXConsoleVariableBase::AddOnChangeFunctor(const AZStd::function& pChangeFunctor) { static int uniqueIdGenerator = 0; int newId = uniqueIdGenerator++; @@ -144,7 +220,7 @@ void CXConsoleVariableBase::CallOnChangeFunctions() const size_t nTotal(m_changeFunctors.size()); for (size_t nCount = 0; nCount < nTotal; ++nCount) { - m_changeFunctors[nCount].second.Call(); + m_changeFunctors[nCount].second(); } } @@ -168,535 +244,325 @@ bool CXConsoleVariableBase::HasCustomLimits() return m_hasCustomLimits; } -void CXConsoleVariableCVarGroup::OnLoadConfigurationEntry(const char* szKey, const char* szValue, const char* szGroup) +const char* CXConsoleVariableBase::GetDataProbeString() const { - assert(szGroup); - assert(szKey); - assert(szValue); - - bool bCheckIfInDefault = false; - - SCVarGroup* pGrp = 0; - - if (azstricmp(szGroup, "default") == 0) // needs to be before the other groups + if (gEnv->IsDedicated() && m_pDataProbeString) { - pGrp = &m_CVarGroupDefault; - - // if(azstricmp(GetName(),szKey)==0) - if (*szKey == 0) - { - m_sDefaultValue = szValue; - int iGrpValue = atoi(szValue); - - // if default state is not part of the mentioned states generate this state, so GetIRealVal() can return this state as well - if (m_CVarGroupStates.find(iGrpValue) == m_CVarGroupStates.end()) - { - m_CVarGroupStates[iGrpValue] = new SCVarGroup; - } - - return; - } - } - else - { - int iGrp; - - if (azsscanf(szGroup, "%d", &iGrp) == 1) - { - if (m_CVarGroupStates.find(iGrp) == m_CVarGroupStates.end()) - { - m_CVarGroupStates[iGrp] = new SCVarGroup; - } - - pGrp = m_CVarGroupStates[iGrp]; - } - else - { - gEnv->pLog->LogError("[CVARS]: [MISSING] [%s] is not a registered console variable group", szGroup); -#if LOG_CVAR_INFRACTIONS_CALLSTACK - gEnv->pSystem->debug_LogCallStack(); -#endif // LOG_CVAR_INFRACTIONS_CALLSTACK - return; - } - - if (*szKey == 0) - { - assert(0); // =%d only expected in default section - return; - } - } - - - if (pGrp) - { - if (pGrp->m_KeyValuePair.find(szKey) != pGrp->m_KeyValuePair.end()) - { - gEnv->pLog->LogError("[CVARS]: [DUPLICATE] [%s] specified multiple times in console variable group [%s] = [%s]", szKey, GetName(), szGroup); - bCheckIfInDefault = true; - } - - pGrp->m_KeyValuePair[szKey] = szValue; - - if (bCheckIfInDefault) - { - if (m_CVarGroupDefault.m_KeyValuePair.find(szKey) == m_CVarGroupDefault.m_KeyValuePair.end()) - { - gEnv->pLog->LogError("[CVARS]: [MISSING] [%s] specified in console variable group [%s] = [%s], but missing from default group", szKey, GetName(), szGroup); - } - } + return m_pDataProbeString; } + return GetOwnDataProbeString(); } - -void CXConsoleVariableCVarGroup::OnLoadConfigurationEntry_End() +void CXConsoleVariableString::Set(const char* s) { - if (!m_sDefaultValue.empty()) - { - gEnv->pConsole->LoadConfigVar(GetName(), m_sDefaultValue.c_str()); - m_sDefaultValue.clear(); - } -} - - -CXConsoleVariableCVarGroup::CXConsoleVariableCVarGroup(CXConsole* pConsole, const char* sName, const char* szFileName, int nFlags) - : CXConsoleVariableInt(pConsole, sName, 0, nFlags, 0) -{ - gEnv->pSystem->LoadConfiguration(szFileName, this); -} - - -AZStd::string CXConsoleVariableCVarGroup::GetDetailedInfo() const -{ - AZStd::string sRet = GetName(); - - sRet += " ["; - - { - TCVarGroupStateMap::const_iterator it, end = m_CVarGroupStates.end(); - - for (it = m_CVarGroupStates.begin(); it != end; ++it) - { - if (it != m_CVarGroupStates.begin()) - { - sRet += "/"; - } - - char szNum[10]; - - azsprintf(szNum, "%d", it->first); - - sRet += szNum; - } - } - - sRet += "/default] [current]:\n"; - - - std::map::const_iterator it, end = m_CVarGroupDefault.m_KeyValuePair.end(); - - for (it = m_CVarGroupDefault.m_KeyValuePair.begin(); it != end; ++it) - { - const AZStd::string& rKey = it->first; - - sRet += " ... "; - sRet += rKey; - sRet += " = "; - - TCVarGroupStateMap::const_iterator it2, end2 = m_CVarGroupStates.end(); - - for (it2 = m_CVarGroupStates.begin(); it2 != end2; ++it2) - { - sRet += GetValueSpec(rKey, &(it2->first)); - sRet += "/"; - } - sRet += GetValueSpec(rKey); - ICVar* pCVar = gEnv->pConsole->GetCVar(rKey.c_str()); - if (pCVar) - { - sRet += " ["; - sRet += pCVar->GetString(); - sRet += "]"; - } - - sRet += "\n"; - } - - return sRet; -} - - - -const char* CXConsoleVariableCVarGroup::GetHelp() -{ - if (m_psHelp) - { - delete m_psHelp; - m_psHelp = NULL; - } - - // create help on demand - AZStd::string sRet = "Console variable group to apply settings to multiple variables\n\n"; - - sRet += GetDetailedInfo(); - - m_psHelp = new char[sRet.size() + 1]; - azstrcpy(m_psHelp, sRet.size() + 1, &sRet[0]); - - return m_psHelp; -} - - - -void CXConsoleVariableCVarGroup::DebugLog(const int iExpectedValue, const ICVar::EConsoleLogMode mode) const -{ - TCVarGroupStateMap::const_iterator it, end = m_CVarGroupStates.end(); - - SCVarGroup* pCurrentGrp = 0; - { - TCVarGroupStateMap::const_iterator itCurrentGrp = m_CVarGroupStates.find(iExpectedValue); - - if (itCurrentGrp != end) - { - pCurrentGrp = itCurrentGrp->second; - } - } - - // try the current state - if (TestCVars(pCurrentGrp, mode)) + if (!s) { return; } + + if ((m_sValue == s) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + if (m_pConsole->OnBeforeVarChange(this, s)) + { + m_nFlags |= VF_MODIFIED; + { + m_sValue = s; + } + + CallOnChangeFunctions(); + + m_pConsole->OnAfterVarChange(this); + } } - -int CXConsoleVariableCVarGroup::GetRealIVal() const +void CXConsoleVariableString::Set(float f) { - TCVarGroupStateMap::const_iterator it, end = m_CVarGroupStates.end(); + stack_string s = stack_string::format("%g", f); - int iValue = GetIVal(); - - SCVarGroup* pCurrentGrp = 0; + if ((m_sValue == s.c_str()) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) { - TCVarGroupStateMap::const_iterator itCurrentGrp = m_CVarGroupStates.find(iValue); - - if (itCurrentGrp != end) - { - pCurrentGrp = itCurrentGrp->second; - } + return; } - // first try the current state - if (TestCVars(pCurrentGrp)) - { - return iValue; - } - - // then all other - for (it = m_CVarGroupStates.begin(); it != end; ++it) - { - SCVarGroup* pLocalGrp = it->second; - - if (pLocalGrp == pCurrentGrp) - { - continue; - } - - int iLocalState = it->first; - - if (TestCVars(pLocalGrp)) - { - return iLocalState; - } - } - - return -1; // no state found that represent the current one + m_nFlags |= VF_MODIFIED; + Set(s.c_str()); } -void CXConsoleVariableCVarGroup::Set(const int i) +void CXConsoleVariableString::Set(int i) { - if (i == m_iValue) + stack_string s = stack_string::format("%d", i); + + if ((m_sValue == s.c_str()) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) { - SCVarGroup* pCurrentGrp = 0; - TCVarGroupStateMap::const_iterator itCurrentGrp = m_CVarGroupStates.find(m_iValue); - - if (itCurrentGrp != m_CVarGroupStates.end()) - { - pCurrentGrp = itCurrentGrp->second; - } - - if (TestCVars(pCurrentGrp)) - { - // All cvars in this group match the current state - no further action is necessary - return; - } + return; } - char sTemp[128]; - azsprintf(sTemp, "%d", i); + m_nFlags |= VF_MODIFIED; + Set(s.c_str()); +} - bool wasProcessingGroup = m_pConsole->GetIsProcessingGroup(); - m_pConsole->SetProcessingGroup(true); - if (m_pConsole->OnBeforeVarChange(this, sTemp)) +const char* CXConsoleVariableInt::GetString() const +{ + static char szReturnString[256]; + + sprintf_s(szReturnString, "%d", GetIVal()); + return szReturnString; +} + +void CXConsoleVariableInt::Set(const char* s) +{ + int nValue = TextToInt(s, m_iValue, (m_nFlags & VF_BITFIELD) != 0); + + Set(nValue); +} + +void CXConsoleVariableInt::Set(float f) +{ + Set((int)f); +} + +void CXConsoleVariableInt::Set(int i) +{ + if (i == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + stack_string s = stack_string::format("%d", i); + + if (m_pConsole->OnBeforeVarChange(this, s.c_str())) { m_nFlags |= VF_MODIFIED; m_iValue = i; CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); } - m_pConsole->SetProcessingGroup(wasProcessingGroup); - - // Useful for debugging cvar groups - //CryLogAlways("[CVARS]: CXConsoleVariableCVarGroup::Set() Group %s in state %d (wanted %d)", GetName(), m_iValue, i); } - -CXConsoleVariableCVarGroup::~CXConsoleVariableCVarGroup() +const char* CXConsoleVariableIntRef::GetString() const { - TCVarGroupStateMap::iterator it, end = m_CVarGroupStates.end(); + static char szReturnString[256]; - for (it = m_CVarGroupStates.begin(); it != end; ++it) - { - SCVarGroup* pGrp = it->second; - - delete pGrp; - } - - delete m_psHelp; + sprintf_s(szReturnString, "%d", m_iValue); + return szReturnString; } - -void CXConsoleVariableCVarGroup::OnCVarChangeFunc(ICVar* pVar) +void CXConsoleVariableIntRef::Set(const char* s) { - CXConsoleVariableCVarGroup* pThis = (CXConsoleVariableCVarGroup*)pVar; - - int iValue = pThis->GetIVal(); - - TCVarGroupStateMap::const_iterator itGrp = pThis->m_CVarGroupStates.find(iValue); - - SCVarGroup* pGrp = 0; - - if (itGrp != pThis->m_CVarGroupStates.end()) + int nValue = TextToInt(s, m_iValue, (m_nFlags & VF_BITFIELD) != 0); + if (nValue == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) { - pGrp = itGrp->second; + return; } - if (pGrp) + if (m_pConsole->OnBeforeVarChange(this, s)) { - pThis->ApplyCVars(*pGrp); - } + m_nFlags |= VF_MODIFIED; + m_iValue = nValue; - pThis->ApplyCVars(pThis->m_CVarGroupDefault, pGrp); + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } } - -bool CXConsoleVariableCVarGroup::TestCVars(const SCVarGroup* pGroup, const ICVar::EConsoleLogMode mode) const +void CXConsoleVariableIntRef::Set(float f) { - if (pGroup) + if ((int)f == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) { - if (!TestCVars(*pGroup, mode)) + return; + } + + char sTemp[128]; + sprintf_s(sTemp, "%g", f); + + if (m_pConsole->OnBeforeVarChange(this, sTemp)) + { + m_nFlags |= VF_MODIFIED; + m_iValue = (int)f; + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableIntRef::Set(int i) +{ + if (i == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + char sTemp[128]; + sprintf_s(sTemp, "%d", i); + + if (m_pConsole->OnBeforeVarChange(this, sTemp)) + { + m_nFlags |= VF_MODIFIED; + m_iValue = i; + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +const char* CXConsoleVariableFloat::GetString() const +{ + static char szReturnString[256]; + + sprintf_s(szReturnString, "%g", m_fValue); // %g -> "2.01", %f -> "2.01000" + return szReturnString; +} + +void CXConsoleVariableFloat::Set(const char* s) +{ + float fValue = 0; + if (s) + { + fValue = (float)atof(s); + } + + if (fValue == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + if (m_pConsole->OnBeforeVarChange(this, s)) + { + m_nFlags |= VF_MODIFIED; + m_fValue = fValue; + + CallOnChangeFunctions(); + + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableFloat::Set(float f) +{ + if (f == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + stack_string s = stack_string::format("%g", f); + + if (m_pConsole->OnBeforeVarChange(this, s.c_str())) + { + m_nFlags |= VF_MODIFIED; + m_fValue = f; + + CallOnChangeFunctions(); + + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableFloat::Set(int i) +{ + if ((float)i == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + char sTemp[128]; + sprintf_s(sTemp, "%d", i); + + if (m_pConsole->OnBeforeVarChange(this, sTemp)) + { + m_nFlags |= VF_MODIFIED; + m_fValue = (float)i; + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +const char* CXConsoleVariableFloatRef::GetString() const +{ + static char szReturnString[256]; + + sprintf_s(szReturnString, "%g", m_fValue); + return szReturnString; +} + +void CXConsoleVariableFloatRef::Set(const char *s) +{ + float fValue = 0; + if (s) + { + fValue = (float)atof(s); + } + if (fValue == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + if (m_pConsole->OnBeforeVarChange(this, s)) + { + m_nFlags |= VF_MODIFIED; + m_fValue = fValue; + + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableFloatRef::Set(float f) +{ + if (f == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + char sTemp[128]; + sprintf_s(sTemp, "%g", f); + + if (m_pConsole->OnBeforeVarChange(this, sTemp)) + { + m_nFlags |= VF_MODIFIED; + m_fValue = f; + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableFloatRef::Set(int i) +{ + if ((float)i == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + char sTemp[128]; + sprintf_s(sTemp, "%d", i); + + if (m_pConsole->OnBeforeVarChange(this, sTemp)) + { + m_nFlags |= VF_MODIFIED; + m_fValue = (float)i; + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); + } +} + +void CXConsoleVariableStringRef::Set(const char *s) +{ + if ((m_sValue == s) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) + { + return; + } + + if (m_pConsole->OnBeforeVarChange(this, s)) + { + m_nFlags |= VF_MODIFIED; { - return false; - } - } - - if (!TestCVars(m_CVarGroupDefault, mode, pGroup)) - { - return false; - } - - return true; -} - -bool CXConsoleVariableCVarGroup::TestCVars(const SCVarGroup& rGroup, const ICVar::EConsoleLogMode mode, const SCVarGroup* pExclude) const -{ - bool bRet = true; - std::map::const_iterator it, end = rGroup.m_KeyValuePair.end(); - - for (it = rGroup.m_KeyValuePair.begin(); it != end; ++it) - { - const AZStd::string& rKey = it->first; - const AZStd::string& rValue = it->second; - - if (pExclude) - { - if (pExclude->m_KeyValuePair.find(rKey) != pExclude->m_KeyValuePair.end()) - { - continue; - } + m_sValue = s; + m_userPtr = m_sValue.c_str(); } - ICVar* pVar = gEnv->pConsole->GetCVar(rKey.c_str()); - - if (pVar) - { - if (pVar->GetFlags() & VF_CVARGRP_IGNOREINREALVAL) // Ignore the cvars which change often and shouldn't be used to determine state - { - continue; - } - - bool bOk = true; - - // compare exact type, - // simple string comparison would fail on some comparisons e.g. 2.0 == 2 - // and GetString() for int and float return pointer to shared array so this - // can cause problems - switch (pVar->GetType()) - { - case CVAR_INT: - { - int iVal; - if (azsscanf(rValue.c_str(), "%d", &iVal) == 1) - { - if (pVar->GetIVal() != atoi(rValue.c_str())) - { - bOk = false; - break; - } - } - - if (pVar->GetIVal() != pVar->GetRealIVal()) - { - bOk = false; - break; - } - } - break; - case CVAR_FLOAT: - { - float fVal; - if (azsscanf(rValue.c_str(), "%f", &fVal) == 1) - { - if (pVar->GetFVal() != fVal) - { - bOk = false; - break; - } - } - } - break; - case CVAR_STRING: - if (rValue != pVar->GetString()) - { - bOk = false; - break; - } - break; - default: - assert(0); - } - - if (!bOk) - { - if (mode == ICVar::eCLM_Off) - { - return false; // exit as early as possible - } - bRet = false; // exit with same return code but log all differences - - if (strcmp(pVar->GetString(), rValue.c_str()) != 0) - { - switch (mode) - { - case ICVar::eCLM_ConsoleAndFile: - CryLog("[CVARS]: $3[FAIL] [%s] = $6[%s] $4(expected [%s] in group [%s] = [%s])", rKey.c_str(), pVar->GetString(), rValue.c_str(), GetName(), GetString()); - break; - - case ICVar::eCLM_FileOnly: - case ICVar::eCLM_FullInfo: - gEnv->pLog->LogToFile("[CVARS]: [FAIL] [%s] = [%s] (expected [%s] in group [%s] = [%s])", rKey.c_str(), pVar->GetString(), rValue.c_str(), GetName(), GetString()); - break; - - default: - assert(0); - } - } - else if (mode == ICVar::eCLM_FullInfo) - { - gEnv->pLog->LogToFile("[CVARS]: [FAIL] [%s] = [%s] (expected [%s] in group [%s] = [%s])", rKey.c_str(), pVar->GetString(), rValue.c_str(), GetName(), GetString()); - } - - pVar->DebugLog(pVar->GetIVal(), mode); // recursion - } - - if (pVar->GetFlags() & (VF_CHEAT | VF_CHEAT_ALWAYS_CHECK | VF_CHEAT_NOCHECK)) - { - // either VF_CHEAT should be removed or the var should be not part of the CVarGroup - gEnv->pLog->LogError("[CVARS]: [%s] is cheat protected; referenced in console variable group [%s] = [%s] ", rKey.c_str(), GetName(), GetString()); - } - } - else - { - // Do not warn about D3D registered cvars, which carry the prefix "q_", as they are not actually registered with the cvar system. - if (strcmp(rKey.c_str(), "q") == -1) - { - gEnv->pLog->LogError("[CVARS]: [MISSING] [%s] is not a registered console variable; referenced when testing console variable group [%s] = [%s]", rKey.c_str(), GetName(), GetString()); - } - } + CallOnChangeFunctions(); + m_pConsole->OnAfterVarChange(this); } - - return bRet; } - - - -AZStd::string CXConsoleVariableCVarGroup::GetValueSpec(const AZStd::string& sKey, const int* pSpec) const -{ - if (pSpec) - { - TCVarGroupStateMap::const_iterator itGrp = m_CVarGroupStates.find(*pSpec); - - if (itGrp != m_CVarGroupStates.end()) - { - const SCVarGroup* pGrp = itGrp->second; - - // check in spec - std::map::const_iterator it = pGrp->m_KeyValuePair.find(sKey); - - if (it != pGrp->m_KeyValuePair.end()) - { - return it->second; - } - } - } - - // check in default - std::map::const_iterator it = m_CVarGroupDefault.m_KeyValuePair.find(sKey); - - if (it != m_CVarGroupDefault.m_KeyValuePair.end()) - { - return it->second; - } - - assert(0); // internal error - return ""; -} - -void CXConsoleVariableCVarGroup::ApplyCVars(const SCVarGroup& rGroup, const SCVarGroup* pExclude) -{ - std::map::const_iterator it, end = rGroup.m_KeyValuePair.end(); - - bool wasProcessingGroup = m_pConsole->GetIsProcessingGroup(); - m_pConsole->SetProcessingGroup(true); - - for (it = rGroup.m_KeyValuePair.begin(); it != end; ++it) - { - const AZStd::string& rKey = it->first; - - if (pExclude) - { - if (pExclude->m_KeyValuePair.find(rKey) != pExclude->m_KeyValuePair.end()) - { - continue; - } - } - - // Useful for debugging cvar groups - //CryLogAlways("[CVARS]: [APPLY] ([%s]) [%s] = [%s]", GetName(), rKey.c_str(), it->second.c_str()); - - m_pConsole->LoadConfigVar(rKey.c_str(), it->second.c_str()); - } - - m_pConsole->SetProcessingGroup(wasProcessingGroup); -} - diff --git a/Code/Legacy/CrySystem/XConsoleVariable.h b/Code/Legacy/CrySystem/XConsoleVariable.h index f761287b41..cb8bdbb4ad 100644 --- a/Code/Legacy/CrySystem/XConsoleVariable.h +++ b/Code/Legacy/CrySystem/XConsoleVariable.h @@ -6,86 +6,13 @@ * */ - -#ifndef CRYINCLUDE_CRYSYSTEM_XCONSOLEVARIABLE_H -#define CRYINCLUDE_CRYSYSTEM_XCONSOLEVARIABLE_H #pragma once +#include #include -#include "BitFiddling.h" -#include "SFunctor.h" +#include class CXConsole; -typedef AZStd::fixed_string<512> stack_string; - -inline int64 TextToInt64(const char* s, int64 nCurrent, bool bBitfield) -{ - int64 nValue = 0; - if (s) - { - char* e; - if (bBitfield) - { - // Bit manipulation. - if (*s == '^') - // Bit number -#if defined(_MSC_VER) - { - nValue = 1LL << _strtoi64(++s, &e, 10); - } -#else - { - nValue = 1LL << strtoll(++s, &e, 10); - } -#endif - else - // Full number -#if defined(_MSC_VER) - { - nValue = _strtoi64(s, &e, 10); - } -#else - { - nValue = strtoll(s, &e, 10); - } -#endif - // Check letter codes. - for (; (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z'); e++) - { - nValue |= AlphaBit64(*e); - } - - if (*e == '+') - { - nValue = nCurrent | nValue; - } - else if (*e == '-') - { - nValue = nCurrent & ~nValue; - } - else if (*e == '^') - { - nValue = nCurrent ^ nValue; - } - } - else -#if defined(_MSC_VER) - { - nValue = _strtoi64(s, &e, 10); - } -#else - { - nValue = strtoll(s, &e, 10); - } -#endif - } - return nValue; -} - -inline int TextToInt(const char* s, int nCurrent, bool bBitfield) -{ - return (int)TextToInt64(s, nCurrent, bBitfield); -} class CXConsoleVariableBase : public ICVar @@ -107,7 +34,7 @@ public: virtual void Release(); virtual void ForceSet(const char* s); virtual void SetOnChangeCallback(ConsoleVarFunc pChangeFunc); - virtual uint64 AddOnChangeFunctor(const SFunctor& pChangeFunctor) override; + virtual uint64 AddOnChangeFunctor(const AZStd::function& pChangeFunctor) override; virtual ConsoleVarFunc GetOnChangeCallback() const; virtual bool ShouldReset() const { return (m_nFlags & VF_RESETTABLE) != 0; } @@ -133,14 +60,7 @@ public: m_pDataProbeString = new char[ strlen(pDataProbeString) + 1 ]; azstrcpy(m_pDataProbeString, strlen(pDataProbeString) + 1, pDataProbeString); } - virtual const char* GetDataProbeString() const - { - if (gEnv->IsDedicated() && m_pDataProbeString) - { - return m_pDataProbeString; - } - return GetOwnDataProbeString(); - } + virtual const char* GetDataProbeString() const; protected: // ------------------------------------------------------------------------------------------ @@ -157,7 +77,7 @@ protected: // ------------------------------------------------------------------ char* m_pDataProbeString; // value client is required to have for data probes int m_nFlags; // e.g. VF_CHEAT, ... - typedef std::vector > ChangeFunctorContainer; + typedef std::vector> > ChangeFunctorContainer; ChangeFunctorContainer m_changeFunctors; ConsoleVarFunc m_pChangeFunc; // Callback function that is called when this variable changes. CXConsole* m_pConsole; // used for the callback OnBeforeVarChange() @@ -185,67 +105,19 @@ public: // interface ICVar -------------------------------------------------------------------------------------- - virtual int GetIVal() const { return atoi(m_sValue.c_str()); } - virtual int64 GetI64Val() const { return _atoi64(m_sValue.c_str()); } - virtual float GetFVal() const { return (float)atof(m_sValue.c_str()); } - virtual const char* GetString() const { return m_sValue.c_str(); } - virtual void ResetImpl() + int GetIVal() const override { return atoi(m_sValue.c_str()); } + int64 GetI64Val() const override { return _atoi64(m_sValue.c_str()); } + float GetFVal() const override { return (float)atof(m_sValue.c_str()); } + const char* GetString() const override { return m_sValue.c_str(); } + void ResetImpl() override { Set(m_sDefault.c_str()); } - virtual void Set(const char* s) - { - if (!s) - { - return; - } + void Set(const char* s) override; + void Set(float f) override; + void Set(int i) override; + int GetType() override { return CVAR_STRING; } - if ((m_sValue == s) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - if (m_pConsole->OnBeforeVarChange(this, s)) - { - m_nFlags |= VF_MODIFIED; - { - m_sValue = s; - } - - CallOnChangeFunctions(); - - m_pConsole->OnAfterVarChange(this); - } - } - - virtual void Set(float f) - { - stack_string s = stack_string::format("%g", f); - - if ((m_sValue == s.c_str()) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - m_nFlags |= VF_MODIFIED; - Set(s.c_str()); - } - - virtual void Set(int i) - { - stack_string s = stack_string::format("%d", i); - - if ((m_sValue == s.c_str()) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - m_nFlags |= VF_MODIFIED; - Set(s.c_str()); - } - virtual int GetType() { return CVAR_STRING; } - - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } private: // -------------------------------------------------------------------------------------------- AZStd::string m_sValue; AZStd::string m_sDefault; //!< @@ -267,122 +139,21 @@ public: // interface ICVar -------------------------------------------------------------------------------------- - virtual int GetIVal() const { return m_iValue; } - virtual int64 GetI64Val() const { return m_iValue; } - virtual float GetFVal() const { return (float)GetIVal(); } - virtual const char* GetString() const - { - static char szReturnString[256]; - - sprintf_s(szReturnString, "%d", GetIVal()); - return szReturnString; - } - virtual void ResetImpl() { Set(m_iDefault); } - virtual void Set(const char* s) - { - int nValue = TextToInt(s, m_iValue, (m_nFlags & VF_BITFIELD) != 0); - - Set(nValue); - } - virtual void Set(float f) - { - Set((int)f); - } - virtual void Set(int i) - { - if (i == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - stack_string s = stack_string::format("%d", i); - - if (m_pConsole->OnBeforeVarChange(this, s.c_str())) - { - m_nFlags |= VF_MODIFIED; - m_iValue = i; - - CallOnChangeFunctions(); - - m_pConsole->OnAfterVarChange(this); - } - } - virtual int GetType() { return CVAR_INT; } - - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } + int GetIVal() const override { return m_iValue; } + int64 GetI64Val() const override { return m_iValue; } + float GetFVal() const override { return (float)GetIVal(); } + const char* GetString() const override; + void ResetImpl() override { Set(m_iDefault); } + void Set(const char* s) override; + void Set(float f) override; + void Set(int i) override; + int GetType() override { return CVAR_INT; } protected: // -------------------------------------------------------------------------------------------- int m_iValue; int m_iDefault; //!< }; - -class CXConsoleVariableInt64 - : public CXConsoleVariableBase -{ -public: - // constructor - CXConsoleVariableInt64(CXConsole* pConsole, const char* sName, const int64 iDefault, int nFlags, const char* help) - : CXConsoleVariableBase(pConsole, sName, nFlags, help) - , m_iValue(iDefault) - , m_iDefault(iDefault) - { - } - - // interface ICVar -------------------------------------------------------------------------------------- - - virtual int GetIVal() const { return (int)m_iValue; } - virtual int64 GetI64Val() const { return m_iValue; } - virtual float GetFVal() const { return (float)GetIVal(); } - virtual const char* GetString() const - { - static char szReturnString[256]; - sprintf_s(szReturnString, "%lld", GetI64Val()); - return szReturnString; - } - virtual void ResetImpl() { Set(m_iDefault); } - virtual void Set(const char* s) - { - int64 nValue = TextToInt64(s, m_iValue, (m_nFlags & VF_BITFIELD) != 0); - - Set(nValue); - } - virtual void Set(float f) - { - Set((int)f); - } - virtual void Set(int i) - { - Set((int64)i); - } - virtual void Set(int64 i) - { - if (i == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - stack_string s = stack_string::format("%lld", i); - - if (m_pConsole->OnBeforeVarChange(this, s.c_str())) - { - m_nFlags |= VF_MODIFIED; - m_iValue = i; - - CallOnChangeFunctions(); - - m_pConsole->OnAfterVarChange(this); - } - } - virtual int GetType() { return CVAR_INT; } - - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } -protected: // -------------------------------------------------------------------------------------------- - - int64 m_iValue; - int64 m_iDefault; //!< -}; - ////////////////////////////////////////////////////////////////////////// class CXConsoleVariableFloat : public CXConsoleVariableBase @@ -401,78 +172,13 @@ public: virtual int GetIVal() const { return (int)m_fValue; } virtual int64 GetI64Val() const { return (int64)m_fValue; } virtual float GetFVal() const { return m_fValue; } - virtual const char* GetString() const - { - static char szReturnString[256]; - - sprintf_s(szReturnString, "%g", m_fValue); // %g -> "2.01", %f -> "2.01000" - return szReturnString; - } + virtual const char* GetString() const; virtual void ResetImpl() { Set(m_fDefault); } - virtual void Set(const char* s) - { - float fValue = 0; - if (s) - { - fValue = (float)atof(s); - } - - if (fValue == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - if (m_pConsole->OnBeforeVarChange(this, s)) - { - m_nFlags |= VF_MODIFIED; - m_fValue = fValue; - - CallOnChangeFunctions(); - - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(float f) - { - if (f == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - stack_string s = stack_string::format("%g", f); - - if (m_pConsole->OnBeforeVarChange(this, s.c_str())) - { - m_nFlags |= VF_MODIFIED; - m_fValue = f; - - CallOnChangeFunctions(); - - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(int i) - { - if ((float)i == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - char sTemp[128]; - sprintf_s(sTemp, "%d", i); - - if (m_pConsole->OnBeforeVarChange(this, sTemp)) - { - m_nFlags |= VF_MODIFIED; - m_fValue = (float)i; - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } + virtual void Set(const char* s); + virtual void Set(float f); + virtual void Set(int i); virtual int GetType() { return CVAR_FLOAT; } - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } - protected: virtual const char* GetOwnDataProbeString() const @@ -509,186 +215,19 @@ public: virtual int GetIVal() const { return m_iValue; } virtual int64 GetI64Val() const { return m_iValue; } virtual float GetFVal() const { return (float)m_iValue; } - virtual const char* GetString() const - { - static char szReturnString[256]; - - sprintf_s(szReturnString, "%d", m_iValue); - return szReturnString; - } + virtual const char* GetString() const; virtual void ResetImpl() { Set(m_iDefault); } - virtual void Set(const char* s) - { - int nValue = TextToInt(s, m_iValue, (m_nFlags & VF_BITFIELD) != 0); - if (nValue == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - if (m_pConsole->OnBeforeVarChange(this, s)) - { - m_nFlags |= VF_MODIFIED; - m_iValue = nValue; - - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(float f) - { - if ((int)f == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - char sTemp[128]; - sprintf_s(sTemp, "%g", f); - - if (m_pConsole->OnBeforeVarChange(this, sTemp)) - { - m_nFlags |= VF_MODIFIED; - m_iValue = (int)f; - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(int i) - { - if (i == m_iValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - char sTemp[128]; - sprintf_s(sTemp, "%d", i); - - if (m_pConsole->OnBeforeVarChange(this, sTemp)) - { - m_nFlags |= VF_MODIFIED; - m_iValue = i; - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } + virtual void Set(const char* s); + virtual void Set(float f); + virtual void Set(int i); virtual int GetType() { return CVAR_INT; } - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } private: // -------------------------------------------------------------------------------------------- int& m_iValue; int m_iDefault; //!< }; - - - - -class CXConsoleVariableFloatRef - : public CXConsoleVariableBase -{ -public: - //! constructor - //!\param pVar must not be 0 - CXConsoleVariableFloatRef(CXConsole* pConsole, const char* sName, float* pVar, int nFlags, const char* help) - : CXConsoleVariableBase(pConsole, sName, nFlags, help) - , m_fValue(*pVar) - , m_fDefault(*pVar) - { - assert(pVar); - } - - // interface ICVar -------------------------------------------------------------------------------------- - - virtual int GetIVal() const { return (int)m_fValue; } - virtual int64 GetI64Val() const { return (int64)m_fValue; } - virtual float GetFVal() const { return m_fValue; } - virtual const char* GetString() const - { - static char szReturnString[256]; - - sprintf_s(szReturnString, "%g", m_fValue); - return szReturnString; - } - virtual void ResetImpl() { Set(m_fDefault); } - virtual void Set(const char* s) - { - float fValue = 0; - if (s) - { - fValue = (float)atof(s); - } - if (fValue == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - if (m_pConsole->OnBeforeVarChange(this, s)) - { - m_nFlags |= VF_MODIFIED; - m_fValue = fValue; - - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(float f) - { - if (f == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - char sTemp[128]; - sprintf_s(sTemp, "%g", f); - - if (m_pConsole->OnBeforeVarChange(this, sTemp)) - { - m_nFlags |= VF_MODIFIED; - m_fValue = f; - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } - virtual void Set(int i) - { - if ((float)i == m_fValue && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - char sTemp[128]; - sprintf_s(sTemp, "%d", i); - - if (m_pConsole->OnBeforeVarChange(this, sTemp)) - { - m_nFlags |= VF_MODIFIED; - m_fValue = (float)i; - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } - virtual int GetType() { return CVAR_FLOAT; } - - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } - -protected: - - virtual const char* GetOwnDataProbeString() const - { - static char szReturnString[8]; - - sprintf_s(szReturnString, "%.1g", m_fValue); - return szReturnString; - } - -private: // -------------------------------------------------------------------------------------------- - - float& m_fValue; - float m_fDefault; //!< -}; - - - class CXConsoleVariableStringRef : public CXConsoleVariableBase { @@ -715,25 +254,7 @@ public: return m_sValue.c_str(); } virtual void ResetImpl() { Set(m_sDefault.c_str()); } - virtual void Set(const char* s) - { - if ((m_sValue == s) && (m_nFlags & VF_ALWAYSONCHANGE) == 0) - { - return; - } - - if (m_pConsole->OnBeforeVarChange(this, s)) - { - m_nFlags |= VF_MODIFIED; - { - m_sValue = s; - m_userPtr = m_sValue.c_str(); - } - - CallOnChangeFunctions(); - m_pConsole->OnAfterVarChange(this); - } - } + virtual void Set(const char* s); virtual void Set(float f) { stack_string s = stack_string::format("%g", f); @@ -746,7 +267,6 @@ public: } virtual int GetType() { return CVAR_STRING; } - virtual void GetMemoryUsage(class ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); } private: // -------------------------------------------------------------------------------------------- AZStd::string m_sValue; @@ -754,84 +274,44 @@ private: // -------------------------------------------------------------------- const char*& m_userPtr; //!< }; - - -// works like CXConsoleVariableInt but when changing it sets other console variables -// getting the value returns the last value it was set to - if that is still what was applied -// to the cvars can be tested with GetRealIVal() -class CXConsoleVariableCVarGroup - : public CXConsoleVariableInt - , public ILoadConfigurationEntrySink +class CXConsoleVariableFloatRef + : public CXConsoleVariableBase { public: - // constructor - CXConsoleVariableCVarGroup(CXConsole* pConsole, const char* sName, const char* szFileName, int nFlags); - - // destructor - ~CXConsoleVariableCVarGroup(); - - // Returns: - // part of the help string - useful to log out detailed description without additional help text - AZStd::string GetDetailedInfo() const; - - // interface ICVar ----------------------------------------------------------------------------------- - - virtual const char* GetHelp(); - - virtual int GetRealIVal() const; - - virtual void DebugLog(const int iExpectedValue, const ICVar::EConsoleLogMode mode) const; - - virtual void Set(int i); - - // ConsoleVarFunc ------------------------------------------------------------------------------------ - - static void OnCVarChangeFunc(ICVar* pVar); - - // interface ILoadConfigurationEntrySink ------------------------------------------------------------- - - virtual void OnLoadConfigurationEntry(const char* szKey, const char* szValue, const char* szGroup); - virtual void OnLoadConfigurationEntry_End(); - - virtual void GetMemoryUsage(class ICrySizer* pSizer) const + //! constructor + //!\param pVar must not be 0 + CXConsoleVariableFloatRef(CXConsole* pConsole, const char* sName, float* pVar, int nFlags, const char* help) + : CXConsoleVariableBase(pConsole, sName, nFlags, help) + , m_fValue(*pVar) + , m_fDefault(*pVar) { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_sDefaultValue); - pSizer->AddObject(m_CVarGroupStates); + assert(pVar); } + + // interface ICVar -------------------------------------------------------------------------------------- + + virtual int GetIVal() const { return (int)m_fValue; } + virtual int64 GetI64Val() const { return (int64)m_fValue; } + virtual float GetFVal() const { return m_fValue; } + virtual const char* GetString() const; + virtual void ResetImpl() { Set(m_fDefault); } + virtual void Set(const char* s); + virtual void Set(float f); + virtual void Set(int i); + virtual int GetType() { return CVAR_FLOAT; } + +protected: + + virtual const char *GetOwnDataProbeString() const + { + static char szReturnString[8]; + + sprintf_s(szReturnString, "%.1g", m_fValue); + return szReturnString; + } + private: // -------------------------------------------------------------------------------------------- - struct SCVarGroup - { - std::map m_KeyValuePair; // e.g. m_KeyValuePair["r_fullscreen"]="0" - void GetMemoryUsage(class ICrySizer* pSizer) const - { - pSizer->AddObject(m_KeyValuePair); - } - }; - - SCVarGroup m_CVarGroupDefault; - typedef std::map TCVarGroupStateMap; - TCVarGroupStateMap m_CVarGroupStates; - AZStd::string m_sDefaultValue; // used by OnLoadConfigurationEntry_End() - - void ApplyCVars(const SCVarGroup& rGroup, const SCVarGroup* pExclude = 0); - - // Arguments: - // sKey - must exist, at least in default - // pSpec - can be 0 - AZStd::string GetValueSpec(const AZStd::string& sKey, const int* pSpec = 0) const; - - // should only be used by TestCVars() - // Returns: - // true=all console variables match the state (excluding default state), false otherwise - bool TestCVars(const SCVarGroup& rGroup, const ICVar::EConsoleLogMode mode, const SCVarGroup* pExclude = 0) const; - - // Arguments: - // pGroup - can be 0 to test if the default state is set - // Returns: - // true=all console variables match the state (including default state), false otherwise - bool TestCVars(const SCVarGroup* pGroup, const ICVar::EConsoleLogMode mode = ICVar::eCLM_Off) const; + float& m_fValue; + float m_fDefault; //!< }; - -#endif // CRYINCLUDE_CRYSYSTEM_XCONSOLEVARIABLE_H diff --git a/Code/Legacy/CrySystem/XML/ReadWriteXMLSink.h b/Code/Legacy/CrySystem/XML/ReadWriteXMLSink.h deleted file mode 100644 index b4dd28e813..0000000000 --- a/Code/Legacy/CrySystem/XML/ReadWriteXMLSink.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_CRYSYSTEM_XML_READWRITEXMLSINK_H -#define CRYINCLUDE_CRYSYSTEM_XML_READWRITEXMLSINK_H -#pragma once - - -#include -#include - -class CReadWriteXMLSink - : public IReadWriteXMLSink -{ -public: - bool ReadXML(const char* definitionFile, const char* dataFile, IReadXMLSink* pSink); - bool ReadXML(const char* definitionFile, XmlNodeRef node, IReadXMLSink* pSink); - bool ReadXML(XmlNodeRef definition, const char* dataFile, IReadXMLSink* pSink); - bool ReadXML(XmlNodeRef definition, XmlNodeRef node, IReadXMLSink* pSink); - - XmlNodeRef CreateXMLFromSource(const char* definitionFile, IWriteXMLSource* pSource); - bool WriteXML(const char* definitionFile, const char* dataFile, IWriteXMLSource* pSource); -}; - - -// helper to define the if/else chain that we need in a few locations... -// types must match IReadXMLSink::TValueTypes -#define XML_SET_PROPERTY_HELPER(ELSE_LOAD_PROPERTY) \ - if (false) {; } \ - ELSE_LOAD_PROPERTY(Vec3); \ - ELSE_LOAD_PROPERTY(int); \ - ELSE_LOAD_PROPERTY(float); \ - ELSE_LOAD_PROPERTY(AZStd::string); \ - ELSE_LOAD_PROPERTY(bool); - - -#endif // CRYINCLUDE_CRYSYSTEM_XML_READWRITEXMLSINK_H diff --git a/Code/Legacy/CrySystem/XML/ReadXMLSink.cpp b/Code/Legacy/CrySystem/XML/ReadXMLSink.cpp deleted file mode 100644 index e75fed22ed..0000000000 --- a/Code/Legacy/CrySystem/XML/ReadXMLSink.cpp +++ /dev/null @@ -1,683 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include "CrySystem_precompiled.h" -#include "ReadWriteXMLSink.h" - -#include -#include - -typedef std::map IdTable; -struct SParseParams -{ - IdTable idTable; - XmlNodeRef useAlways; - bool strict; - - SParseParams() - { - strict = true; - } -}; - -static XmlNodeRef Clone(XmlNodeRef source); -static void CopyAttributes(const XmlNodeRef& source, XmlNodeRef& dest); -static bool IsOptionalReadXML(const SParseParams& parseParams, XmlNodeRef& definition); -static bool CheckEnum(const SParseParams& parseParams, const char* name, XmlNodeRef& definition, XmlNodeRef& data); - -static bool LoadTableInner(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadArray(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadProperty(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadTable(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadReferencedId(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadSomething(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); -static bool LoadArraySetValueTable(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink, int elem); - -typedef bool (* LoadArraySetValue)(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink, int elem); -typedef bool (* LoadDefinitionFunction)(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink); - - -template -struct ReadPropertyTyped; - -template -struct ReadPropertyTyped -{ - static bool Load(const SParseParams& parseParams, const char* name, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) - { - T value; - memset(&value, 0, sizeof(T)); - - if (!pSink->IsCreationMode()) - { - if (!data->haveAttr(name)) - { - return false; - } - if (!data->getAttr(name, value)) - { - return false; - } - if (!CheckEnum(parseParams, name, definition, data)) - { - return false; - } - } - - IReadXMLSink::TValue vvalue(value); - pSink->SetValue(name, vvalue, definition); - return true; - } - static bool LoadArray([[maybe_unused]] const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink, int elem) - { - T value; - memset(&value, 0, sizeof(T)); - - if (!pSink->IsCreationMode()) - { - if (!data->haveAttr("value")) - { - return false; - } - if (!data->getAttr("value", value)) - { - return false; - } - } - - IReadXMLSink::TValue vvalue(value); - pSink->SetAt(elem, vvalue, definition); - return true; - } -}; - -template <> -struct ReadPropertyTyped -{ - static bool Load(const SParseParams& parseParams, const char* name, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) - { - const char* value = 0; - - if (!pSink->IsCreationMode()) - { - if (!data->haveAttr(name)) - { - return false; - } - if (!CheckEnum(parseParams, name, definition, data)) - { - return false; - } - - value = data->getAttr(name); - } - - IReadXMLSink::TValue vvalue(value); - pSink->SetValue(name, vvalue, definition); - return true; - } - static bool LoadArray([[maybe_unused]] const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink, int elem) - { - const char* value = 0; - - if (!pSink->IsCreationMode()) - { - if (!data->haveAttr("value")) - { - return false; - } - - value = data->getAttr("value"); - } - - IReadXMLSink::TValue vvalue(value); - pSink->SetAt(elem, vvalue, definition); - return true; - } -}; - -XmlNodeRef Clone(XmlNodeRef source) -{ - assert(source != (IXmlNode*)NULL); - - // Can't use clone() on XmlNodeRef objects since they can contain a CXMLBinaryNode, which doesn't support - // clone(). Instead we just create a regular xml node and manually copy content, tag, attributes and children - XmlNodeRef cloned = GetISystem()->CreateXmlNode(source->getTag()); - cloned->setContent(source->getContent()); - CopyAttributes(source, cloned); - const int iChildCount = source->getChildCount(); - for (int i = 0; i < iChildCount; ++i) - { - cloned->addChild(Clone(source->getChild(i))); - } - - return cloned; -} - -void CopyAttributes(const XmlNodeRef& source, XmlNodeRef& dest) -{ - // Not as fast as CXmlNode::copyAttributes(), but that method will have undefined behavior if the XmlNodeRef contains - // a CBinaryXmlNode object - int nNumAttributes = source->getNumAttributes(); - for (int i = 0; i < nNumAttributes; ++i) - { - const char* key = NULL; - const char* value = NULL; - if (source->getAttributeByIndex(i, &key, &value)) - { - dest->setAttr(key, value); - } - } -} - -bool IsOptionalReadXML(const SParseParams& parseParams, XmlNodeRef& definition) -{ - // If strict mode is off, then everything is optional - if (parseParams.strict == false) - { - return true; - } - - bool optional = false; - definition->getAttr("optional", optional); - return optional; -} - -bool CheckEnum([[maybe_unused]] const SParseParams& parseParams, [[maybe_unused]] const char* name, XmlNodeRef& definition, [[maybe_unused]] XmlNodeRef& data) -{ - if (XmlNodeRef enumNode = definition->findChild("Enum")) - { - // If strict mode is off, then no need to check the enum value - return true; - } - return true; -} - -bool LoadProperty(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Property has no name"); - return false; - } - - const char* type = definition->getAttr("type"); - if (0 == strlen(type)) - { - CryLog("Property '%s' has no type", type); - return false; - } - - XmlNodeRef dataToRead = data; - if (!pSink->IsCreationMode()) - { - // This check is done so the data xml can specify child elements instead of attributes if desired, - // since the rest of the code assume only attributes - if (XmlNodeRef childRef = data->findChild(name)) - { - if (data->haveAttr(name)) - { - CryLog("Duplicate definition (attribute and element) for %s", name); - return false; - } - if (childRef->getChildCount()) - { - CryLog("Property-style elements can not have children (property was %s)", name); - return false; - } - - dataToRead = GetISystem()->CreateXmlNode(data->getTag()); - - AZStd::string content = childRef->getContent(); - AZ::StringFunc::TrimWhiteSpace(content, true, true); - dataToRead->setAttr(name, content.c_str()); - } - - if (!dataToRead->haveAttr(name)) - { - if (!IsOptionalReadXML(parseParams, definition)) - { - CryLog("Failed to load property %s", name); - return false; - } - return true; - } - } - - bool ok = false; -#define LOAD_PROPERTY(whichType) else if (0 == strcmp(type, #whichType)) ok = ReadPropertyTyped::Load(parseParams, name, definition, dataToRead, pSink) - XML_SET_PROPERTY_HELPER(LOAD_PROPERTY); -#undef LOAD_PROPERTY - - if (!ok) - { - CryLog("Failed loading attribute %s of type %s", name, type); - } - - return ok; -} - -bool LoadArraySetValueTable(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink, int elem) -{ - IReadXMLSinkPtr pChildSink = pSink->BeginTableAt(elem, definition); - - if (pSink->IsCreationMode() && definition->haveAttr("type")) - { - if (!LoadSomething(parseParams, definition, data, &*pChildSink)) - { - return false; - } - } - else - { - if (!LoadTableInner(parseParams, definition, data, &*pChildSink)) - { - return false; - } - } - - if (!pChildSink->EndTableAt(elem)) - { - CryLog("Failed to finish table at element %d", elem); - return false; - } - - return true; -} - -bool LoadArray(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Array has no name"); - return false; - } - - const char* elementName = definition->getAttr("elementName"); - if (0 == strlen(elementName)) - { - elementName = "element"; - } - - bool validateArray = true; - if (definition->haveAttr(elementName)) - { - definition->getAttr("validate", validateArray); - } - - - XmlNodeRef childData; - - if (!pSink->IsCreationMode()) - { - childData = data->findChild(name); - if (!childData) - { - bool ok = IsOptionalReadXML(parseParams, definition); - if (!ok) - { - CryLog("Failed to load child table %s", name); - } - return ok; - } - } - - IReadXMLSinkPtr childSink = pSink->BeginArray(name, definition); - if (!childSink) - { - CryLog("Failed to begin array named %s", name); - return false; - } - - LoadArraySetValue setter = NULL; - if (definition->haveAttr("type")) - { - setter = NULL; - const char* type = definition->getAttr("type"); -#define SETTER_PROPERTY(whichType) else if (0 == strcmp(type, #whichType)) setter = ReadPropertyTyped::LoadArray - XML_SET_PROPERTY_HELPER(SETTER_PROPERTY); -#undef SETTER_PROPERTY - if (!setter) - { - CryLog("Unknown type %s in array %s", type, name); - return false; - } - } - else - { - setter = LoadArraySetValueTable; - } - - if (!pSink->IsCreationMode()) - { - int numElems = childData->getChildCount(); - int elem = 1; - for (int i = 0; i < numElems; i++) - { - XmlNodeRef elemData = childData->getChild(i); - if (0 == strcmp(elemData->getTag(), elementName)) - { - int increment = 1; - if (elemData->haveAttr("_index")) - { - if (!elemData->getAttr("_index", elem)) - { - CryLog("_index is not an integer in array %s (pos hint=%d)", name, elem); - return false; - } - } - if (!setter(parseParams, definition, elemData, &*childSink, elem)) - { - CryLog("Failed loading element %d of array %s", elem, name); - return false; - } - elem += increment; - } - else if (validateArray) - { - CryLog("Invalid node %s in array %s", elemData->getTag(), name); - return false; - } - } - } - else - { - // only process array content for the array being created - if (0 == strcmp(name, pSink->GetCreationNode()->getAttr("name"))) - { - if (!setter(parseParams, definition, data, &*childSink, 1)) - { - CryLog("[ReadXML CreationMode]: Failed loading element %d of array %s", 1, name); - return false; - } - } - } - - if (!pSink->EndArray(name)) - { - CryLog("Failed to finish array named %s", name); - return false; - } - - return true; -} - -bool LoadTable(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Child-table has no name"); - return false; - } - - XmlNodeRef childData; - - if (!pSink->IsCreationMode()) - { - childData = data->findChild(name); - if (!childData) - { - bool ok = IsOptionalReadXML(parseParams, definition); - if (!ok) - { - CryLog("Failed to load child table %s", name); - } - return ok; - } - } - - IReadXMLSinkPtr childSink = pSink->BeginTable(name, definition); - if (!childSink) - { - CryLog("Sink creation failed for table %s", name); - return false; - } - - - if (!LoadTableInner(parseParams, definition, childData, childSink)) - { - CryLog("Failed to load data for child table %s", name); - return false; - } - - if (!pSink->EndTable(name)) - { - CryLog("Table %s failed to complete in sink", name); - return false; - } - - return true; -} - -bool LoadSomething(const SParseParams& parseParams, XmlNodeRef& nodeDefinition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - // Ignore if it's the useAlways array - if (parseParams.useAlways == nodeDefinition) - { - return true; - } - - static struct - { - const char* name; - LoadDefinitionFunction loader; - } loaderTypes[] = { - {"Property", &LoadProperty}, - {"Array", &LoadArray}, - {"Table", &LoadTable}, - {"Use", &LoadReferencedId}, - }; - static const int numLoaderTypes = sizeof(loaderTypes) / sizeof(*loaderTypes); - - const char* nodeDefinitionTag = nodeDefinition->getTag(); - bool ok = false; - int i; - - for (i = 0; i < numLoaderTypes; i++) - { - if (0 == strcmp(loaderTypes[i].name, nodeDefinitionTag)) - { - ok = loaderTypes[i].loader(parseParams, nodeDefinition, data, pSink); - break; - } - } - - if (0 == _stricmp("Settings", nodeDefinitionTag)) - { - return true; - } - - if (!ok) - { - if (i == numLoaderTypes) - { - CryLog("Invalid definition node type %s, line %d", nodeDefinitionTag, nodeDefinition->getLine()); - } - } - return ok; -} - -bool LoadReferencedId(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - IdTable::const_iterator iter = parseParams.idTable.find(definition->getAttr("id")); - if (iter == parseParams.idTable.end()) - { - CryLog("No definition with id '%s'", definition->getAttr("id")); - return false; - } - XmlNodeRef useDefinition = Clone(iter->second); - CopyAttributes(definition, useDefinition); - - return LoadSomething(parseParams, useDefinition, data, pSink); -} - -bool LoadTableInner(const SParseParams& parseParams, XmlNodeRef& definition, XmlNodeRef& data, IReadXMLSink* pSink) -{ - const int nChildrenDefinition = definition->getChildCount(); - - for (int nChildDefinition = 0; nChildDefinition < nChildrenDefinition; nChildDefinition++) - { - XmlNodeRef nodeDefinition = definition->getChild(nChildDefinition); - - if (!LoadSomething(parseParams, nodeDefinition, data, pSink)) - { - return false; - } - } - - if (parseParams.useAlways != (IXmlNode*)NULL) - { - assert(!definition->haveAttr("type")); - - const int nUseAlwaysDefCount = parseParams.useAlways->getChildCount(); - for (int i = 0; i < nUseAlwaysDefCount; ++i) - { - XmlNodeRef nodeDefinition = parseParams.useAlways->getChild(i); - - // Don't continue loading useAlways nodes in creation mode - if (!pSink->IsCreationMode()) - { - if (!LoadSomething(parseParams, nodeDefinition, data, pSink)) - { - return false; - } - } - } - } - - return true; -} - -bool CReadWriteXMLSink::ReadXML(XmlNodeRef rootDefinition, XmlNodeRef rootData, IReadXMLSink* pSink) -{ - if (!pSink->IsCreationMode()) - { - if (0 == rootData) - { - return false; - } - - if (0 != strcmp(rootDefinition->getTag(), "Definition")) - { - CryLog("Root tag of definition file was %s; expected Definition", rootDefinition->getTag()); - return false; - } - if (rootDefinition->haveAttr("root")) - { - if (0 != strcmp(rootDefinition->getAttr("root"), rootData->getTag())) - { - CryLog("Root data has wrong tag; was %s expected %s", rootData->getTag(), rootDefinition->getAttr("root")); - return false; - } - } - } - - SParseParams parseParams; - parseParams.useAlways = rootDefinition->findChild("AllowAlways"); - - if (XmlNodeRef settingsParams = rootDefinition->findChild("Settings")) - { - settingsParams->getAttr("strict", parseParams.strict); - } - - // scan for id's in the structure (for the Use member) - std::stack scanStack; - scanStack.push(rootDefinition); - while (!scanStack.empty()) - { - XmlNodeRef refNode = scanStack.top(); - scanStack.pop(); - - int numChildren = refNode->getChildCount(); - const char* tag = refNode->getTag(); - - for (int i = 0; i < numChildren; i++) - { - const XmlNodeRef& childNodeRef = refNode->getChild(i); - if (parseParams.useAlways != childNodeRef) - { - scanStack.push(childNodeRef); - } - } - - // If the element has an attribute id="" and is not a "" element add it to the idTable map - if (refNode->haveAttr("id") && 0 != strcmp("Use", tag)) - { - parseParams.idTable[refNode->getAttr("id")] = refNode; - } - } - - if (pSink->IsCreationMode() && rootDefinition->haveAttr("type")) - { - // if creating from a 0-child definition node, load itself - if (!LoadSomething(parseParams, rootDefinition, rootData, pSink)) - { - return false; - } - } - else - { - // load content - if (!LoadTableInner(parseParams, rootDefinition, rootData, pSink)) - { - return false; - } - } - - bool ok = pSink->Complete(); - if (!ok) - { - CryLog("Warning: sink failed to complete reading"); - } - - return ok; -} - -bool CReadWriteXMLSink::ReadXML(XmlNodeRef definition, const char* dataFile, IReadXMLSink* pSink) -{ - XmlNodeRef rootData = GetISystem()->LoadXmlFromFile(dataFile); - if (!rootData) - { - CryLog("Unable to load XML-Lua data file: %s", dataFile); - return false; - } - return ReadXML(definition, rootData, pSink); -} - -bool CReadWriteXMLSink::ReadXML(const char* definitionFile, XmlNodeRef rootData, IReadXMLSink* pSink) -{ - XmlNodeRef rootDefinition = GetISystem()->LoadXmlFromFile(definitionFile); - if (!rootDefinition) - { - CryLog("Unable to load XML-Lua definition file: %s", definitionFile); - return false; - } - return ReadXML(rootDefinition, rootData, pSink); -} - -bool CReadWriteXMLSink::ReadXML(const char* definitionFile, const char* dataFile, IReadXMLSink* pSink) -{ - XmlNodeRef rootData = GetISystem()->LoadXmlFromFile(dataFile); - if (!rootData) - { - CryLog("Unable to load XML-Lua data file: %s", dataFile); - return false; - } - if (!ReadXML(definitionFile, rootData, pSink)) - { - CryLog("Unable to load file %s", dataFile); - return false; - } - return true; -} - - diff --git a/Code/Legacy/CrySystem/XML/SerializeXMLReader.cpp b/Code/Legacy/CrySystem/XML/SerializeXMLReader.cpp index 841697ecdb..528e3dbcc5 100644 --- a/Code/Legacy/CrySystem/XML/SerializeXMLReader.cpp +++ b/Code/Legacy/CrySystem/XML/SerializeXMLReader.cpp @@ -104,23 +104,6 @@ bool CSerializeXMLReaderImpl::Value(const char* name, CTimeValue& value) return true; } -bool CSerializeXMLReaderImpl::Value(const char* name, XmlNodeRef& value) -{ - DefaultValue(value); // Set input value to default. - if (m_nErrors) - { - return false; - } - - if (BeginOptionalGroup(name, true)) - { - value = CurNode()->getChild(0); - EndGroup(); - } - - return true; -} - void CSerializeXMLReaderImpl::BeginGroup(const char* szName) { if (m_nErrors) @@ -173,32 +156,3 @@ void CSerializeXMLReaderImpl::EndGroup() } assert(!m_nodeStack.empty()); } - -////////////////////////////////////////////////////////////////////////// -AZStd::string CSerializeXMLReaderImpl::GetStackInfo() const -{ - AZStd::string str; - for (int i = 0; i < (int)m_nodeStack.size(); i++) - { - const char* name = m_nodeStack[i].m_node->getAttr(TAG_SCRIPT_NAME); - if (name && name[0]) - { - str += name; - } - else - { - str += m_nodeStack[i].m_node->getTag(); - } - if (i != m_nodeStack.size() - 1) - { - str += "/"; - } - } - return str; -} - -void CSerializeXMLReaderImpl::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->Add(*this); - pSizer->AddContainer(m_nodeStack); -} diff --git a/Code/Legacy/CrySystem/XML/SerializeXMLReader.h b/Code/Legacy/CrySystem/XML/SerializeXMLReader.h index f87350d3fe..58c150db24 100644 --- a/Code/Legacy/CrySystem/XML/SerializeXMLReader.h +++ b/Code/Legacy/CrySystem/XML/SerializeXMLReader.h @@ -6,22 +6,16 @@ * */ - -#ifndef CRYINCLUDE_CRYSYSTEM_XML_SERIALIZEXMLREADER_H -#define CRYINCLUDE_CRYSYSTEM_XML_SERIALIZEXMLREADER_H #pragma once - #include "SimpleSerialize.h" #include #include #include -#include -#include #include "xml.h" class CSerializeXMLReaderImpl - : public CSimpleSerializeImpl + : public CSimpleSerializeImpl { public: CSerializeXMLReaderImpl(const XmlNodeRef& nodeRef); @@ -41,7 +35,7 @@ public: g_pXmlStrCmp = &strcmp; // Do case-sensitive compare bool bReturn = node->haveAttr(name); if (bReturn) - { + { value = node->getAttr(name); } g_pXmlStrCmp = pPrevCmpFunc; @@ -51,10 +45,6 @@ public: { return false; } - ILINE bool GetAttr([[maybe_unused]] const XmlNodeRef& node, [[maybe_unused]] const char* name, [[maybe_unused]] SNetObjectID& value) - { - return false; - } template bool Value(const char* name, T_Value& value) @@ -77,23 +67,12 @@ public: bool Value(const char* name, int8& value); bool Value(const char* name, AZStd::string& value); bool Value(const char* name, CTimeValue& value); - bool Value(const char* name, XmlNodeRef& value); - - template - bool Value(const char* name, T_Value& value, [[maybe_unused]] const T_Policy& policy) - { - return Value(name, value); - } void BeginGroup(const char* szName); bool BeginOptionalGroup(const char* szName, bool condition); void EndGroup(); - AZStd::string GetStackInfo() const; - - void GetMemoryUsage(ICrySizer* pSizer) const; private: - //CTimeValue m_curTime; XmlNodeRef CurNode() { return m_nodeStack.back().m_node; } XmlNodeRef NextOf(const char* name) { @@ -171,13 +150,9 @@ private: void DefaultValue(Ang3& v) const { v.x = 0; v.y = 0; v.z = 0; } void DefaultValue(Quat& v) const { v.w = 1.0f; v.v.x = 0; v.v.y = 0; v.v.z = 0; } void DefaultValue(CTimeValue& v) const { v.SetValue(0); } - //void DefaultValue( char *str ) const { if (str) str[0] = 0; } void DefaultValue(AZStd::string& str) const { str = ""; } void DefaultValue([[maybe_unused]] const AZStd::string& str) const {} - void DefaultValue([[maybe_unused]] SNetObjectID& id) const {} void DefaultValue([[maybe_unused]] SSerializeString& str) const {} void DefaultValue(XmlNodeRef& ref) const { ref = NULL; } ////////////////////////////////////////////////////////////////////////// }; - -#endif // CRYINCLUDE_CRYSYSTEM_XML_SERIALIZEXMLREADER_H diff --git a/Code/Legacy/CrySystem/XML/SerializeXMLWriter.cpp b/Code/Legacy/CrySystem/XML/SerializeXMLWriter.cpp index ce3fbcc2b1..5a3e403218 100644 --- a/Code/Legacy/CrySystem/XML/SerializeXMLWriter.cpp +++ b/Code/Legacy/CrySystem/XML/SerializeXMLWriter.cpp @@ -49,16 +49,6 @@ bool CSerializeXMLWriterImpl::Value(const char* name, CTimeValue value) return true; } -bool CSerializeXMLWriterImpl::Value(const char* name, XmlNodeRef& value) -{ - if (BeginOptionalGroup(name, value != NULL)) - { - CurNode()->addChild(value); - EndGroup(); - } - return true; -} - void CSerializeXMLWriterImpl::BeginGroup(const char* szName) { if (strchr(szName, ' ') != 0) @@ -104,13 +94,6 @@ void CSerializeXMLWriterImpl::EndGroup() assert(!m_nodeStack.empty()); } -void CSerializeXMLWriterImpl::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->Add(*this); - pSizer->AddObject(m_nodeStack); - pSizer->AddContainer(m_luaSaveStack); -} - ////////////////////////////////////////////////////////////////////////// AZStd::string CSerializeXMLWriterImpl::GetStackInfo() const { diff --git a/Code/Legacy/CrySystem/XML/SerializeXMLWriter.h b/Code/Legacy/CrySystem/XML/SerializeXMLWriter.h index 5f3e9f2c53..26fbe4b29c 100644 --- a/Code/Legacy/CrySystem/XML/SerializeXMLWriter.h +++ b/Code/Legacy/CrySystem/XML/SerializeXMLWriter.h @@ -15,11 +15,10 @@ #include #include #include -#include "IValidator.h" #include "SimpleSerialize.h" class CSerializeXMLWriterImpl - : public CSimpleSerializeImpl + : public CSimpleSerializeImpl { public: CSerializeXMLWriterImpl(const XmlNodeRef& nodeRef); @@ -32,21 +31,12 @@ public: return true; } - template - bool Value(const char* name, T_Value& value, [[maybe_unused]] const T_Policy& policy) - { - return Value(name, value); - } - bool Value(const char* name, CTimeValue value); - bool Value(const char* name, XmlNodeRef& value); void BeginGroup(const char* szName); bool BeginOptionalGroup(const char* szName, bool condition); void EndGroup(); - void GetMemoryUsage(ICrySizer* pSizer) const; - private: ////////////////////////////////////////////////////////////////////////// // Vars. @@ -99,10 +89,6 @@ private: { AddValue(name, value.c_str()); } - void AddValue([[maybe_unused]] const char* name, [[maybe_unused]] const SNetObjectID& value) - { - assert(false); - } template void AddTypedValue(const char* name, const T& value, const char* type) { diff --git a/Code/Legacy/CrySystem/XML/WriteXMLSource.cpp b/Code/Legacy/CrySystem/XML/WriteXMLSource.cpp deleted file mode 100644 index c5fa3839e0..0000000000 --- a/Code/Legacy/CrySystem/XML/WriteXMLSource.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include "CrySystem_precompiled.h" -#include "ReadWriteXMLSink.h" - -#include - -typedef std::map IdTable; - -static bool IsOptionalWriteXML(XmlNodeRef& definition); - -static bool SaveTableInner(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveReferencedId(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveSomething(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveArray(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveProperty(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveTable(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); -static bool SaveArraySetValueTable(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource, int elem); - -typedef bool (* SaveArraySetValue)(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource, int elem); -typedef bool (* SaveDefinitionFunction)(const IdTable&, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource); - -template -struct WritePropertyTyped; - -template -struct WritePropertyTyped -{ - static bool Save(const char* name, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) - { - IWriteXMLSource::TValue vvalue((T())); - if (!pSource->GetValue(name, vvalue, definition)) - { - return false; - } - T* pValue = AZStd::get_if(&vvalue); - if (!pValue) - { - return false; - } - data->setAttr(name, *pValue); - return true; - } - static bool SaveArray([[maybe_unused]] const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource, int elem) - { - IWriteXMLSource::TValue vvalue((T())); - if (!pSource->GetAt(elem, vvalue, definition)) - { - return false; - } - T* pValue = AZStd::get_if(&vvalue); - if (!pValue) - { - return false; - } - data->setAttr("value", *pValue); - return true; - } -}; - -template <> -struct WritePropertyTyped - : public WritePropertyTyped -{ -}; - -bool IsOptionalWriteXML(XmlNodeRef& definition) -{ - bool optional = false; - definition->getAttr("optional", optional); - return optional; -} - -bool SaveProperty([[maybe_unused]] const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Property has no name"); - return false; - } - - const char* type = definition->getAttr("type"); - if (0 == strlen(type)) - { - CryLog("Property '%s' has no type", type); - return false; - } - - if (IsOptionalWriteXML(definition) && !pSource->HaveValue(name)) - { - return true; - } - - bool ok = false; -#define SAVE_PROPERTY(whichType) else if (0 == strcmp(type, #whichType)) ok = WritePropertyTyped::Save(name, definition, data, pSource) - XML_SET_PROPERTY_HELPER(SAVE_PROPERTY); -#undef SAVE_PROPERTY - - if (!ok) - { - CryLog("Failed loading attribute %s of type %s", name, type); - } - - return ok; -} - -bool SaveArraySetValueTable(const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource, int elem) -{ - IWriteXMLSourcePtr pChildSource = pSource->BeginTableAt(elem); - if (!pChildSource) - { - CryLog("Failed to find source table at %d", elem); - return false; - } - - if (!SaveTableInner(idTable, definition, data, &*pChildSource)) - { - return false; - } - - if (!pChildSource->EndTableAt(elem)) - { - CryLog("Failed to finish table at element %d", elem); - return false; - } - - return true; -} - -bool SaveArray(const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Array has no name"); - return false; - } - - const char* elementName = definition->getAttr("elementName"); - if (0 == strlen(elementName)) - { - elementName = "element"; - } - - bool validateArray = true; - if (definition->haveAttr(elementName)) - { - definition->getAttr("validate", validateArray); - } - - size_t numElems = 0; - IWriteXMLSourcePtr childSource = pSource->BeginArray(name, &numElems, definition); - if (!childSource) - { - bool ok = IsOptionalWriteXML(definition); - if (!ok) - { - CryLog("Failed to begin array named %s", name); - } - return ok; - } - - XmlNodeRef childData = data->createNode(name); - - SaveArraySetValue setter = NULL; - if (definition->haveAttr("type")) - { - setter = NULL; - const char* type = definition->getAttr("type"); -#define SETTER_PROPERTY(whichType) else if (0 == strcmp(type, #whichType)) setter = WritePropertyTyped::SaveArray - XML_SET_PROPERTY_HELPER(SETTER_PROPERTY); -#undef SETTER_PROPERTY - if (!setter) - { - CryLog("Unknown type %s in array %s", type, name); - return false; - } - } - else - { - setter = SaveArraySetValueTable; - } - - bool needIndex = false; - for (size_t sizei = 1; sizei <= numElems; sizei++) - { - const int i = static_cast(sizei); - if (!childSource->HaveElemAt(i)) - { - needIndex = true; - } - else - { - XmlNodeRef elemData = childData->createNode(elementName); - if (needIndex) - { - elemData->setAttr("_index", i); - } - needIndex = false; - - if (!setter(idTable, definition, elemData, &*childSource, i)) - { - CryLog("Failed saving element %d of array %s", int(i), name); - return false; - } - - childData->addChild(elemData); - } - } - - if (!pSource->EndArray(name)) - { - CryLog("Failed to finish array named %s", name); - return false; - } - - data->addChild(childData); - - return true; -} - -bool SaveTable(const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - const char* name = definition->getAttr("name"); - if (0 == strlen(name)) - { - CryLog("Child-table has no name"); - return false; - } - - IWriteXMLSourcePtr childSource = pSource->BeginTable(name); - if (!childSource) - { - bool ok = IsOptionalWriteXML(definition); - if (!ok) - { - CryLog("Source creation failed for table %s", name); - } - return ok; - } - - XmlNodeRef childData = data->createNode(name); - - if (!SaveTableInner(idTable, definition, childData, childSource)) - { - CryLog("Failed to load data for child table %s", name); - return false; - } - - if (!pSource->EndTable(name)) - { - CryLog("Table %s failed to complete in sink", name); - return false; - } - - data->addChild(childData); - - return true; -} - -bool SaveSomething(const IdTable& idTable, XmlNodeRef& nodeDefinition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - static struct - { - const char* name; - SaveDefinitionFunction saver; - } saverTypes[] = { - {"Property", &SaveProperty}, - {"Array", &SaveArray}, - {"Table", &SaveTable}, - {"Use", &SaveReferencedId}, - }; - static const int numSaverTypes = sizeof(saverTypes) / sizeof(*saverTypes); - - const char* nodeDefinitionTag = nodeDefinition->getTag(); - bool ok = false; - int i; - for (i = 0; i < numSaverTypes; i++) - { - if (0 == strcmp(saverTypes[i].name, nodeDefinitionTag)) - { - ok = saverTypes[i].saver(idTable, nodeDefinition, data, pSource); - break; - } - } - if (!ok) - { - if (i == numSaverTypes) - { - CryLog("Invalid definition node type %s", nodeDefinitionTag); - } - } - return ok; -} - -bool SaveReferencedId(const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - IdTable::const_iterator iter = idTable.find(definition->getAttr("id")); - if (iter == idTable.end()) - { - CryLog("No definition with id '%s'", definition->getAttr("id")); - return false; - } - XmlNodeRef useDefinition = iter->second; - useDefinition = useDefinition->clone(); - int numAttrs = definition->getNumAttributes(); - for (int i = 0; i < numAttrs; i++) - { - const char* key, * value; - definition->getAttributeByIndex(i, &key, &value); - useDefinition->setAttr(key, value); - } - return SaveSomething(idTable, useDefinition, data, pSource); -} - -bool SaveTableInner(const IdTable& idTable, XmlNodeRef& definition, XmlNodeRef& data, IWriteXMLSource* pSource) -{ - const int nChildrenDefinition = definition->getChildCount(); - for (int nChildDefinition = 0; nChildDefinition < nChildrenDefinition; nChildDefinition++) - { - XmlNodeRef nodeDefinition = definition->getChild(nChildDefinition); - - if (!SaveSomething(idTable, nodeDefinition, data, pSource)) - { - return false; - } - } - return true; -} - -XmlNodeRef CReadWriteXMLSink::CreateXMLFromSource(const char* definitionFile, IWriteXMLSource* pSource) -{ - XmlNodeRef rootDefinition = GetISystem()->LoadXmlFromFile(definitionFile); - if (!rootDefinition) - { - CryLog("Unable to load XML-Lua definition file: %s", definitionFile); - return 0; - } - if (0 != strcmp(rootDefinition->getTag(), "Definition")) - { - CryLog("Root tag of definition file was %s; expected Definition", rootDefinition->getTag()); - return 0; - } - const char* rootNode = "Root"; - if (rootDefinition->haveAttr("root")) - { - rootNode = rootDefinition->getAttr("root"); - } - XmlNodeRef rootData = GetISystem()->CreateXmlNode(rootNode); - - XmlNodeRef allowAlways = rootDefinition->findChild("AllowAlways"); - if (allowAlways != 0) - { - rootDefinition->removeChild(allowAlways); - } - - XmlNodeRef settingsParams = rootDefinition->findChild("Settings"); - if (settingsParams != 0) - { - rootDefinition->removeChild(settingsParams); - } - - // scan for id's in the structure (for the Use member) - IdTable idTable; - std::stack scanStack; - scanStack.push(rootDefinition); - while (!scanStack.empty()) - { - XmlNodeRef refNode = scanStack.top(); - scanStack.pop(); - - int numChildren = refNode->getChildCount(); - const char* tag = refNode->getTag(); - - for (int i = 0; i < numChildren; i++) - { - scanStack.push(refNode->getChild(i)); - } - - if (refNode->haveAttr("id") && 0 != strcmp("Use", tag)) - { - idTable[refNode->getAttr("id")] = refNode; - } - - if (allowAlways != 0 && (!strcmp("Table", tag) || !strcmp("Array", tag))) - { - for (int i = 0; i < allowAlways->getChildCount(); ++i) - { - refNode->addChild(allowAlways->getChild(i)->clone()); - } - } - } - - if (!SaveTableInner(idTable, rootDefinition, rootData, pSource)) - { - CryLog("Error createing xml using definition %s", definitionFile); - return 0; - } - - bool ok = pSource->Complete(); - if (!ok) - { - CryLog("Warning: sink failed to complete writing"); - return 0; - } - - return rootData; -} - -bool CReadWriteXMLSink::WriteXML(const char* definitionFile, const char* dataFile, IWriteXMLSource* pSource) -{ - XmlNodeRef data = CreateXMLFromSource(definitionFile, pSource); - if (!data) - { - CryLog("Failed creating %s", dataFile); - return false; - } - if (!data->saveToFile(dataFile)) - { - CryLog("Failed saving %s", dataFile); - return false; - } - return true; -} diff --git a/Code/Legacy/CrySystem/XML/XMLBinaryNode.cpp b/Code/Legacy/CrySystem/XML/XMLBinaryNode.cpp index d209478957..ec154b31e8 100644 --- a/Code/Legacy/CrySystem/XML/XMLBinaryNode.cpp +++ b/Code/Legacy/CrySystem/XML/XMLBinaryNode.cpp @@ -8,8 +8,8 @@ #include +#include "Cry_Color.h" #include "XMLBinaryNode.h" -#include ////////////////////////////////////////////////////////////////////////// CBinaryXmlData::CBinaryXmlData() @@ -38,24 +38,10 @@ CBinaryXmlData::~CBinaryXmlData() pBinaryNodes = 0; } -void CBinaryXmlData::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(pFileContents, nFileSize); - const XMLBinary::BinaryFileHeader* pHeader = reinterpret_cast(pFileContents); - pSizer->AddObject(pBinaryNodes, sizeof(CBinaryXmlNode) * pHeader->nNodeCount); -} - ////////////////////////////////////////////////////////////////////////// // CBinaryXmlNode implementation. ////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////// -// collect allocated memory informations -void CBinaryXmlNode::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(m_pData); -} - ////////////////////////////////////////////////////////////////////////// XmlNodeRef CBinaryXmlNode::getParent() const { @@ -244,21 +230,6 @@ bool CBinaryXmlNode::getAttr(const char* key, Vec4& value) const return false; } -bool CBinaryXmlNode::getAttr(const char* key, Vec3d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - double x, y, z; - if (azsscanf(svalue, "%lf,%lf,%lf", &x, &y, &z) == 3) - { - value = Vec3d(x, y, z); - return true; - } - } - return false; -} - ////////////////////////////////////////////////////////////////////////// bool CBinaryXmlNode::getAttr(const char* key, Vec2& value) const { @@ -275,22 +246,6 @@ bool CBinaryXmlNode::getAttr(const char* key, Vec2& value) const return false; } -////////////////////////////////////////////////////////////////////////// -bool CBinaryXmlNode::getAttr(const char* key, Vec2d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - double x, y; - if (azsscanf(svalue, "%lf,%lf", &x, &y) == 2) - { - value = Vec2d(x, y); - return true; - } - } - return false; -} - ////////////////////////////////////////////////////////////////////////// bool CBinaryXmlNode::getAttr(const char* key, Quat& value) const { diff --git a/Code/Legacy/CrySystem/XML/XMLBinaryNode.h b/Code/Legacy/CrySystem/XML/XMLBinaryNode.h index 34e0ca22ce..855ef8b348 100644 --- a/Code/Legacy/CrySystem/XML/XMLBinaryNode.h +++ b/Code/Legacy/CrySystem/XML/XMLBinaryNode.h @@ -41,8 +41,6 @@ public: CBinaryXmlData(); ~CBinaryXmlData(); - - void GetMemoryUsage(ICrySizer* pSizer) const; }; // forward declaration @@ -59,9 +57,6 @@ class CBinaryXmlNode { public: - // collect allocated memory informations - void GetMemoryUsage(ICrySizer* pSizer) const; - ////////////////////////////////////////////////////////////////////////// // Custom new/delete with pool allocator. ////////////////////////////////////////////////////////////////////////// @@ -163,11 +158,9 @@ public: void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] float value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] f64 value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Vec2& value) { assert(0); }; - void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Vec2d& value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Ang3& value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Vec3& value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Vec4& value) { assert(0); }; - void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Vec3d& value) { assert(0); }; void setAttr([[maybe_unused]] const char* key, [[maybe_unused]] const Quat& value) { assert(0); }; void delAttr([[maybe_unused]] const char* key) { assert(0); }; void removeAllAttributes() { assert(0); }; @@ -182,11 +175,9 @@ public: bool getAttr(const char* key, bool& value) const; bool getAttr(const char* key, XmlString& value) const {const char* v(NULL); bool boHasAttribute(getAttr(key, &v)); value = v; return boHasAttribute; } bool getAttr(const char* key, Vec2& value) const; - bool getAttr(const char* key, Vec2d& value) const; bool getAttr(const char* key, Ang3& value) const; bool getAttr(const char* key, Vec3& value) const; bool getAttr(const char* key, Vec4& value) const; - bool getAttr(const char* key, Vec3d& value) const; bool getAttr(const char* key, Quat& value) const; bool getAttr(const char* key, ColorB& value) const; diff --git a/Code/Legacy/CrySystem/XML/XMLBinaryWriter.cpp b/Code/Legacy/CrySystem/XML/XMLBinaryWriter.cpp index 265953850f..63bf4adef2 100644 --- a/Code/Legacy/CrySystem/XML/XMLBinaryWriter.cpp +++ b/Code/Legacy/CrySystem/XML/XMLBinaryWriter.cpp @@ -12,40 +12,6 @@ #include "CryEndian.h" #include // memcpy() -////////////////////////////////////////////////////////////////////////// -namespace XMLBinary -{ - void SwapEndianness_Node(Node& t) - { - SwapEndian(t.nTagStringOffset, true); - SwapEndian(t.nContentStringOffset, true); - SwapEndian(t.nAttributeCount, true); - SwapEndian(t.nChildCount, true); - SwapEndian(t.nParentIndex, true); - SwapEndian(t.nFirstAttributeIndex, true); - SwapEndian(t.nFirstChildIndex, true); - } - - void SwapEndianness_Attribute(Attribute& t) - { - SwapEndian(t.nKeyStringOffset, true); - SwapEndian(t.nValueStringOffset, true); - } - - void SwapEndianness_Header(BinaryFileHeader& t) - { - SwapEndian(t.nXMLSize, true); - SwapEndian(t.nNodeTablePosition, true); - SwapEndian(t.nNodeCount, true); - SwapEndian(t.nAttributeTablePosition, true); - SwapEndian(t.nAttributeCount, true); - SwapEndian(t.nChildTablePosition, true); - SwapEndian(t.nChildCount, true); - SwapEndian(t.nStringDataPosition, true); - SwapEndian(t.nStringDataSize, true); - } -} - ////////////////////////////////////////////////////////////////////////// XMLBinary::CXMLBinaryWriter::CXMLBinaryWriter() { @@ -84,7 +50,7 @@ static void write(XMLBinary::IDataWriter* const pFile, size_t& nPosition, const } ////////////////////////////////////////////////////////////////////////// -bool XMLBinary::CXMLBinaryWriter::WriteNode(IDataWriter* pFile, XmlNodeRef node, bool bNeedSwapEndian, XMLBinary::IFilter* pFilter, AZStd::string& error) +bool XMLBinary::CXMLBinaryWriter::WriteNode(IDataWriter* pFile, XmlNodeRef node, XMLBinary::IFilter* pFilter, AZStd::string& error) { error = ""; @@ -135,24 +101,6 @@ bool XMLBinary::CXMLBinaryWriter::WriteNode(IDataWriter* pFile, XmlNodeRef node, header.nXMLSize = static_cast(nTheoreticalPosition); - // Swap endianness of the data structures - if (bNeedSwapEndian) - { - SwapEndianness_Header(header); - for (size_t i = 0, iCount = m_nodes.size(); i < iCount; ++i) - { - SwapEndianness_Node(m_nodes[i]); - } - for (size_t i = 0, iCount = m_attributes.size(); i < iCount; ++i) - { - SwapEndianness_Attribute(m_attributes[i]); - } - for (size_t i = 0, iCount = m_childs.size(); i < iCount; ++i) - { - SwapEndian(m_childs[i], true); - } - } - // Write file { nTheoreticalPosition = 0; diff --git a/Code/Legacy/CrySystem/XML/XMLBinaryWriter.h b/Code/Legacy/CrySystem/XML/XMLBinaryWriter.h index 810a2268c9..4b0d19fe26 100644 --- a/Code/Legacy/CrySystem/XML/XMLBinaryWriter.h +++ b/Code/Legacy/CrySystem/XML/XMLBinaryWriter.h @@ -25,7 +25,7 @@ namespace XMLBinary { public: CXMLBinaryWriter(); - bool WriteNode(IDataWriter* pFile, XmlNodeRef node, bool bNeedSwapEndian, XMLBinary::IFilter* pFilter, AZStd::string & error); + bool WriteNode(IDataWriter* pFile, XmlNodeRef node, XMLBinary::IFilter* pFilter, AZStd::string & error); private: bool CompileTables(XmlNodeRef node, XMLBinary::IFilter* pFilter, AZStd::string& error); diff --git a/Code/Legacy/CrySystem/XML/XMLPatcher.cpp b/Code/Legacy/CrySystem/XML/XMLPatcher.cpp deleted file mode 100644 index 03c5af92d3..0000000000 --- a/Code/Legacy/CrySystem/XML/XMLPatcher.cpp +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#include "CrySystem_precompiled.h" -#include "XMLPatcher.h" - -CXMLPatcher::CXMLPatcher(XmlNodeRef& patchXML) -{ - m_patchXML = patchXML; - -#if DATA_PATCH_DEBUG - m_pDumpFilesCVar = REGISTER_INT("g_datapatcher_dumpfiles", 0, NULL, "will dump a copy of every file data patched, before and after patching"); -#endif -} - -CXMLPatcher::~CXMLPatcher() -{ -#if DATA_PATCH_DEBUG - if (IConsole* pIC = gEnv->pConsole) - { - pIC->UnregisterVariable(m_pDumpFilesCVar->GetName()); - } -#endif -} - -XmlNodeRef CXMLPatcher::DuplicateForPatching( - const XmlNodeRef& inOrig, - bool inShareChildren) -{ - XmlNodeRef newNode(0); - - if (m_patchXML) - { - newNode = m_patchXML->createNode(inOrig->getTag()); - if (newNode) - { - // copy attributes in a safe way, copyAttributes() itself assumes the node being copied from is of the same type - int numAttr = inOrig->getNumAttributes(); - - for (int i = 0; i < numAttr; i++) - { - const char* pKey, * pValue; - if (inOrig->getAttributeByIndex(i, &pKey, &pValue)) - { - newNode->setAttr(pKey, pValue); - } - } - - if (inShareChildren) - { - newNode->shareChildren(inOrig); - } - } - } - - return newNode; -} - -void CXMLPatcher::PatchFail( - const char* pInReason) -{ - CryLogAlways("Failed to apply data patch for file '%s' - reason '%s'", m_pFileBeingPatched, pInReason); -} - -XmlNodeRef CXMLPatcher::FindPatchForFile( - const char* pInFileToPatch) -{ - XmlNodeRef result; - - if (m_patchXML) - { - for (int i = 0, m = m_patchXML->getChildCount(); i < m; i++) - { - XmlNodeRef child = m_patchXML->getChild(i); - - if (child->isTag("patch")) - { - const char* pForFile = child->getAttr("forfile"); - - if (pForFile && AZ::StringFunc::Find(pForFile, pInFileToPatch) != AZStd::string::npos) - { - result = child; - break; - } - } - } - } - - return result; -} - -XmlNodeRef CXMLPatcher::ApplyPatchToNode( - const XmlNodeRef& inNode, - const XmlNodeRef& inPatch) -{ - XmlNodeRef result = inNode; - - for (int i = 0, m = inPatch->getChildCount(); i < m; i++) - { - XmlNodeRef patchNode = inPatch->getChild(i); - if (!patchNode || _stricmp(patchNode->getTag(), "patchnode") != 0) - { - continue; - } - - int indexToPatch; - if (!patchNode->getAttr("index", indexToPatch)) - { - PatchFail("found patchnode missing index"); - continue; - } - - int maxChildren = result->getChildCount(); - - if ((indexToPatch < 0 || indexToPatch >= maxChildren) && indexToPatch != -1) - { - PatchFail("patchnode index out of valid range"); - continue; - } - - XmlNodeRef childToPatch = (indexToPatch != -1) ? result->getChild(indexToPatch) : XmlNodeRef(0); - XmlNodeRef matchTag = GetMatchTag(patchNode); - - if (childToPatch && matchTag && !CompareTags(matchTag, childToPatch)) - { - PatchFail("patch failed to apply, data did not match what was expected"); - continue; - } - - // we need to apply a patch to this child, make it patchable by duplicating the node - - if (inNode == result) - { - // make parent patchable if not already - result = DuplicateForPatching(inNode, true); - } - - if (XmlNodeRef insertTag = GetInsertTag(patchNode)) - { - // insert a new child after this node - XmlNodeRef newChild = DuplicateForPatching(insertTag, true); // have to duplicate it as we don't have an 'insert shared child' function - result->insertChild(indexToPatch + 1, newChild); - } - else - { - if (indexToPatch == -1) - { - PatchFail("child indices of -1 can only be used when inserting new nodes"); - continue; - } - } - - bool shouldReplaceChildren = false; - - if (XmlNodeRef replaceTag = GetReplaceTag(patchNode, &shouldReplaceChildren)) - { - XmlNodeRef newChild = DuplicateForPatching(replaceTag, false); - - if (!shouldReplaceChildren) - { - newChild->shareChildren(childToPatch); - } - else - { - // note: this is inserting children that belong to the data patcher into the data being patched - // this is fine to do, as long as the caller doesn't make any permanent changes to the xml tree - // returned. if they did they would alter the patcher's nodes and thus affect future patches - // applied using the same patch - // as most callers are working with binary xmls they don't try and modify them - as this is not - // a supported operation - // note, if a second patch was applied to this patched tree containing the patch nodes, it - // wouldn't mess up the patch, as patching a tree never modifies it, it always returns a new tree - // that may share parts of the original tree - newChild->shareChildren(replaceTag); - } - - result->replaceChild(indexToPatch, newChild); - - childToPatch = newChild; - } - - if (XmlNodeRef deleteTag = GetDeleteTag(patchNode)) - { - result->deleteChildAt(indexToPatch); - childToPatch = 0; // deleted - don't recurse into it - } - - if (childToPatch) - { - // Apply recursively - XmlNodeRef newChild = ApplyPatchToNode(childToPatch, patchNode); - - // child has been patched, insert new child into parent - if (newChild != childToPatch) - { - result->replaceChild(indexToPatch, newChild); - } - } - } - - return result; -} - -XmlNodeRef CXMLPatcher::ApplyXMLDataPatch( - const XmlNodeRef& inNode, - const char* pInXMLFileName) -{ - XmlNodeRef result = inNode; - - if (m_patchingEnabled) - { - if (m_patchXML) - { - XmlNodeRef patchForFile = FindPatchForFile(pInXMLFileName); - if (patchForFile) - { - m_pFileBeingPatched = pInXMLFileName; - CryLog("Applying game data patch to %s", pInXMLFileName); - XmlNodeRef containerNode = m_patchXML->createNode(""); - containerNode->addChild(inNode); - containerNode = ApplyPatchToNode(containerNode, patchForFile); - result = containerNode->getChild(0); - m_pFileBeingPatched = NULL; - -#if DATA_PATCH_DEBUG - if (inNode != result) - { - DumpFiles(pInXMLFileName, inNode, result); - } -#endif - } - } - } - - return result; -} - -XmlNodeRef CXMLPatcher::GetMatchTag( - const XmlNodeRef& inNode) -{ - XmlNodeRef result; - XmlNodeRef nr = inNode->findChild("match"); - if (nr && nr->getChildCount() == 1) - { - result = nr->getChild(0); - } - return result; -} - -XmlNodeRef CXMLPatcher::GetReplaceTag( - const XmlNodeRef& inNode, - bool* outShouldReplaceChildren) -{ - XmlNodeRef result; - XmlNodeRef nr = inNode->findChild("replacewith"); - if (nr && nr->getChildCount() == 1) - { - if (!nr->getAttr("replaceChildren", *outShouldReplaceChildren)) - { - *outShouldReplaceChildren = false; - } - result = nr->getChild(0); - } - return result; -} - - -XmlNodeRef CXMLPatcher::GetInsertTag( - const XmlNodeRef& inNode) -{ - XmlNodeRef result; - XmlNodeRef nr = inNode->findChild("insertAfter"); - if (nr && nr->getChildCount() == 1) - { - result = nr->getChild(0); - } - return result; -} - -XmlNodeRef CXMLPatcher::GetDeleteTag( - const XmlNodeRef& inNode) -{ - XmlNodeRef result = inNode->findChild("delete"); - return result; -} - -// compares the two tags for equality of tag and attributes -// used to ensure the source data being patched meets the patches expectations -// only compares tag and attribs, doesn't do deep compare of children -bool CXMLPatcher::CompareTags( - const XmlNodeRef& inA, - const XmlNodeRef& inB) -{ - bool result = true; - - if (inA != inB) - { - result = false; - - if (_stricmp(inA->getTag(), inB->getTag()) == 0) - { - if (inA->getNumAttributes() == inB->getNumAttributes()) - { - result = true; - - for (int i = 0, m = inA->getNumAttributes(); i < m; i++) - { - const char* pAKey, * pBKey; - const char* pAValue, * pBValue; - - inA->getAttributeByIndex(i, &pAKey, &pAValue); - inB->getAttributeByIndex(i, &pBKey, &pBValue); - - if (_stricmp(pAKey, pBKey) || _stricmp(pAValue, pBValue)) - { - result = false; - break; - } - } - } - } - } - - return result; -} - -#if DATA_PATCH_DEBUG - -static const char* k_lotsOfTabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; - -#define INDENT() \ - if (inIndent > 0) \ - { \ - pPak->FWrite(k_lotsOfTabs, inIndent, inFileHandle); \ - } - -void CXMLPatcher::DumpXMLNodes( - AZ::IO::HandleType inFileHandle, - int inIndent, - const XmlNodeRef& inNode, - AZStd::fixed_string<512>* ioTempString) -{ - auto pPak = gEnv->pCryPak; - - inIndent = min(inIndent, int(sizeof(k_lotsOfTabs) - 1)); - - INDENT(); - - *ioTempString = AZStd::fixed_string<512>::format("<%s ", inNode->getTag()); - - pPak->FWrite(ioTempString->c_str(), ioTempString->length(), inFileHandle); - - for (int i = 0, m = inNode->getNumAttributes(); i < m; i++) - { - const char* pKey, * pVal; - inNode->getAttributeByIndex(i, &pKey, &pVal); - *ioTempString = AZStd::fixed_string<512>::format("%s=\"%s\" ", pKey, pVal); - pPak->FWrite(ioTempString->c_str(), ioTempString->length(), inFileHandle); - } - pPak->FWrite(">\n", 2, inFileHandle); - - for (int i = 0, m = inNode->getChildCount(); i < m; i++) - { - DumpXMLNodes(inFileHandle, inIndent + 1, inNode->getChild(i), ioTempString); - } - - INDENT(); - *ioTempString = AZStd::fixed_string<512>::format("\n", inNode->getTag()); - pPak->FWrite(ioTempString->c_str(), ioTempString->length(), inFileHandle); -} - - -void CXMLPatcher::DumpFiles( - const char* pInXMLFileName, - const XmlNodeRef& inBefore, - const XmlNodeRef& inAfter) -{ - if (m_pDumpFilesCVar->GetIVal()) - { - CryLog("Dumping before and after data files for '%s'", pInXMLFileName); - - const char* pOrigFileName = strrchr(pInXMLFileName, '/'); - if (pOrigFileName) - { - pOrigFileName++; - - DumpXMLFile(AZStd::string::format("PATCH_%s", pOrigFileName).c_str(), inBefore); - - AZStd::string newFileName(pOrigFileName); - AZ::StringFunc::Replace(newFileName, ".xml", "_patched.xml"); - - DumpXMLFile(AZStd::string::format("PATCH_%s", newFileName.c_str()).c_str(), inAfter); - } - else - { - CryLog("Couldn't determine file name for path '%s' can't output diffs", pInXMLFileName); - } - } -} - -void CXMLPatcher::DumpXMLFile( - const char* pInFilePath, - const XmlNodeRef& inNode) -{ - auto pIPak = GetISystem()->GetIPak(); - AZ::IO::HandleType fileHandle = pIPak->FOpen(pInFilePath, "wb"); - - if (fileHandle != AZ::IO::InvalidHandle) - { - AZStd::fixed_string<512> tempStr; - - DumpXMLNodes(fileHandle, 0, inNode, &tempStr); - - pIPak->FClose(fileHandle); - } -} -#endif diff --git a/Code/Legacy/CrySystem/XML/XMLPatcher.h b/Code/Legacy/CrySystem/XML/XMLPatcher.h deleted file mode 100644 index ccc5f481eb..0000000000 --- a/Code/Legacy/CrySystem/XML/XMLPatcher.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_CRYSYSTEM_XML_XMLPATCHER_H -#define CRYINCLUDE_CRYSYSTEM_XML_XMLPATCHER_H -#pragma once - - -#if defined(WIN32) && !defined(_RELEASE) -#define DATA_PATCH_DEBUG 1 -#else -#define DATA_PATCH_DEBUG 0 -#endif - -class CXMLPatcher -{ -protected: -#if DATA_PATCH_DEBUG - ICVar * m_pDumpFilesCVar; -#endif - - XmlNodeRef m_patchXML; - const char* m_pFileBeingPatched; - bool m_patchingEnabled; - - void PatchFail( - const char* pInReason); - XmlNodeRef ApplyPatchToNode( - const XmlNodeRef& inNode, - const XmlNodeRef& inPatch); - - XmlNodeRef DuplicateForPatching( - const XmlNodeRef& inOrig, - bool inShareChildren); - - bool CompareTags( - const XmlNodeRef& inA, - const XmlNodeRef& inB); - XmlNodeRef GetMatchTag( - const XmlNodeRef& inNode); - XmlNodeRef GetReplaceTag( - const XmlNodeRef& inNode, - bool* outShouldReplaceChildren); - XmlNodeRef GetInsertTag( - const XmlNodeRef& inNode); - XmlNodeRef GetDeleteTag( - const XmlNodeRef& inNode); - XmlNodeRef FindPatchForFile( - const char* pInFileToPatch); - -#if DATA_PATCH_DEBUG - void DumpXMLNodes( - AZ::IO::HandleType inFileHandle, - int inIndent, - const XmlNodeRef& inNode, - AZStd::fixed_string<512>* ioTempString); - void DumpFiles( - const char* pInXMLFileName, - const XmlNodeRef& inBefore, - const XmlNodeRef& inAfter); - void DumpXMLFile( - const char* pInFilePath, - const XmlNodeRef& inNode); -#endif - -public: - CXMLPatcher(XmlNodeRef& patchXML); - ~CXMLPatcher(); - - XmlNodeRef ApplyXMLDataPatch( - const XmlNodeRef& inNode, - const char* pInXMLFileName); -}; - -#endif // CRYINCLUDE_CRYSYSTEM_XML_XMLPATCHER_H diff --git a/Code/Legacy/CrySystem/XML/XmlUtils.cpp b/Code/Legacy/CrySystem/XML/XmlUtils.cpp index 56944eb344..0afa5e19db 100644 --- a/Code/Legacy/CrySystem/XML/XmlUtils.cpp +++ b/Code/Legacy/CrySystem/XML/XmlUtils.cpp @@ -11,7 +11,6 @@ #include #include "xml.h" #include "XmlUtils.h" -#include "ReadWriteXMLSink.h" #include "../SimpleStringPool.h" #include "SerializeXMLReader.h" @@ -20,7 +19,6 @@ #include "XMLBinaryWriter.h" #include "XMLBinaryReader.h" -#include "XMLPatcher.h" #include ////////////////////////////////////////////////////////////////////////// @@ -28,23 +26,14 @@ SXmlNodeStats* g_pCXmlNode_Stats = 0; #endif -extern bool g_bEnableBinaryXmlLoading; - ////////////////////////////////////////////////////////////////////////// CXmlUtils::CXmlUtils(ISystem* pSystem) { m_pSystem = pSystem; - // create IReadWriteXMLSink object - m_pReadWriteXMLSink = new CReadWriteXMLSink(); #ifdef CRY_COLLECT_XML_NODE_STATS g_pCXmlNode_Stats = new SXmlNodeStats(); #endif - m_pStatsXmlNodePool = 0; -#ifndef _RELEASE - m_statsThreadOwner = CryGetCurrentThreadId(); -#endif - m_pXMLPatcher = NULL; } ////////////////////////////////////////////////////////////////////////// @@ -53,8 +42,6 @@ CXmlUtils::~CXmlUtils() #ifdef CRY_COLLECT_XML_NODE_STATS delete g_pCXmlNode_Stats; #endif - SAFE_DELETE(m_pStatsXmlNodePool); - SAFE_DELETE(m_pXMLPatcher); } ////////////////////////////////////////////////////////////////////////// @@ -65,21 +52,13 @@ IXmlParser* CXmlUtils::CreateXmlParser() } ////////////////////////////////////////////////////////////////////////// -XmlNodeRef CXmlUtils::LoadXmlFromFile(const char* sFilename, bool bReuseStrings, bool bEnablePatching) +XmlNodeRef CXmlUtils::LoadXmlFromFile(const char* sFilename, bool bReuseStrings) { - XmlParser parser(bReuseStrings); - XmlNodeRef node = parser.ParseFile(sFilename, true); - // XmlParser is supposed to log warnings and errors (if any), // so we don't need to call parser.getErrorString(), // CryLog() etc here. - - if (node && bEnablePatching && m_pXMLPatcher) - { - node = m_pXMLPatcher->ApplyXMLDataPatch(node, sFilename); - } - - return node; + XmlParser parser(bReuseStrings); + return parser.ParseFile(sFilename, true); } ////////////////////////////////////////////////////////////////////////// @@ -99,29 +78,6 @@ void GetMD5(const char* pSrcBuffer, int nSrcSize, char signatureMD5[16]) MD5Final((unsigned char*)signatureMD5, &md5c); } -////////////////////////////////////////////////////////////////////////// -const char* CXmlUtils::HashXml(XmlNodeRef node) -{ - static char signature[16 * 2 + 1]; - static char temp[16]; - static const char* hex = "0123456789abcdef"; - XmlString str = node->getXML(); - GetMD5(str.data(), static_cast(str.length()), temp); - for (int i = 0; i < 16; i++) - { - signature[2 * i + 0] = hex[((uint8)temp[i]) >> 4]; - signature[2 * i + 1] = hex[((uint8)temp[i]) & 0xf]; - } - signature[16 * 2] = 0; - return signature; -} - -////////////////////////////////////////////////////////////////////////// -IReadWriteXMLSink* CXmlUtils::GetIReadWriteXMLSink() -{ - return m_pReadWriteXMLSink; -} - ////////////////////////////////////////////////////////////////////////// class CXmlSerializer : public IXmlSerializer @@ -172,12 +128,6 @@ public: return m_pReaderSer; } - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->Add(*this); - pSizer->AddObject(m_pReaderImpl); - pSizer->AddObject(m_pWriterImpl); - } ////////////////////////////////////////////////////////////////////////// private: int m_nRefCount; @@ -194,62 +144,6 @@ IXmlSerializer* CXmlUtils::CreateXmlSerializer() return new CXmlSerializer; } -////////////////////////////////////////////////////////////////////////// -void CXmlUtils::GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) -{ -#ifdef CRY_COLLECT_XML_NODE_STATS - // yes, slow - std::vector rootNodes; - { - TXmlNodeSet::const_iterator iter = g_pCXmlNode_Stats->nodeSet.begin(); - TXmlNodeSet::const_iterator iterEnd = g_pCXmlNode_Stats->nodeSet.end(); - while (iter != iterEnd) - { - const CXmlNode* pNode = *iter; - if (pNode->getParent() == 0) - { - rootNodes.push_back(pNode); - } - ++iter; - } - } - - // use the following to log to console -#if 0 - CryLogAlways("NumXMLRootNodes=%d NumXMLNodes=%d TotalAllocs=%d TotalFrees=%d", - rootNodes.size(), g_pCXmlNode_Stats->nodeSet.size(), - g_pCXmlNode_Stats->nAllocs, g_pCXmlNode_Stats->nFrees); -#endif - - - // use the following to debug the nodes in the system -#if 0 - { - std::vector::const_iterator iter = rootNodes.begin(); - std::vector::const_iterator iterEnd = rootNodes.end(); - while (iter != iterEnd) - { - const CXmlNode* pNode = *iter; - CryLogAlways("Node 0x%p Tag='%s'", pNode, pNode->getTag()); - ++iter; - } - } -#endif - - // only for debugging, add it as pseudo numbers to the CrySizer. - // shift it by 10, so we get the actual number - { - SIZER_COMPONENT_NAME(pSizer, "#NumTotalNodes"); - pSizer->Add("#NumTotalNodes", g_pCXmlNode_Stats->nodeSet.size() << 10); - } - - { - SIZER_COMPONENT_NAME(pSizer, "#NumRootNodes"); - pSizer->Add("#NumRootNodes", rootNodes.size() << 10); - } -#endif -} - ////////////////////////////////////////////////////////////////////////// class CXmlBinaryDataWriterFile : public XMLBinary::IDataWriter @@ -282,49 +176,13 @@ private: AZ::IO::HandleType m_fileHandle; }; -////////////////////////////////////////////////////////////////////////// -bool CXmlUtils::SaveBinaryXmlFile(const char* filename, XmlNodeRef root) -{ - CXmlBinaryDataWriterFile fileSink(filename); - if (!fileSink.IsOk()) - { - return false; - } - XMLBinary::CXMLBinaryWriter writer; - AZStd::string error; - return writer.WriteNode(&fileSink, root, false, 0, error); -} - -////////////////////////////////////////////////////////////////////////// -XmlNodeRef CXmlUtils::LoadBinaryXmlFile(const char* filename, bool bEnablePatching) -{ - XMLBinary::XMLBinaryReader reader; - XMLBinary::XMLBinaryReader::EResult result; - XmlNodeRef root = reader.LoadFromFile(filename, result); - - if (result == XMLBinary::XMLBinaryReader::eResult_Success && bEnablePatching == true && m_pXMLPatcher != NULL) - { - root = m_pXMLPatcher->ApplyXMLDataPatch(root, filename); - } - - return root; -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlUtils::EnableBinaryXmlLoading(bool bEnable) -{ - bool bPrev = g_bEnableBinaryXmlLoading; - g_bEnableBinaryXmlLoading = bEnable; - return bPrev; -} - ////////////////////////////////////////////////////////////////////////// class CXmlTableReader : public IXmlTableReader { public: CXmlTableReader(); - virtual ~CXmlTableReader(); + ~CXmlTableReader() override; virtual void Release(); @@ -332,7 +190,6 @@ public: virtual int GetEstimatedRowCount(); virtual bool ReadRow(int& rowIndex); virtual bool ReadCell(int& columnIndex, const char*& pContent, size_t& contentSize); - float GetCurrentRowHeight() override; private: bool m_bExcel; @@ -341,7 +198,6 @@ private: XmlNodeRef m_rowNode; - float m_currentRowHeight; int m_rowNodeIndex; int m_row; @@ -411,7 +267,6 @@ int CXmlTableReader::GetEstimatedRowCount() ////////////////////////////////////////////////////////////////////////// bool CXmlTableReader::ReadRow(int& rowIndex) { - m_currentRowHeight = 0.0f; if (!m_tableNode) { return false; @@ -459,12 +314,6 @@ bool CXmlTableReader::ReadRow(int& rowIndex) } m_row = index; } - float height; - if (m_rowNode->getAttr("ss:Height", height)) - { - m_currentRowHeight = height; - } - rowIndex = m_row; return true; } @@ -617,75 +466,8 @@ bool CXmlTableReader::ReadCell(int& columnIndex, const char*& pContent, size_t& } } -float CXmlTableReader::GetCurrentRowHeight() -{ - return m_currentRowHeight; -} ////////////////////////////////////////////////////////////////////////// IXmlTableReader* CXmlUtils::CreateXmlTableReader() { return new CXmlTableReader; } - -////////////////////////////////////////////////////////////////////////// -// Init xml stats nodes pool -void CXmlUtils::InitStatsXmlNodePool(uint32 nPoolSize) -{ - CHECK_STATS_THREAD_OWNERSHIP(); - if (0 == m_pStatsXmlNodePool) - { - // create special xml node pools for game statistics - - const bool bReuseStrings = true; // TODO parameterise? - m_pStatsXmlNodePool = new CXmlNodePool(nPoolSize, bReuseStrings); - assert(m_pStatsXmlNodePool); - } - else - { - CryLog("[CXmlNodePool]: Xml stats nodes pool already initialized"); - } -} - -////////////////////////////////////////////////////////////////////////// -// Creates new xml node for statistics. -XmlNodeRef CXmlUtils::CreateStatsXmlNode(const char* sNodeName) -{ - CHECK_STATS_THREAD_OWNERSHIP(); - if (0 == m_pStatsXmlNodePool) - { - CryLog("[CXmlNodePool]: Xml stats nodes pool isn't initialized. Perform default initialization."); - InitStatsXmlNodePool(); - } - return m_pStatsXmlNodePool->GetXmlNode(sNodeName); -} - -void CXmlUtils::SetStatsOwnerThread([[maybe_unused]] threadID threadId) -{ -#ifndef _RELEASE - m_statsThreadOwner = threadId; -#endif -} - -void CXmlUtils::FlushStatsXmlNodePool() -{ - CHECK_STATS_THREAD_OWNERSHIP(); - if (m_pStatsXmlNodePool) - { - if (m_pStatsXmlNodePool->empty()) - { - SAFE_DELETE(m_pStatsXmlNodePool); - } - } -} - -void CXmlUtils::SetXMLPatcher(XmlNodeRef* pPatcher) -{ - SAFE_DELETE(m_pXMLPatcher); - - if (pPatcher != NULL) - { - m_pXMLPatcher = new CXMLPatcher(*pPatcher); - } -} - - diff --git a/Code/Legacy/CrySystem/XML/XmlUtils.h b/Code/Legacy/CrySystem/XML/XmlUtils.h index d81dc4b642..b9d1c87554 100644 --- a/Code/Legacy/CrySystem/XML/XmlUtils.h +++ b/Code/Legacy/CrySystem/XML/XmlUtils.h @@ -20,7 +20,6 @@ #endif class CXmlNodePool; -class CXMLPatcher; ////////////////////////////////////////////////////////////////////////// // Implements IXmlUtils interface. @@ -39,57 +38,17 @@ public: virtual IXmlParser* CreateXmlParser(); // Load xml from file, returns 0 if load failed. - virtual XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false, bool bEnablePatching = true); + virtual XmlNodeRef LoadXmlFromFile(const char* sFilename, bool bReuseStrings = false); // Load xml from memory buffer, returns 0 if load failed. virtual XmlNodeRef LoadXmlFromBuffer(const char* buffer, size_t size, bool bReuseStrings = false, bool bSuppressWarnings = false); - // create an MD5 hash of an XML file - virtual const char* HashXml(XmlNodeRef node); - - // Get an object that can read a xml into a IReadXMLSink - // and write a xml from a IWriteXMLSource - virtual IReadWriteXMLSink* GetIReadWriteXMLSink(); - virtual IXmlSerializer* CreateXmlSerializer(); - virtual bool SaveBinaryXmlFile(const char* sFilename, XmlNodeRef root); - virtual XmlNodeRef LoadBinaryXmlFile(const char* sFilename, bool bEnablePatching = true); - - virtual bool EnableBinaryXmlLoading(bool bEnable); - // Create XML Table reader. virtual IXmlTableReader* CreateXmlTableReader(); ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - virtual void GetMemoryUsage(ICrySizer* pSizer); - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - // Init xml stats nodes pool - virtual void InitStatsXmlNodePool(uint32 nPoolSize = 1024*1024); - - // Create new xml node for statistics - virtual XmlNodeRef CreateStatsXmlNode(const char* sNodeName = ""); - - // Set owner thread - virtual void SetStatsOwnerThread(threadID threadId); - - // Free memory if stats xml node pool is empty - virtual void FlushStatsXmlNodePool(); - - // Set the XML Patcher. This is an XML object that modifies named XML files as they are loaded - // EXCEPT for xml files loaded from a buffer, for which names aren't passed in - virtual void SetXMLPatcher(XmlNodeRef* pPatcher); - private: ISystem* m_pSystem; - IReadWriteXMLSink* m_pReadWriteXMLSink; - CXmlNodePool* m_pStatsXmlNodePool; - CXMLPatcher* m_pXMLPatcher; //If set, applies data patches to any XML file that is loaded by this class -#ifndef _RELEASE - threadID m_statsThreadOwner; -#endif }; #endif // CRYINCLUDE_CRYSYSTEM_XML_XMLUTILS_H diff --git a/Code/Legacy/CrySystem/XML/xml.cpp b/Code/Legacy/CrySystem/XML/xml.cpp index cc3ea7f820..b1f18142f1 100644 --- a/Code/Legacy/CrySystem/XML/xml.cpp +++ b/Code/Legacy/CrySystem/XML/xml.cpp @@ -9,8 +9,6 @@ #include "CrySystem_precompiled.h" -//#define _CRT_SECURE_NO_DEPRECATE 1 -//#define _CRT_NONSTDC_NO_DEPRECATE #include #define XML_STATIC // Alternative to defining this here would be setting it project-wide @@ -19,6 +17,7 @@ #include #include #include +#include #include "XMLBinaryReader.h" #define FLOAT_FMT "%.8g" @@ -77,7 +76,6 @@ static int __cdecl ascii_stricmp(const char* dst, const char* src) ////////////////////////////////////////////////////////////////////////// XmlStrCmpFunc g_pXmlStrCmp = &ascii_stricmp; -bool g_bEnableBinaryXmlLoading = true; ////////////////////////////////////////////////////////////////////////// class CXmlStringData @@ -113,10 +111,6 @@ public: void Clear() { m_stringPool.Clear(); } void SetBlockSize(unsigned int nBlockSize) { m_stringPool.SetBlockSize(nBlockSize); } - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(m_stringPool); - } private: CSimpleStringPool m_stringPool; }; @@ -174,23 +168,6 @@ CXmlNode::CXmlNode(const char* tag, bool bReuseStrings, bool bIsProcessingInstru m_tag = m_pStringPool->AddString(tag); } -////////////////////////////////////////////////////////////////////////// -// collect allocated memory informations -void CXmlNode::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_pStringPool); - - if (m_pChilds) - { - pSizer->AddObject(*m_pChilds); - } - if (m_pAttributes) - { - pSizer->AddContainer(*m_pAttributes); - } -} - ////////////////////////////////////////////////////////////////////////// XmlNodeRef CXmlNode::createNode(const char* tag) { @@ -378,13 +355,6 @@ void CXmlNode::setAttr(const char* key, const Vec4& value) setAttr(key, str); } -void CXmlNode::setAttr(const char* key, const Vec3d& value) -{ - char str[128]; - SCOPED_LOCALE_RESETTER; - sprintf_s(str, DOUBLE_FMT "," DOUBLE_FMT "," DOUBLE_FMT, value.x, value.y, value.z); - setAttr(key, str); -} void CXmlNode::setAttr(const char* key, const Vec2& value) { char str[128]; @@ -392,13 +362,6 @@ void CXmlNode::setAttr(const char* key, const Vec2& value) sprintf_s(str, FLOAT_FMT "," FLOAT_FMT, value.x, value.y); setAttr(key, str); } -void CXmlNode::setAttr(const char* key, const Vec2d& value) -{ - char str[128]; - SCOPED_LOCALE_RESETTER; - sprintf_s(str, DOUBLE_FMT "," DOUBLE_FMT, value.x, value.y); - setAttr(key, str); -} void CXmlNode::setAttr(const char* key, const Quat& value) { @@ -557,22 +520,6 @@ bool CXmlNode::getAttr(const char* key, Vec4& value) const return false; } -bool CXmlNode::getAttr(const char* key, Vec3d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - SCOPED_LOCALE_RESETTER; - double x, y, z; - if (azsscanf(svalue, "%lf,%lf,%lf", &x, &y, &z) == 3) - { - value = Vec3d(x, y, z); - return true; - } - } - return false; -} - ////////////////////////////////////////////////////////////////////////// bool CXmlNode::getAttr(const char* key, Vec2& value) const { @@ -590,22 +537,6 @@ bool CXmlNode::getAttr(const char* key, Vec2& value) const return false; } -bool CXmlNode::getAttr(const char* key, Vec2d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - SCOPED_LOCALE_RESETTER; - double x, y; - if (azsscanf(svalue, "%lf,%lf", &x, &y) == 2) - { - value = Vec2d(x, y); - return true; - } - } - return false; -} - ////////////////////////////////////////////////////////////////////////// bool CXmlNode::getAttr(const char* key, Quat& value) const { @@ -1369,14 +1300,6 @@ public: // Add new string to pool. const char* AddString(const char* str) { return m_stringPool.Append(str, (int)strlen(str)); } - //char* AddString( const char *str ) { return (char*)str; } - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_stringPool); - pSizer->AddObject(m_nodeStack); - } protected: void onStartElement(const char* tagName, const char** atts); void onEndElement(const char* tagName); @@ -1410,12 +1333,6 @@ protected: { XmlNodeRef node; std::vector childs; //TODO: is it worth lazily initializing this, like CXmlNode::m_pChilds? - - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(node); - pSizer->AddObject(childs); - } }; // First node will become root node. @@ -1735,38 +1652,35 @@ XmlNodeRef XmlParserImp::ParseFile(const char* filename, XmlString& errorString, AZStd::replace(pakPath.begin(), pakPath.end(), '\\', '/'); } - if (g_bEnableBinaryXmlLoading) + XMLBinary::XMLBinaryReader reader; + XMLBinary::XMLBinaryReader::EResult result; + root = reader.LoadFromBuffer(XMLBinary::XMLBinaryReader::eBufferMemoryHandling_TakeOwnership, pFileContents, fileSize, result); + if (root) { - XMLBinary::XMLBinaryReader reader; - XMLBinary::XMLBinaryReader::EResult result; - root = reader.LoadFromBuffer(XMLBinary::XMLBinaryReader::eBufferMemoryHandling_TakeOwnership, pFileContents, fileSize, result); - if (root) + return root; + } + if (result != XMLBinary::XMLBinaryReader::eResult_NotBinXml) + { + delete [] pFileContents; + sprintf_s(str, "%s%s (%s)", errorPrefix, reader.GetErrorDescription(), filename); + errorString = str; + CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "%s", str); + return 0; + } + else + { + // not binary XML - refuse to load if in scripts dir and not in bin xml to help reduce hacking + // wish we could compile the text xml parser out, but too much work to get everything moved over + constexpr AZStd::fixed_string<32> strScripts{"Scripts/"}; + // exclude files and PAKs from Mods folder + constexpr AZStd::fixed_string<8> modsStr{"Mods/"}; + if (_strnicmp(filename, strScripts.c_str(), strScripts.length()) == 0 && + _strnicmp(adjustedFilename.c_str(), modsStr.c_str(), modsStr.length()) != 0 && + _strnicmp(pakPath.c_str(), modsStr.c_str(), modsStr.length()) != 0) { - return root; - } - if (result != XMLBinary::XMLBinaryReader::eResult_NotBinXml) - { - delete [] pFileContents; - sprintf_s(str, "%s%s (%s)", errorPrefix, reader.GetErrorDescription(), filename); - errorString = str; - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "%s", str); - return 0; - } - else - { - // not binary XML - refuse to load if in scripts dir and not in bin xml to help reduce hacking - // wish we could compile the text xml parser out, but too much work to get everything moved over - constexpr AZStd::fixed_string<32> strScripts{"Scripts/"}; - // exclude files and PAKs from Mods folder - constexpr AZStd::fixed_string<8> modsStr{"Mods/"}; - if (_strnicmp(filename, strScripts.c_str(), strScripts.length()) == 0 && - _strnicmp(adjustedFilename.c_str(), modsStr.c_str(), modsStr.length()) != 0 && - _strnicmp(pakPath.c_str(), modsStr.c_str(), modsStr.length()) != 0) - { #ifdef _RELEASE CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Non binary XML found in scripts dir (%s)", filename); #endif - } } } @@ -1806,12 +1720,6 @@ XmlParser::~XmlParser() m_pImpl->Release(); } -void XmlParser::GetMemoryUsage(ICrySizer* pSizer) const -{ - pSizer->AddObject(this, sizeof(*this)); - pSizer->AddObject(m_pImpl); -} - ////////////////////////////////////////////////////////////////////////// XmlNodeRef XmlParser::ParseBuffer(const char* buffer, int nBufLen, bool bCleanPools, bool bSuppressWarnings) { diff --git a/Code/Legacy/CrySystem/XML/xml.h b/Code/Legacy/CrySystem/XML/xml.h index 912767eae7..f4bf6b2969 100644 --- a/Code/Legacy/CrySystem/XML/xml.h +++ b/Code/Legacy/CrySystem/XML/xml.h @@ -34,7 +34,6 @@ public: } }; virtual const char* AddString(const char* str) = 0; - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; private: int m_refCount; }; @@ -68,8 +67,6 @@ public: const char* getErrorString() const { return m_errorString; } - void GetMemoryUsage(ICrySizer* pSizer) const; - private: int m_nRefCount; XmlString m_errorString; @@ -88,8 +85,6 @@ struct XmlAttribute const char* key; const char* value; - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{} - bool operator<(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) < 0; } bool operator>(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) > 0; } bool operator==(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) == 0; } @@ -119,9 +114,6 @@ public: //! Destructor. ~CXmlNode(); - // collect allocated memory informations - void GetMemoryUsage(ICrySizer* pSizer) const; - ////////////////////////////////////////////////////////////////////////// // Custom new/delete with pool allocator. ////////////////////////////////////////////////////////////////////////// @@ -219,11 +211,9 @@ public: void setAttr(const char* key, float value); void setAttr(const char* key, double value); void setAttr(const char* key, const Vec2& value); - void setAttr(const char* key, const Vec2d& value); void setAttr(const char* key, const Ang3& value); void setAttr(const char* key, const Vec3& value); void setAttr(const char* key, const Vec4& value); - void setAttr(const char* key, const Vec3d& value); void setAttr(const char* key, const Quat& value); //! Delete attrbute. @@ -243,11 +233,9 @@ public: bool getAttr(const char* key, XmlString& value) const {const char* v(NULL); bool boHasAttribute(getAttr(key, &v)); value = v; return boHasAttribute; } bool getAttr(const char* key, Vec2& value) const; - bool getAttr(const char* key, Vec2d& value) const; bool getAttr(const char* key, Ang3& value) const; bool getAttr(const char* key, Vec3& value) const; bool getAttr(const char* key, Vec4& value) const; - bool getAttr(const char* key, Vec3d& value) const; bool getAttr(const char* key, Quat& value) const; bool getAttr(const char* key, ColorB& value) const; diff --git a/Code/Legacy/CrySystem/XML/xml_string.h b/Code/Legacy/CrySystem/XML/xml_string.h deleted file mode 100644 index 5973143509..0000000000 --- a/Code/Legacy/CrySystem/XML/xml_string.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - - -#ifndef CRYINCLUDE_CRYSYSTEM_XML_XML_STRING_H -#define CRYINCLUDE_CRYSYSTEM_XML_XML_STRING_H -#pragma once - - -typedef string xml_string; - -#endif // CRYINCLUDE_CRYSYSTEM_XML_XML_STRING_H diff --git a/Code/Legacy/CrySystem/crysystem_files.cmake b/Code/Legacy/CrySystem/crysystem_files.cmake index ac0fd7989c..fc923705f2 100644 --- a/Code/Legacy/CrySystem/crysystem_files.cmake +++ b/Code/Legacy/CrySystem/crysystem_files.cmake @@ -23,7 +23,6 @@ set(FILES Timer.cpp XConsole.cpp XConsoleVariable.cpp - XML/ReadWriteXMLSink.h AZCrySystemInitLogSink.h AZCoreLogSink.h CmdLine.h @@ -36,7 +35,6 @@ set(FILES SimpleStringPool.h CrySystem_precompiled.h System.h - SystemCFG.h SystemEventDispatcher.h Timer.h XConsole.h @@ -44,16 +42,11 @@ set(FILES XML/SerializeXMLReader.cpp XML/SerializeXMLWriter.cpp XML/xml.cpp - XML/XMLPatcher.cpp XML/XmlUtils.cpp XML/SerializeXMLReader.h XML/SerializeXMLWriter.h XML/xml.h - XML/XMLPatcher.h - XML/xml_string.h XML/XmlUtils.h - XML/ReadXMLSink.cpp - XML/WriteXMLSource.cpp LocalizedStringManager.cpp LocalizedStringManager.h Huffman.cpp diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h index 6d361c01ae..8862462093 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h @@ -82,7 +82,6 @@ namespace AZ FontFamilyPtr LoadFontFamily(const char* fontFamilyName) override; FontFamilyPtr GetFontFamily(const char* fontFamilyName) override; void AddCharsToFontTextures(FontFamilyPtr fontFamily, const char* chars, int glyphSizeX = ICryFont::defaultGlyphSizeX, int glyphSizeY = ICryFont::defaultGlyphSizeY) override; - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {} AZStd::string GetLoadedFontNames() const; void OnLanguageChanged() override; void ReloadAllFonts() override; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h index 4820d1c176..b394efe6e1 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h @@ -44,8 +44,6 @@ namespace AZ void WrapText(AZStd::string& result, [[maybe_unused]] float maxWidth, const char* str, [[maybe_unused]] const TextDrawContext& ctx) override { result = str; } - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {} - void GetGradientTextureCoord([[maybe_unused]] float& minU, [[maybe_unused]] float& minV, [[maybe_unused]] float& maxU, [[maybe_unused]] float& maxV) const override {} unsigned int GetEffectId([[maybe_unused]] const char* effectName) const override { return 0; } @@ -75,7 +73,6 @@ namespace AZ virtual FontFamilyPtr LoadFontFamily([[maybe_unused]] const char* fontFamilyName) override { CRY_ASSERT(false); return nullptr; } virtual FontFamilyPtr GetFontFamily([[maybe_unused]] const char* fontFamilyName) override { CRY_ASSERT(false); return nullptr; } virtual void AddCharsToFontTextures([[maybe_unused]] FontFamilyPtr fontFamily, [[maybe_unused]] const char* chars, [[maybe_unused]] int glyphSizeX, [[maybe_unused]] int glyphSizeY) override {}; - virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {} virtual AZStd::string GetLoadedFontNames() const override { return ""; } virtual void OnLanguageChanged() override { } virtual void ReloadAllFonts() override { } diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FBitmap.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FBitmap.h index 6443633245..2570fd2b17 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FBitmap.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FBitmap.h @@ -52,8 +52,6 @@ namespace AZ void SetRenderData(void* renderData) { m_renderData = renderData; }; void* GetRenderData() { return m_renderData; }; - void GetMemoryUsage ([[maybe_unused]] class ICrySizer* sizer) {}; - unsigned char* GetData() { return m_data; } public: diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h index 6f56d912a0..83f53ffec2 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FFont.h @@ -16,9 +16,6 @@ #if !defined(USE_NULLFONT_ALWAYS) #include -#include -#include -#include #include #include "AtomFont.h" @@ -104,20 +101,10 @@ namespace AZ struct FontRenderingPass { - ColorB m_color; - Vec2 m_posOffset; - int m_blendSrc; - int m_blendDest; - - FontRenderingPass() - : m_color(255, 255, 255, 255) - , m_posOffset(0, 0) - , m_blendSrc(GS_BLSRC_SRCALPHA) - , m_blendDest(GS_BLDST_ONEMINUSSRCALPHA) - { - } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} + ColorB m_color = {255, 255, 255, 255}; + Vec2 m_posOffset = {0,0}; + int m_blendSrc = GS_BLSRC_SRCALPHA; + int m_blendDest = GS_BLDST_ONEMINUSSRCALPHA; }; struct FontEffect @@ -141,8 +128,6 @@ namespace AZ { m_passes.resize(0); } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} }; typedef std::vector FontEffects; @@ -179,7 +164,6 @@ namespace AZ Vec2 GetTextSize(const char* str, const bool asciiMultiLine, const TextDrawContext& ctx) override; size_t GetTextLength(const char* str, const bool asciiMultiLine) const override; void WrapText(AZStd::string& result, float maxWidth, const char* str, const TextDrawContext& ctx) override; - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {}; void GetGradientTextureCoord(float& minU, float& minV, float& maxU, float& maxV) const override; unsigned int GetEffectId(const char* effectName) const override; unsigned int GetNumEffects() const override; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontRenderer.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontRenderer.h index 3cfb900055..91e8c6ae9f 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontRenderer.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontRenderer.h @@ -79,8 +79,6 @@ namespace AZ int GetGlyph(GlyphBitmap* glyphBitmap, int* horizontalAdvance, uint8_t* glyphWidth, uint8_t* glyphHeight, int32_t& m_characterOffsetX, int32_t& m_characterOffsetY, int iX, int iY, int characterCode, const FFont::FontHintParams& glyphFlags = FFont::FontHintParams()); int GetGlyphScaled(GlyphBitmap* glyphBitmap, int* glyphWidth, int* glyphHeight, int iX, int iY, float scaleX, float scaleY, int characterCode); - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} - bool GetMonospaced() const { return FT_IS_FIXED_WIDTH(m_face) != 0; } Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontTexture.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontTexture.h index f20b0463d9..42766f8910 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontTexture.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/FontTexture.h @@ -51,8 +51,6 @@ namespace AZ { m_slotUsage = 0xffff; } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} }; //! Stores the glyphs of a font within a single cpu texture. @@ -131,8 +129,6 @@ namespace AZ int WriteToFile(const AZStd::string& fileName); - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} - bool GetMonospaced() const { return m_glyphCache.GetMonospaced(); } Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphBitmap.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphBitmap.h index 1f3aa6955f..c82ba111e2 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphBitmap.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphBitmap.h @@ -14,8 +14,6 @@ #include #include -class ICrySizer; - namespace AZ { class GlyphBitmap @@ -40,8 +38,6 @@ namespace AZ int GetWidth() { return m_width; } int GetHeight() { return m_height; } - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} - private: AZStd::unique_ptr m_buffer; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphCache.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphCache.h index 271b6810d3..2e57a70132 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphCache.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/GlyphCache.h @@ -55,8 +55,6 @@ namespace AZ m_glyphBitmap.Clear(); } - - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} }; //! The glyph cache maps UTF32 codepoints to their corresponding FreeType data. @@ -110,8 +108,6 @@ namespace AZ //! \sa FontRenderer::GetGlyph, FontTexture::UpdateSlot int GetGlyph(GlyphBitmap** glyph, int* horizontalAdvance, int* width, int* height, int32_t& m_characterOffsetX, int32_t& m_characterOffsetY, uint32_t character, const AtomFont::GlyphSize& glyphSize = AtomFont::defaultGlyphSize, const FFont::FontHintParams& glyphFlags = FFont::FontHintParams()); - void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const {} - bool GetMonospaced() const { return m_fontRenderer.GetMonospaced(); } Vec2 GetKerning(uint32_t leftGlyph, uint32_t rightGlyph); diff --git a/Gems/Blast/Code/Source/Family/DamageManager.h b/Gems/Blast/Code/Source/Family/DamageManager.h index 4bffd8c5e0..ed8d03da18 100644 --- a/Gems/Blast/Code/Source/Family/DamageManager.h +++ b/Gems/Blast/Code/Source/Family/DamageManager.h @@ -7,6 +7,8 @@ */ #pragma once +#include "AzCore/Interface/Interface.h" + #include #include #include diff --git a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYAssetExplorer.cpp b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYAssetExplorer.cpp index af37e0139a..055537a8bb 100644 --- a/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYAssetExplorer.cpp +++ b/Gems/ImGui/Code/Source/LYCommonMenu/ImGuiLYAssetExplorer.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialHandle.h b/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialHandle.h index 1d6ef4040d..b8b9e316ff 100644 --- a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialHandle.h +++ b/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialHandle.h @@ -8,20 +8,19 @@ #pragma once -#include -#include +#include #include +struct IMaterial; + namespace AZ { class BehaviorContext; } - namespace LmbrCentral { //! Wraps a IMaterial pointer in a way that BehaviorContext can use it class MaterialHandle - : public AZ::RenderNotificationsBus::Handler { public: AZ_CLASS_ALLOCATOR(MaterialHandle, AZ::SystemAllocator, 0); @@ -29,13 +28,15 @@ namespace LmbrCentral MaterialHandle() { - AZ::RenderNotificationsBus::Handler::BusConnect(); } MaterialHandle(const MaterialHandle& handle) : m_material(handle.m_material) { - AZ::RenderNotificationsBus::Handler::BusConnect(); + } + + ~MaterialHandle() + { } MaterialHandle& operator=(const MaterialHandle& rhs) @@ -44,20 +45,7 @@ namespace LmbrCentral return *this; } - ~MaterialHandle() override - { - AZ::RenderNotificationsBus::Handler::BusDisconnect(); - } - - //! Handle the renderer's free resources event by nullifying m_material. - //! This is used to prevent material handles that may have been queued for release in the next frame - //! from having dangling pointers after the renderer has already shut down. - void OnRendererFreeResources([[maybe_unused]] int flags) override - { - m_material = nullptr; - } - - _smart_ptr m_material; + IMaterial* m_material; static void Reflect(AZ::BehaviorContext* behaviorContext); static void Reflect(AZ::SerializeContext* serializeContext); diff --git a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialOwnerBus.h b/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialOwnerBus.h deleted file mode 100644 index 2162a9f7ed..0000000000 --- a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MaterialOwnerBus.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ -#pragma once - -#include -#include -#include -#include - -namespace LmbrCentral -{ - /*! - * Messages serviced by components that support materials (e.g. Mesh, Decal). - * We specifically chose the name "MaterialOwnerRequestBus" rather than just "MaterialRequestBus" to communicate - * the fact that the requests are not for a Material directly, but for an Entity/Component that uses a Material. - */ - class MaterialOwnerRequests - : public AZ::ComponentBus - { - public: - - //! Sets the component's current material. - virtual void SetMaterial(_smart_ptr) = 0; - //! Gets the component's current material. - virtual _smart_ptr GetMaterial() = 0; - - //! Indicates whether the Material Owner is fully initialized, and MaterialOwnerRequestBus can be used on the Material. - virtual bool IsMaterialOwnerReady() { return true; } - - //! Sets the component's current material. This MaterialHandle version provides support for BehaviorContext reflection. - //! \param materialHandle New material handle - virtual void SetMaterialHandle(const MaterialHandle& /*materialHandle*/) {}; - //! Gets the component's current material. This MaterialHandle version provides support for BehaviorContext reflection. - virtual MaterialHandle GetMaterialHandle() { return MaterialHandle(); } - - //! Sets a Material property for the bus Entity. The Material will be cloned once before any changes are applied, so other instances are not affected. - //! \param name Name of the material param to set. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param value New value for the param - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - virtual void SetMaterialParamVector4(const AZStd::string& /*name*/, const AZ::Vector4& /*value*/, int /*materialId = 1*/) {}; - - //! Sets a Material property for the bus Entity. The Material will be cloned once before any changes are applied, so other instances are not affected. - //! \param name Name of the material param to set. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param value New value for the param - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - virtual void SetMaterialParamVector3(const AZStd::string& /*name*/, const AZ::Vector3& /*value*/, int /*materialId = 1*/) {}; - - //! Sets a Material property for the bus Entity. The Material will be cloned once before any changes are applied, so other instances are not affected. - //! \param name Name of the material param to set. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param value New value for the param - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - virtual void SetMaterialParamColor(const AZStd::string& /*name*/, const AZ::Color& /*value*/, int /*materialId = 1*/) {}; - - //! Sets a Material property for the bus Entity. The Material will be cloned once before any changes are applied, so other instances are not affected. - //! \param name Name of the material param to set. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param value New value for the param - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - virtual void SetMaterialParamFloat(const AZStd::string& /*name*/, float /*value*/, int /*materialId = 1*/) {}; - - //! Returns a Material property value for the bus Entity. - //! \param name Name of the material param to get. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - //! \return The value of the param, or 0's if the param could not be found. - virtual AZ::Vector4 GetMaterialParamVector4(const AZStd::string& /*name*/, int /*materialId = 1*/) { return AZ::Vector4::CreateZero(); }; - - //! Returns a Material property value for the bus Entity. - //! \param name Name of the material param to get. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - //! \return The value of the param, or 0's if the param could not be found. - virtual AZ::Vector3 GetMaterialParamVector3(const AZStd::string& /*name*/, int /*materialId = 1*/) { return AZ::Vector3::CreateZero(); }; - - //! Returns a Material property value for the bus Entity. - //! \param name Name of the material param to get. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - //! \return The value of the param, or 0's if the param could not be found. - virtual AZ::Color GetMaterialParamColor(const AZStd::string& /*name*/, int /*materialId = 1*/) { return AZ::Color::CreateZero(); }; - - //! Returns a Material property value for the bus Entity. - //! \param name Name of the material param to get. May be a custom defined param in the shader, or one of the standard lighting params (diffuse, specular, emissive_color, emissive_intensity, shininess, opacity, alpha). - //! \param materialId ID of the desired material slot. The first slot is Material ID 1. - //! \return The value of the param, or 0 if the param could not be found. - virtual float GetMaterialParamFloat(const AZStd::string& /*name*/, int /*materialId = 1*/) { return 0.0f; }; - }; - - using MaterialOwnerRequestBus = AZ::EBus; - - /*! - * Messages sent by components that support materials (e.g. Mesh, Decal). - * We specifically chose the name "MaterialOwnerNotificationBus" rather than just "MaterialNotificationBus" to communicate - * the fact that the requests are not for a Material directly, but for an Entity/Component that uses a Material. - */ - class MaterialOwnerNotifications - : public AZ::ComponentBus - { - public: - - //! Sent when the material owner is fully initialized, and MaterialOwnerRequestBus can be used on the Material. - //! Before this event, MaterialOwnerRequestBus functions probably won't do anything, because the Material likely - //! doesn't exist yet. - virtual void OnMaterialOwnerReady() = 0; - - /** - * When connecting to this bus, if the material owner is ready you will immediately get an OnMaterialOwnerReady event - **/ - template - struct ConnectionPolicy - : public AZ::EBusConnectionPolicy - { - static void Connect(typename Bus::BusPtr& busPtr, typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::Context::ConnectLockGuard& connectLock, const typename Bus::BusIdType& id = 0) - { - AZ::EBusConnectionPolicy::Connect(busPtr, context, handler, connectLock, id); - - bool readyResult = false; - LmbrCentral::MaterialOwnerRequestBus::EventResult( - readyResult, - id, - &LmbrCentral::MaterialOwnerRequestBus::Events::IsMaterialOwnerReady); - - if (readyResult) - { - handler->OnMaterialOwnerReady(); - } - } - }; - }; - - using MaterialOwnerNotificationBus = AZ::EBus; - -} // namespace LmbrCentral diff --git a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MeshAsset.h b/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MeshAsset.h index a1a8c5daba..66e992890e 100644 --- a/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MeshAsset.h +++ b/Gems/LmbrCentral/Code/include/LmbrCentral/Rendering/MeshAsset.h @@ -18,7 +18,7 @@ namespace LmbrCentral : public AZ::Data::AssetData { public: - using MeshPtr = _smart_ptr; + using MeshPtr = IStatObj*; AZ_RTTI(MeshAsset, "{C2869E3B-DDA0-4E01-8FE3-6770D788866B}", AZ::Data::AssetData); AZ_CLASS_ALLOCATOR(MeshAsset, AZ::SystemAllocator, 0); diff --git a/Gems/LmbrCentral/Code/lmbrcentral_files.cmake b/Gems/LmbrCentral/Code/lmbrcentral_files.cmake index 73cd12d2b7..d663d2ec06 100644 --- a/Gems/LmbrCentral/Code/lmbrcentral_files.cmake +++ b/Gems/LmbrCentral/Code/lmbrcentral_files.cmake @@ -34,7 +34,6 @@ set(FILES include/LmbrCentral/Rendering/LightComponentBus.h include/LmbrCentral/Rendering/MaterialAsset.h include/LmbrCentral/Rendering/MaterialHandle.h - include/LmbrCentral/Rendering/MaterialOwnerBus.h include/LmbrCentral/Rendering/MeshAsset.h include/LmbrCentral/Rendering/MeshModificationBus.h include/LmbrCentral/Rendering/RenderNodeBus.h diff --git a/Gems/LyShine/Code/Source/Tests/internal/test_UiTextComponent.cpp b/Gems/LyShine/Code/Source/Tests/internal/test_UiTextComponent.cpp index 05e670fdd5..33c2738e54 100644 --- a/Gems/LyShine/Code/Source/Tests/internal/test_UiTextComponent.cpp +++ b/Gems/LyShine/Code/Source/Tests/internal/test_UiTextComponent.cpp @@ -110,7 +110,7 @@ namespace ++drawBatchIt) { const UiTextComponent::DrawBatch& drawBatch = *drawBatchIt; - numNewlinesFound += static_cast(AZStd::count_if(drawBatch.text.begin(), drawBatch.text.end(), + numNewlinesFound += static_cast(AZStd::count_if(drawBatch.text.begin(), drawBatch.text.end(), [](char c) -> bool { return c == '\n'; @@ -135,11 +135,11 @@ namespace } //! \brief Verify fonts that ship with Open 3D Engine load correctly. - //! + //! //! This test depends on the LyShineExamples and UiBasics gems being //! included in the project. //! - //! There are other fonts that ship in other projects (SamplesProject, + //! There are other fonts that ship in other projects (SamplesProject, //! FeatureTests), but that would call for project-specific unit-tests //! which don't belong here. void VerifyShippingFonts() @@ -168,7 +168,7 @@ namespace AZ_Assert(AZStd::string(inputStringCopy.c_str()) == inputString, "Test failed"); } } - + } void BuildDrawBatchesTests(FontFamily* fontFamily) @@ -179,7 +179,7 @@ namespace STextDrawContext fontContext; fontContext.SetEffect(0); fontContext.SetSizeIn800x600(false); - fontContext.SetSize(vector2f(32.0f, 32.0f)); + fontContext.SetSize(Vec2(32.0f, 32.0f)); const float defaultAscent = fontFamily->normal->GetAscender(fontContext); // Plain string @@ -635,7 +635,7 @@ namespace } } - // Anchor tag with multiple colors within link + // Anchor tag with multiple colors within link { const LyShine::StringType markupTestString("this is a test!"); @@ -2021,7 +2021,7 @@ namespace STextDrawContext fontContext; fontContext.SetEffect(0); fontContext.SetSizeIn800x600(false); - fontContext.SetSize(vector2f(32.0f, 32.0f)); + fontContext.SetSize(Vec2(32.0f, 32.0f)); const float defaultAscent = fontFamily->normal->GetAscender(fontContext); { @@ -2082,7 +2082,7 @@ namespace AZ_Assert(0 == fontFamilyRefs.size(), "Test failed"); AZ_Assert(2 == drawBatches.size(), "Test failed"); AssertTextNotEmpty(drawBatches); - + StringList stringList; stringList.push_back("this"); stringList.push_back(" is a test!"); @@ -2149,7 +2149,7 @@ namespace STextDrawContext fontContext; fontContext.SetEffect(0); fontContext.SetSizeIn800x600(false); - fontContext.SetSize(vector2f(32.0f, 32.0f)); + fontContext.SetSize(Vec2(32.0f, 32.0f)); UiTextComponent::InlineImageContainer inlineImages; float defaultImageHeight = 32.0f; @@ -2581,7 +2581,7 @@ namespace } } - // Next line + // Next line ++batchLineIter; { const auto& batchLine = *batchLineIter; @@ -2667,7 +2667,7 @@ namespace } } - // Next line + // Next line ++batchLineIter; { const auto& batchLine = *batchLineIter; @@ -2725,7 +2725,7 @@ namespace { expectedWidth = 0.0f; } - + AZ_Assert(IsClose(newWidth, expectedWidth), "Test failed: Character Spacing, %s. Expected: %f, actual: %f", testName, expectedWidth, newWidth); lyshine->ReleaseCanvas(canvasEntityId, false); @@ -2981,7 +2981,7 @@ namespace AZ::EntityId testElemId = testElem->GetId(); // Verify that GetText and GetAsIs returns the unlocalized key "@ui_Hello" along - // with the original (escaped) markup characters + // with the original (escaped) markup characters { AZStd::string testString("&<>% @ui_Hello"); UiTextInterface::SetTextFlags setTextFlags = static_cast(UiTextInterface::SetEscapeMarkup | UiTextInterface::SetLocalized); @@ -3011,7 +3011,7 @@ namespace // Tests: Setting localized text with abutting invalid localization key chars // // Purpose: localization tokens appear in strings surrounded by characters that - // shouldn't be part of the localization key. + // shouldn't be part of the localization key. // // For example: // "@ui_Hello, @ui_Welcome!" @@ -3110,12 +3110,12 @@ namespace // Test that markup is disabled by default. EBUS_EVENT_ID_RESULT(enabled, testElemId, UiTextBus, GetIsMarkupEnabled); AZ_Assert(!enabled, "Test failed"); - + // Test that setting it to false when it is already false, does not set it to true. EBUS_EVENT_ID(testElemId, UiTextBus, SetIsMarkupEnabled, false); EBUS_EVENT_ID_RESULT(enabled, testElemId, UiTextBus, GetIsMarkupEnabled); AZ_Assert(!enabled, "Test failed"); - + // Check that the flag is actually disabled by checking the size of the textbox EBUS_EVENT_ID_RESULT(NewSize, testElemId, UiTextBus, GetTextSize); AZ_Assert(NewSize == MarkUpDisabledSize, "Test failed"); @@ -3287,7 +3287,7 @@ void FontSharedPtrTests() // This is a negative test which is difficult to support currently. // Uncommenting this line should trigger an assert in CryFont because - // the font was de-allocated while still being referenced by a + // the font was de-allocated while still being referenced by a // FontFamily //notoSans->normal->Release(); @@ -3418,7 +3418,7 @@ void FontSharedPtrTests() AZ_Assert(fontBoldItalic == notoSans->boldItalic, "Test failed"); } - // Once FontFamilyPtr goes out of scope, all associated font family + // Once FontFamilyPtr goes out of scope, all associated font family // fonts should get unloaded too. IFFont* fontRegular = GetISystem()->GetICryFont()->GetFont(notoSansRegular); AZ_Assert(!fontRegular, "Test failed"); @@ -3454,11 +3454,11 @@ void FontSharedPtrTests() const char* veraFontFamilyFile = "fonts/vera.fontfamily"; FontFamilyPtr veraFontFamily = gEnv->pCryFont->LoadFontFamily(veraFontFamilyFile); - + // BEGIN JAV_LY_FORK: The above "vera.font" is a pass-through font (not a font family) // and is now mapped by by its full filepath rather than just the filename. AZ_Assert(veraFontFamily.get(), "Test failed"); - + // The vera font family uses vera.font for its regular-weighted font, // so the ref count for vera.font increases by one, from 4 to 5. AZ_Assert(6 == veraFont->normal->AddRef(), "Test failed"); @@ -3483,12 +3483,12 @@ void UiTextComponent::UnitTest(CLyShine* lyshine, IConsoleCmdArgs* cmdArgs) else { // These tests assume the unit-tests run at startup in order for ref count - // values to make sense. + // values to make sense. AZ_Warning("LyShine", false, "Unit-tests: skipping FontSharedPtrTests due to tests running " "ad-hoc. Run unit tests at startup for full coverage. See ui_RunUnitTestsOnStartup."); } - + VerifyShippingFonts(); // These fonts are required for subsequent unit-tests to work. diff --git a/Gems/LyShine/Code/Source/UiTextComponent.cpp b/Gems/LyShine/Code/Source/UiTextComponent.cpp index 1c8189fa2a..e18a9cefe2 100644 --- a/Gems/LyShine/Code/Source/UiTextComponent.cpp +++ b/Gems/LyShine/Code/Source/UiTextComponent.cpp @@ -62,7 +62,7 @@ namespace AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement) { - // This element is a pre-version-8 text component. Prior to version 8 there was no MarkupEnabled + // This element is a pre-version-8 text component. Prior to version 8 there was no MarkupEnabled // flag and markup was always enabled. Going forward, for new components we want to default to // markupEnabled = false because of the performance hit of parsing text strings for XML. // However, we want to be backward compatible with old data so for pre-version-8 components @@ -168,10 +168,10 @@ namespace //! Migrate legacy shrink-to-fit setting to new ShrinkToFit enum. //! - //! As of V8 of text component, the "shrink to fit" setting was a value of + //! As of V8 of text component, the "shrink to fit" setting was a value of //! the WrapTextSetting enum. With V9, a new ShrinkToFit enum was introduced //! and offered an additional "width-only" option (previously, shrink-to-fit - //! only performed uniform scaling along both axes). + //! only performed uniform scaling along both axes). bool ConvertV8ShrinkToFitSetting( AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement) @@ -194,7 +194,7 @@ namespace if (shrinkToFitSettingNeedsUpdating) { // It wasn't possible to word-wrap and have shrink-to-fit before, so we just - // reset the wrap text setting to NoWrap to maintain backwards compatibilty. + // reset the wrap text setting to NoWrap to maintain backwards compatibilty. if (!wrapTextSettingNode.SetData(context, static_cast(UiTextInterface::WrapTextSetting::NoWrap))) { AZ_Error("Serialization", false, "Unable to set WrapTextSetting to NoWrap (%d).", static_cast(UiTextInterface::WrapTextSetting::NoWrap)); @@ -964,7 +964,7 @@ namespace //! \param imageStartPos Upper-left coordinate of unclipped image //! \param imageEndPos Bottom-right coordinate of unclipped image void ClipImageQuadAndUvs( - AZ::Vector3* imageQuad, + AZ::Vector3* imageQuad, AZ::Vector2* uvs, const UiTransformInterface::RectPoints& points, const UiTextComponent::DrawBatch& drawBatch, @@ -1022,7 +1022,7 @@ namespace //! Note that this assumes the lines have been word-wrapped and don't overflow horizontally. int GetNumNonOverflowingLinesForElement( const UiTextComponent::DrawBatchLineContainer& batchLines, - const AZ::Vector2& currentElementSize, + const AZ::Vector2& currentElementSize, float lineSpacing) { int maxLinesElementCanHold = 0; @@ -1426,7 +1426,7 @@ bool UiTextComponent::DrawBatchLine::CheckAndSplitLine(const STextDrawContext& c DrawBatchLine& newDrawBatchLineOut) { bool lineSplit = false; - + // Allow a space at the end of the line to overflow. This is to remain consistent with the non-image // line split implementation. If the space at the end of the line was simply removed, the character // indexes wouldn't match the localized text character indexes, and would cause issues with cursor positioning @@ -1453,7 +1453,7 @@ bool UiTextComponent::DrawBatchLine::CheckAndSplitLine(const STextDrawContext& c // Check whether current batch is overflowing and get overflow info UiTextComponent::DrawBatch::OverflowInfo overflowInfoOut; bool overflowing = drawBatchIterator->GetOverflowInfo(ctx, availableWidth, skipFirstChar, overflowInfoOut); - + // Check if this batch has a space and remember for later if (overflowInfoOut.lastSpaceIndex >= 0) { @@ -1483,7 +1483,7 @@ bool UiTextComponent::DrawBatchLine::CheckAndSplitLine(const STextDrawContext& c isLastSpaceAtEndOfBatch = false; numCharsSinceLastSpace = -1; } - + if (overflowing) { // Find a batch to split @@ -1667,13 +1667,13 @@ void UiTextComponent::ResetOverrides() m_overrideColor = m_color; colorChanged = true; } - + if (m_overrideAlpha != m_alpha) { m_overrideAlpha = m_alpha; alphaChanged = true; } - + if (m_overrideFontFamily != m_fontFamily) { m_overrideFontFamily = m_fontFamily; @@ -1771,7 +1771,7 @@ void UiTextComponent::Render(LyShine::IRenderGraph* renderGraph) float finalAlpha = fade * m_overrideAlpha; uint8 finalAlphaByte = static_cast(finalAlpha * 255.0f); - // if we have any cached text batches that have transparency in their font effects then we need to + // if we have any cached text batches that have transparency in their font effects then we need to // regenerate the render cache if alpha has changed. This is fairly unusual so it still // makes sense to not mark the render cache dirty on most fades or alpha changes. if (m_drawBatchLines.m_fontEffectHasTransparency) @@ -1779,7 +1779,7 @@ void UiTextComponent::Render(LyShine::IRenderGraph* renderGraph) if (!m_renderCache.m_batches.empty() && m_renderCache.m_batches[0]->m_color.a != finalAlphaByte) { MarkRenderCacheDirty(); - } + } } // If the cache is out of date then regenerate it @@ -1889,7 +1889,7 @@ void UiTextComponent::Render(LyShine::IRenderGraph* renderGraph) batch->m_color.a = finalAlphaByte; } - // We always use wrap mode for text (isClamp false). This is historically what was done + // We always use wrap mode for text (isClamp false). This is historically what was done // in CryFont and without it characters that are on the left of the font texture look bad // because there is no padding on the left of the glyphs. bool isClampTextureMode = false; @@ -2029,7 +2029,7 @@ void UiTextComponent::SetColor(const AZ::Color& color) { if (m_drawBatchLines.m_fontEffectHasTransparency) { - MarkRenderCacheDirty(); + MarkRenderCacheDirty(); } else { @@ -2378,7 +2378,7 @@ void UiTextComponent::SetSelectionRange(int startIndex, int endIndex, const AZ:: // The render cache stores positions based on these values so mark it dirty MarkRenderCacheDirty(); -} +} //////////////////////////////////////////////////////////////////////////////////////////////////// void UiTextComponent::ClearSelectionRange() @@ -2691,7 +2691,7 @@ void UiTextComponent::GetClickableTextRects(UiClickableTextInterface::ClickableT alignedPosition.SetX(alignedPosition.GetX() + xDrawPosOffset); Vec2 textSize(drawBatch.size.GetX(), drawBatch.size.GetY()); xDrawPosOffset = textSize.x; - + if (drawBatch.IsClickable()) { UiClickableTextInterface::ClickableTextRect clickableRect; @@ -2736,7 +2736,7 @@ void UiTextComponent::SetClickableTextColor(int id, const AZ::Color& color) if (id == drawBatch.clickableId) { // Don't return here. We purposely continue iterating in - // case there are subsequent draw batches (especially + // case there are subsequent draw batches (especially // across multiple draw batch lines) with the same ID. // This will occur with word-wrapped text. drawBatch.color = color.GetAsVector3(); @@ -2851,7 +2851,7 @@ float UiTextComponent::GetTargetWidth(float maxWidth) // for rendering, a new empty line will be added to account for the newline that gets added // due to not having enough room for the trailing space bool excludeTrailingSpaceWidth = false; - + DrawBatchLines drawBatchLines; CalculateDrawBatchLines(drawBatchLines, forceNoWrap, maxWidth, excludeTrailingSpaceWidth); @@ -2891,7 +2891,7 @@ float UiTextComponent::GetTargetHeight(float maxHeight) const bool haveMaxHeight = LyShine::IsUiLayoutCellSizeSpecified(maxHeight); const bool ellipsis = m_overflowMode == OverflowMode::Ellipsis; const bool shrinkToFit = m_shrinkToFit == ShrinkToFit::Uniform; - + const bool handleOverflow = haveMaxHeight && (ellipsis || shrinkToFit); const bool handleNoOverflow = !haveMaxHeight && (m_drawBatchLines.fontSizeScale.GetY() != 1.0f); @@ -3431,7 +3431,7 @@ void UiTextComponent::OnFontSizeChange() { m_isRequestFontSizeDirty = true; - // We need to re-prepare the text for rendering, however this may not be + // We need to re-prepare the text for rendering, however this may not be // very efficient since completely re-preparing the text (parsing markup, // preparing batches, etc.) may not be necessary. MarkDrawBatchLinesDirty(true); @@ -3499,7 +3499,7 @@ void UiTextComponent::OnLineSpacingChange() // If shrink-to-fit applies, we need to re-create draw batch lines in // order to ensure overflow conditions are properly applied. if (m_shrinkToFit != ShrinkToFit::None) - { + { MarkDrawBatchLinesDirty(true); } else @@ -3863,7 +3863,7 @@ void UiTextComponent::CalculateDrawBatchLines( drawBatches.push_back(DrawBatch()); drawBatches.front().font = font; drawBatches.front().text = m_locText; - + // If the font effect we are using has any passes with alpha of less than 1 (not common) then // we set a flag in the batch lines since it affects how we can update the alpha in the cache drawBatchLinesOut.m_fontEffectHasTransparency = font->DoesEffectHaveTransparency(fontContext.m_fxIdx); @@ -3875,7 +3875,7 @@ void UiTextComponent::CalculateDrawBatchLines( delete image; } prevInlineImages.clear(); - + // Check if we have any inline images that require us to connect to the texture atlas bus if (drawBatchLinesOut.inlineImages.size() > 0) { @@ -4107,7 +4107,7 @@ void UiTextComponent::RenderDrawBatchLines( const AZ::Vector2 imageStartPos = AZ::Vector2( alignedPosition.GetX() + drawBatch.image->m_leftPadding, alignedPosition.GetY() + drawBatch.yOffset); - + const AZ::Vector2 imageEndPos = AZ::Vector2( imageStartPos.GetX() + drawBatch.image->m_size.GetX(), imageStartPos.GetY() + drawBatch.image->m_size.GetY()); @@ -4121,7 +4121,7 @@ void UiTextComponent::RenderDrawBatchLines( AZ::Vector2 uvs[4]; if (drawBatch.image->m_atlas) { - uvs[0] = AZ::Vector2(static_cast(drawBatch.image->m_coordinates.GetLeft()) / drawBatch.image->m_atlas->GetWidth(), + uvs[0] = AZ::Vector2(static_cast(drawBatch.image->m_coordinates.GetLeft()) / drawBatch.image->m_atlas->GetWidth(), static_cast(drawBatch.image->m_coordinates.GetTop()) / drawBatch.image->m_atlas->GetHeight()); uvs[2] = AZ::Vector2(static_cast(drawBatch.image->m_coordinates.GetRight()) / drawBatch.image->m_atlas->GetWidth(), static_cast(drawBatch.image->m_coordinates.GetBottom()) / drawBatch.image->m_atlas->GetHeight()); @@ -4227,9 +4227,9 @@ STextDrawContext UiTextComponent::GetTextDrawContextPrototype(int requestFontSiz // Shrink-to-fit scaling (fontSizeScale) gets applied to font size, but not request size. // This means that re-rendered fonts will not re-render characters that are scaled via // shrink-to-fit - a scale transformation is applied for these characters instead. For - // higher quality font scaling with shrink-to-fit, consider taking m_fontSizeScale into + // higher quality font scaling with shrink-to-fit, consider taking m_fontSizeScale into // account. - ctx.SetSize(vector2f(m_fontSize * fontSizeScale.GetX(), m_fontSize * fontSizeScale.GetY())); + ctx.SetSize(Vec2(m_fontSize * fontSizeScale.GetX(), m_fontSize * fontSizeScale.GetY())); ctx.m_requestSize = Vec2i(requestFontSize, requestFontSize); ctx.m_processSpecialChars = false; ctx.m_tracking = (m_charSpacing * ctx.m_size.x) / 1000.0f; // m_charSpacing units are 1/1000th of ems, 1 em is equal to font size. @@ -4406,7 +4406,7 @@ void UiTextComponent::HandleShrinkToFitWithWrapping( //////////////////////////////////////////////////////////////////////////////////////////////////// void UiTextComponent::HandleWidthOnlyShrinkToFitWithWrapping( UiTextComponent::DrawBatchLines& drawBatchLinesOut, - const AZ::Vector2& currentElementSize, + const AZ::Vector2& currentElementSize, int maxLinesElementCanHold) { bool textStillOverflows = true; @@ -4418,8 +4418,8 @@ void UiTextComponent::HandleWidthOnlyShrinkToFitWithWrapping( DrawBatchLineContainer::reverse_iterator riter; int overflowLineCount = 0; float overflowingLineSize = 0.0f; - for (riter = drawBatchLinesOut.batchLines.rbegin(); - riter != drawBatchLinesOut.batchLines.rend() && overflowLineCount < numOverflowingLines; + for (riter = drawBatchLinesOut.batchLines.rbegin(); + riter != drawBatchLinesOut.batchLines.rend() && overflowLineCount < numOverflowingLines; ++riter, ++overflowLineCount) { DrawBatchLine& batchLine = *riter; @@ -4458,7 +4458,7 @@ void UiTextComponent::HandleWidthOnlyShrinkToFitWithWrapping( maxLinesElementCanHold = GetNumNonOverflowingLinesForElement(drawBatchLinesOut.batchLines, currentElementSize, m_lineSpacing); // Just because we applied a scale doesn't mean the text fits. This is due to word wrap. - // Even though we calculate the exact scale to accmmodate all the characters for the + // Even though we calculate the exact scale to accmmodate all the characters for the // max number of lines the element can hold, word-wrap divides the characters unevenly // across the total space required by the text, because overflowing words/characters are // wrapped to the next line (and a character is "atomic" and can't be divided arbitrarily @@ -4485,7 +4485,7 @@ void UiTextComponent::HandleUniformShrinkToFitWithWrapping( // This keeps track of the last known largest scale that fits the text // to the element bounds with word wrap. float bestScaleFoundSoFar = curFontScale; - + // Calculate a default scale multiplier used to reduce the font scale by a percentage // until the text no longer overflows. // The default scale multiplier is the ratio of available height to the required height. @@ -4500,14 +4500,14 @@ void UiTextComponent::HandleUniformShrinkToFitWithWrapping( // If min shrink scale applies, and it's bigger than the default scale multplier, // we set the scale to be half the difference between 1.0f (no scale) and the // min shrink scale (a "half step"). This gives a starting point that avoids - // applying a scale that is too small too soon (esp for text that "almost fits" + // applying a scale that is too small too soon (esp for text that "almost fits" // the element bounds). const float minShrinkScaleHalfStep = (1.0f - m_minShrinkScale) * 0.5f + m_minShrinkScale; const bool useMinShrinkScale = m_minShrinkScale > 0.0f; const float scaleMultiplierUnclamped = useMinShrinkScale ? minShrinkScaleHalfStep : defaultScaleMultiplier; const float scaleMultiplier = AZStd::GetMax(defaultScaleMultiplier, scaleMultiplierUnclamped); - + // Text always starts out overflowing bool textStillOverflows = true; @@ -4532,7 +4532,7 @@ void UiTextComponent::HandleUniformShrinkToFitWithWrapping( maxLinesElementCanHold = GetNumNonOverflowingLinesForElement(drawBatchLinesOut.batchLines, currentElementSize, m_lineSpacing); // Just because we applied a scale doesn't mean the text fits. This is due to word wrap. - // Even though we calculate the exact scale to accmmodate all the characters for the + // Even though we calculate the exact scale to accmmodate all the characters for the // max number of lines the element can hold, word-wrap divides the characters unevenly // across the total space required by the text, because overflowing words/characters are // wrapped to the next line (and a character is "atomic" and can't be divided arbitrarily @@ -4585,7 +4585,7 @@ void UiTextComponent::HandleEllipsis(UiTextComponent::DrawBatchLines& drawBatchL { return; } - + AZ::Vector2 textSize = GetTextSizeFromDrawBatchLines(drawBatchLinesOut); AZ::Vector2 currentElementSize; // This needs to be computed with the unscaled size. This is because scaling happens after the text is laid out. EBUS_EVENT_ID_RESULT(currentElementSize, GetEntityId(), UiTransformBus, GetCanvasSpaceSizeNoScaleRotate); @@ -4651,7 +4651,7 @@ void UiTextComponent::HandleEllipsis(UiTextComponent::DrawBatchLines& drawBatchL const bool noOtherBatches = 1 == lineToEllipsisPtr->drawBatchList.size(); const bool removeBatchContainingOnlyEllipsis = batchContainsOnlyEllipsis && noOtherBatches; if (removeBatchContainingOnlyEllipsis) - { + { linesToRemove.push_back(lineToEllipsis); } else @@ -4716,7 +4716,7 @@ void UiTextComponent::GetLineToEllipsisAndLinesToTruncate(UiTextComponent::DrawB prevBatchLine = iter; continue; } - + // Prevent the first line of text from being removed, even if the text // is overflowing. With ellipsis enabled, this content will be clipped. const bool firstLine = iter == drawBatchLinesOut.batchLines.begin(); @@ -4776,7 +4776,7 @@ UiTextComponent::DrawBatch* UiTextComponent::GetDrawBatchToEllipseAndPositions(c ellipsisSize = drawBatchToEllipse->font->GetTextSize(ellipseText, true, ctx).x; // Calculate where the ellipsis must start in order to be contained within the - // element bounds. Also, guard against narrow elements that aren't wide enough + // element bounds. Also, guard against narrow elements that aren't wide enough // to accommodate ellipsis. *ellipsisPos = AZStd::GetMax(0.0f, currentElementSize.GetX() - ellipsisSize); *drawBatchStartPos = startPositions->back().second; @@ -4838,7 +4838,7 @@ int UiTextComponent::GetStartEllipseIndexInDrawBatch(const DrawBatch* drawBatchT char codepoint[5] = { 0 }; char* codepointPtr = codepoint; Utf8::Unchecked::octet_iterator::to_utf8_sequence(ch, codepointPtr, maxSize); - + overflowStringSize += drawBatchToEllipse->font->GetTextSize(codepoint, true, ctx).x; if (prevCh && ctx.m_kerningEnabled) @@ -4863,7 +4863,7 @@ int UiTextComponent::GetStartEllipseIndexInDrawBatch(const DrawBatch* drawBatchT } ellipsisCharPos = stringBufferIndex; - + } return ellipsisCharPos; @@ -4939,7 +4939,7 @@ AZ::Vector2 UiTextComponent::CalculateAlignedPositionWithYOffset(const UiTransfo AZ::Vector2 pos; const DrawBatchLines& drawBatchLines = GetDrawBatchLines(); size_t numLinesOfText = drawBatchLines.batchLines.size(); - + switch (m_textHAlignment) { case IDraw2d::HAlign::Left: @@ -5047,7 +5047,7 @@ bool UiTextComponent::VersionConverter(AZ::SerializeContext& context, } } - // conversion from version 8 to current: + // conversion from version 8 to current: // - "shrink to fit" wrap text setting now becomes the "uniform" value of the new "shrink to fit" enum // - legacy "ResizeToText" overflow mode (enum value 2) gets reset back to zero (overflow) if (classElement.GetVersion() <= 8) diff --git a/Gems/LyShineExamples/Code/Include/LyShineExamples/UiCustomImageBus.h b/Gems/LyShineExamples/Code/Include/LyShineExamples/UiCustomImageBus.h index 0830e4229a..26f793d774 100644 --- a/Gems/LyShineExamples/Code/Include/LyShineExamples/UiCustomImageBus.h +++ b/Gems/LyShineExamples/Code/Include/LyShineExamples/UiCustomImageBus.h @@ -42,10 +42,10 @@ public: // types void UnitClamp() { - m_left = FClamp(m_left, 0.0f, 1.0f); - m_top = FClamp(m_top, 0.0f, 1.0f); - m_right = FClamp(m_right, 0.0f, 1.0f); - m_bottom = FClamp(m_bottom, 0.0f, 1.0f); + m_left = AZStd::clamp(m_left, 0.0f, 1.0f); + m_top = AZStd::clamp(m_top, 0.0f, 1.0f); + m_right = AZStd::clamp(m_right, 0.0f, 1.0f); + m_bottom = AZStd::clamp(m_bottom, 0.0f, 1.0f); } bool operator==(const UVRect& rhs) const diff --git a/Gems/Maestro/Code/Source/Cinematics/CharacterTrackAnimator.h b/Gems/Maestro/Code/Source/Cinematics/CharacterTrackAnimator.h index e7c974e7a9..ae9f6bfce3 100644 --- a/Gems/Maestro/Code/Source/Cinematics/CharacterTrackAnimator.h +++ b/Gems/Maestro/Code/Source/Cinematics/CharacterTrackAnimator.h @@ -11,7 +11,7 @@ Utility class to handle Animation of Character Tracks (aka 'Animation' Tracks in the TrackView UI) */ -#include +#include struct SAnimContext; struct ICharacterKey; @@ -36,11 +36,6 @@ public: float m_jumpTime[3]; }; - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - void OnReset(IAnimNode* animNode); ILINE bool IsAnimationPlaying(const SAnimState& animState) const; diff --git a/Gems/Maestro/Code/Source/Cinematics/MaterialNode.cpp b/Gems/Maestro/Code/Source/Cinematics/MaterialNode.cpp index 9a54b21d7f..d124b37490 100644 --- a/Gems/Maestro/Code/Source/Cinematics/MaterialNode.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/MaterialNode.cpp @@ -6,20 +6,19 @@ * */ - -#include #include "MaterialNode.h" #include "AnimTrack.h" +#include -#include #include #include +#include #include "AnimSplineTrack.h" #include "CompoundSplineTrack.h" #include "Maestro/Types/AnimNodeType.h" -#include "Maestro/Types/AnimValueType.h" #include "Maestro/Types/AnimParamType.h" +#include "Maestro/Types/AnimValueType.h" // Don't remove or the console builds will break! #define s_nodeParamsInitialized s_nodeParamsInitializedMat @@ -39,11 +38,11 @@ namespace param.valueType = valueType; s_nodeParams.push_back(param); } -} +} // namespace enum EMaterialNodeParam { - MTL_PARAM_SHADER_PARAM1 = static_cast(AnimParamType::User) + 100, + MTL_PARAM_SHADER_PARAM1 = static_cast(AnimParamType::User) + 100, }; ////////////////////////////////////////////////////////////////////////// @@ -105,7 +104,7 @@ void CAnimMaterialNode::UpdateDynamicParamsInternal() m_nameToDynamicShaderParam.clear(); const char* pName = GetName(); - _smart_ptr pMtl = GetMaterialByName(pName); + IMaterial* pMtl = GetMaterialByName(pName); if (!pMtl) { @@ -123,7 +122,7 @@ void CAnimMaterialNode::UpdateDynamicParamsInternal() for (int i = 0; i < shaderParams.size(); ++i) { SShaderParam& shaderParam = shaderParams[i]; - m_nameToDynamicShaderParam[ shaderParams[i].m_Name.c_str() ] = i; + m_nameToDynamicShaderParam[shaderParams[i].m_Name.c_str()] = i; CAnimNode::SParamInfo paramInfo; @@ -184,8 +183,9 @@ CAnimParamType CAnimMaterialNode::GetParamType(unsigned int nIndex) const { return s_nodeParams[nIndex].paramType; } - else if (nIndex >= (unsigned int)s_nodeParams.size() && - nIndex < ((unsigned int)s_nodeParams.size() + (unsigned int)m_dynamicShaderParamInfos.size())) + else if ( + nIndex >= (unsigned int)s_nodeParams.size() && + nIndex < ((unsigned int)s_nodeParams.size() + (unsigned int)m_dynamicShaderParamInfos.size())) { return m_dynamicShaderParamInfos[nIndex - (int)s_nodeParams.size()].paramType; } @@ -264,7 +264,7 @@ void CAnimMaterialNode::Animate(SAnimContext& ec) // Find material. const char* pName = GetName(); - _smart_ptr pMtl = GetMaterialByName(pName); + IMaterial* pMtl = GetMaterialByName(pName); if (!pMtl) { @@ -348,7 +348,8 @@ void CAnimMaterialNode::Animate(SAnimContext& ec) } } -void CAnimMaterialNode::AnimateNamedParameter(SAnimContext& ec, IRenderShaderResources* pShaderResources, const char* name, IAnimTrack* pTrack) +void CAnimMaterialNode::AnimateNamedParameter( + SAnimContext& ec, IRenderShaderResources* pShaderResources, const char* name, IAnimTrack* pTrack) { TDynamicShaderParamsMap::iterator findIter = m_nameToDynamicShaderParam.find(name); if (findIter != m_nameToDynamicShaderParam.end()) @@ -387,7 +388,7 @@ void CAnimMaterialNode::AnimateNamedParameter(SAnimContext& ec, IRenderShaderRes } } -_smart_ptr CAnimMaterialNode::GetMaterialByName(const char*) +IMaterial* CAnimMaterialNode::GetMaterialByName(const char*) { return nullptr; } @@ -404,8 +405,7 @@ void CAnimMaterialNode::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { - serializeContext->Class() - ->Version(1); + serializeContext->Class()->Version(1); } } diff --git a/Gems/Maestro/Code/Source/Cinematics/MaterialNode.h b/Gems/Maestro/Code/Source/Cinematics/MaterialNode.h index 0c8bc38f1a..fcc308e5c8 100644 --- a/Gems/Maestro/Code/Source/Cinematics/MaterialNode.h +++ b/Gems/Maestro/Code/Source/Cinematics/MaterialNode.h @@ -54,7 +54,7 @@ protected: void UpdateDynamicParamsInternal() override; private: void AnimateNamedParameter(SAnimContext& ec, IRenderShaderResources* pShaderResources, const char* name, IAnimTrack* pTrack); - _smart_ptr GetMaterialByName(const char* pName); + IMaterial * GetMaterialByName(const char* pName); float m_fMinKeyValue; float m_fMaxKeyValue; diff --git a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp index 467ab37dab..3654af52dd 100644 --- a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp @@ -709,7 +709,7 @@ void CMovieSystem::NotifyListeners(IAnimSequence* sequence, IMovieListener::EMov { /* * When a sequence is stopped, Resume is called just before stopped (not sure why). To ensure that a OnStop notification is sent out after the Resume, - * notifications for eMovieEvent_Started and eMovieEvent_Stopped are handled in IAnimSequence::OnStart and IAnimSequence::OnStop + * notifications for eMovieEvent_Started and eMovieEvent_Stopped are handled in IAnimSequence::OnStart and IAnimSequence::OnStop */ case IMovieListener::eMovieEvent_Aborted: { @@ -726,7 +726,7 @@ void CMovieSystem::NotifyListeners(IAnimSequence* sequence, IMovieListener::EMov // do nothing for unhandled IMovieListener events break; } - } + } } ////////////////////////////////////////////////////////////////////////// @@ -1860,12 +1860,6 @@ void CMovieSystem::OnSequenceActivated(IAnimSequence* sequence) m_newlyActivatedSequences.push_back(sequence); } -////////////////////////////////////////////////////////////////////////// -ILightAnimWrapper* CMovieSystem::CreateLightAnimWrapper(const char* name) const -{ - return CLightAnimWrapper::Create(name); -} - ////////////////////////////////////////////////////////////////////////// StaticInstance CLightAnimWrapper::ms_lightAnimWrapperCache; AZStd::intrusive_ptr CLightAnimWrapper::ms_pLightAnimSet; diff --git a/Gems/Maestro/Code/Source/Cinematics/Movie.h b/Gems/Maestro/Code/Source/Cinematics/Movie.h index 0d7d1743f1..8ab888178d 100644 --- a/Gems/Maestro/Code/Source/Cinematics/Movie.h +++ b/Gems/Maestro/Code/Source/Cinematics/Movie.h @@ -154,7 +154,6 @@ public: bool IsRecording() const { return m_bRecording; }; void EnableCameraShake(bool bEnabled){ m_bEnableCameraShake = bEnabled; }; - bool IsCameraShakeEnabled() const {return m_bEnableCameraShake; }; void SetCallback(IMovieCallback* pCallback) { m_pCallback = pCallback; } IMovieCallback* GetCallback() { return m_pCallback; } @@ -187,8 +186,6 @@ public: virtual void EnableBatchRenderMode(bool bOn) { m_bBatchRenderMode = bOn; } virtual bool IsInBatchRenderMode() const { return m_bBatchRenderMode; } - ILightAnimWrapper* CreateLightAnimWrapper(const char* name) const; - void SerializeNodeType(AnimNodeType& animNodeType, XmlNodeRef& xmlNode, bool bLoading, const uint version, int flags) override; virtual void LoadParamTypeFromXml(CAnimParamType& animParamType, const XmlNodeRef& xmlNode, const uint version) override; virtual void SaveParamTypeToXml(const CAnimParamType& animParamType, XmlNodeRef& xmlNode) override; diff --git a/Gems/Maestro/Code/Source/Cinematics/SoundTrack.h b/Gems/Maestro/Code/Source/Cinematics/SoundTrack.h index 58ba8c78c6..c55b2de520 100644 --- a/Gems/Maestro/Code/Source/Cinematics/SoundTrack.h +++ b/Gems/Maestro/Code/Source/Cinematics/SoundTrack.h @@ -6,35 +6,20 @@ * */ - -#ifndef CRYINCLUDE_CRYMOVIE_SOUNDTRACK_H -#define CRYINCLUDE_CRYMOVIE_SOUNDTRACK_H +#pragma once #include "AnimTrack.h" -#include struct SSoundInfo { - SSoundInfo() - : nSoundKeyStart(-1) - , nSoundKeyStop(-1) - { - Reset(); - } - void Reset() { nSoundKeyStart = -1; nSoundKeyStop = -1; } - void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - int nSoundKeyStart; - int nSoundKeyStop; + int nSoundKeyStart = -1; + int nSoundKeyStop = -1; }; class CSoundTrack @@ -54,5 +39,3 @@ public: static void Reflect(AZ::ReflectContext* context); }; - -#endif // CRYINCLUDE_CRYMOVIE_SOUNDTRACK_H diff --git a/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp b/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp index e4c65c8667..f65768cec9 100644 --- a/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp +++ b/Gems/PhysX/Code/Editor/Source/Components/EditorSystemComponent.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsLegacyDefinitions.h b/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsLegacyDefinitions.h index 3a0575c129..b61d07295d 100644 --- a/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsLegacyDefinitions.h +++ b/Gems/ScriptEvents/Code/Include/ScriptEvents/ScriptEventsLegacyDefinitions.h @@ -18,32 +18,24 @@ namespace ScriptEventsLegacy { - - class IValidator - { - public: - virtual AZ::Outcome Validate() = 0; - }; - - /** - * This class represents an EBus event parameter. + * This class represents an EBus event parameter. * void Foo(parameterType parameterName) - * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ * parameter */ struct ParameterDefinition { AZ_TYPE_INFO(ParameterDefinition, "{6586FFB5-0FF6-424F-A542-C797E2FF3458}"); AZ_CLASS_ALLOCATOR(ParameterDefinition, AZ::SystemAllocator, 0); - + ParameterDefinition() = default; ParameterDefinition(const AZStd::string& name, const AZStd::string& tooltip, const AZ::Uuid& type) : m_name(name) , m_tooltip(tooltip) - , m_type(type) + , m_type(type) {} - + AZStd::string m_name; AZStd::string m_tooltip; AZ::Uuid m_type = AZ::BehaviorContext::GetVoidTypeId(); @@ -52,20 +44,20 @@ namespace ScriptEventsLegacy /** * This class represents an EBus event. * void Foo (parameterType parameterName, parameterType2 parameterName2) - * ^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + * ^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * m_returnType, m_name, m_parameters */ struct EventDefinition { AZ_TYPE_INFO(EventDefinition, "{211BB356-FA42-400F-B3DD-9326C6A686B6}"); AZ_CLASS_ALLOCATOR(EventDefinition, AZ::SystemAllocator, 0); - + EventDefinition() = default; EventDefinition(const AZStd::string& eventName, const AZStd::string& tooltip, const AZ::Uuid& returnValue, const AZStd::vector& parameters) : m_name(eventName) , m_tooltip(tooltip) , m_returnType(returnValue) - , m_parameters(parameters) + , m_parameters(parameters) {} AZStd::string m_name; @@ -86,7 +78,7 @@ namespace ScriptEventsLegacy TypeTraitsDefinition() = default; TypeTraitsDefinition(const AZ::Uuid& busIdType) : m_busIdType(busIdType) {} - + AZ::Uuid m_busIdType = AZ::BehaviorContext::GetVoidTypeId(); }; diff --git a/Gems/Vegetation/Code/Tests/VegetationMocks.h b/Gems/Vegetation/Code/Tests/VegetationMocks.h index ebc51d1b3b..97eaa50b69 100644 --- a/Gems/Vegetation/Code/Tests/VegetationMocks.h +++ b/Gems/Vegetation/Code/Tests/VegetationMocks.h @@ -32,13 +32,6 @@ #include #include -// used for the mock for IStatObj -#ifndef CRYINCLUDE_CRY3DENGINE_STATOBJ_H -struct SPhysGeomArray -{ -}; -#endif - ////////////////////////////////////////////////////////////////////////// // mock event bus classes for testing vegetation namespace UnitTest From 1d4487f4f8fa95f2cf363e7330ea1505e4933ce1 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 7 Sep 2021 11:53:40 -0700 Subject: [PATCH 11/16] Improvement suggestion from another PR Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- cmake/3rdParty.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake/3rdParty.cmake b/cmake/3rdParty.cmake index 310e341305..f70ed1aa02 100644 --- a/cmake/3rdParty.cmake +++ b/cmake/3rdParty.cmake @@ -123,10 +123,8 @@ function(ly_add_external_target) else() # only install external 3rdParty that are within the source tree - cmake_path(RELATIVE_PATH ly_add_external_target_3RDPARTY_ROOT_DIRECTORY - BASE_DIRECTORY ${LY_ROOT_FOLDER} - OUTPUT_VARIABLE relative_path) - if(relative_path AND NOT relative_path MATCHES "^../") + cmake_path(IS_PREFIX LY_ROOT_FOLDER ${ly_add_external_target_3RDPARTY_ROOT_DIRECTORY} NORMALIZE is_in_source_tree) + if(is_in_source_tree) ly_install_external_target(${ly_add_external_target_3RDPARTY_ROOT_DIRECTORY}) endif() set(BASE_PATH "${ly_add_external_target_3RDPARTY_ROOT_DIRECTORY}") From fd007548e00f30bb4d5c705178e6bbef34d02013 Mon Sep 17 00:00:00 2001 From: dmcdiar Date: Tue, 7 Sep 2021 12:16:04 -0700 Subject: [PATCH 12/16] MeshFeatureProcessor::SetVisible now adds or removes the mesh from the raytracing scene as appropriate. Signed-off-by: dmcdiar --- .../Common/Code/Source/Mesh/MeshFeatureProcessor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp index f52d9fe37c..67702a8176 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp @@ -425,6 +425,7 @@ namespace AZ if (meshHandle.IsValid()) { meshHandle->SetVisible(visible); + SetRayTracingEnabled(meshHandle, visible); } } @@ -696,8 +697,13 @@ namespace AZ void MeshDataInstance::SetRayTracingData() { + if (!m_model) + { + return; + } + RayTracingFeatureProcessor* rayTracingFeatureProcessor = m_scene->GetFeatureProcessor(); - if (rayTracingFeatureProcessor == nullptr) + if (!rayTracingFeatureProcessor) { return; } From 214ebb730864e922aab709b1d30796f5d99b7224 Mon Sep 17 00:00:00 2001 From: Guthrie Adams Date: Tue, 7 Sep 2021 14:40:20 -0500 Subject: [PATCH 13/16] Adding null checks to Gestures gem if gEnv isn't set Signed-off-by: Guthrie Adams --- .../Code/Include/Gestures/GestureRecognizerClickOrTap.inl | 6 +++--- .../Code/Include/Gestures/GestureRecognizerDrag.inl | 4 ++-- Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.h | 2 +- .../Code/Include/Gestures/GestureRecognizerHold.inl | 4 ++-- .../Code/Include/Gestures/GestureRecognizerPinch.inl | 2 +- .../Code/Include/Gestures/GestureRecognizerRotate.inl | 2 +- .../Code/Include/Gestures/GestureRecognizerSwipe.inl | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerClickOrTap.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerClickOrTap.inl index 9333c5cbc9..77f6044642 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerClickOrTap.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerClickOrTap.inl @@ -73,7 +73,7 @@ inline Gestures::RecognizerClickOrTap::~RecognizerClickOrTap() //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerClickOrTap::OnPressedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -120,7 +120,7 @@ inline bool Gestures::RecognizerClickOrTap::OnPressedEvent(const AZ::Vector2& sc //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerClickOrTap::OnDownEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -159,7 +159,7 @@ inline bool Gestures::RecognizerClickOrTap::OnDownEvent(const AZ::Vector2& scree //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerClickOrTap::OnReleasedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerDrag.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerDrag.inl index 642ae9b852..c473293765 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerDrag.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerDrag.inl @@ -59,7 +59,7 @@ inline Gestures::RecognizerDrag::~RecognizerDrag() //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerDrag::OnPressedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -90,7 +90,7 @@ inline bool Gestures::RecognizerDrag::OnPressedEvent(const AZ::Vector2& screenPo //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerDrag::OnDownEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.h b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.h index facdd899c8..11bd56ff4d 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.h +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.h @@ -64,7 +64,7 @@ namespace Gestures AZ::Vector2 GetStartPosition() const { return m_startPosition; } AZ::Vector2 GetCurrentPosition() const { return m_currentPosition; } - float GetDuration() const { return gEnv->pTimer->GetFrameStartTime().GetDifferenceInSeconds(m_startTime); } + float GetDuration() const { return (gEnv && gEnv->pTimer) ? gEnv->pTimer->GetFrameStartTime().GetDifferenceInSeconds(m_startTime) : 0.0f; } private: enum class State diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.inl index a85acfe466..99a3f7042c 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerHold.inl @@ -59,7 +59,7 @@ inline Gestures::RecognizerHold::~RecognizerHold() //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerHold::OnPressedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -90,7 +90,7 @@ inline bool Gestures::RecognizerHold::OnPressedEvent(const AZ::Vector2& screenPo //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerHold::OnDownEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerPinch.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerPinch.inl index 1a198eab59..c64e310c36 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerPinch.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerPinch.inl @@ -106,7 +106,7 @@ inline float AngleInDegreesBetweenVectors(const AZ::Vector2& vec0, const AZ::Vec //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerPinch::OnDownEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex > s_maxPinchPointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex > s_maxPinchPointerIndex) { return false; } diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerRotate.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerRotate.inl index 6cc82f47dc..da6f84afca 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerRotate.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerRotate.inl @@ -95,7 +95,7 @@ inline bool Gestures::RecognizerRotate::OnPressedEvent(const AZ::Vector2& screen //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerRotate::OnDownEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex > s_maxRotatePointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex > s_maxRotatePointerIndex) { return false; } diff --git a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerSwipe.inl b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerSwipe.inl index 8d59525e93..f84e85df52 100644 --- a/Gems/Gestures/Code/Include/Gestures/GestureRecognizerSwipe.inl +++ b/Gems/Gestures/Code/Include/Gestures/GestureRecognizerSwipe.inl @@ -59,7 +59,7 @@ inline Gestures::RecognizerSwipe::~RecognizerSwipe() //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerSwipe::OnPressedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -89,7 +89,7 @@ inline bool Gestures::RecognizerSwipe::OnPressedEvent(const AZ::Vector2& screenP //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerSwipe::OnDownEvent([[maybe_unused]] const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } @@ -125,7 +125,7 @@ inline bool Gestures::RecognizerSwipe::OnDownEvent([[maybe_unused]] const AZ::Ve //////////////////////////////////////////////////////////////////////////////////////////////////// inline bool Gestures::RecognizerSwipe::OnReleasedEvent(const AZ::Vector2& screenPosition, uint32_t pointerIndex) { - if (pointerIndex != m_config.pointerIndex) + if (!gEnv || !gEnv->pTimer || pointerIndex != m_config.pointerIndex) { return false; } From fe8f4a772070d1f0c923dc49ac8a1d0ac1f54644 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 7 Sep 2021 12:55:07 -0700 Subject: [PATCH 14/16] typo Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/Plugins/FFMPEGPlugin/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp index fed0ec8678..f7d3dfd57b 100644 --- a/Code/Editor/Plugins/FFMPEGPlugin/main.cpp +++ b/Code/Editor/Plugins/FFMPEGPlugin/main.cpp @@ -24,7 +24,7 @@ PLUGIN_API IPlugin* CreatePluginInstance(PLUGIN_INIT_PARAM* pInitParam) // Make sure the ffmpeg command can be executed before registering the command if (!CFFMPEGPlugin::RuntimeTest()) { - GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmepg. Please install FFmepg."); + GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmpeg. Please install FFmpeg."); } else { From 8edcc504bd13c4d9e8ef57abddf1ff17c6e5ff68 Mon Sep 17 00:00:00 2001 From: Junbo Liang <68558268+junbo75@users.noreply.github.com> Date: Tue, 7 Sep 2021 13:02:13 -0700 Subject: [PATCH 15/16] Add AWSI automation tests to a new test suite and pipe (#3913) Signed-off-by: junbo --- .../Gem/PythonTests/AWS/CMakeLists.txt | 4 +-- .../aws_metrics_automation_test.py | 2 +- .../aws_client_auth_automation_test.py | 2 +- .../core/test_aws_resource_interaction.py | 2 +- .../Source/TestImpactCommandLineOptions.cpp | 5 ++-- .../TestImpactTestSequence.h | 3 ++- .../Runtime/Code/Source/TestImpactUtils.cpp | 2 ++ cmake/LYTestWrappers.cmake | 13 ++++++---- ctest_pytest.ini | 1 + .../build/Platform/Linux/build_config.json | 4 +-- .../build/Platform/Windows/build_config.json | 25 ++++++++++++++++--- scripts/ctest/ctest_driver.py | 3 ++- scripts/ctest/sanity_test.py | 4 +++ 13 files changed, 51 insertions(+), 19 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt b/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt index a589a395c1..2a5e1d7cab 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonTests/AWS/CMakeLists.txt @@ -17,15 +17,15 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) return() endif() - # Enable after installing NodeJS and CDK on jenkins Windows AMI. ly_add_pytest( NAME AutomatedTesting::AWSTests - TEST_SUITE periodic + TEST_SUITE awsi TEST_SERIAL PATH ${CMAKE_CURRENT_LIST_DIR}/${PAL_PLATFORM_NAME}/ RUNTIME_DEPENDENCIES Legacy::Editor AZ::AssetProcessor + AutomatedTesting.GameLauncher AutomatedTesting.Assets COMPONENT AWS diff --git a/AutomatedTesting/Gem/PythonTests/AWS/Windows/aws_metrics/aws_metrics_automation_test.py b/AutomatedTesting/Gem/PythonTests/AWS/Windows/aws_metrics/aws_metrics_automation_test.py index 061db991cf..1fb35cb9e8 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/Windows/aws_metrics/aws_metrics_automation_test.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/Windows/aws_metrics/aws_metrics_automation_test.py @@ -133,7 +133,7 @@ def update_kinesis_analytics_application_status(aws_metrics_utils: pytest.fixtur aws_metrics_utils.stop_kinesis_data_analytics_application( resource_mappings.get_resource_name_id('AWSMetrics.AnalyticsApplicationName')) -@pytest.mark.SUITE_periodic +@pytest.mark.SUITE_awsi @pytest.mark.usefixtures('automatic_process_killer') @pytest.mark.usefixtures('aws_credentials') @pytest.mark.usefixtures('resource_mappings') diff --git a/AutomatedTesting/Gem/PythonTests/AWS/Windows/client_auth/aws_client_auth_automation_test.py b/AutomatedTesting/Gem/PythonTests/AWS/Windows/client_auth/aws_client_auth_automation_test.py index b56d3f88f5..198fb934d9 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/Windows/client_auth/aws_client_auth_automation_test.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/Windows/client_auth/aws_client_auth_automation_test.py @@ -21,7 +21,7 @@ AWS_CLIENT_AUTH_FEATURE_NAME = 'AWSClientAuth' logger = logging.getLogger(__name__) -@pytest.mark.SUITE_periodic +@pytest.mark.SUITE_awsi @pytest.mark.usefixtures('asset_processor') @pytest.mark.usefixtures('automatic_process_killer') @pytest.mark.usefixtures('aws_utils') diff --git a/AutomatedTesting/Gem/PythonTests/AWS/Windows/core/test_aws_resource_interaction.py b/AutomatedTesting/Gem/PythonTests/AWS/Windows/core/test_aws_resource_interaction.py index 529151f3f6..949186ad50 100644 --- a/AutomatedTesting/Gem/PythonTests/AWS/Windows/core/test_aws_resource_interaction.py +++ b/AutomatedTesting/Gem/PythonTests/AWS/Windows/core/test_aws_resource_interaction.py @@ -74,7 +74,7 @@ def write_test_data_to_dynamodb_table(resource_mappings: pytest.fixture, aws_uti raise -@pytest.mark.SUITE_periodic +@pytest.mark.SUITE_awsi @pytest.mark.usefixtures('automatic_process_killer') @pytest.mark.usefixtures('asset_processor') @pytest.mark.parametrize('feature_name', [AWS_CORE_FEATURE_NAME]) diff --git a/Code/Tools/TestImpactFramework/Frontend/Console/Code/Source/TestImpactCommandLineOptions.cpp b/Code/Tools/TestImpactFramework/Frontend/Console/Code/Source/TestImpactCommandLineOptions.cpp index 0d1f352f21..1bd57e49aa 100644 --- a/Code/Tools/TestImpactFramework/Frontend/Console/Code/Source/TestImpactCommandLineOptions.cpp +++ b/Code/Tools/TestImpactFramework/Frontend/Console/Code/Source/TestImpactCommandLineOptions.cpp @@ -266,7 +266,8 @@ namespace TestImpact { { SuiteTypeAsString(SuiteType::Main), SuiteType::Main }, { SuiteTypeAsString(SuiteType::Periodic), SuiteType::Periodic }, - { SuiteTypeAsString(SuiteType::Sandbox), SuiteType::Sandbox } + { SuiteTypeAsString(SuiteType::Sandbox), SuiteType::Sandbox }, + { SuiteTypeAsString(SuiteType::AWSI), SuiteType::AWSI } }; return ParseMultiStateOption(OptionKeys[SuiteFilterKey], states, cmd).value_or(SuiteType::Main); @@ -472,7 +473,7 @@ namespace TestImpact " available, no prioritization will occur).\n" " -maxconcurrency= The maximum number of concurrent test targets/shards to be in flight at \n" " any given moment.\n" - " -suite= The test suite to select from for this test sequence."; + " -suite= The test suite to select from for this test sequence."; return help; } diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Include/TestImpactFramework/TestImpactTestSequence.h b/Code/Tools/TestImpactFramework/Runtime/Code/Include/TestImpactFramework/TestImpactTestSequence.h index 38b716398c..0a62b7a004 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Include/TestImpactFramework/TestImpactTestSequence.h +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Include/TestImpactFramework/TestImpactTestSequence.h @@ -30,7 +30,8 @@ namespace TestImpact { Main = 0, Periodic, - Sandbox + Sandbox, + AWSI }; //! Result of a test sequence that was run. diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/TestImpactUtils.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/TestImpactUtils.cpp index 993aee9af5..3f6c9dafd4 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/TestImpactUtils.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/TestImpactUtils.cpp @@ -53,6 +53,8 @@ namespace TestImpact return "periodic"; case SuiteType::Sandbox: return "sandbox"; + case SuiteType::AWSI: + return "awsi"; default: throw(Exception("Unexpected suite type")); } diff --git a/cmake/LYTestWrappers.cmake b/cmake/LYTestWrappers.cmake index 8e71cb3db1..a305f0be38 100644 --- a/cmake/LYTestWrappers.cmake +++ b/cmake/LYTestWrappers.cmake @@ -18,7 +18,7 @@ set(LY_GOOGLETEST_EXTRA_PARAMS CACHE STRING "Allows injection of additional opti find_package(Python REQUIRED MODULE) ly_set(LY_PYTEST_EXECUTABLE ${LY_PYTHON_CMD} -B -m pytest -v --tb=short --show-capture=log -c ${LY_ROOT_FOLDER}/ctest_pytest.ini --build-directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$") -ly_set(LY_TEST_GLOBAL_KNOWN_SUITE_NAMES "smoke" "main" "periodic" "benchmark" "sandbox") +ly_set(LY_TEST_GLOBAL_KNOWN_SUITE_NAMES "smoke" "main" "periodic" "benchmark" "sandbox" "awsi") ly_set(LY_TEST_GLOBAL_KNOWN_REQUIREMENTS "gpu") # Set default test aborts to 25 minutes, avoids hitting the CI pipeline inactivity timeout usually set to 30 minutes @@ -71,11 +71,14 @@ endfunction() # \arg:PARENT_NAME(optional) - Name of the parent test run target (if this is a subsequent call to specify a suite) # \arg:TEST_REQUIRES(optional) - List of system resources that are required to run this test. # Only available option is "gpu" -# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "sandbox" - prevents the test from running normally +# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "benchmark" or "sandbox" or "awsi" - prevents the test from running normally # and instead places it a special suite of tests that only run when requested. # Otherwise, do not specify a TEST_SUITE value and the default ("main") will apply. +# "smoke" is tiny, quick tests of fundamental operation (tests with no suite marker will also execute here in CI) +# "periodic" is low-priority verification, which should not block code submission # "benchmark" is currently reserved for Google Benchmarks # "sandbox" should be only be used for the workflow of flaky tests +# "awsi" Time consuming AWS integration end-to-end tests # \arg:TIMEOUT (optional) The timeout in seconds for the module. Defaults to LY_TEST_DEFAULT_TIMEOUT. # \arg:TEST_COMMAND - Command which runs the tests. It is a required argument # \arg:NON_IDE_PARAMS - extra params that will be run in ctest, but will not be used in the IDE. @@ -279,7 +282,7 @@ endfunction() # \arg:RUNTIME_DEPENDENCIES (optional) - List of additional runtime dependencies required by this test. # \arg:COMPONENT (optional) - Scope of the feature area that the test belongs to (eg. physics, graphics, etc.). # \arg:EXCLUDE_TEST_RUN_TARGET_FROM_IDE(bool) - If set the test run target will be not be shown in the IDE -# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "sandbox" - prevents the test from running normally +# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "sandbox" or "awsi" - prevents the test from running normally # and instead places it a special suite of tests that only run when requested. # \arg:TIMEOUT (optional) The timeout in seconds for the module. If not set defaults to LY_TEST_DEFAULT_TIMEOUT # @@ -331,7 +334,7 @@ endfunction() # \arg:TARGET Name of the target module that is being run for tests. If not provided, will default to 'NAME' # \arg:TEST_REQUIRES(optional) List of system resources that are required to run this test. # Only available option is "gpu" -# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "sandbox" - prevents the test from running normally +# \arg:TEST_SUITE(optional) - "smoke" or "periodic" or "sandbox" or "awsi" - prevents the test from running normally # and instead places it a special suite of tests that only run when requested. # \arg:TEST_COMMAND(optional) - Command which runs the tests. # If not supplied, a default of "AzTestRunner $ AzRunUnitTests" will be used @@ -372,7 +375,7 @@ function(ly_add_googletest) # will actually run everything in main OR everything tagged as requiring a GPU # instead of only tests tagged with BOTH main and gpu... # so we have to do it this way (negating all others) - set(non_ide_params "--gtest_filter=-*SUITE_smoke*:*SUITE_periodic*:*SUITE_benchmark*:*SUITE_sandbox*") + set(non_ide_params "--gtest_filter=-*SUITE_smoke*:*SUITE_periodic*:*SUITE_benchmark*:*SUITE_sandbox*:*SUITE_awsi*") endif() if(NOT ly_add_googletest_TEST_COMMAND) diff --git a/ctest_pytest.ini b/ctest_pytest.ini index 8365e07988..93310a522d 100644 --- a/ctest_pytest.ini +++ b/ctest_pytest.ini @@ -18,6 +18,7 @@ markers = SUITE_smoke: Tiny, quick tests of fundamental operation (tests with no SUITE_periodic: low-priority verification, which should not block code submission SUITE_benchmark: Benchmarks which do not pass or fail but instead output statistics SUITE_sandbox: Temporarly contains flaky/unstable tests, this should not block code submission. This test suite should be ideally empty + SUITE_awsi: Time consuming AWS integration end-to-end tests # secondary markers which may appear alongisde a suite marker: REQUIRES_gpu: Tests which require a physical GPU # custom markers not listed above will cause pytest to emit a typo warning diff --git a/scripts/build/Platform/Linux/build_config.json b/scripts/build/Platform/Linux/build_config.json index e60b5deee9..e70fa32878 100644 --- a/scripts/build/Platform/Linux/build_config.json +++ b/scripts/build/Platform/Linux/build_config.json @@ -83,7 +83,7 @@ "CMAKE_OPTIONS": "-G 'Ninja Multi-Config' -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 -DLY_UNITY_BUILD=TRUE -DLY_PARALLEL_LINK_JOBS=4", "CMAKE_LY_PROJECTS": "AutomatedTesting", "CMAKE_TARGET": "all", - "CTEST_OPTIONS": "-E Gem::EMotionFX.Editor.Tests -LE SUITE_sandbox -L FRAMEWORK_googletest" + "CTEST_OPTIONS": "-E Gem::EMotionFX.Editor.Tests -LE (SUITE_sandbox|SUITE_awsi) -L FRAMEWORK_googletest" } }, "test_profile_nounity": { @@ -95,7 +95,7 @@ "CMAKE_OPTIONS": "-G 'Ninja Multi-Config' -DCMAKE_C_COMPILER=clang-6.0 -DCMAKE_CXX_COMPILER=clang++-6.0 -DLY_UNITY_BUILD=FALSE -DLY_PARALLEL_LINK_JOBS=4", "CMAKE_LY_PROJECTS": "AutomatedTesting", "CMAKE_TARGET": "all", - "CTEST_OPTIONS": "-E Gem::EMotionFX.Editor.Tests -LE SUITE_sandbox -L FRAMEWORK_googletest" + "CTEST_OPTIONS": "-E Gem::EMotionFX.Editor.Tests -LE (SUITE_sandbox|SUITE_awsi) -L FRAMEWORK_googletest" } }, "asset_profile": { diff --git a/scripts/build/Platform/Windows/build_config.json b/scripts/build/Platform/Windows/build_config.json index 583a73b58b..689ba6935d 100644 --- a/scripts/build/Platform/Windows/build_config.json +++ b/scripts/build/Platform/Windows/build_config.json @@ -213,19 +213,38 @@ "ASSET_PROCESSOR_PLATFORMS": "pc,server" } }, - "periodic_test_profile_vs2019_pipe": { + "awsi_test_profile_vs2019_pipe": { "TAGS": [ "nightly-incremental", "nightly-clean" ], "steps": [ "awsi_deployment", - "periodic_test_profile_vs2019" + "awsi_test_profile_vs2019" ] }, + "awsi_test_profile_vs2019": { + "TAGS": [ + "weekly-build-metrics" + ], + "COMMAND": "build_test_windows.cmd", + "PARAMETERS": { + "CONFIGURATION": "profile", + "OUTPUT_DIRECTORY": "build\\windows_vs2019", + "CMAKE_OPTIONS": "-G \"Visual Studio 16 2019\" -DCMAKE_SYSTEM_VERSION=10.0 -DLY_UNITY_BUILD=TRUE", + "CMAKE_LY_PROJECTS": "AutomatedTesting", + "CMAKE_TARGET": "TEST_SUITE_awsi", + "CMAKE_NATIVE_BUILD_ARGS": "/m /nologo", + "CTEST_OPTIONS": "-L \"(SUITE_awsi)\" -T Test", + "TEST_METRICS": "True", + "TEST_RESULTS": "True" + } + }, "periodic_test_profile_vs2019": { "TAGS": [ - "weekly-build-metrics" + "nightly-incremental", + "nightly-clean", + "weekly-build-metrics" ], "COMMAND": "build_test_windows.cmd", "PARAMETERS": { diff --git a/scripts/ctest/ctest_driver.py b/scripts/ctest/ctest_driver.py index 3fc07921fd..aaad523186 100755 --- a/scripts/ctest/ctest_driver.py +++ b/scripts/ctest/ctest_driver.py @@ -19,7 +19,8 @@ SUITES_AND_DESCRIPTIONS = { "main": "The default set of tests, covers most of all testing.", "periodic": "Tests which can take a long time and should be done periodially instead of every commit - these should not block code submission", "benchmark": "Benchmarks - instead of pass/fail, these collect data for comparison against historic data", - "sandbox": "Flaky/Intermittent failing tests, this is used as a temporary spot to hold flaky tests, this will not block code submission. Ideally, this suite should always be empty" + "sandbox": "Flaky/Intermittent failing tests, this is used as a temporary spot to hold flaky tests, this will not block code submission. Ideally, this suite should always be empty", + "awsi": "Time consuming AWS integration end-to-end tests" } BUILD_CONFIGURATIONS = [ diff --git a/scripts/ctest/sanity_test.py b/scripts/ctest/sanity_test.py index dcbab281bb..2972546c65 100755 --- a/scripts/ctest/sanity_test.py +++ b/scripts/ctest/sanity_test.py @@ -32,6 +32,10 @@ def test_Sanity_Benchmark_Pass(): def test_Sanity_Sandbox_Pass(): pass +@pytest.mark.SUITE_awsi +def test_Sanity_AWSI_Pass(): + pass + @pytest.mark.REQUIRES_gpu def test_Sanity_RequireGpu_Pass(): pass From 12fb91a484ecd473bca49d79ead2a30a24c17857 Mon Sep 17 00:00:00 2001 From: bosnichd Date: Tue, 7 Sep 2021 15:08:39 -0600 Subject: [PATCH 16/16] Fix some debug compile errors introduced by https://github.com/o3de/o3de/pull/3903 Signed-off-by: bosnichd --- Code/Legacy/CryCommon/Cry_Camera.h | 2 - Code/Legacy/CryCommon/Cry_Matrix34.h | 77 ++++++++++++++++++++++++++++ Code/Legacy/CryCommon/Cry_Vector4.h | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Code/Legacy/CryCommon/Cry_Camera.h b/Code/Legacy/CryCommon/Cry_Camera.h index 668d15cbc1..6ccae5bce1 100644 --- a/Code/Legacy/CryCommon/Cry_Camera.h +++ b/Code/Legacy/CryCommon/Cry_Camera.h @@ -279,8 +279,6 @@ inline void CCamera::SetFrustum(int nWidth, int nHeight, f32 FOV, f32 nearplane, m_edge_plt.y = projLeftTopY; m_edge_plt.z = projLeftTopZ; - assert(fabs(acos_tpl(Vec3d(0, m_edge_plt.y, m_edge_plt.z).GetNormalized().y) * 2 - m_fov) < 0.001); - float invProjLeftTopY = 1.0f / projLeftTopY; //Apply asym shift to the camera frustum - Necessary for properly culling tessellated objects in VR diff --git a/Code/Legacy/CryCommon/Cry_Matrix34.h b/Code/Legacy/CryCommon/Cry_Matrix34.h index 8dcb48cf6a..eb9c22086b 100644 --- a/Code/Legacy/CryCommon/Cry_Matrix34.h +++ b/Code/Legacy/CryCommon/Cry_Matrix34.h @@ -587,6 +587,30 @@ struct Matrix34_tpl m22 = m33.m22; } + //check if we have an orthonormal-base (general case, works even with reflection matrices) + int IsOrthonormal(F threshold = 0.001) const + { + f32 d0 = fabs_tpl(GetColumn0() | GetColumn1()); + if (d0 > threshold) + { + return 0; + } + f32 d1 = fabs_tpl(GetColumn0() | GetColumn2()); + if (d1 > threshold) + { + return 0; + } + f32 d2 = fabs_tpl(GetColumn1() | GetColumn2()); + if (d2 > threshold) + { + return 0; + } + int a = (fabs_tpl(1 - (GetColumn0() | GetColumn0()))) < threshold; + int b = (fabs_tpl(1 - (GetColumn1() | GetColumn1()))) < threshold; + int c = (fabs_tpl(1 - (GetColumn2() | GetColumn2()))) < threshold; + return a & b & c; + } + //check if we have an orthonormal-base (assuming we are using a right-handed coordinate system) int IsOrthonormalRH(F threshold = 0.001) const { @@ -604,6 +628,59 @@ struct Matrix34_tpl ); } + bool IsValid() const + { + if (!NumberValid(m00)) + { + return false; + } + if (!NumberValid(m01)) + { + return false; + } + if (!NumberValid(m02)) + { + return false; + } + if (!NumberValid(m03)) + { + return false; + } + if (!NumberValid(m10)) + { + return false; + } + if (!NumberValid(m11)) + { + return false; + } + if (!NumberValid(m12)) + { + return false; + } + if (!NumberValid(m13)) + { + return false; + } + if (!NumberValid(m20)) + { + return false; + } + if (!NumberValid(m21)) + { + return false; + } + if (!NumberValid(m22)) + { + return false; + } + if (!NumberValid(m23)) + { + return false; + } + return true; + } + /*! * Create a matrix with SCALING, ROTATION and TRANSLATION (in this order). * diff --git a/Code/Legacy/CryCommon/Cry_Vector4.h b/Code/Legacy/CryCommon/Cry_Vector4.h index 2b1af84c54..ddb4bf5ffe 100644 --- a/Code/Legacy/CryCommon/Cry_Vector4.h +++ b/Code/Legacy/CryCommon/Cry_Vector4.h @@ -27,7 +27,7 @@ struct Vec4 f32 x, y, z, w; #if defined(_DEBUG) - ILINE Vec4_tpl() + ILINE Vec4() { if constexpr (sizeof(f32) == 4) {