mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-06 05:50:31 +00:00
Initial Implementation of the Taml, Asset and Modules systems.
Only has example and shape assets currently.
This commit is contained in:
parent
2044b2691e
commit
7a3b40a86d
123 changed files with 30435 additions and 181 deletions
|
|
@ -209,6 +209,13 @@ namespace Con
|
|||
return ret;
|
||||
}
|
||||
|
||||
char* getBoolArg(bool arg)
|
||||
{
|
||||
char *ret = STR.getArgBuffer(32);
|
||||
dSprintf(ret, 32, "%d", arg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *getStringArg( const char *arg )
|
||||
{
|
||||
U32 len = dStrlen( arg ) + 1;
|
||||
|
|
|
|||
|
|
@ -1566,6 +1566,494 @@ void popInstantGroup()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
typedef HashMap<StringTableEntry, StringTableEntry> typePathExpandoMap;
|
||||
static typePathExpandoMap PathExpandos;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void addPathExpando(const char* pExpandoName, const char* pPath)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pExpandoName != NULL, "Expando name cannot be NULL.");
|
||||
AssertFatal(pPath != NULL, "Expando path cannot be NULL.");
|
||||
|
||||
// Fetch expando name.
|
||||
StringTableEntry expandoName = StringTable->insert(pExpandoName);
|
||||
|
||||
// Fetch the length of the path.
|
||||
S32 pathLength = dStrlen(pPath);
|
||||
|
||||
char pathBuffer[1024];
|
||||
|
||||
// Sanity!
|
||||
if (pathLength == 0 || pathLength >= sizeof(pathBuffer))
|
||||
{
|
||||
Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Strip repeat slashes.
|
||||
if (!Con::stripRepeatSlashes(pathBuffer, pPath, sizeof(pathBuffer)))
|
||||
{
|
||||
Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch new path length.
|
||||
pathLength = dStrlen(pathBuffer);
|
||||
|
||||
// Sanity!
|
||||
if (pathLength == 0)
|
||||
{
|
||||
Con::warnf("Cannot add path expando '%s' with path '%s' as the path is an invalid length.", pExpandoName, pPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any terminating slash.
|
||||
if (pathBuffer[pathLength - 1] == '/')
|
||||
pathBuffer[pathLength - 1] = 0;
|
||||
|
||||
// Fetch expanded path.
|
||||
StringTableEntry expandedPath = StringTable->insert(pathBuffer);
|
||||
|
||||
// Info.
|
||||
#if defined(TORQUE_DEBUG)
|
||||
Con::printf("Adding path expando of '%s' as '%s'.", expandoName, expandedPath);
|
||||
#endif
|
||||
|
||||
// Find any existing path expando.
|
||||
typePathExpandoMap::iterator expandoItr = PathExpandos.find(pExpandoName);
|
||||
|
||||
// Does the expando exist?
|
||||
if (expandoItr != PathExpandos.end())
|
||||
{
|
||||
// Yes, so modify the path.
|
||||
expandoItr->value = expandedPath;
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert expando.
|
||||
PathExpandos.insert(expandoName, expandedPath);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry getPathExpando(const char* pExpandoName)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pExpandoName != NULL, "Expando name cannot be NULL.");
|
||||
|
||||
// Fetch expando name.
|
||||
StringTableEntry expandoName = StringTable->insert(pExpandoName);
|
||||
|
||||
// Find any existing path expando.
|
||||
typePathExpandoMap::iterator expandoItr = PathExpandos.find(expandoName);
|
||||
|
||||
// Does the expando exist?
|
||||
if (expandoItr != PathExpandos.end())
|
||||
{
|
||||
// Yes, so return it.
|
||||
return expandoItr->value;
|
||||
}
|
||||
|
||||
// Not found.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void removePathExpando(const char* pExpandoName)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pExpandoName != NULL, "Expando name cannot be NULL.");
|
||||
|
||||
// Fetch expando name.
|
||||
StringTableEntry expandoName = StringTable->insert(pExpandoName);
|
||||
|
||||
// Find any existing path expando.
|
||||
typePathExpandoMap::iterator expandoItr = PathExpandos.find(expandoName);
|
||||
|
||||
// Does the expando exist?
|
||||
if (expandoItr == PathExpandos.end())
|
||||
{
|
||||
// No, so warn.
|
||||
#if defined(TORQUE_DEBUG)
|
||||
Con::warnf("Removing path expando of '%s' but it does not exist.", expandoName);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Info.
|
||||
#if defined(TORQUE_DEBUG)
|
||||
Con::printf("Removing path expando of '%s' as '%s'.", expandoName, expandoItr->value);
|
||||
#endif
|
||||
// Remove expando.
|
||||
PathExpandos.erase(expandoItr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool isPathExpando(const char* pExpandoName)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pExpandoName != NULL, "Expando name cannot be NULL.");
|
||||
|
||||
// Fetch expando name.
|
||||
StringTableEntry expandoName = StringTable->insert(pExpandoName);
|
||||
|
||||
return PathExpandos.contains(expandoName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
U32 getPathExpandoCount(void)
|
||||
{
|
||||
return PathExpandos.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry getPathExpandoKey(U32 expandoIndex)
|
||||
{
|
||||
// Finish if index is out of range.
|
||||
if (expandoIndex >= PathExpandos.size())
|
||||
return NULL;
|
||||
|
||||
// Find indexed iterator.
|
||||
typePathExpandoMap::iterator expandoItr = PathExpandos.begin();
|
||||
while (expandoIndex > 0) { ++expandoItr; --expandoIndex; }
|
||||
|
||||
return expandoItr->key;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry getPathExpandoValue(U32 expandoIndex)
|
||||
{
|
||||
// Finish if index is out of range.
|
||||
if (expandoIndex >= PathExpandos.size())
|
||||
return NULL;
|
||||
|
||||
// Find indexed iterator.
|
||||
typePathExpandoMap::iterator expandoItr = PathExpandos.begin();
|
||||
while (expandoIndex > 0) { ++expandoItr; --expandoIndex; }
|
||||
|
||||
return expandoItr->value;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool expandPath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint, const bool ensureTrailingSlash)
|
||||
{
|
||||
char pathBuffer[2048];
|
||||
const char* pSrc = pSrcPath;
|
||||
char* pSlash;
|
||||
|
||||
// Fetch leading character.
|
||||
const char leadingToken = *pSrc;
|
||||
|
||||
// Fetch following token.
|
||||
const char followingToken = leadingToken != 0 ? pSrc[1] : 0;
|
||||
|
||||
// Expando.
|
||||
if (leadingToken == '^')
|
||||
{
|
||||
// Initial prefix search.
|
||||
const char* pPrefixSrc = pSrc + 1;
|
||||
char* pPrefixDst = pathBuffer;
|
||||
|
||||
// Search for end of expando.
|
||||
while (*pPrefixSrc != '/' && *pPrefixSrc != 0)
|
||||
{
|
||||
// Copy prefix character.
|
||||
*pPrefixDst++ = *pPrefixSrc++;
|
||||
}
|
||||
|
||||
// Yes, so terminate the expando string.
|
||||
*pPrefixDst = 0;
|
||||
|
||||
// Fetch the expando path.
|
||||
StringTableEntry expandoPath = getPathExpando(pathBuffer);
|
||||
|
||||
// Does the expando exist?
|
||||
if (expandoPath == NULL)
|
||||
{
|
||||
// No, so error.
|
||||
Con::errorf("expandPath() : Could not find path expando '%s' for path '%s'.", pathBuffer, pSrcPath);
|
||||
|
||||
// Are we ensuring the trailing slash?
|
||||
if (ensureTrailingSlash)
|
||||
{
|
||||
// Yes, so ensure it.
|
||||
Con::ensureTrailingSlash(pDstPath, pSrcPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, so just use the source path.
|
||||
dStrcpy(pDstPath, pSrcPath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip the expando and the following slash.
|
||||
pSrc += dStrlen(pathBuffer) + 1;
|
||||
|
||||
// Format the output path.
|
||||
dSprintf(pathBuffer, sizeof(pathBuffer), "%s/%s", expandoPath, pSrc);
|
||||
|
||||
// Are we ensuring the trailing slash?
|
||||
if (ensureTrailingSlash)
|
||||
{
|
||||
// Yes, so ensure it.
|
||||
Con::ensureTrailingSlash(pathBuffer, pathBuffer);
|
||||
}
|
||||
|
||||
// Strip repeat slashes.
|
||||
Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Script-Relative.
|
||||
if (leadingToken == '.')
|
||||
{
|
||||
// Fetch the code-block file-path.
|
||||
const StringTableEntry codeblockFullPath = CodeBlock::getCurrentCodeBlockFullPath();
|
||||
|
||||
// Do we have a code block full path?
|
||||
if (codeblockFullPath == NULL)
|
||||
{
|
||||
// No, so error.
|
||||
Con::errorf("expandPath() : Could not find relative path from code-block for path '%s'.", pSrcPath);
|
||||
|
||||
// Are we ensuring the trailing slash?
|
||||
if (ensureTrailingSlash)
|
||||
{
|
||||
// Yes, so ensure it.
|
||||
Con::ensureTrailingSlash(pDstPath, pSrcPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, so just use the source path.
|
||||
dStrcpy(pDstPath, pSrcPath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Yes, so use it as the prefix.
|
||||
dStrncpy(pathBuffer, codeblockFullPath, sizeof(pathBuffer) - 1);
|
||||
|
||||
// Find the final slash in the code-block.
|
||||
pSlash = dStrrchr(pathBuffer, '/');
|
||||
|
||||
// Is this a parent directory token?
|
||||
if (followingToken == '.')
|
||||
{
|
||||
// Yes, so terminate after the slash so we include it.
|
||||
pSlash[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, it's a current directory token so terminate at the slash so we don't include it.
|
||||
pSlash[0] = 0;
|
||||
|
||||
// Skip the current directory token.
|
||||
pSrc++;
|
||||
}
|
||||
|
||||
// Format the output path.
|
||||
dStrncat(pathBuffer, "/", sizeof(pathBuffer) - 1 - strlen(pathBuffer));
|
||||
dStrncat(pathBuffer, pSrc, sizeof(pathBuffer) - 1 - strlen(pathBuffer));
|
||||
|
||||
// Are we ensuring the trailing slash?
|
||||
if (ensureTrailingSlash)
|
||||
{
|
||||
// Yes, so ensure it.
|
||||
Con::ensureTrailingSlash(pathBuffer, pathBuffer);
|
||||
}
|
||||
|
||||
// Strip repeat slashes.
|
||||
Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// All else.
|
||||
|
||||
//Using a special case here because the code below barfs on trying to build a full path for apk reading
|
||||
#ifdef TORQUE_OS_ANDROID
|
||||
if (leadingToken == '/' || strstr(pSrcPath, "/") == NULL)
|
||||
Platform::makeFullPathName(pSrcPath, pathBuffer, sizeof(pathBuffer), pWorkingDirectoryHint);
|
||||
else
|
||||
dSprintf(pathBuffer, sizeof(pathBuffer), "/%s", pSrcPath);
|
||||
#else
|
||||
Platform::makeFullPathName(pSrcPath, pathBuffer, sizeof(pathBuffer), pWorkingDirectoryHint);
|
||||
#endif
|
||||
|
||||
// Are we ensuring the trailing slash?
|
||||
if (ensureTrailingSlash)
|
||||
{
|
||||
// Yes, so ensure it.
|
||||
Con::ensureTrailingSlash(pathBuffer, pathBuffer);
|
||||
}
|
||||
|
||||
// Strip repeat slashes.
|
||||
Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool isBasePath(const char* SrcPath, const char* pBasePath)
|
||||
{
|
||||
char expandBuffer[1024];
|
||||
Con::expandPath(expandBuffer, sizeof(expandBuffer), SrcPath);
|
||||
return dStrnicmp(pBasePath, expandBuffer, dStrlen(pBasePath)) == 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void collapsePath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint)
|
||||
{
|
||||
// Check path against expandos. If there are multiple matches, choose the
|
||||
// expando that produces the shortest relative path.
|
||||
|
||||
char pathBuffer[2048];
|
||||
|
||||
// Fetch expando count.
|
||||
const U32 expandoCount = getPathExpandoCount();
|
||||
|
||||
// Iterate expandos.
|
||||
U32 expandoRelativePathLength = U32_MAX;
|
||||
for (U32 expandoIndex = 0; expandoIndex < expandoCount; ++expandoIndex)
|
||||
{
|
||||
// Fetch expando value (path).
|
||||
StringTableEntry expandoValue = getPathExpandoValue(expandoIndex);
|
||||
|
||||
// Skip if not the base path.
|
||||
if (!isBasePath(pSrcPath, expandoValue))
|
||||
continue;
|
||||
|
||||
// Fetch path relative to expando path.
|
||||
StringTableEntry relativePath = Platform::makeRelativePathName(pSrcPath, expandoValue);
|
||||
|
||||
// If the relative path is simply a period
|
||||
if (relativePath[0] == '.')
|
||||
relativePath++;
|
||||
|
||||
if (dStrlen(relativePath) > expandoRelativePathLength)
|
||||
{
|
||||
// This expando covers less of the path than any previous one found.
|
||||
// We will keep the previous one.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep track of the relative path length
|
||||
expandoRelativePathLength = dStrlen(relativePath);
|
||||
|
||||
// Fetch expando key (name).
|
||||
StringTableEntry expandoName = getPathExpandoKey(expandoIndex);
|
||||
|
||||
// Format against expando.
|
||||
dSprintf(pathBuffer, sizeof(pathBuffer), "^%s/%s", expandoName, relativePath);
|
||||
}
|
||||
|
||||
// Check if we've found a suitable expando
|
||||
if (expandoRelativePathLength != U32_MAX)
|
||||
{
|
||||
// Strip repeat slashes.
|
||||
Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the working directory.
|
||||
StringTableEntry workingDirectory = pWorkingDirectoryHint != NULL ? pWorkingDirectoryHint : Platform::getCurrentDirectory();
|
||||
|
||||
// Fetch path relative to current directory.
|
||||
StringTableEntry relativePath = Platform::makeRelativePathName(pSrcPath, workingDirectory);
|
||||
|
||||
// If the relative path is simply a period
|
||||
if (relativePath[0] == '.' && relativePath[1] != '.')
|
||||
relativePath++;
|
||||
|
||||
// Format against expando.
|
||||
dSprintf(pathBuffer, sizeof(pathBuffer), "%s/%s", workingDirectory, relativePath);
|
||||
|
||||
// Strip repeat slashes.
|
||||
Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
|
||||
}
|
||||
|
||||
|
||||
void ensureTrailingSlash(char* pDstPath, const char* pSrcPath)
|
||||
{
|
||||
// Copy to target.
|
||||
dStrcpy(pDstPath, pSrcPath);
|
||||
|
||||
// Find trailing character index.
|
||||
S32 trailIndex = dStrlen(pDstPath);
|
||||
|
||||
// Ignore if empty string.
|
||||
if (trailIndex == 0)
|
||||
return;
|
||||
|
||||
// Finish if the trailing slash already exists.
|
||||
if (pDstPath[trailIndex - 1] == '/')
|
||||
return;
|
||||
|
||||
// Add trailing slash.
|
||||
pDstPath[trailIndex++] = '/';
|
||||
pDstPath[trailIndex] = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool stripRepeatSlashes(char* pDstPath, const char* pSrcPath, S32 dstSize)
|
||||
{
|
||||
// Note original destination.
|
||||
char* pOriginalDst = pDstPath;
|
||||
|
||||
// Reset last source character.
|
||||
char lastSrcChar = 0;
|
||||
|
||||
// Search source...
|
||||
while (dstSize > 0)
|
||||
{
|
||||
// Fetch characters.
|
||||
const char srcChar = *pSrcPath++;
|
||||
|
||||
// Do we have a repeat slash?
|
||||
if (srcChar == '/' && lastSrcChar == '/')
|
||||
{
|
||||
// Yes, so skip it.
|
||||
continue;
|
||||
}
|
||||
|
||||
// No, so copy character.
|
||||
*pDstPath++ = srcChar;
|
||||
|
||||
// Finish if end of source.
|
||||
if (srcChar == 0)
|
||||
return true;
|
||||
|
||||
// Reduce room left in destination.
|
||||
dstSize--;
|
||||
|
||||
// Set last character.
|
||||
lastSrcChar = srcChar;
|
||||
}
|
||||
|
||||
// Terminate the destination string as we ran out of room.
|
||||
*pOriginalDst = 0;
|
||||
|
||||
// Fail!
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end of Console namespace
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -486,6 +486,20 @@ namespace Con
|
|||
bool expandToolScriptFilename(char *filename, U32 size, const char *src);
|
||||
bool collapseScriptFilename(char *filename, U32 size, const char *src);
|
||||
|
||||
bool expandPath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint = NULL, const bool ensureTrailingSlash = false);
|
||||
void collapsePath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint = NULL);
|
||||
bool isBasePath(const char* SrcPath, const char* pBasePath);
|
||||
void ensureTrailingSlash(char* pDstPath, const char* pSrcPath);
|
||||
bool stripRepeatSlashes(char* pDstPath, const char* pSrcPath, S32 dstSize);
|
||||
|
||||
void addPathExpando(const char* pExpandoName, const char* pPath);
|
||||
void removePathExpando(const char* pExpandoName);
|
||||
bool isPathExpando(const char* pExpandoName);
|
||||
StringTableEntry getPathExpando(const char* pExpandoName);
|
||||
U32 getPathExpandoCount(void);
|
||||
StringTableEntry getPathExpandoKey(U32 expandoIndex);
|
||||
StringTableEntry getPathExpandoValue(U32 expandoIndex);
|
||||
|
||||
bool isCurrentScriptToolScript();
|
||||
|
||||
StringTableEntry getModNameFromPath(const char *path);
|
||||
|
|
@ -739,6 +753,13 @@ namespace Con
|
|||
/// @see Con::errorf()
|
||||
void errorf(ConsoleLogEntry::Type type, const char *_format, ...);
|
||||
|
||||
//some additions from t2d
|
||||
/// Prints a separator to the console.
|
||||
inline void printSeparator(void) { printf("--------------------------------------------------------------------------------"); }
|
||||
|
||||
/// Prints a separator to the console.
|
||||
inline void printBlankLine(void) { printf(""); }
|
||||
|
||||
/// @}
|
||||
|
||||
/// Returns true when called from the main thread, false otherwise
|
||||
|
|
@ -815,6 +836,7 @@ namespace Con
|
|||
char* getArgBuffer(U32 bufferSize);
|
||||
char* getFloatArg(F64 arg);
|
||||
char* getIntArg (S32 arg);
|
||||
char* getBoolArg(bool arg);
|
||||
char* getStringArg( const char* arg );
|
||||
char* getStringArg( const String& arg );
|
||||
/// @}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,25 @@ bool AbstractClassRep::initialized = false;
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
AbstractClassRep* AbstractClassRep::findFieldRoot(StringTableEntry fieldName)
|
||||
{
|
||||
// Find the field.
|
||||
const Field* pField = findField(fieldName);
|
||||
|
||||
// Finish if not found.
|
||||
if (pField == NULL)
|
||||
return NULL;
|
||||
|
||||
// We're the root if we have no parent.
|
||||
if (getParentClass() == NULL)
|
||||
return this;
|
||||
|
||||
// Find the field root via the parent.
|
||||
AbstractClassRep* pFieldRoot = getParentClass()->findFieldRoot(fieldName);
|
||||
|
||||
// We're the root if the parent does not have it else return the field root.
|
||||
return pFieldRoot == NULL ? this : pFieldRoot;
|
||||
}
|
||||
|
||||
void AbstractClassRep::init()
|
||||
{
|
||||
|
|
@ -349,6 +367,7 @@ void ConsoleObject::addGroup(const char* in_pGroupname, const char* in_pGroupDoc
|
|||
f.validator = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -371,6 +390,7 @@ void ConsoleObject::endGroup(const char* in_pGroupname)
|
|||
f.validator = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.elementCount = 0;
|
||||
|
||||
// Add to field list.
|
||||
|
|
@ -393,6 +413,7 @@ void ConsoleObject::addArray( const char *arrayName, S32 count )
|
|||
f.validator = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -412,6 +433,7 @@ void ConsoleObject::endArray( const char *arrayName )
|
|||
f.validator = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.elementCount = 0;
|
||||
|
||||
// Add to field list.
|
||||
|
|
@ -433,13 +455,77 @@ void ConsoleObject::addField(const char* in_pFieldname,
|
|||
flags );
|
||||
}
|
||||
|
||||
void ConsoleObject::addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
addField(
|
||||
in_pFieldname,
|
||||
in_fieldType,
|
||||
in_fieldOffset,
|
||||
in_writeDataFn,
|
||||
1,
|
||||
in_pFieldDocs,
|
||||
flags);
|
||||
}
|
||||
|
||||
void ConsoleObject::addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
addField(in_pFieldname,
|
||||
in_fieldType,
|
||||
in_fieldOffset,
|
||||
&defaultProtectedWriteFn,
|
||||
in_elementCount,
|
||||
in_pFieldDocs,
|
||||
flags);
|
||||
}
|
||||
|
||||
void ConsoleObject::addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
AbstractClassRep::Field f;
|
||||
f.pFieldname = StringTable->insert(in_pFieldname);
|
||||
|
||||
if (in_pFieldDocs)
|
||||
f.pFieldDocs = in_pFieldDocs;
|
||||
|
||||
f.type = in_fieldType;
|
||||
f.offset = in_fieldOffset;
|
||||
f.elementCount = in_elementCount;
|
||||
f.validator = NULL;
|
||||
f.flag = flags;
|
||||
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = in_writeDataFn;
|
||||
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType(in_fieldType);
|
||||
AssertFatal(conType, "ConsoleObject::addField - invalid console type");
|
||||
f.table = conType->getEnumTable();
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
}
|
||||
|
||||
void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags )
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
addProtectedField(
|
||||
in_pFieldname,
|
||||
|
|
@ -447,67 +533,81 @@ void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
|||
in_fieldOffset,
|
||||
in_setDataFn,
|
||||
in_getDataFn,
|
||||
&defaultProtectedWriteFn,
|
||||
1,
|
||||
in_pFieldDocs,
|
||||
flags );
|
||||
}
|
||||
|
||||
|
||||
void ConsoleObject::addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags )
|
||||
{
|
||||
AbstractClassRep::Field f;
|
||||
f.pFieldname = StringTable->insert(in_pFieldname);
|
||||
|
||||
if(in_pFieldDocs)
|
||||
f.pFieldDocs = in_pFieldDocs;
|
||||
|
||||
f.type = in_fieldType;
|
||||
f.offset = in_fieldOffset;
|
||||
f.elementCount = in_elementCount;
|
||||
f.validator = NULL;
|
||||
f.flag = flags;
|
||||
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType( in_fieldType );
|
||||
AssertFatal( conType, "ConsoleObject::addField - invalid console type" );
|
||||
f.table = conType->getEnumTable();
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
flags);
|
||||
}
|
||||
|
||||
void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags )
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
addProtectedField(
|
||||
in_pFieldname,
|
||||
in_fieldType,
|
||||
in_fieldOffset,
|
||||
in_setDataFn,
|
||||
in_getDataFn,
|
||||
in_writeDataFn,
|
||||
1,
|
||||
in_pFieldDocs,
|
||||
flags);
|
||||
}
|
||||
|
||||
void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
addProtectedField(
|
||||
in_pFieldname,
|
||||
in_fieldType,
|
||||
in_fieldOffset,
|
||||
in_setDataFn,
|
||||
in_getDataFn,
|
||||
&defaultProtectedWriteFn,
|
||||
1,
|
||||
in_pFieldDocs,
|
||||
flags);
|
||||
}
|
||||
void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags)
|
||||
{
|
||||
AbstractClassRep::Field f;
|
||||
f.pFieldname = StringTable->insert(in_pFieldname);
|
||||
f.pFieldname = StringTable->insert(in_pFieldname);
|
||||
|
||||
if(in_pFieldDocs)
|
||||
f.pFieldDocs = in_pFieldDocs;
|
||||
if (in_pFieldDocs)
|
||||
f.pFieldDocs = in_pFieldDocs;
|
||||
|
||||
f.type = in_fieldType;
|
||||
f.offset = in_fieldOffset;
|
||||
f.type = in_fieldType;
|
||||
f.offset = in_fieldOffset;
|
||||
f.elementCount = in_elementCount;
|
||||
f.validator = NULL;
|
||||
f.flag = flags;
|
||||
f.validator = NULL;
|
||||
f.flag = flags;
|
||||
|
||||
f.setDataFn = in_setDataFn;
|
||||
f.getDataFn = in_getDataFn;
|
||||
f.writeDataFn = in_writeDataFn;
|
||||
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType( in_fieldType );
|
||||
AssertFatal( conType, "ConsoleObject::addProtectedField - invalid console type" );
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType(in_fieldType);
|
||||
AssertFatal(conType, "ConsoleObject::addProtectedField - invalid console type");
|
||||
f.table = conType->getEnumTable();
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -529,6 +629,7 @@ void ConsoleObject::addFieldV(const char* in_pFieldname,
|
|||
f.table = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.validator = v;
|
||||
v->fieldIndex = sg_tempFieldList.size();
|
||||
|
||||
|
|
@ -546,6 +647,7 @@ void ConsoleObject::addDeprecatedField(const char *fieldName)
|
|||
f.validator = NULL;
|
||||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@
|
|||
#ifndef _SIMOBJECTREF_H_
|
||||
#include "console/simObjectRef.h"
|
||||
#endif
|
||||
|
||||
#ifndef TINYXML_INCLUDED
|
||||
#include "tinyXML/tinyxml.h"
|
||||
#endif
|
||||
|
||||
/// @file
|
||||
/// Legacy console object system.
|
||||
|
|
@ -201,6 +203,9 @@ public:
|
|||
|
||||
typedef ConsoleBaseType Parent;
|
||||
|
||||
/// Allows the writing of a custom TAML schema.
|
||||
typedef void(*WriteCustomTamlSchema)(const AbstractClassRep* pClassRep, TiXmlElement* pParentElement);
|
||||
|
||||
/// @name 'Tructors
|
||||
/// @{
|
||||
|
||||
|
|
@ -321,6 +326,9 @@ public:
|
|||
|
||||
/// Return the AbstractClassRep of the class that this class is derived from.
|
||||
AbstractClassRep* getParentClass() const { return parentClass; }
|
||||
|
||||
virtual AbstractClassRep* getContainerChildClass(const bool recurse) = 0;
|
||||
virtual WriteCustomTamlSchema getCustomTamlSchema(void) = 0;
|
||||
|
||||
/// Return the size of instances of this class in bytes.
|
||||
S32 getSizeof() const { return mClassSizeof; }
|
||||
|
|
@ -376,6 +384,8 @@ public:
|
|||
|
||||
virtual ConsoleObject* create () const = 0;
|
||||
|
||||
AbstractClassRep* findFieldRoot(StringTableEntry fieldName);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void init();
|
||||
|
|
@ -421,6 +431,13 @@ public:
|
|||
typedef bool (*SetDataNotify)( void *obj, const char *array, const char *data );
|
||||
typedef const char *(*GetDataNotify)( void *obj, const char *data );
|
||||
|
||||
/// This is a function pointer typedef to support optional writing for fields.
|
||||
typedef bool(*WriteDataNotify)(void* obj, StringTableEntry pFieldName);
|
||||
|
||||
/// Allows the writing of a custom TAML schema.
|
||||
typedef void(*WriteCustomTamlSchema)(const AbstractClassRep* pClassRep, TiXmlElement* pParentElement);
|
||||
|
||||
|
||||
/// These are special field type values used to mark
|
||||
/// groups and arrays in the field list.
|
||||
/// @see Field::type
|
||||
|
|
@ -494,6 +511,7 @@ public:
|
|||
TypeValidator *validator; ///< Validator, if any.
|
||||
SetDataNotify setDataFn; ///< Set data notify Fn
|
||||
GetDataNotify getDataFn; ///< Get data notify Fn
|
||||
WriteDataNotify writeDataFn; ///< Function to determine whether data should be written or not.
|
||||
};
|
||||
typedef Vector<Field> FieldList;
|
||||
|
||||
|
|
@ -595,6 +613,27 @@ class ConcreteClassRep : public AbstractClassRep
|
|||
registerClassRep(this);
|
||||
};
|
||||
|
||||
virtual AbstractClassRep* getContainerChildClass(const bool recurse)
|
||||
{
|
||||
// Fetch container children type.
|
||||
AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
|
||||
if (!recurse || pChildren != NULL)
|
||||
return pChildren;
|
||||
|
||||
// Fetch parent type.
|
||||
AbstractClassRep* pParent = T::getParentStaticClassRep();
|
||||
if (pParent == NULL)
|
||||
return NULL;
|
||||
|
||||
// Get parent container children.
|
||||
return pParent->getContainerChildClass(recurse);
|
||||
}
|
||||
|
||||
virtual WriteCustomTamlSchema getCustomTamlSchema(void)
|
||||
{
|
||||
return T::getStaticWriteCustomTamlSchema();
|
||||
}
|
||||
|
||||
/// Perform class specific initialization tasks.
|
||||
///
|
||||
/// Link namespaces, call initPersistFields() and consoleInit().
|
||||
|
|
@ -652,7 +691,7 @@ template< typename T > EnginePropertyTable& ConcreteClassRep< T >::smPropertyTab
|
|||
//------------------------------------------------------------------------------
|
||||
// Forward declaration of this function so it can be used in the class
|
||||
const char *defaultProtectedGetFn( void *obj, const char *data );
|
||||
|
||||
bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName);
|
||||
|
||||
//=============================================================================
|
||||
// ConsoleObject.
|
||||
|
|
@ -781,6 +820,14 @@ public:
|
|||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0 );
|
||||
|
||||
static void addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const U32 in_elementCount = 1,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0);
|
||||
|
||||
/// Register a simple field.
|
||||
///
|
||||
/// @param in_pFieldname Name of the field.
|
||||
|
|
@ -793,6 +840,13 @@ public:
|
|||
const char* in_pFieldDocs,
|
||||
U32 flags = 0 );
|
||||
|
||||
static void addField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn,
|
||||
const char* in_pFieldDocs,
|
||||
U32 flags = 0);
|
||||
|
||||
/// Register a validated field.
|
||||
///
|
||||
/// A validated field is just like a normal field except that you can't
|
||||
|
|
@ -821,10 +875,20 @@ public:
|
|||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn,
|
||||
const U32 in_elementCount,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0 );
|
||||
AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
|
||||
const U32 in_elementCount = 1,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0);
|
||||
|
||||
static void addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
|
||||
const U32 in_elementCount = 1,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0);
|
||||
|
||||
/// Register a simple protected field.
|
||||
///
|
||||
|
|
@ -839,8 +903,17 @@ public:
|
|||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
|
||||
AbstractClassRep::WriteDataNotify in_writeDataFn = &defaultProtectedWriteFn,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0 );
|
||||
U32 flags = 0);
|
||||
|
||||
static void addProtectedField(const char* in_pFieldname,
|
||||
const U32 in_fieldType,
|
||||
const dsize_t in_fieldOffset,
|
||||
AbstractClassRep::SetDataNotify in_setDataFn,
|
||||
AbstractClassRep::GetDataNotify in_getDataFn = &defaultProtectedGetFn,
|
||||
const char* in_pFieldDocs = NULL,
|
||||
U32 flags = 0);
|
||||
|
||||
/// Add a deprecated field.
|
||||
///
|
||||
|
|
@ -1045,6 +1118,8 @@ inline bool& ConsoleObject::getDynamicGroupExpand()
|
|||
static AbstractClassRep* getParentStaticClassRep(); \
|
||||
static AbstractClassRep* getStaticClassRep(); \
|
||||
static SimObjectRefConsoleBaseType< className > ptrRefType; \
|
||||
static AbstractClassRep::WriteCustomTamlSchema getStaticWriteCustomTamlSchema(); \
|
||||
static AbstractClassRep* getContainerChildStaticClassRep(); \
|
||||
virtual AbstractClassRep* getClassRep() const
|
||||
|
||||
#define DECLARE_CATEGORY( string ) \
|
||||
|
|
@ -1061,6 +1136,44 @@ inline bool& ConsoleObject::getDynamicGroupExpand()
|
|||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
|
||||
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
#define IMPLEMENT_CONOBJECT_CHILDREN( className ) \
|
||||
IMPLEMENT_CLASS( className, NULL ) \
|
||||
END_IMPLEMENT_CLASS; \
|
||||
S32 className::_smTypeId; \
|
||||
SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
|
||||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
|
||||
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
#define IMPLEMENT_CONOBJECT_SCHEMA( className, schema ) \
|
||||
IMPLEMENT_CLASS( className, NULL ) \
|
||||
END_IMPLEMENT_CLASS; \
|
||||
S32 className::_smTypeId; \
|
||||
SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
|
||||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
|
||||
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
#define IMPLEMENT_CONOBJECT_CHILDREN_SCHEMA( className, schema ) \
|
||||
IMPLEMENT_CLASS( className, NULL ) \
|
||||
END_IMPLEMENT_CLASS; \
|
||||
S32 className::_smTypeId; \
|
||||
SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
|
||||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return Children::getStaticClassRep(); } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
|
||||
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
#define IMPLEMENT_CO_NETOBJECT_V1( className ) \
|
||||
|
|
@ -1071,6 +1184,8 @@ inline bool& ConsoleObject::getDynamicGroupExpand()
|
|||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
|
||||
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeObject, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
#define IMPLEMENT_CO_DATABLOCK_V1( className ) \
|
||||
|
|
@ -1081,6 +1196,8 @@ inline bool& ConsoleObject::getDynamicGroupExpand()
|
|||
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
|
||||
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
|
||||
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
|
||||
AbstractClassRep* className::getContainerChildStaticClassRep() { return NULL; } \
|
||||
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return NULL; } \
|
||||
ConcreteClassRep<className> className::dynClassRep(#className, "Type" #className, &_smTypeId, NetClassGroupGameMask, NetClassTypeDataBlock, 0, className::getParentStaticClassRep(), &Parent::__description )
|
||||
|
||||
// Support for adding properties to classes CONOBJECT style.
|
||||
|
|
@ -1133,6 +1250,21 @@ inline const char *emptyStringProtectedGetFn( void *obj, const char *data )
|
|||
return "";
|
||||
}
|
||||
|
||||
inline bool defaultProtectedWriteFn(void* obj, StringTableEntry pFieldName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool defaultProtectedNotSetFn(void* obj, const char *array, const char* data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool defaultProtectedNotWriteFn(void* obj, StringTableEntry pFieldName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
#endif //_CONSOLEOBJECT_H_
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeString
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( string, TypeString, const char* )
|
||||
ConsoleType( string, TypeString, const char*, "" )
|
||||
ImplementConsoleTypeCasters( TypeString, const char* );
|
||||
|
||||
ConsoleGetType( TypeString )
|
||||
|
|
@ -53,7 +53,7 @@ ConsoleSetType( TypeString )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeCaseString
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( caseString, TypeCaseString, const char* )
|
||||
ConsoleType(caseString, TypeCaseString, const char*, "")
|
||||
|
||||
ConsoleSetType( TypeCaseString )
|
||||
{
|
||||
|
|
@ -71,7 +71,7 @@ ConsoleGetType( TypeCaseString )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeRealString
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( string, TypeRealString, String )
|
||||
ConsoleType(string, TypeRealString, String, "")
|
||||
ImplementConsoleTypeCasters( TypeRealString, String )
|
||||
|
||||
ConsoleGetType( TypeRealString )
|
||||
|
|
@ -94,7 +94,7 @@ ConsoleSetType( TypeRealString )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeCommand
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( string, TypeCommand, String )
|
||||
ConsoleType(string, TypeCommand, String, "")
|
||||
|
||||
ConsoleGetType( TypeCommand )
|
||||
{
|
||||
|
|
@ -284,7 +284,7 @@ ConsoleProcessData( TypeShapeFilename )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeS8
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( char, TypeS8, S8 )
|
||||
ConsoleType(char, TypeS8, S8, "")
|
||||
ImplementConsoleTypeCasters( TypeS8, S8 )
|
||||
|
||||
ConsoleGetType( TypeS8 )
|
||||
|
|
@ -306,7 +306,7 @@ ConsoleSetType( TypeS8 )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeS32
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( int, TypeS32, S32 )
|
||||
ConsoleType(int, TypeS32, S32, "")
|
||||
ImplementConsoleTypeCasters(TypeS32, S32)
|
||||
|
||||
ConsoleGetType( TypeS32 )
|
||||
|
|
@ -329,7 +329,7 @@ ConsoleSetType( TypeS32 )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeS32Vector
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( intList, TypeS32Vector, Vector<S32> )
|
||||
ConsoleType(intList, TypeS32Vector, Vector<S32>, "")
|
||||
ImplementConsoleTypeCasters( TypeS32Vector, Vector< S32 > )
|
||||
|
||||
ConsoleGetType( TypeS32Vector )
|
||||
|
|
@ -386,7 +386,7 @@ ConsoleSetType( TypeS32Vector )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeF32
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( float, TypeF32, F32 )
|
||||
ConsoleType(float, TypeF32, F32, "")
|
||||
ImplementConsoleTypeCasters(TypeF32, F32)
|
||||
|
||||
ConsoleGetType( TypeF32 )
|
||||
|
|
@ -407,7 +407,7 @@ ConsoleSetType( TypeF32 )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeF32Vector
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( floatList, TypeF32Vector, Vector<F32> )
|
||||
ConsoleType(floatList, TypeF32Vector, Vector<F32>, "")
|
||||
ImplementConsoleTypeCasters( TypeF32Vector, Vector< F32 > )
|
||||
|
||||
ConsoleGetType( TypeF32Vector )
|
||||
|
|
@ -464,7 +464,7 @@ ConsoleSetType( TypeF32Vector )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeBool
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( bool, TypeBool, bool )
|
||||
ConsoleType(bool, TypeBool, bool, "")
|
||||
ImplementConsoleTypeCasters( TypeBool, bool )
|
||||
|
||||
ConsoleGetType( TypeBool )
|
||||
|
|
@ -484,7 +484,7 @@ ConsoleSetType( TypeBool )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeBoolVector
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( boolList, TypeBoolVector, Vector<bool> )
|
||||
ConsoleType(boolList, TypeBoolVector, Vector<bool>, "")
|
||||
ImplementConsoleTypeCasters( TypeBoolVector, Vector< bool > )
|
||||
|
||||
ConsoleGetType( TypeBoolVector )
|
||||
|
|
@ -541,7 +541,7 @@ ConsoleSetType( TypeBoolVector )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeFlag
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( flag, TypeFlag, S32 )
|
||||
ConsoleType(flag, TypeFlag, S32, "")
|
||||
|
||||
ConsoleGetType( TypeFlag )
|
||||
{
|
||||
|
|
@ -567,7 +567,7 @@ ConsoleSetType( TypeFlag )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeColorF
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( ColorF, TypeColorF, ColorF )
|
||||
ConsoleType(ColorF, TypeColorF, ColorF, "")
|
||||
ImplementConsoleTypeCasters( TypeColorF, ColorF )
|
||||
|
||||
ConsoleGetType( TypeColorF )
|
||||
|
|
@ -640,7 +640,7 @@ ConsoleSetType( TypeColorF )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeColorI
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( ColorI, TypeColorI, ColorI )
|
||||
ConsoleType(ColorI, TypeColorI, ColorI, "")
|
||||
ImplementConsoleTypeCasters( TypeColorI, ColorI )
|
||||
|
||||
ConsoleGetType( TypeColorI )
|
||||
|
|
@ -713,7 +713,7 @@ ConsoleSetType( TypeColorI )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeSimObjectName
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( SimObject, TypeSimObjectName, SimObject* )
|
||||
ConsoleType(SimObject, TypeSimObjectName, SimObject*, "")
|
||||
|
||||
ConsoleSetType( TypeSimObjectName )
|
||||
{
|
||||
|
|
@ -738,7 +738,7 @@ ConsoleGetType( TypeSimObjectName )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeName
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( string, TypeName, const char* )
|
||||
ConsoleType(string, TypeName, const char*, "")
|
||||
|
||||
ConsoleGetType( TypeName )
|
||||
{
|
||||
|
|
@ -753,7 +753,7 @@ ConsoleSetType( TypeName )
|
|||
//------------------------------------------------------------------------------
|
||||
// TypeParticleParameterString
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleType( string, TypeParticleParameterString, const char* )
|
||||
ConsoleType(string, TypeParticleParameterString, const char*, "")
|
||||
|
||||
ConsoleGetType( TypeParticleParameterString )
|
||||
{
|
||||
|
|
@ -772,7 +772,7 @@ ConsoleSetType( TypeParticleParameterString )
|
|||
// TypeMaterialName
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType( string, TypeMaterialName, String )
|
||||
ConsoleType(string, TypeMaterialName, String, "")
|
||||
|
||||
ConsoleGetType( TypeMaterialName )
|
||||
{
|
||||
|
|
@ -794,7 +794,7 @@ ConsoleSetType( TypeMaterialName )
|
|||
// TypeTerrainMaterialIndex
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType( int, TypeTerrainMaterialIndex, S32 )
|
||||
ConsoleType(int, TypeTerrainMaterialIndex, S32, "")
|
||||
|
||||
ConsoleGetType( TypeTerrainMaterialIndex )
|
||||
{
|
||||
|
|
@ -816,7 +816,7 @@ ConsoleSetType( TypeTerrainMaterialIndex )
|
|||
// TypeTerrainMaterialName
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType( string, TypeTerrainMaterialName, const char* )
|
||||
ConsoleType(string, TypeTerrainMaterialName, const char*, "")
|
||||
|
||||
ConsoleGetType( TypeTerrainMaterialName )
|
||||
{
|
||||
|
|
@ -835,7 +835,7 @@ ConsoleSetType( TypeTerrainMaterialName )
|
|||
// TypeCubemapName
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType( string, TypeCubemapName, String )
|
||||
ConsoleType(string, TypeCubemapName, String, "")
|
||||
|
||||
ConsoleGetType( TypeCubemapName )
|
||||
{
|
||||
|
|
@ -856,7 +856,7 @@ ConsoleSetType( TypeCubemapName )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeRectUV
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( RectF, TypeRectUV, RectF )
|
||||
ConsoleType(RectF, TypeRectUV, RectF, "")
|
||||
|
||||
ConsoleGetType( TypeRectUV )
|
||||
{
|
||||
|
|
@ -882,7 +882,7 @@ ConsoleSetType( TypeRectUV )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeUUID
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( uuid, TypeUUID, Torque::UUID )
|
||||
ConsoleType(uuid, TypeUUID, Torque::UUID, "")
|
||||
ImplementConsoleTypeCasters( TypeUUID, Torque::UUID )
|
||||
|
||||
ConsoleGetType( TypeUUID )
|
||||
|
|
@ -906,7 +906,7 @@ ConsoleSetType( TypeUUID )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypePID
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( pid, TypePID, SimPersistID* )
|
||||
ConsoleType(pid, TypePID, SimPersistID*, "")
|
||||
ImplementConsoleTypeCasters( TypePID, SimPersistID* )
|
||||
|
||||
ConsoleGetType( TypePID )
|
||||
|
|
@ -945,7 +945,7 @@ ConsoleSetType( TypePID )
|
|||
//-----------------------------------------------------------------------------
|
||||
// TypeSimPersistId
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType( SimPersistId, TypeSimPersistId, SimPersistID* )
|
||||
ConsoleType(SimPersistId, TypeSimPersistId, SimPersistID*, "")
|
||||
|
||||
ConsoleGetType( TypeSimPersistId )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@
|
|||
#include "console/engineTypeInfo.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGTABLE_H_
|
||||
#include "core/stringTable.h"
|
||||
#endif
|
||||
|
||||
/// @file
|
||||
/// Support for legacy TorqueScript console types.
|
||||
|
|
@ -151,6 +154,8 @@ class ConsoleBaseType
|
|||
virtual const bool isDatablock() { return false; };
|
||||
|
||||
virtual const char* prepData( const char* data, char* buffer, U32 bufferLen ) { return data; };
|
||||
|
||||
virtual StringTableEntry getTypePrefix(void) const { return StringTable->EmptyString(); }
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
|
@ -259,7 +264,7 @@ const EngineTypeInfo* _MAPTYPE() { return TYPE< T >(); }
|
|||
DefineConsoleType( type, nativeType ) \
|
||||
template<> inline const EngineTypeInfo* _MAPTYPE< nativeType >() { return NULL; }
|
||||
|
||||
#define ConsoleType( typeName, type, nativeType ) \
|
||||
#define ConsoleType( typeName, type, nativeType, typePrefix ) \
|
||||
S32 type; \
|
||||
class ConsoleType##type : public ConsoleBaseType \
|
||||
{ \
|
||||
|
|
@ -275,6 +280,7 @@ const EngineTypeInfo* _MAPTYPE() { return TYPE< T >(); }
|
|||
virtual const char *getTypeClassName() { return #typeName ; } \
|
||||
virtual void *getNativeVariable() { T* var = new T; return (void*)var; } \
|
||||
virtual void deleteNativeVariable(void* var) { T* nativeVar = reinterpret_cast<T*>(var); delete nativeVar; } \
|
||||
virtual StringTableEntry getTypePrefix( void ) const { return StringTable->insert( typePrefix ); } \
|
||||
}; \
|
||||
ConsoleType ## type gConsoleType ## type ## Instance;
|
||||
|
||||
|
|
@ -304,6 +310,9 @@ const EngineTypeInfo* _MAPTYPE() { return TYPE< T >(); }
|
|||
}; \
|
||||
ConsoleType ## type gConsoleType ## type ## Instance;
|
||||
|
||||
#define ConsoleTypeFieldPrefix( type, typePrefix ) \
|
||||
StringTableEntry ConsoleType##type::getTypePrefix( void ) const { return StringTable->insert( typePrefix ); }
|
||||
|
||||
#define ConsoleSetType( type ) \
|
||||
void ConsoleType##type::setData(void *dptr, S32 argc, const char **argv, const EnumTable *tbl, BitSet32 flag)
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,27 @@ public:
|
|||
parentClass = parent;
|
||||
};
|
||||
|
||||
virtual AbstractClassRep* getContainerChildClass(const bool recurse)
|
||||
{
|
||||
// Fetch container children type.
|
||||
AbstractClassRep* pChildren = T::getContainerChildStaticClassRep();
|
||||
if (!recurse || pChildren != NULL)
|
||||
return pChildren;
|
||||
|
||||
// Fetch parent type.
|
||||
AbstractClassRep* pParent = T::getParentStaticClassRep();
|
||||
if (pParent == NULL)
|
||||
return NULL;
|
||||
|
||||
// Get parent container children.
|
||||
return pParent->getContainerChildClass(recurse);
|
||||
}
|
||||
|
||||
virtual WriteCustomTamlSchema getCustomTamlSchema(void)
|
||||
{
|
||||
return T::getStaticWriteCustomTamlSchema();
|
||||
}
|
||||
|
||||
/// Perform class specific initialization tasks.
|
||||
///
|
||||
/// Link namespaces, call initPersistFields() and consoleInit().
|
||||
|
|
|
|||
|
|
@ -230,6 +230,11 @@ bool expandOldScriptFilename(char *filename, U32 size, const char *src)
|
|||
else if (dStrncmp(src, "./", 2) == 0)
|
||||
// dot path means load from current codeblock/mod path
|
||||
slash = dStrrchr(cbName, '/');
|
||||
else if (dStrncmp(src, "^", 1) == 0)
|
||||
{
|
||||
Platform::makeFullPathName(src + 1, filename, size);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise path must be fully specified
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ public:
|
|||
Entry *next;
|
||||
ConsoleBaseType *type;
|
||||
};
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HashTableSize = 19
|
||||
};
|
||||
Entry *mHashTable[HashTableSize];
|
||||
|
||||
private:
|
||||
static Entry *smFreeList;
|
||||
|
||||
void freeEntry(Entry *entry);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
#include "core/frameAllocator.h"
|
||||
#include "core/stream/fileStream.h"
|
||||
#include "core/fileObject.h"
|
||||
|
||||
#include "persistence/taml/tamlCustom.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( SimObject );
|
||||
|
||||
|
|
@ -437,6 +437,97 @@ SimPersistID* SimObject::getOrCreatePersistentId()
|
|||
return mPersistentId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimObject::onTamlCustomRead(TamlCustomNodes const& customNodes)
|
||||
{
|
||||
// Debug Profiling.
|
||||
//PROFILE_SCOPE(SimObject_OnTamlCustomRead);
|
||||
|
||||
// Fetch field list.
|
||||
const AbstractClassRep::FieldList& fieldList = getFieldList();
|
||||
const U32 fieldCount = fieldList.size();
|
||||
for (U32 index = 0; index < fieldCount; ++index)
|
||||
{
|
||||
// Fetch field.
|
||||
const AbstractClassRep::Field* pField = &fieldList[index];
|
||||
|
||||
// Ignore if field not appropriate.
|
||||
if (pField->type == AbstractClassRep::StartArrayFieldType || pField->elementCount > 1)
|
||||
{
|
||||
// Find cell custom node.
|
||||
const TamlCustomNode* pCustomCellNodes = NULL;
|
||||
if (pField->pGroupname != NULL)
|
||||
pCustomCellNodes = customNodes.findNode(pField->pGroupname);
|
||||
if (!pCustomCellNodes)
|
||||
{
|
||||
char* niceFieldName = const_cast<char *>(pField->pFieldname);
|
||||
niceFieldName[0] = dToupper(niceFieldName[0]);
|
||||
String str_niceFieldName = String(niceFieldName);
|
||||
pCustomCellNodes = customNodes.findNode(str_niceFieldName + "s");
|
||||
}
|
||||
|
||||
// Continue if we have explicit cells.
|
||||
if (pCustomCellNodes != NULL)
|
||||
{
|
||||
// Fetch children cell nodes.
|
||||
const TamlCustomNodeVector& cellNodes = pCustomCellNodes->getChildren();
|
||||
|
||||
U8 idx = 0;
|
||||
// Iterate cells.
|
||||
for (TamlCustomNodeVector::const_iterator cellNodeItr = cellNodes.begin(); cellNodeItr != cellNodes.end(); ++cellNodeItr)
|
||||
{
|
||||
char buf[5];
|
||||
dSprintf(buf, 5, "%d", idx);
|
||||
|
||||
// Fetch cell node.
|
||||
TamlCustomNode* pCellNode = *cellNodeItr;
|
||||
|
||||
// Fetch node name.
|
||||
StringTableEntry nodeName = pCellNode->getNodeName();
|
||||
|
||||
// Is this a valid alias?
|
||||
if (nodeName != pField->pFieldname)
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("SimObject::onTamlCustomRead() - Encountered an unknown custom name of '%s'. Only '%s' is valid.", nodeName, pField->pFieldname);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch fields.
|
||||
const TamlCustomFieldVector& fields = pCellNode->getFields();
|
||||
|
||||
// Iterate property fields.
|
||||
for (TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr)
|
||||
{
|
||||
// Fetch field.
|
||||
const TamlCustomField* pField = *fieldItr;
|
||||
|
||||
// Fetch field name.
|
||||
StringTableEntry fieldName = pField->getFieldName();
|
||||
|
||||
const AbstractClassRep::Field* field = findField(fieldName);
|
||||
|
||||
// Check common fields.
|
||||
if (field)
|
||||
{
|
||||
setDataField(fieldName, buf, pField->getFieldValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown name so warn.
|
||||
Con::warnf("SimObject::onTamlCustomRead() - Encountered an unknown custom field name of '%s'.", fieldName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool SimObject::_setPersistentID( void* object, const char* index, const char* data )
|
||||
|
|
@ -925,6 +1016,220 @@ const char *SimObject::getDataField(StringTableEntry slotName, const char *array
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
const char *SimObject::getPrefixedDataField(StringTableEntry fieldName, const char *array)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(fieldName != NULL, "Cannot get field value with NULL field name.");
|
||||
|
||||
// Fetch field value.
|
||||
const char* pFieldValue = getDataField(fieldName, array);
|
||||
|
||||
// Sanity.
|
||||
//AssertFatal(pFieldValue != NULL, "Field value cannot be NULL.");
|
||||
if (!pFieldValue)
|
||||
return NULL;
|
||||
|
||||
// Return without the prefix if there's no value.
|
||||
if (*pFieldValue == 0)
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Fetch the field prefix.
|
||||
StringTableEntry fieldPrefix = getDataFieldPrefix(fieldName);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL.");
|
||||
|
||||
// Calculate a buffer size including prefix.
|
||||
const U32 valueBufferSize = dStrlen(fieldPrefix) + dStrlen(pFieldValue) + 1;
|
||||
|
||||
// Fetch a buffer.
|
||||
char* pValueBuffer = Con::getReturnBuffer(valueBufferSize);
|
||||
|
||||
// Format the value buffer.
|
||||
dSprintf(pValueBuffer, valueBufferSize, "%s%s", fieldPrefix, pFieldValue);
|
||||
|
||||
return pValueBuffer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SimObject::setPrefixedDataField(StringTableEntry fieldName, const char *array, const char *value)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(fieldName != NULL, "Cannot set object field value with NULL field name.");
|
||||
AssertFatal(value != NULL, "Field value cannot be NULL.");
|
||||
|
||||
// Set value without prefix if there's no value.
|
||||
if (*value == 0)
|
||||
{
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the field prefix.
|
||||
StringTableEntry fieldPrefix = getDataFieldPrefix(fieldName);
|
||||
|
||||
// Sanity.
|
||||
AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL.");
|
||||
|
||||
// Do we have a field prefix?
|
||||
if (fieldPrefix == StringTable->EmptyString())
|
||||
{
|
||||
// No, so set the data field in the usual way.
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Yes, so fetch the length of the field prefix.
|
||||
const U32 fieldPrefixLength = dStrlen(fieldPrefix);
|
||||
|
||||
// Yes, so does it start with the object field prefix?
|
||||
if (dStrnicmp(value, fieldPrefix, fieldPrefixLength) != 0)
|
||||
{
|
||||
// No, so set the data field in the usual way.
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Yes, so set the data excluding the prefix.
|
||||
setDataField(fieldName, NULL, value + fieldPrefixLength);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const char *SimObject::getPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const S32 fieldType)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(fieldName != NULL, "Cannot get field value with NULL field name.");
|
||||
|
||||
// Fetch field value.
|
||||
const char* pFieldValue = getDataField(fieldName, array);
|
||||
|
||||
// Sanity.
|
||||
AssertFatal(pFieldValue != NULL, "Field value cannot be NULL.");
|
||||
|
||||
// Return the field if no field type is specified.
|
||||
if (fieldType == -1)
|
||||
return pFieldValue;
|
||||
|
||||
// Return without the prefix if there's no value.
|
||||
if (*pFieldValue == 0)
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Fetch the console base type.
|
||||
ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType(fieldType);
|
||||
|
||||
// Did we find the console base type?
|
||||
if (pConsoleBaseType == NULL)
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("getPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.",
|
||||
fieldType, fieldName, pFieldValue);
|
||||
}
|
||||
|
||||
// Fetch the field prefix.
|
||||
StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix();
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL.");
|
||||
|
||||
// Calculate a buffer size including prefix.
|
||||
const U32 valueBufferSize = dStrlen(fieldPrefix) + dStrlen(pFieldValue) + 1;
|
||||
|
||||
// Fetch a buffer.
|
||||
char* pValueBuffer = Con::getReturnBuffer(valueBufferSize);
|
||||
|
||||
// Format the value buffer.
|
||||
dSprintf(pValueBuffer, valueBufferSize, "%s%s", fieldPrefix, pFieldValue);
|
||||
|
||||
return pValueBuffer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SimObject::setPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(fieldName != NULL, "Cannot set object field value with NULL field name.");
|
||||
AssertFatal(value != NULL, "Field value cannot be NULL.");
|
||||
|
||||
// Set value without prefix if no field type was specified.
|
||||
if (fieldType == -1)
|
||||
{
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the console base type.
|
||||
ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType(fieldType);
|
||||
|
||||
// Did we find the console base type?
|
||||
if (pConsoleBaseType == NULL)
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("setPrefixedDynamicDataField() - Invalid field type '%d' specified for field '%s' with value '%s'.",
|
||||
fieldType, fieldName, value);
|
||||
}
|
||||
|
||||
// Set value without prefix if there's no value or we didn't find the console base type.
|
||||
if (*value == 0 || pConsoleBaseType == NULL)
|
||||
{
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the field prefix.
|
||||
StringTableEntry fieldPrefix = pConsoleBaseType->getTypePrefix();
|
||||
|
||||
// Sanity.
|
||||
AssertFatal(fieldPrefix != NULL, "Field prefix cannot be NULL.");
|
||||
|
||||
// Do we have a field prefix?
|
||||
if (fieldPrefix == StringTable->EmptyString())
|
||||
{
|
||||
// No, so set the data field in the usual way.
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Yes, so fetch the length of the field prefix.
|
||||
const U32 fieldPrefixLength = dStrlen(fieldPrefix);
|
||||
|
||||
// Yes, so does it start with the object field prefix?
|
||||
if (dStrnicmp(value, fieldPrefix, fieldPrefixLength) != 0)
|
||||
{
|
||||
// No, so set the data field in the usual way.
|
||||
setDataField(fieldName, NULL, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Yes, so set the data excluding the prefix.
|
||||
setDataField(fieldName, NULL, value + fieldPrefixLength);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry SimObject::getDataFieldPrefix(StringTableEntry fieldName)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(fieldName != NULL, "Cannot get field prefix with NULL field name.");
|
||||
|
||||
// Find the field.
|
||||
const AbstractClassRep::Field* pField = findField(fieldName);
|
||||
|
||||
// Return nothing if field was not found.
|
||||
if (pField == NULL)
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Yes, so fetch the console base type.
|
||||
ConsoleBaseType* pConsoleBaseType = ConsoleBaseType::getType(pField->type);
|
||||
|
||||
// Fetch the type prefix.
|
||||
return pConsoleBaseType->getTypePrefix();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
U32 SimObject::getDataFieldType( StringTableEntry slotName, const char* array )
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@
|
|||
#include "core/bitSet.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TAML_CALLBACKS_H_
|
||||
#include "persistence/taml/tamlCallbacks.h"
|
||||
#endif
|
||||
|
||||
class Stream;
|
||||
class LightManager;
|
||||
|
|
@ -226,7 +229,7 @@ class SimPersistID;
|
|||
/// set automatically by the console constructor code.
|
||||
///
|
||||
/// @nosubgrouping
|
||||
class SimObject: public ConsoleObject
|
||||
class SimObject: public ConsoleObject, public TamlCallbacks
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
@ -298,6 +301,8 @@ class SimObject: public ConsoleObject
|
|||
/// Flags internal to the object management system.
|
||||
BitSet32 mFlags;
|
||||
|
||||
StringTableEntry mProgenitorFile;
|
||||
|
||||
/// Object we are copying fields from.
|
||||
SimObject* mCopySource;
|
||||
|
||||
|
|
@ -348,13 +353,42 @@ class SimObject: public ConsoleObject
|
|||
static bool setSuperClass(void *object, const char *index, const char *data)
|
||||
{ static_cast<SimObject*>(object)->setSuperClassNamespace(data); return false; };
|
||||
|
||||
static bool writeObjectName(void* obj, StringTableEntry pFieldName)
|
||||
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->objectName != NULL && simObject->objectName != StringTable->EmptyString(); }
|
||||
static bool writeCanSaveDynamicFields(void* obj, StringTableEntry pFieldName)
|
||||
{ return static_cast<SimObject*>(obj)->mCanSaveFieldDictionary == false; }
|
||||
static bool writeInternalName(void* obj, StringTableEntry pFieldName)
|
||||
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mInternalName != NULL && simObject->mInternalName != StringTable->EmptyString(); }
|
||||
static bool setParentGroup(void* obj, const char* data);
|
||||
static bool writeParentGroup(void* obj, StringTableEntry pFieldName)
|
||||
{ return static_cast<SimObject*>(obj)->mGroup != NULL; }
|
||||
static bool writeSuperclass(void* obj, StringTableEntry pFieldName)
|
||||
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mSuperClassName != NULL && simObject->mSuperClassName != StringTable->EmptyString(); }
|
||||
static bool writeClass(void* obj, StringTableEntry pFieldName)
|
||||
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mClassName != NULL && simObject->mClassName != StringTable->EmptyString(); }
|
||||
static bool writeClassName(void* obj, StringTableEntry pFieldName)
|
||||
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mClassName != NULL && simObject->mClassName != StringTable->EmptyString(); }
|
||||
|
||||
|
||||
// Group hierarchy protected set method
|
||||
static bool setProtectedParent(void *object, const char *index, const char *data);
|
||||
|
||||
// Object name protected set method
|
||||
static bool setProtectedName(void *object, const char *index, const char *data);
|
||||
|
||||
public:
|
||||
inline void setProgenitorFile(const char* pFile) { mProgenitorFile = StringTable->insert(pFile); }
|
||||
inline StringTableEntry getProgenitorFile(void) const { return mProgenitorFile; }
|
||||
|
||||
protected:
|
||||
/// Taml callbacks.
|
||||
virtual void onTamlPreWrite(void) {}
|
||||
virtual void onTamlPostWrite(void) {}
|
||||
virtual void onTamlPreRead(void) {}
|
||||
virtual void onTamlPostRead(const TamlCustomNodes& customNodes) {}
|
||||
virtual void onTamlAddParent(SimObject* pParentObject) {}
|
||||
virtual void onTamlCustomWrite(TamlCustomNodes& customNodes) {}
|
||||
virtual void onTamlCustomRead(const TamlCustomNodes& customNodes);
|
||||
|
||||
/// Id number for this object.
|
||||
SimObjectId mId;
|
||||
|
|
@ -461,6 +495,16 @@ class SimObject: public ConsoleObject
|
|||
/// @param value Value to store.
|
||||
void setDataField(StringTableEntry slotName, const char *array, const char *value);
|
||||
|
||||
const char *getPrefixedDataField(StringTableEntry fieldName, const char *array);
|
||||
|
||||
void setPrefixedDataField(StringTableEntry fieldName, const char *array, const char *value);
|
||||
|
||||
const char *getPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const S32 fieldType = -1);
|
||||
|
||||
void setPrefixedDynamicDataField(StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType = -1);
|
||||
|
||||
StringTableEntry getDataFieldPrefix(StringTableEntry fieldName);
|
||||
|
||||
/// Get the type of a field on the object.
|
||||
///
|
||||
/// @param slotName Field to access.
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include "core/util/tSignal.h"
|
||||
#endif
|
||||
|
||||
#include "persistence/taml/tamlChildren.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/// A set of SimObjects.
|
||||
|
|
@ -89,7 +90,7 @@
|
|||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
class SimSet: public SimObject
|
||||
class SimSet : public SimObject, public TamlChildren
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
@ -152,8 +153,10 @@ class SimSet: public SimObject
|
|||
iterator end() { return objectList.end(); }
|
||||
value operator[] (S32 index) { return objectList[U32(index)]; }
|
||||
|
||||
iterator find( iterator first, iterator last, SimObject *obj)
|
||||
inline iterator find( iterator first, iterator last, SimObject *obj)
|
||||
{ return ::find(first, last, obj); }
|
||||
inline iterator find(SimObject *obj)
|
||||
{ return ::find(begin(), end(), obj); }
|
||||
|
||||
/// Reorder the position of "obj" to either be the last object in the list or, if
|
||||
/// "target" is given, to come before "target" in the list of children.
|
||||
|
|
@ -222,7 +225,7 @@ class SimSet: public SimObject
|
|||
/// @note The child sets themselves count towards the total too.
|
||||
U32 sizeRecursive();
|
||||
|
||||
SimObject* findObjectByInternalName(StringTableEntry internalName, bool searchChildren = false);
|
||||
virtual SimObject* findObjectByInternalName(StringTableEntry internalName, bool searchChildren = false);
|
||||
SimObject* findObjectByLineNumber(const char* fileName, S32 declarationLine, bool searchChildren = false);
|
||||
|
||||
/// Find the given object in this set. Returns NULL if the object
|
||||
|
|
@ -277,6 +280,32 @@ class SimSet: public SimObject
|
|||
virtual bool readObject(Stream *stream);
|
||||
|
||||
virtual SimSet* clone();
|
||||
|
||||
// TamlChildren
|
||||
virtual U32 getTamlChildCount(void) const
|
||||
{
|
||||
return (U32)size();
|
||||
}
|
||||
|
||||
virtual SimObject* getTamlChild(const U32 childIndex) const
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(childIndex < (U32)size(), "SimSet::getTamlChild() - Child index is out of range.");
|
||||
|
||||
// For when the assert is not used.
|
||||
if (childIndex >= (U32)size())
|
||||
return NULL;
|
||||
|
||||
return at(childIndex);
|
||||
}
|
||||
|
||||
virtual void addTamlChild(SimObject* pSimObject)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pSimObject != NULL, "SimSet::addTamlChild() - Cannot add a NULL child object.");
|
||||
|
||||
addObject(pSimObject);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef TORQUE_DEBUG_GUARD
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue