enhanced-field-mgmt -- Enhancements to dynamic field handling that allow for name filtering and replacement limiting

This commit is contained in:
Marc Chapman 2017-07-26 21:49:45 +01:00
parent bc90e97d35
commit 64e742f053
4 changed files with 92 additions and 1 deletions

View file

@ -20,6 +20,10 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "platform/platform.h"
#include "console/simFieldDictionary.h"
@ -361,4 +365,62 @@ SimFieldDictionary::Entry* SimFieldDictionaryIterator::operator++()
SimFieldDictionary::Entry* SimFieldDictionaryIterator::operator*()
{
return(mEntry);
}
}
// A variation of the stock SimFieldDictionary::setFieldValue(), this method adds the
// <no_replace> argument which, when true, prohibits the replacement of fields that
// already have a value.
//
// AFX uses this when an effects-choreographer (afxMagicSpell, afxEffectron) is created
// using the new operator. It prevents any in-line effect parameters from being overwritten
// by default parameters that are copied over later.
void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *value, ConsoleBaseType *type, bool no_replace)
{
if (!no_replace)
{
setFieldValue(slotName, value);
return;
}
if (!value || !*value)
return;
U32 bucket = getHashValue(slotName);
Entry **walk = &mHashTable[bucket];
while(*walk && (*walk)->slotName != slotName)
walk = &((*walk)->next);
Entry *field = *walk;
if (field)
return;
addEntry( bucket, slotName, type, dStrdup( value ) );
}
// A variation of the stock SimFieldDictionary::assignFrom(), this method adds <no_replace>
// and <filter> arguments. When true, <no_replace> prohibits the replacement of fields that already
// have a value. When <filter> is specified, only fields with leading characters that exactly match
// the characters in <filter> are copied.
void SimFieldDictionary::assignFrom(SimFieldDictionary *dict, const char* filter, bool no_replace)
{
dsize_t filter_len = (filter) ? dStrlen(filter) : 0;
if (filter_len == 0 && !no_replace)
{
assignFrom(dict);
return;
}
mVersion++;
if (filter_len == 0)
{
for(U32 i = 0; i < HashTableSize; i++)
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
}
else
{
for(U32 i = 0; i < HashTableSize; i++)
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
if (dStrncmp(walk->slotName, filter, filter_len) == 0)
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
}
}