From b9cfce8165fd368018a6ea73f25f42828f523899 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Mon, 2 Aug 2021 09:26:06 -0700 Subject: [PATCH] Gems/AtomLyIntegration Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../Platform/Windows/FFontXML_Windows.cpp | 7 +++- .../AtomFont/Code/Source/FFont.cpp | 42 ++++++++++++------- .../AtomFont/Code/Source/FontRenderer.cpp | 7 ++-- .../AtomFont/Code/Source/FontTexture.cpp | 10 ++--- .../AtomFont/Code/Source/GlyphCache.cpp | 2 +- .../Source/AnimGraph/GameController.cpp | 21 +++++----- 6 files changed, 53 insertions(+), 36 deletions(-) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Platform/Windows/FFontXML_Windows.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Platform/Windows/FFontXML_Windows.cpp index 4c923c43c4..dc7c6ccbb2 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Platform/Windows/FFontXML_Windows.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Platform/Windows/FFontXML_Windows.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -16,11 +17,13 @@ namespace AtomFontInternal { void XmlFontShader::FoundElementImpl() { - TCHAR sysFontPath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(0, CSIDL_FONTS, 0, SHGFP_TYPE_DEFAULT, sysFontPath))) + wchar_t sysFontPathW[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPath(0, CSIDL_FONTS, 0, SHGFP_TYPE_DEFAULT, sysFontPathW))) { const AZ::IO::PathView fontName = AZ::IO::PathView(m_strFontPath.c_str()).Filename(); + AZStd::string sysFontPath; + AZStd::to_string(sysFontPath, sysFontPathW); AZ::IO::Path newFontPath(sysFontPath); newFontPath /= fontName; m_font->Load(newFontPath.c_str(), m_FontTexSize.x, m_FontTexSize.y, m_slotSizes.x, m_slotSizes.y, CreateTTFFontFlag(m_FontSmoothMethod, m_FontSmoothAmount), m_SizeRatio); diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index ddb2fa6292..fe6f733abc 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -13,6 +13,8 @@ #if !defined(USE_NULLFONT_ALWAYS) +#include + #include #include #include @@ -26,7 +28,6 @@ #include #include #include -#include #include #include @@ -409,6 +410,9 @@ Vec2 AZ::FFont::GetTextSizeUInternal( const size_t fxIdx = ctx.m_fxIdx < fxSize ? ctx.m_fxIdx : 0; const FontEffect& fx = m_effects[fxIdx]; + AZStd::wstring strW; + AZStd::to_wstring(strW, str); + for (size_t i = 0, numPasses = fx.m_passes.size(); i < numPasses; ++i) { const FontRenderingPass* pass = &fx.m_passes[numPasses - i - 1]; @@ -426,7 +430,7 @@ Vec2 AZ::FFont::GetTextSizeUInternal( // parse the string, ignoring control characters uint32_t nextCh = 0; - Unicode::CIterator pChar(str); + const wchar_t* pChar = strW.c_str(); while (uint32_t ch = *pChar) { ++pChar; @@ -556,6 +560,9 @@ uint32_t AZ::FFont::GetNumQuadsForText(const char* str, const bool asciiMultiLin const size_t fxIdx = ctx.m_fxIdx < fxSize ? ctx.m_fxIdx : 0; const FontEffect& fx = m_effects[fxIdx]; + AZStd::wstring strW; + AZStd::to_wstring(strW, str); + for (size_t j = 0, numPasses = fx.m_passes.size(); j < numPasses; ++j) { size_t i = numPasses - j - 1; @@ -567,7 +574,7 @@ uint32_t AZ::FFont::GetNumQuadsForText(const char* str, const bool asciiMultiLin } uint32_t nextCh = 0; - Unicode::CIterator pChar(str); + const wchar_t* pChar = strW.c_str(); while (uint32_t ch = *pChar) { ++pChar; @@ -862,9 +869,12 @@ int AZ::FFont::CreateQuadsForText(const RHI::Viewport& viewport, float x, float } } + AZStd::wstring strW; + AZStd::to_wstring(strW, str); + // parse the string, ignoring control characters uint32_t nextCh = 0; - Unicode::CIterator pChar(str); + const wchar_t* pChar = strW.c_str(); while (uint32_t ch = *pChar) { ++pChar; @@ -1188,7 +1198,7 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, const bool multiLine = strSize.y > GetRestoredFontSize(ctx).y; int lastSpace = -1; - const char* pLastSpace = NULL; + const wchar_t* pLastSpace = NULL; float lastSpaceWidth = 0.0f; float curCharWidth = 0.0f; @@ -1197,7 +1207,9 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, float widthSum = 0.0f; int curChar = 0; - Unicode::CIterator pChar(result.c_str()); + AZStd::wstring resultW; + AZStd::to_wstring(resultW, result.c_str()); + const wchar_t* pChar = resultW.c_str(); while (uint32_t ch = *pChar) { // Dollar sign escape codes. The following scenarios can happen with dollar signs embedded in a string. @@ -1224,7 +1236,7 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, // get char width and sum it to the line width // Note: This is not unicode compatible, since char-width depends on surrounding context (ie, combining diacritics etc) char codepoint[5]; - Unicode::Convert(codepoint, ch); + AZStd::to_string(codepoint, 5, (wchar_t*)&ch, 1); curCharWidth = GetTextSize(codepoint, true, ctx).x; // keep track of spaces @@ -1233,15 +1245,15 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, { lastSpace = curChar; lastSpaceWidth = curLineWidth + curCharWidth; - pLastSpace = pChar.GetPosition(); + pLastSpace = pChar; assert(*pLastSpace == ' '); } bool prevCharWasNewline = false; - const bool notFirstChar = pChar.GetPosition() != result.c_str(); + const bool notFirstChar = pChar != resultW.c_str(); if (*pChar && notFirstChar) { - const char* pPrevCharStr = pChar.GetPosition() - 1; + const wchar_t* pPrevCharStr = pChar - 1; prevCharWasNewline = pPrevCharStr[0] == '\n'; } @@ -1268,12 +1280,12 @@ void AZ::FFont::WrapText(AZStd::string& result, float maxWidth, const char* str, } else { - const char* buf = pChar.GetPosition(); - size_t bytesProcessed = buf - result.c_str(); - result.insert(bytesProcessed, '\n'); // Insert the newline, this invalidates the iterator - buf = result.c_str() + bytesProcessed; // In case reallocation occurs, we ensure we are inside the new buffer + const wchar_t* buf = pChar; + size_t bytesProcessed = buf - resultW.c_str(); + resultW.insert(resultW.begin() + bytesProcessed, L'\n'); // Insert the newline, this invalidates the iterator + buf = resultW.c_str() + bytesProcessed; // In case reallocation occurs, we ensure we are inside the new buffer assert(*buf == '\n'); - pChar.SetPosition(buf); // pChar once again points inside the target string, at the current character + pChar = buf; // pChar once again points inside the target string, at the current character assert(*pChar == ch); ++pChar; ++curChar; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp index 101a506ddc..17ac896cf7 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontRenderer.cpp @@ -22,6 +22,8 @@ #include +#include + // Sizes are defined in in 26.6 fixed float format (TT_F26Dot6), where // 1 unit is 1/64 of a pixel. constexpr int FractionalPixelUnits = 64; @@ -94,7 +96,7 @@ AZ::FontRenderer::~FontRenderer() } //------------------------------------------------------------------------------------------------- -int AZ::FontRenderer::LoadFromFile(const string& fileName) +int AZ::FontRenderer::LoadFromFile(const AZStd::string& fileName) { int iError = FT_Init_FreeType(&m_library); @@ -309,8 +311,7 @@ Vec2 AZ::FontRenderer::GetKerning(uint32_t leftGlyph, uint32_t rightGlyph) #if !defined(_RELEASE) if (0 != ftError) { - string warnMsg; - warnMsg.Format("FT_Get_Kerning returned %d", ftError); + AZStd::string warnMsg = AZStd::string::format("FT_Get_Kerning returned %d", ftError); CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, warnMsg.c_str()); } #endif diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontTexture.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontTexture.cpp index 6008881ec3..1ee7f80eda 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FontTexture.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FontTexture.cpp @@ -14,8 +14,8 @@ #if !defined(USE_NULLFONT_ALWAYS) #include -#include #include +#include //------------------------------------------------------------------------------------------------- AZ::FontTexture::FontTexture() @@ -44,7 +44,7 @@ AZ::FontTexture::~FontTexture() } //------------------------------------------------------------------------------------------------- -int AZ::FontTexture::CreateFromFile(const string& fileName, int width, int height, AZ::FontSmoothMethod smoothMethod, AZ::FontSmoothAmount smoothAmount, int widthCellCount, int heightCellCount) +int AZ::FontTexture::CreateFromFile(const AZStd::string& fileName, int width, int height, AZ::FontSmoothMethod smoothMethod, AZ::FontSmoothAmount smoothAmount, int widthCellCount, int heightCellCount) { if (!m_glyphCache.LoadFontFromFile(fileName)) { @@ -255,10 +255,10 @@ int AZ::FontTexture::PreCacheString(const char* string, int* updated, float size uint16_t slotUsage = m_slotUsage++; int updateCount = 0; - uint32_t character; - for (Unicode::CIterator it(string); *it; ++it) + AZStd::wstring stringW; + AZStd::to_wstring(stringW, string); + for (wchar_t character : stringW) { - character = *it; TextureSlot* slot = GetCharSlot(character, clampedGlyphSize); if (!slot) diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/GlyphCache.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/GlyphCache.cpp index 12ebd99183..ee52d36af5 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/GlyphCache.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/GlyphCache.cpp @@ -124,7 +124,7 @@ int AZ::GlyphCache::Release() } //------------------------------------------------------------------------------------------------- -int AZ::GlyphCache::LoadFontFromFile(const string& fileName) +int AZ::GlyphCache::LoadFontFromFile(const AZStd::string & fileName) { return m_fontRenderer.LoadFromFile(fileName); } diff --git a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/GameController.cpp b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/GameController.cpp index 7038441e4c..c3b929ae7a 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/GameController.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Tools/EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/GameController.cpp @@ -12,6 +12,7 @@ #if AZ_TRAIT_EMOTIONFX_HAS_GAME_CONTROLLER #include +#include // joystick enum callback @@ -20,7 +21,7 @@ BOOL CALLBACK GameController::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdid GameController* manager = static_cast(pContext); // store the name - manager->mDeviceInfo.mName = pdidInstance->tszProductName; + AZStd::to_string(manager->mDeviceInfo.mName, pdidInstance->tszProductName); // Skip anything other than the perferred Joystick device as defined by the control panel. // Instead you could store all the enumerated Joysticks and let the user pick. @@ -71,7 +72,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_XAxis) { - manager->mDeviceElements[ ELEM_POS_X ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_POS_X ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_POS_X ].mPresent = true; manager->mDeviceElements[ ELEM_POS_X ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_POS_X ].mCalibrationValue = 0.0f; @@ -81,7 +82,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_YAxis) { - manager->mDeviceElements[ ELEM_POS_Y ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_POS_Y ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_POS_Y ].mPresent = true; manager->mDeviceElements[ ELEM_POS_Y ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_POS_Y ].mCalibrationValue = 0.0f; @@ -91,7 +92,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_ZAxis) { - manager->mDeviceElements[ ELEM_POS_Z ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_POS_Z ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_POS_Z ].mPresent = true; manager->mDeviceElements[ ELEM_POS_Z ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_POS_Z ].mCalibrationValue = 0.0f; @@ -101,7 +102,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_RxAxis) { - manager->mDeviceElements[ ELEM_ROT_X ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_ROT_X ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_ROT_X ].mPresent = true; manager->mDeviceElements[ ELEM_ROT_X ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_ROT_X ].mCalibrationValue = 0.0f; @@ -111,7 +112,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_RyAxis) { - manager->mDeviceElements[ ELEM_ROT_Y ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_ROT_Y ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_ROT_Y ].mPresent = true; manager->mDeviceElements[ ELEM_ROT_Y ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_ROT_Y ].mCalibrationValue = 0.0f; @@ -121,7 +122,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_RzAxis) { - manager->mDeviceElements[ ELEM_ROT_Z ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_ROT_Z ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_ROT_Z ].mPresent = true; manager->mDeviceElements[ ELEM_ROT_Z ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_ROT_Z ].mCalibrationValue = 0.0f; @@ -134,7 +135,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* { if (manager->mDeviceInfo.mNumSliders == 0) { - manager->mDeviceElements[ ELEM_SLIDER_1 ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_SLIDER_1 ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_SLIDER_1 ].mPresent = true; manager->mDeviceElements[ ELEM_SLIDER_1 ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_SLIDER_1 ].mCalibrationValue = 0.0f; @@ -142,7 +143,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* } else { - manager->mDeviceElements[ ELEM_SLIDER_2 ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_SLIDER_2 ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_SLIDER_2 ].mPresent = true; manager->mDeviceElements[ ELEM_SLIDER_2 ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_SLIDER_2 ].mCalibrationValue = 0.0f; @@ -156,7 +157,7 @@ BOOL CALLBACK GameController::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* if (pdidoi->guidType == GUID_POV) { const uint32 povIndex = manager->mDeviceInfo.mNumPOVs; - manager->mDeviceElements[ ELEM_POV_1 + povIndex ].mName = pdidoi->tszName; + AZStd::to_string(manager->mDeviceElements[ ELEM_POV_1 + povIndex ].mName, pdidoi->tszName); manager->mDeviceElements[ ELEM_POV_1 + povIndex ].mPresent = true; manager->mDeviceElements[ ELEM_POV_1 + povIndex ].mValue = 0.0f; //manager->mDeviceElements[ ELEM_POV_1 + povIndex ].mCalibrationValue = 0.0f;