Files
o3de/Gems/PhysX/Code/Editor/UniqueStringContainer.cpp
T
Aaron Ruiz Mora 9d41954d0e Added configurable physics materials per asset in PhysX group in FBX Settings. (#1186)
- Added back the' Physics Materials from Asset' tick in the collider components.
- Made physics materials names case insensitive.
- Refactored how to gather material information from fbx and used the same code for exporter and physx groups.
2021-06-10 12:22:16 +01:00

108 lines
4.0 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "PhysX_precompiled.h"
#include <AzCore/std/string/conversions.h>
#include "UniqueStringContainer.h"
namespace PhysX
{
void UniqueStringContainer::AddString(AZ::Crc32 stringGroupId
, const AZStd::string& stringIn)
{
StringGroups::iterator stringGroupsIter = m_stringGroups.find(stringGroupId);
if (stringGroupsIter == m_stringGroups.end())
{
m_stringGroups.emplace(stringGroupId, StringSet());
}
m_stringGroups[stringGroupId].insert(stringIn);
}
AZStd::string UniqueStringContainer::GetUniqueString(AZ::Crc32 stringGroupId
, const AZStd::string& stringIn
, AZ::u64 maxStringLength
, const StringSet& forbiddenStrings) const
{
StringGroups::const_iterator stringGroupsIter = m_stringGroups.find(stringGroupId);
// Group for string does not yet exist. It will be unique if a new group that contains only this string is added.
// String is not any of the forbidden string values.
if (stringGroupsIter == m_stringGroups.end()
&& forbiddenStrings.find(stringIn) == forbiddenStrings.end()
&& stringIn.length() != 0)
{
return stringIn;
}
AZStd::string stringOut;
const StringSet& stringGroup = (stringGroupsIter == m_stringGroups.end())? StringSet():stringGroupsIter->second;
// Attempts to append a post-fix value, e.g. "_1" etc., to the original string so it is unique.
// A unique post-fix index can be found by iterating total number of invalid string plus 1.
const size_t totalNumInvalidStrings = stringGroup.size() + forbiddenStrings.size() + 1;
for (size_t nameIndex = 1; nameIndex <= totalNumInvalidStrings; ++nameIndex)
{
AZStd::string postFix;
to_string(postFix, nameIndex);
postFix = "_" + postFix;
size_t trimLength = (stringIn.length() + postFix.length()) - maxStringLength;
if (trimLength > 0)
{
stringOut = stringIn.substr(0, stringIn.length() - trimLength) + postFix;
}
else
{
stringOut = stringIn + postFix;
}
if (stringGroup.find(stringOut) == stringGroup.end()
&& forbiddenStrings.find(stringOut) == forbiddenStrings.end())
{
break;
}
}
return stringOut;
}
bool UniqueStringContainer::IsStringUnique(AZ::Crc32 stringGroupId
, const AZStd::string& stringIn) const
{
StringGroups::const_iterator stringGroupsIter = m_stringGroups.find(stringGroupId);
// String group does not yet exist. String would be unique if group is created for it.
if (stringGroupsIter == m_stringGroups.end())
{
return true;
}
const StringSet& stringSet = stringGroupsIter->second;
return stringSet.find(stringIn) == stringSet.end();
}
void UniqueStringContainer::RemoveString(AZ::Crc32 stringGroupId
, const AZStd::string& stringIn)
{
StringGroups::iterator stringGroupsIter = m_stringGroups.find(stringGroupId);
if (stringGroupsIter == m_stringGroups.end())
{
AZ_Warning("AzToolsFramework"
, false
, "Could not remove string %s from unrecognized group"
, stringIn.c_str());
return;
}
stringGroupsIter->second.erase(stringIn);
}
}