Added support for excluding properties from generation results that already have valid names. Plus some more property names

This commit is contained in:
Aruki
2018-10-14 20:29:50 -06:00
parent bd8579167d
commit 95d270cde7
18 changed files with 176 additions and 52 deletions

View File

@@ -101,6 +101,9 @@ struct SNameValue
/** Name of the property */
TString Name;
/** Whether this name is valid */
bool IsValid;
/** List of all properties using this ID */
std::list<IProperty*> PropertyList;
@@ -154,6 +157,14 @@ void LoadMap()
CXMLReader Reader(gpkMapPath);
ASSERT(Reader.IsValid());
Reader << SerialParameter("PropertyMap", gNameMap, SH_HexDisplay);
// Iterate over the map and set up the valid flags
for (auto Iter = gNameMap.begin(); Iter != gNameMap.end(); Iter++)
{
const SNameKey& kKey = Iter->first;
SNameValue& Value = Iter->second;
Value.IsValid = (CalculatePropertyID(*Value.Name, *gHashToTypeName[kKey.TypeHash]) == kKey.ID);
}
}
gMapIsLoaded = true;
@@ -230,13 +241,31 @@ const char* GetPropertyName(u32 ID, const char* pkTypeName)
return MapFind == gNameMap.end() ? "Unknown" : *MapFind->second.Name;
}
/** Calculate the property ID of a given name/type. */
u32 CalculatePropertyID(const char* pkName, const char* pkTypeName)
{
CCRC32 CRC;
CRC.Hash(pkName);
CRC.Hash(pkTypeName);
return CRC.Digest();
}
/** Returns whether the specified ID is in the map. */
bool IsValidPropertyID(u32 ID, const char* pkTypeName)
bool IsValidPropertyID(u32 ID, const char* pkTypeName, bool* pOutIsValid /*= nullptr*/)
{
SNameKey Key = CreateKey(ID, pkTypeName);
auto MapFind = gNameMap.find(Key);
return MapFind != gNameMap.end();
if (MapFind != gNameMap.end())
{
if (pOutIsValid != nullptr)
{
SNameValue& Value = MapFind->second;
*pOutIsValid = Value.IsValid;
}
return true;
}
else return false;
}
/** Retrieves a list of all properties that match the requested property ID. */
@@ -355,6 +384,7 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char*
{
SNameValue Value;
Value.Name = pProperty->Name();
Value.IsValid = ( CalculatePropertyID(*Value.Name, pkNewTypeName) == pProperty->ID() );
gNameMap[NewKey] = Value;
Find = gNameMap.find(NewKey);
}
@@ -365,7 +395,7 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char*
}
}
gHashToTypeName[NewTypeHash] = pkNewTypeName;
RegisterTypeName(NewTypeHash, pkNewTypeName);
}
/** Change a type name. */
@@ -401,6 +431,7 @@ void ChangeTypeNameGlobally(const char* pkOldTypeName, const char* pkNewTypeName
}
}
RegisterTypeName(NewTypeHash, pkNewTypeName);
gHashToTypeName[NewTypeHash] = pkNewTypeName;
}
@@ -430,6 +461,7 @@ void RegisterProperty(IProperty* pProperty)
SNameValue Value;
Value.Name = LegacyMapFind->second;
Value.IsValid = ( CalculatePropertyID(*Value.Name, pProperty->HashableTypeName()) == pProperty->ID() );
pProperty->SetName(Value.Name);
gNameMap[Key] = Value;
@@ -465,4 +497,50 @@ void UnregisterProperty(IProperty* pProperty)
}
}
/** Class for iterating through the map */
class CIteratorImpl
{
public:
std::map<SNameKey, SNameValue>::const_iterator mIter;
};
CIterator::CIterator()
{
mpImpl = new CIteratorImpl;
mpImpl->mIter = gNameMap.begin();
}
CIterator::~CIterator()
{
delete mpImpl;
}
u32 CIterator::ID() const
{
return mpImpl->mIter->first.ID;
}
const char* CIterator::Name() const
{
return *mpImpl->mIter->second.Name;
}
const char* CIterator::TypeName() const
{
u32 TypeHash = mpImpl->mIter->first.TypeHash;
auto Find = gHashToTypeName.find(TypeHash);
ASSERT(Find != gHashToTypeName.end());
return *Find->second;
}
CIterator::operator bool() const
{
return mpImpl->mIter != gNameMap.end();
}
void CIterator::operator++()
{
mpImpl->mIter++;
}
}

View File

@@ -22,8 +22,14 @@ const char* GetPropertyName(IProperty* pProperty);
*/
const char* GetPropertyName(u32 ID, const char* pkTypeName);
/** Returns whether the specified name is in the map. */
bool IsValidPropertyID(u32 ID, const char* pkTypeName);
/** Calculate the property ID of a given name/type. */
u32 CalculatePropertyID(const char* pkName, const char* pkTypeName);
/**
* Returns whether the specified name is in the map.
* If the ID is valid and pOutIsValid is non-null, it will return whether the current name is correct.
*/
bool IsValidPropertyID(u32 ID, const char* pkTypeName, bool* pOutIsValid = nullptr);
/** Retrieves a list of all properties that match the requested property ID. */
void RetrievePropertiesWithID(u32 ID, const char* pkTypeName, std::list<IProperty*>& OutList);
@@ -46,6 +52,24 @@ void RegisterProperty(IProperty* pProperty);
/** Unregisters a property from the name map. Should be called on all properties that use the map on destruction. */
void UnregisterProperty(IProperty* pProperty);
/** Class that allows for iteration through the name map */
class CIterator
{
/** Private implementation */
class CIteratorImpl* mpImpl;
public:
CIterator();
~CIterator();
u32 ID() const;
const char* Name() const;
const char* TypeName() const;
operator bool() const;
void operator ++();
};
}
#endif // NPROPERTYMAP_H

View File

@@ -176,7 +176,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
u32 PropertyID = FullHash.Digest();
// Check if this hash is a property ID
if (IsValidPropertyID(PropertyID, pkTypeName))
if (IsValidPropertyID(PropertyID, pkTypeName, rkParams))
{
SGeneratedPropertyName PropertyName;
NPropertyMap::RetrieveXMLsWithProperty(PropertyID, pkTypeName, PropertyName.XmlList);
@@ -253,7 +253,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
}
/** Returns whether a given property ID is valid */
bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType)
bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType, const SPropertyNameGenerationParameters& rkParams)
{
if (!mValidTypePairMap.empty())
{
@@ -267,5 +267,9 @@ bool CPropertyNameGenerator::IsValidPropertyID(u32 ID, const char* pkType)
return false;
}
else
return NPropertyMap::IsValidPropertyID(ID, pkType);
{
bool IsAlreadyNamed;
bool IsValid = NPropertyMap::IsValidPropertyID(ID, pkType, &IsAlreadyNamed);
return IsValid && (!IsAlreadyNamed || !rkParams.ExcludeAccuratelyNamedProperties);
}
}

View File

@@ -40,6 +40,9 @@ struct SPropertyNameGenerationParameters
/** List of ID/type pairs to check against. If empty, all properties are valid. */
std::vector<SPropertyIdTypePair> ValidIdPairs;
/** Whether to exclude properties that already have accurate names from the generation results. */
bool ExcludeAccuratelyNamedProperties;
/** Whether to print the output from the generation process to the log */
bool PrintToLog;
};
@@ -99,7 +102,7 @@ public:
void Generate(const SPropertyNameGenerationParameters& rkParams, IProgressNotifier* pProgressNotifier);
/** Returns whether a given property ID is valid */
bool IsValidPropertyID(u32 ID, const char* pkType);
bool IsValidPropertyID(u32 ID, const char* pkType, const SPropertyNameGenerationParameters& rkParams);
/** Accessors */
bool IsRunning() const