Merge branch 'development' into EngineAPI-Refactor

This commit is contained in:
Areloch 2018-12-09 14:48:50 -06:00 committed by GitHub
commit 3a71c75596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1937 changed files with 102332 additions and 70549 deletions

View file

@ -52,7 +52,7 @@ enum TypeReq
/// each representing a different language construct.
struct StmtNode
{
StmtNode *next; ///< Next entry in parse tree.
StmtNode *mNext; ///< Next entry in parse tree.
StmtNode();
virtual ~StmtNode() {}
@ -62,7 +62,7 @@ struct StmtNode
///
void append(StmtNode *next);
StmtNode *getNext() const { return next; }
StmtNode *getNext() const { return mNext; }
/// @}

View file

@ -140,7 +140,7 @@ void StmtNode::addBreakLine(CodeStream &code)
StmtNode::StmtNode()
{
next = NULL;
mNext = NULL;
dbgFileName = CodeBlock::smCurrentParser->getCurrentFile();
}
@ -151,9 +151,9 @@ void StmtNode::setPackage(StringTableEntry)
void StmtNode::append(StmtNode *next)
{
StmtNode *walk = this;
while (walk->next)
walk = walk->next;
walk->next = next;
while (walk->mNext)
walk = walk->mNext;
walk->mNext = next;
}

View file

@ -392,14 +392,14 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st)
if (size)
{
globalFloats = new F64[size];
for (U32 i = 0; i < size; i++)
for (i = 0; i < size; i++)
st.read(&globalFloats[i]);
}
st.read(&size);
if (size)
{
functionFloats = new F64[size];
for (U32 i = 0; i < size; i++)
for (i = 0; i < size; i++)
st.read(&functionFloats[i]);
}
U32 codeLength;
@ -698,10 +698,10 @@ String CodeBlock::getFunctionArgs(U32 ip)
{
StringBuilder str;
U32 fnArgc = code[ip + 5];
U32 fnArgc = code[ip + 8];
for (U32 i = 0; i < fnArgc; ++i)
{
StringTableEntry var = CodeToSTE(code, ip + (i * 2) + 6);
StringTableEntry var = CodeToSTE(code, ip + (i * 2) + 9);
if (i != 0)
str.append(", ");

View file

@ -400,11 +400,11 @@ ConsoleValueRef CodeInterpreter::exec(U32 ip,
breakContinueLabel:
OPCodeReturn ret = (this->*gOpCodeArray[mCurrentInstruction])(ip);
if (ret == OPCodeReturn::exitCode)
goto exitLabel;
break;
else if (ret == OPCodeReturn::breakContinue)
goto breakContinueLabel;
}
exitLabel:
if (telDebuggerOn && setFrame < 0)
TelDebugger->popStackFrame();
@ -426,12 +426,12 @@ exitLabel:
}
if (thisNamespace && thisNamespace->mName)
{
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), sizeof(sTraceBuffer) - dStrlen(sTraceBuffer),
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), (U32)(sizeof(sTraceBuffer) - dStrlen(sTraceBuffer)),
"%s::%s() - return %s", thisNamespace->mName, mThisFunctionName, STR.getStringValue());
}
else
{
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), sizeof(sTraceBuffer) - dStrlen(sTraceBuffer),
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), (U32)(sizeof(sTraceBuffer) - dStrlen(sTraceBuffer)),
"%s() - return %s", mThisFunctionName, STR.getStringValue());
}
Con::printf("%s", sTraceBuffer);
@ -477,12 +477,12 @@ void CodeInterpreter::parseArgs(U32 &ip)
}
if (mExec.thisNamespace && mExec.thisNamespace->mName)
{
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), sizeof(sTraceBuffer) - dStrlen(sTraceBuffer),
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), (U32)(sizeof(sTraceBuffer) - dStrlen(sTraceBuffer)),
"%s::%s(", mExec.thisNamespace->mName, mThisFunctionName);
}
else
{
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), sizeof(sTraceBuffer) - dStrlen(sTraceBuffer),
dSprintf(sTraceBuffer + dStrlen(sTraceBuffer), (U32)(sizeof(sTraceBuffer) - dStrlen(sTraceBuffer)),
"%s(", mThisFunctionName);
}
for (S32 i = 0; i < wantedArgc; i++)
@ -2132,12 +2132,27 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
{
if (!mExec.noCalls && !(routingId == MethodOnComponent))
{
Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName);
if (callType == FuncCallExprNode::MethodCall)
{
Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "",
gEvalState.thisObject->getId(), Con::getNamespaceList(ns));
if (gEvalState.thisObject != NULL)
{
// Try to use the name instead of the id
StringTableEntry name = gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : gEvalState.thisObject->getIdString();
Con::warnf(ConsoleLogEntry::General, "%s: Unknown method %s.%s Namespace List: %s", mCodeBlock->getFileLine(ip - 6), name, fnName, Con::getNamespaceList(ns));
}
else
{
// NULL.
Con::warnf(ConsoleLogEntry::General, "%s: Unknown method NULL.%s", mCodeBlock->getFileLine(ip - 6), fnName);
}
}
else if (callType == FuncCallExprNode::ParentCall)
{
Con::warnf(ConsoleLogEntry::General, "%s: Unknown parent call %s.", mCodeBlock->getFileLine(ip - 6), fnName);
}
else
{
Con::warnf(ConsoleLogEntry::General, "%s: Unknown function %s.", mCodeBlock->getFileLine(ip - 6), fnName);
}
}
STR.popFrame();
@ -2328,7 +2343,7 @@ OPCodeReturn CodeInterpreter::op_callfunc_pointer(U32 &ip)
{
if (!mExec.noCalls)
{
Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName);
Con::warnf(ConsoleLogEntry::General, "%s: Unknown function %s.", mCodeBlock->getFileLine(ip - 6), fnName);
}
STR.popFrame();
CSTK.popFrame();
@ -2373,9 +2388,6 @@ OPCodeReturn CodeInterpreter::op_callfunc_pointer(U32 &ip)
{
const char* nsName = "";
Namespace::Entry::CallbackUnion * nsCb = &mNSEntry->cb;
const char * nsUsage = mNSEntry->mUsage;
#ifndef TORQUE_DEBUG
// [tom, 12/13/2006] This stops tools functions from working in the console,
// which is useful behavior when debugging so I'm ifdefing this out for debug builds.
@ -2511,7 +2523,7 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip)
ip += 2;
CSTK.getArgcArgv(fnName, &mCallArgc, &mCallArgv);
Namespace *ns = mThisObject->getNamespace();
Namespace *ns = mThisObject ? mThisObject->getNamespace() : NULL;
if (ns)
mNSEntry = ns->lookup(fnName);
else
@ -2521,10 +2533,17 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip)
{
if (!mExec.noCalls)
{
Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName);
Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
mThisObject->getName() ? mThisObject->getName() : "",
mThisObject->getId(), Con::getNamespaceList(ns));
if (mThisObject)
{
// Try to use the name instead of the id
StringTableEntry name = mThisObject->getName() ? mThisObject->getName() : mThisObject->getIdString();
Con::warnf(ConsoleLogEntry::General, "%s: Unknown method %s.%s Namespace List: %s", mCodeBlock->getFileLine(ip - 6), name, fnName, Con::getNamespaceList(ns));
}
else
{
// At least let the scripter know that they access the object.
Con::warnf(ConsoleLogEntry::General, "%s: Unknown method NULL.%s", mCodeBlock->getFileLine(ip - 6), fnName);
}
}
STR.popFrame();
CSTK.popFrame();
@ -2567,8 +2586,6 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip)
}
else
{
Namespace::Entry::CallbackUnion * nsCb = &mNSEntry->cb;
const char * nsUsage = mNSEntry->mUsage;
const char* nsName = ns ? ns->mName : "";
#ifndef TORQUE_DEBUG
// [tom, 12/13/2006] This stops tools functions from working in the console,

View file

@ -41,6 +41,7 @@
#include "core/frameAllocator.h"
#include "console/codeInterpreter.h"
#include "console/returnBuffer.h"
#ifndef TORQUE_TGB_ONLY
#include "materials/materialDefinition.h"
@ -101,17 +102,17 @@ F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
namespace Con
{
ReturnBuffer retBuffer;
char *getReturnBuffer(U32 bufferSize)
{
return STR.getReturnBuffer(bufferSize);
return retBuffer.getBuffer(bufferSize);
}
char *getReturnBuffer(const char *stringToCopy)
{
U32 len = dStrlen(stringToCopy) + 1;
char *ret = STR.getReturnBuffer(len);
char *ret = retBuffer.getBuffer(len);
dMemcpy(ret, stringToCopy, len);
return ret;
}
@ -119,7 +120,7 @@ namespace Con
char* getReturnBuffer(const String& str)
{
const U32 size = str.size();
char* ret = STR.getReturnBuffer(size);
char* ret = retBuffer.getBuffer(size);
dMemcpy(ret, str.c_str(), size);
return ret;
}

View file

@ -49,7 +49,7 @@ ExprEvalState gEvalState;
StmtNode *gStatementList;
StmtNode *gAnonFunctionList;
U32 gAnonFunctionID = 0;
ConsoleConstructor *ConsoleConstructor::first = NULL;
ConsoleConstructor *ConsoleConstructor::mFirst = NULL;
bool gWarnUndefinedScriptVariables;
static char scratchBuffer[4096];
@ -85,47 +85,47 @@ static const char * prependPercent ( const char * name )
//--------------------------------------
void ConsoleConstructor::init( const char *cName, const char *fName, const char *usg, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
mina = minArgs;
maxa = maxArgs;
funcName = fName;
usage = usg;
className = cName;
sc = 0; fc = 0; vc = 0; bc = 0; ic = 0;
callback = group = false;
next = first;
ns = false;
first = this;
toolOnly = isToolOnly;
this->header = header;
mMina = minArgs;
mMaxa = maxArgs;
mFuncName = fName;
mUsage = usg;
mClassName = cName;
mSC = 0; mFC = 0; mVC = 0; mBC = 0; mIC = 0;
mCallback = mGroup = false;
mNext = mFirst;
mNS = false;
mFirst = this;
mToolOnly = isToolOnly;
mHeader = header;
}
void ConsoleConstructor::setup()
{
for(ConsoleConstructor *walk = first; walk; walk = walk->next)
for(ConsoleConstructor *walk = mFirst; walk; walk = walk->mNext)
{
#ifdef TORQUE_DEBUG
walk->validate();
#endif
if( walk->sc )
Con::addCommand( walk->className, walk->funcName, walk->sc, walk->usage, walk->mina, walk->maxa, walk->toolOnly, walk->header );
else if( walk->ic )
Con::addCommand( walk->className, walk->funcName, walk->ic, walk->usage, walk->mina, walk->maxa, walk->toolOnly, walk->header );
else if( walk->fc )
Con::addCommand( walk->className, walk->funcName, walk->fc, walk->usage, walk->mina, walk->maxa, walk->toolOnly, walk->header );
else if( walk->vc )
Con::addCommand( walk->className, walk->funcName, walk->vc, walk->usage, walk->mina, walk->maxa, walk->toolOnly, walk->header );
else if( walk->bc )
Con::addCommand( walk->className, walk->funcName, walk->bc, walk->usage, walk->mina, walk->maxa, walk->toolOnly, walk->header );
else if( walk->group )
Con::markCommandGroup( walk->className, walk->funcName, walk->usage );
else if( walk->callback )
Con::noteScriptCallback( walk->className, walk->funcName, walk->usage, walk->header );
else if( walk->ns )
if( walk->mSC )
Con::addCommand( walk->mClassName, walk->mFuncName, walk->mSC, walk->mUsage, walk->mMina, walk->mMaxa, walk->mToolOnly, walk->mHeader);
else if( walk->mIC )
Con::addCommand( walk->mClassName, walk->mFuncName, walk->mIC, walk->mUsage, walk->mMina, walk->mMaxa, walk->mToolOnly, walk->mHeader);
else if( walk->mFC )
Con::addCommand( walk->mClassName, walk->mFuncName, walk->mFC, walk->mUsage, walk->mMina, walk->mMaxa, walk->mToolOnly, walk->mHeader);
else if( walk->mVC )
Con::addCommand( walk->mClassName, walk->mFuncName, walk->mVC, walk->mUsage, walk->mMina, walk->mMaxa, walk->mToolOnly, walk->mHeader);
else if( walk->mBC )
Con::addCommand( walk->mClassName, walk->mFuncName, walk->mBC, walk->mUsage, walk->mMina, walk->mMaxa, walk->mToolOnly, walk->mHeader);
else if( walk->mGroup )
Con::markCommandGroup( walk->mClassName, walk->mFuncName, walk->mUsage);
else if( walk->mClassName)
Con::noteScriptCallback( walk->mClassName, walk->mFuncName, walk->mUsage, walk->mHeader);
else if( walk->mNS )
{
Namespace* ns = Namespace::find( StringTable->insert( walk->className ) );
Namespace* ns = Namespace::find( StringTable->insert( walk->mClassName) );
if( ns )
ns->mUsage = walk->usage;
ns->mUsage = walk->mUsage;
}
else
{
@ -137,38 +137,38 @@ void ConsoleConstructor::setup()
ConsoleConstructor::ConsoleConstructor(const char *className, const char *funcName, StringCallback sfunc, const char *usage, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
init( className, funcName, usage, minArgs, maxArgs, isToolOnly, header );
sc = sfunc;
mSC = sfunc;
}
ConsoleConstructor::ConsoleConstructor(const char *className, const char *funcName, IntCallback ifunc, const char *usage, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
init( className, funcName, usage, minArgs, maxArgs, isToolOnly, header );
ic = ifunc;
mIC = ifunc;
}
ConsoleConstructor::ConsoleConstructor(const char *className, const char *funcName, FloatCallback ffunc, const char *usage, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
init( className, funcName, usage, minArgs, maxArgs, isToolOnly, header );
fc = ffunc;
mFC = ffunc;
}
ConsoleConstructor::ConsoleConstructor(const char *className, const char *funcName, VoidCallback vfunc, const char *usage, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
init( className, funcName, usage, minArgs, maxArgs, isToolOnly, header );
vc = vfunc;
mVC = vfunc;
}
ConsoleConstructor::ConsoleConstructor(const char *className, const char *funcName, BoolCallback bfunc, const char *usage, S32 minArgs, S32 maxArgs, bool isToolOnly, ConsoleFunctionHeader* header )
{
init( className, funcName, usage, minArgs, maxArgs, isToolOnly, header );
bc = bfunc;
mBC = bfunc;
}
ConsoleConstructor::ConsoleConstructor(const char* className, const char* groupName, const char* aUsage)
{
init(className, groupName, usage, -1, -2);
init(className, groupName, mUsage, -1, -2);
group = true;
mGroup = true;
// Somewhere, the entry list is getting flipped, partially.
// so we have to do tricks to deal with making sure usage
@ -179,36 +179,36 @@ ConsoleConstructor::ConsoleConstructor(const char* className, const char* groupN
if(aUsage)
lastUsage = (char *)aUsage;
usage = lastUsage;
mUsage = lastUsage;
}
ConsoleConstructor::ConsoleConstructor(const char *className, const char *callbackName, const char *usage, ConsoleFunctionHeader* header )
{
init( className, callbackName, usage, -2, -3, false, header );
callback = true;
ns = true;
mCallback = true;
mNS = true;
}
void ConsoleConstructor::validate()
{
#ifdef TORQUE_DEBUG
// Don't do the following check if we're not a method/func.
if(this->group)
if(mGroup)
return;
// In debug, walk the list and make sure this isn't a duplicate.
for(ConsoleConstructor *walk = first; walk; walk = walk->next)
for(ConsoleConstructor *walk = mFirst; walk; walk = walk->mNext)
{
// Skip mismatching func/method names.
if(dStricmp(walk->funcName, this->funcName))
if(dStricmp(walk->mFuncName, mFuncName))
continue;
// Don't compare functions with methods or vice versa.
if(bool(this->className) != bool(walk->className))
if(bool(mClassName) != bool(walk->mClassName))
continue;
// Skip mismatching classnames, if they're present.
if(this->className && walk->className && dStricmp(walk->className, this->className))
if(mClassName && walk->mClassName && dStricmp(walk->mClassName, mClassName))
continue;
// If we encounter ourselves, stop searching; this prevents duplicate
@ -218,13 +218,13 @@ void ConsoleConstructor::validate()
break;
// Match!
if(this->className)
if(mClassName)
{
AssertISV(false, avar("ConsoleConstructor::setup - ConsoleMethod '%s::%s' collides with another of the same name.", this->className, this->funcName));
AssertISV(false, avar("ConsoleConstructor::setup - ConsoleMethod '%s::%s' collides with another of the same name.", mClassName, mFuncName));
}
else
{
AssertISV(false, avar("ConsoleConstructor::setup - ConsoleFunction '%s' collides with another of the same name.", this->funcName));
AssertISV(false, avar("ConsoleConstructor::setup - ConsoleFunction '%s' collides with another of the same name.", mFuncName));
}
}
#endif
@ -842,9 +842,9 @@ void setIntVariable(const char *varName, S32 value)
if (getVariableObjectField(varName, &obj, &objField))
{
char scratchBuffer[32];
dSprintf(scratchBuffer, sizeof(scratchBuffer), "%d", value);
obj->setDataField(StringTable->insert(objField), 0, scratchBuffer);
char varBuffer[32];
dSprintf(varBuffer, sizeof(varBuffer), "%d", value);
obj->setDataField(StringTable->insert(objField), 0, varBuffer);
}
else
{
@ -861,9 +861,9 @@ void setFloatVariable(const char *varName, F32 value)
if (getVariableObjectField(varName, &obj, &objField))
{
char scratchBuffer[32];
dSprintf(scratchBuffer, sizeof(scratchBuffer), "%g", value);
obj->setDataField(StringTable->insert(objField), 0, scratchBuffer);
char varBuffer[32];
dSprintf(varBuffer, sizeof(varBuffer), "%g", value);
obj->setDataField(StringTable->insert(objField), 0, varBuffer);
}
else
{

View file

@ -972,38 +972,38 @@ public:
/// @ref console_autodoc
/// @{
StringCallback sc; ///< A function/method that returns a string.
IntCallback ic; ///< A function/method that returns an int.
FloatCallback fc; ///< A function/method that returns a float.
VoidCallback vc; ///< A function/method that returns nothing.
BoolCallback bc; ///< A function/method that returns a bool.
bool group; ///< Indicates that this is a group marker.
bool ns; ///< Indicates that this is a namespace marker.
StringCallback mSC; ///< A function/method that returns a string.
IntCallback mIC; ///< A function/method that returns an int.
FloatCallback mFC; ///< A function/method that returns a float.
VoidCallback mVC; ///< A function/method that returns nothing.
BoolCallback mBC; ///< A function/method that returns a bool.
bool mGroup; ///< Indicates that this is a group marker.
bool mNS; ///< Indicates that this is a namespace marker.
/// @deprecated Unused.
bool callback; ///< Is this a callback into script?
bool mCallback; ///< Is this a callback into script?
/// @}
/// Minimum number of arguments expected by the function.
S32 mina;
S32 mMina;
/// Maximum number of arguments accepted by the funtion. Zero for varargs.
S32 maxa;
S32 mMaxa;
/// Name of the function/method.
const char* funcName;
const char* mFuncName;
/// Name of the class namespace to which to add the method.
const char* className;
const char* mClassName;
/// Usage string for documentation.
const char* usage;
const char* mUsage;
/// Whether this is a TORQUE_TOOLS only function.
bool toolOnly;
bool mToolOnly;
/// The extended function header.
ConsoleFunctionHeader* header;
ConsoleFunctionHeader* mHeader;
/// @name ConsoleConstructor Innards
///
@ -1066,8 +1066,8 @@ public:
/// @{
///
ConsoleConstructor *next;
static ConsoleConstructor *first;
ConsoleConstructor *mNext;
static ConsoleConstructor *mFirst;
void init(const char* cName, const char* fName, const char *usg, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);

View file

@ -88,7 +88,7 @@ void printClassHeader(const char* usage, const char * className, const char * su
if((usage != NULL) && strlen(usage))
{
// Copy Usage Document
S32 usageLen = dStrlen( usage );
S32 usageLen = dStrlen( usage ) + 1;
FrameTemp<char> usageStr( usageLen );
dStrcpy( usageStr, usage, usageLen );

View file

@ -672,13 +672,13 @@ DefineEngineFunction( strreplace, const char*, ( const char* source, const char*
U32 dstp = 0;
for(;;)
{
const char *scan = dStrstr(source + scanp, from);
if(!scan)
const char *subScan = dStrstr(source + scanp, from);
if(!subScan)
{
dStrcpy(ret + dstp, source + scanp, retLen - dstp);
return ret;
}
U32 len = scan - (source + scanp);
U32 len = subScan - (source + scanp);
dStrncpy(ret + dstp, source + scanp, getMin(len, retLen - dstp));
dstp += len;
dStrcpy(ret + dstp, to, retLen - dstp);

View file

@ -48,13 +48,6 @@ template<typename T> inline const T nullAsType(){ return nullptr; }
/// @ingroup console_system Console System
/// @{
#if _MSC_VER >= 1911
#ifdef offsetof
#undef offsetof
#endif // offsetof
#define offsetof(s,m) ((size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))
#endif
#ifndef Offset
#define Offset(x, cls) offsetof(cls, x)
#endif

View file

@ -248,13 +248,13 @@ static void dumpFunction( Stream &stream,
const char* brief = dStrstr( doc, "@brief" );
if( !brief )
{
String brief = entry->getBriefDescription( &doc );
String briefStr = entry->getBriefDescription( &doc );
brief.trim();
if( !brief.isEmpty() )
briefStr.trim();
if( !briefStr.isEmpty() )
{
stream.writeText( "@brief " );
stream.writeText( brief );
stream.writeText(briefStr);
stream.writeText( "\r\n\r\n" );
}
}

View file

@ -449,10 +449,10 @@ void FieldBrushObject::copyFields( SimObject* pSimObject, const char* fieldList
// Yes, so is this field name selected?
// Iterate fields...
for ( U32 fieldIndex = 0; fieldIndex < fields.size(); ++fieldIndex )
for ( U32 findFieldIDx = 0; findFieldIDx < fields.size(); ++findFieldIDx)
{
// Field selected?
if ( staticField.pFieldname == fields[fieldIndex] )
if ( staticField.pFieldname == fields[findFieldIDx] )
{
// Yes, so flag as such.
fieldSpecified = true;

View file

@ -0,0 +1,83 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "returnBuffer.h"
ReturnBuffer::ReturnBuffer()
{
mBuffer = nullptr;
mBufferSize = 0;
mStart = 0;
//Decent starting alloc of ~1 page = 4kb
ensureSize(4 * 1024);
}
ReturnBuffer::~ReturnBuffer()
{
if (mBuffer)
{
dFree(mBuffer);
}
}
void ReturnBuffer::ensureSize(U32 newSize)
{
//Round up to nearest multiple of 16 bytes
if (newSize & 0xF)
{
newSize = (newSize & ~0xF) + 0x10;
}
if (mBuffer == NULL)
{
//First alloc
mBuffer = (char *)dMalloc(newSize * sizeof(char));
mBufferSize = newSize;
}
else if (mBufferSize < newSize)
{
//Just use the expected size
mBuffer = (char *)dRealloc(mBuffer, newSize * sizeof(char));
mBufferSize = newSize;
}
}
char *ReturnBuffer::getBuffer(U32 size, U32 alignment)
{
ensureSize(size);
//Align the start if necessary
if (mStart % alignment != 0)
{
mStart += alignment - (mStart % alignment);
}
if (size + mStart > mBufferSize)
{
//Restart
mStart = 0;
}
char *buffer = mBuffer + mStart;
mStart += size;
return buffer;
}

View file

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _RETURNBUFFER_H_
#define _RETURNBUFFER_H_
#ifndef _PLATFORM_H_
#include <platform/platform.h>
#endif
/// Simple circular buffer class for temporary return storage.
class ReturnBuffer
{
char *mBuffer;
U32 mBufferSize;
U32 mStart;
/// Possibly expand the buffer to be larger than newSize
void ensureSize(U32 newSize);
public:
ReturnBuffer();
~ReturnBuffer();
/// Get a temporary buffer with a given size (and alignment)
/// @note The buffer will be re-used so do not consider it permanent
char *getBuffer(U32 size, U32 alignment = 16);
};
#endif //_RETURNBUFFER_H_

View file

@ -62,20 +62,20 @@ SimDataBlock::SimDataBlock()
SimDataBlock::SubstitutionStatement::SubstitutionStatement(StringTableEntry slot, S32 idx, const char* value)
{
this->slot = slot;
this->idx = idx;
this->value = dStrdup(value);
this->mSlot = slot;
this->mIdx = idx;
this->mValue = dStrdup(value);
}
SimDataBlock::SubstitutionStatement::~SubstitutionStatement()
{
dFree(value);
dFree(mValue);
}
void SimDataBlock::SubstitutionStatement::replaceValue(const char* value)
{
dFree(this->value);
this->value = dStrdup(value);
dFree(this->mValue);
this->mValue = dStrdup(value);
}
// this is the copy-constructor for creating temp-clones.
@ -109,7 +109,7 @@ void SimDataBlock::addSubstitution(StringTableEntry slot, S32 idx, const char* s
for (S32 i = 0; i < substitutions.size(); i++)
{
if (substitutions[i] && substitutions[i]->slot == slot && substitutions[i]->idx == idx)
if (substitutions[i] && substitutions[i]->mSlot == slot && substitutions[i]->mIdx == idx)
{
if (empty_subs)
{
@ -137,8 +137,8 @@ const char* SimDataBlock::getSubstitution(StringTableEntry slot, S32 idx)
{
for (S32 i = 0; i < substitutions.size(); i++)
{
if (substitutions[i] && substitutions[i]->slot == slot && substitutions[i]->idx == idx)
return substitutions[i]->value;
if (substitutions[i] && substitutions[i]->mSlot == slot && substitutions[i]->mIdx == idx)
return substitutions[i]->mValue;
}
return 0;
@ -147,7 +147,7 @@ const char* SimDataBlock::getSubstitution(StringTableEntry slot, S32 idx)
bool SimDataBlock::fieldHasSubstitution(StringTableEntry slot)
{
for (S32 i = 0; i < substitutions.size(); i++)
if (substitutions[i] && substitutions[i]->slot == slot)
if (substitutions[i] && substitutions[i]->mSlot == slot)
return true;
return false;
}
@ -156,7 +156,7 @@ void SimDataBlock::printSubstitutions()
{
for (S32 i = 0; i < substitutions.size(); i++)
if (substitutions[i])
Con::errorf("SubstitutionStatement[%s] = \"%s\" -- %d", substitutions[i]->slot, substitutions[i]->value, i);
Con::errorf("SubstitutionStatement[%s] = \"%s\" -- %d", substitutions[i]->mSlot, substitutions[i]->mValue, i);
}
void SimDataBlock::copySubstitutionsFrom(SimDataBlock* other)
@ -170,7 +170,7 @@ void SimDataBlock::copySubstitutionsFrom(SimDataBlock* other)
if (other->substitutions[i])
{
SubstitutionStatement* subs = other->substitutions[i];
substitutions.push_back(new SubstitutionStatement(subs->slot, subs->idx, subs->value));
substitutions.push_back(new SubstitutionStatement(subs->mSlot, subs->mIdx, subs->mValue));
}
}
}
@ -212,7 +212,7 @@ void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* o
char* b = buffer;
// perform special token expansion (%% and ##)
const char* v = substitutions[i]->value;
const char* v = substitutions[i]->mValue;
while (*v != '\0')
{
// identify "%%" tokens and replace with <obj> id
@ -258,7 +258,7 @@ void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* o
if (Compiler::gSyntaxError)
{
Con::errorf("Field Substitution Failed: field=\"%s\" substitution=\"%s\" -- syntax error",
substitutions[i]->slot, substitutions[i]->value);
substitutions[i]->mSlot, substitutions[i]->mValue);
Compiler::gSyntaxError = false;
return;
}
@ -267,7 +267,7 @@ void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* o
if (result == 0 || result[0] == '\0')
{
Con::errorf("Field Substitution Failed: field=\"%s\" substitution=\"%s\" -- empty result",
substitutions[i]->slot, substitutions[i]->value);
substitutions[i]->mSlot, substitutions[i]->mValue);
return;
}
@ -282,29 +282,29 @@ void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* o
result = "";
}
const AbstractClassRep::Field* field = dblock->getClassRep()->findField(substitutions[i]->slot);
const AbstractClassRep::Field* field = dblock->getClassRep()->findField(substitutions[i]->mSlot);
if (!field)
{
// this should be very unlikely...
Con::errorf("Field Substitution Failed: unknown field, \"%s\".", substitutions[i]->slot);
Con::errorf("Field Substitution Failed: unknown field, \"%s\".", substitutions[i]->mSlot);
continue;
}
if (field->keepClearSubsOnly && result[0] != '\0')
{
Con::errorf("Field Substitution Failed: field \"%s\" of datablock %s only allows \"$$ ~~\" (keep) and \"$$ ~0\" (clear) field substitutions. [%s]",
substitutions[i]->slot, this->getClassName(), this->getName());
substitutions[i]->mSlot, this->getClassName(), this->getName());
continue;
}
// substitute the field value with its replacement
Con::setData(field->type, (void*)(((const char*)(dblock)) + field->offset), substitutions[i]->idx, 1, &result, field->table, field->flag);
Con::setData(field->type, (void*)(((const char*)(dblock)) + field->offset), substitutions[i]->mIdx, 1, &result, field->table, field->flag);
//dStrncpy(buffer, result, 255);
//Con::errorf("SUBSTITUTION %s.%s[%d] = %s idx=%s", Con::getIntArg(getId()), substitutions[i]->slot, substitutions[i]->idx, buffer, index_str);
// notify subclasses of a field modification
dblock->onStaticModified(substitutions[i]->slot);
dblock->onStaticModified(substitutions[i]->mSlot);
}
}
@ -366,9 +366,9 @@ void SimDataBlock::packData(BitStream* stream)
if (substitutions[i])
{
stream->writeFlag(true);
stream->writeString(substitutions[i]->slot);
stream->write(substitutions[i]->idx);
stream->writeString(substitutions[i]->value);
stream->writeString(substitutions[i]->mSlot);
stream->write(substitutions[i]->mIdx);
stream->writeString(substitutions[i]->mValue);
}
}
stream->writeFlag(false);

View file

@ -179,9 +179,9 @@ public:
protected:
struct SubstitutionStatement
{
StringTableEntry slot;
S32 idx;
char* value;
StringTableEntry mSlot;
S32 mIdx;
char* mValue;
SubstitutionStatement(StringTableEntry slot, S32 idx, const char* value);
~SubstitutionStatement();
void replaceValue(const char* value);

View file

@ -45,13 +45,13 @@ SimNameDictionary::~SimNameDictionary()
void SimNameDictionary::insert(SimObject* obj)
{
if (!obj || !obj->objectName)
if (!obj || !obj->getName())
return;
SimObject* checkForDup = find(obj->objectName);
SimObject* checkForDup = find(obj->getName());
if (checkForDup)
Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->objectName);
Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->getName());
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
@ -64,7 +64,7 @@ void SimNameDictionary::insert(SimObject* obj)
dMemset(hashTable, 0, sizeof(*hashTable) * DefaultTableSize);
}
S32 idx = HashPointer(obj->objectName) % hashTableSize;
S32 idx = HashPointer(obj->getName()) % hashTableSize;
obj->nextNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
@ -86,7 +86,7 @@ void SimNameDictionary::insert(SimObject* obj)
{
SimObject* next = object->nextNameObject;
idx = HashPointer(object->objectName) % newHashTableSize;
idx = HashPointer(object->getName()) % newHashTableSize;
object->nextNameObject = newHashTable[idx];
newHashTable[idx] = object;
@ -118,7 +118,7 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
SimObject *walk = hashTable[idx];
while (walk)
{
if (walk->objectName == name)
if (walk->getName() == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -139,12 +139,12 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
void SimNameDictionary::remove(SimObject* obj)
{
if (!obj || !obj->objectName)
if (!obj || !obj->getName())
return;
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
SimObject **walk = &hashTable[HashPointer(obj->getName()) % hashTableSize];
while (*walk)
{
if (*walk == obj)
@ -190,12 +190,12 @@ SimManagerNameDictionary::~SimManagerNameDictionary()
void SimManagerNameDictionary::insert(SimObject* obj)
{
if (!obj || !obj->objectName)
if (!obj || !obj->getName())
return;
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = HashPointer(obj->objectName) % hashTableSize;
S32 idx = HashPointer(obj->getName()) % hashTableSize;
obj->nextManagerNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
@ -217,7 +217,7 @@ void SimManagerNameDictionary::insert(SimObject* obj)
{
SimObject* next = object->nextManagerNameObject;
idx = HashPointer(object->objectName) % newHashTableSize;
idx = HashPointer(object->getName()) % newHashTableSize;
object->nextManagerNameObject = newHashTable[idx];
newHashTable[idx] = object;
@ -247,7 +247,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
SimObject *walk = hashTable[idx];
while (walk)
{
if (walk->objectName == name)
if (walk->getName() == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -267,13 +267,13 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
void SimManagerNameDictionary::remove(SimObject* obj)
{
if (!obj || !obj->objectName)
if (!obj || !obj->getName())
return;
#ifndef USE_NEW_SIMDICTIONARY
Mutex::lockMutex(mutex);
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
SimObject **walk = &hashTable[HashPointer(obj->getName()) % hashTableSize];
while (*walk)
{
if (*walk == obj)

View file

@ -245,17 +245,17 @@ void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop
const AbstractClassRep::FieldList &list = obj->getFieldList();
Vector<Entry *> flist(__FILE__, __LINE__);
for (U32 i = 0; i < HashTableSize; i++)
for (U32 curEntry = 0; curEntry < HashTableSize; curEntry++)
{
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
for (Entry *walk = mHashTable[curEntry]; walk; walk = walk->next)
{
// make sure we haven't written this out yet:
U32 i;
for (i = 0; i < list.size(); i++)
if (list[i].pFieldname == walk->slotName)
U32 curField;
for (curField = 0; curField < list.size(); curField++)
if (list[curField].pFieldname == walk->slotName)
break;
if (i != list.size())
if (curField != list.size())
continue;
@ -293,17 +293,17 @@ void SimFieldDictionary::printFields(SimObject *obj)
char expandedBuffer[4096];
Vector<Entry *> flist(__FILE__, __LINE__);
for (U32 i = 0; i < HashTableSize; i++)
for (U32 curEntry = 0; curEntry < HashTableSize; curEntry++)
{
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
for (Entry *walk = mHashTable[curEntry]; walk; walk = walk->next)
{
// make sure we haven't written this out yet:
U32 i;
for (i = 0; i < list.size(); i++)
if (list[i].pFieldname == walk->slotName)
U32 curField;
for (curField = 0; curField < list.size(); curField++)
if (list[curField].pFieldname == walk->slotName)
break;
if (i != list.size())
if (curField != list.size())
continue;
flist.push_back(walk);

View file

@ -612,6 +612,6 @@ void SimDataBlockGroup::sort()
if(mLastModifiedKey != SimDataBlock::getNextModifiedKey())
{
mLastModifiedKey = SimDataBlock::getNextModifiedKey();
dQsort(objectList.address(),objectList.size(),sizeof(SimObject *),compareModifiedKey);
dQsort(mObjectList.address(), mObjectList.size(),sizeof(SimObject *),compareModifiedKey);
}
}

View file

@ -71,7 +71,7 @@ namespace Sim
SimObject::SimObject()
{
objectName = NULL;
mObjectName = NULL;
mOriginalName = NULL;
mInternalName = NULL;
nextNameObject = nullptr;
@ -128,10 +128,10 @@ SimObject::~SimObject()
AssertFatal(nextNameObject == nullptr,avar(
"SimObject::~SimObject: Not removed from dictionary: name %s, id %i",
objectName, mId));
mObjectName, mId));
AssertFatal(nextManagerNameObject == nullptr,avar(
"SimObject::~SimObject: Not removed from manager dictionary: name %s, id %i",
objectName,mId));
mObjectName,mId));
AssertFatal(mFlags.test(Added) == 0, "SimObject::object "
"missing call to SimObject::onRemove");
}
@ -149,7 +149,7 @@ void SimObject::initPersistFields()
{
addGroup( "Ungrouped" );
addProtectedField( "name", TypeName, Offset(objectName, SimObject), &setProtectedName, &defaultProtectedGetFn,
addProtectedField( "name", TypeName, Offset(mObjectName, SimObject), &setProtectedName, &defaultProtectedGetFn,
"Optional global name of this object." );
endGroup( "Ungrouped" );
@ -211,8 +211,8 @@ String SimObject::describeSelf() const
if( mId != 0 )
desc = avar( "%s|id: %i", desc.c_str(), mId );
if( objectName )
desc = avar( "%s|name: %s", desc.c_str(), objectName );
if(mObjectName)
desc = avar( "%s|name: %s", desc.c_str(), mObjectName);
if( mInternalName )
desc = avar( "%s|internal: %s", desc.c_str(), mInternalName );
if( mNameSpace )
@ -529,17 +529,17 @@ void SimObject::onTamlCustomRead(TamlCustomNodes const& customNodes)
for (TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr)
{
// Fetch field.
const TamlCustomField* pField = *fieldItr;
const TamlCustomField* cField = *fieldItr;
// Fetch field name.
StringTableEntry fieldName = pField->getFieldName();
StringTableEntry fieldName = cField->getFieldName();
const AbstractClassRep::Field* field = findField(fieldName);
// Check common fields.
if (field)
{
setDataField(fieldName, buf, pField->getFieldValue());
setDataField(fieldName, buf, cField->getFieldValue());
}
else
{
@ -754,9 +754,9 @@ void SimObject::setId(SimObjectId newId)
void SimObject::assignName(const char *name)
{
if( objectName && !isNameChangeAllowed() )
if(mObjectName && !isNameChangeAllowed() )
{
Con::errorf( "SimObject::assignName - not allowed to change name of object '%s'", objectName );
Con::errorf( "SimObject::assignName - not allowed to change name of object '%s'", mObjectName);
return;
}
@ -781,7 +781,7 @@ void SimObject::assignName(const char *name)
Sim::gNameDictionary->remove( this );
}
objectName = newName;
mObjectName = newName;
if( mGroup )
mGroup->mNameDictionary.insert( this );
@ -1373,7 +1373,7 @@ SimObject::SimObject(const SimObject& other, bool temp_clone)
{
is_temp_clone = temp_clone;
objectName = other.objectName;
mObjectName = other.mObjectName;
mOriginalName = other.mOriginalName;
nextNameObject = other.nextNameObject;
nextManagerNameObject = other.nextManagerNameObject;

View file

@ -293,7 +293,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
};
// dictionary information stored on the object
StringTableEntry objectName;
StringTableEntry mObjectName;
StringTableEntry mOriginalName;
SimObject* nextNameObject;
SimObject* nextManagerNameObject;
@ -358,7 +358,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
{ 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(); }
{ SimObject* simObject = static_cast<SimObject*>(obj); return simObject->mObjectName != NULL && simObject->mObjectName != StringTable->EmptyString(); }
static bool writeCanSaveDynamicFields(void* obj, StringTableEntry pFieldName)
{ return static_cast<SimObject*>(obj)->mCanSaveFieldDictionary == false; }
static bool writeInternalName(void* obj, StringTableEntry pFieldName)
@ -761,7 +761,7 @@ class SimObject: public ConsoleObject, public TamlCallbacks
const char* getIdString() const { return mIdString; }
/// Return the name of this object.
StringTableEntry getName() const { return objectName; }
StringTableEntry getName() const { return mObjectName; }
/// Return the SimGroup that this object is contained in. Never NULL except for
/// RootGroup and unregistered objects.

View file

@ -118,7 +118,7 @@ IMPLEMENT_CALLBACK( SimSet, onObjectRemoved, void, ( SimObject* object ), ( obje
SimSet::SimSet()
{
VECTOR_SET_ASSOCIATION( objectList );
VECTOR_SET_ASSOCIATION(mObjectList);
mMutex = Mutex::createMutex();
}
@ -139,7 +139,7 @@ void SimSet::addObject( SimObject* obj )
lock();
const bool added = objectList.pushBack( obj );
const bool added = mObjectList.pushBack( obj );
if( added )
deleteNotify( obj );
@ -159,7 +159,7 @@ void SimSet::removeObject( SimObject* obj )
{
lock();
const bool removed = objectList.remove( obj );
const bool removed = mObjectList.remove( obj );
if( removed )
clearNotify( obj );
@ -182,7 +182,7 @@ void SimSet::pushObject( SimObject* obj )
lock();
bool added = objectList.pushBackForce( obj );
bool added = mObjectList.pushBackForce( obj );
if( added )
deleteNotify( obj );
@ -200,15 +200,15 @@ void SimSet::pushObject( SimObject* obj )
void SimSet::popObject()
{
if( objectList.empty() )
if(mObjectList.empty() )
{
AssertWarn(false, "Stack underflow in SimSet::popObject");
return;
}
lock();
SimObject* object = objectList.last();
objectList.pop_back();
SimObject* object = mObjectList.last();
mObjectList.pop_back();
clearNotify( object );
unlock();
@ -223,7 +223,7 @@ void SimSet::popObject()
void SimSet::scriptSort( const String &scriptCallbackFn )
{
lock();
objectList.scriptSort( scriptCallbackFn );
mObjectList.scriptSort( scriptCallbackFn );
unlock();
}
@ -303,8 +303,8 @@ bool SimSet::reOrder( SimObject *obj, SimObject *target )
if ( itrS != (end()-1) )
{
// remove object from its current location and push to back of list
objectList.erase(itrS);
objectList.push_back(obj);
mObjectList.erase(itrS);
mObjectList.push_back(obj);
}
}
else
@ -314,12 +314,12 @@ bool SimSet::reOrder( SimObject *obj, SimObject *target )
// target must be in list
return false;
objectList.erase(itrS);
mObjectList.erase(itrS);
// once itrS has been erased, itrD won't be pointing at the
// same place anymore - re-find...
itrD = find(begin(),end(),target);
objectList.insert(itrD, obj);
mObjectList.insert(itrD, obj);
}
return true;
@ -340,15 +340,15 @@ void SimSet::onRemove()
MutexHandle handle;
handle.lock( mMutex );
if( !objectList.empty() )
if( !mObjectList.empty() )
{
objectList.sortId();
mObjectList.sortId();
// This backwards iterator loop doesn't work if the
// list is empty, check the size first.
for( SimObjectList::iterator ptr = objectList.end() - 1;
ptr >= objectList.begin(); ptr -- )
for( SimObjectList::iterator ptr = mObjectList.end() - 1;
ptr >= mObjectList.begin(); ptr -- )
clearNotify( *ptr );
}
@ -417,8 +417,8 @@ void SimSet::deleteAllObjects()
lock();
while( !empty() )
{
SimObject* object = objectList.last();
objectList.pop_back();
SimObject* object = mObjectList.last();
mObjectList.pop_back();
object->deleteObject();
}
@ -536,7 +536,7 @@ SimObject* SimSet::findObjectByLineNumber(const char* fileName, S32 declarationL
SimObject* SimSet::getRandom()
{
if (size() > 0)
return objectList[mRandI(0, size() - 1)];
return mObjectList[mRandI(0, size() - 1)];
return NULL;
}
@ -640,7 +640,7 @@ void SimGroup::_addObject( SimObject* obj, bool forcePushBack )
if( obj->getGroup() )
obj->getGroup()->removeObject( obj );
if( forcePushBack ? objectList.pushBack( obj ) : objectList.pushBackForce( obj ) )
if( forcePushBack ? mObjectList.pushBack( obj ) : mObjectList.pushBackForce( obj ) )
{
mNameDictionary.insert( obj );
obj->mGroup = this;
@ -685,7 +685,7 @@ void SimGroup::_removeObjectNoLock( SimObject* obj )
obj->onGroupRemove();
mNameDictionary.remove( obj );
objectList.remove( obj );
mObjectList.remove( obj );
obj->mGroup = 0;
getSetModificationSignal().trigger( SetObjectRemoved, this, obj );
@ -709,14 +709,14 @@ void SimGroup::popObject()
MutexHandle handle;
handle.lock( mMutex );
if( objectList.empty() )
if(mObjectList.empty() )
{
AssertWarn( false, "SimGroup::popObject - Stack underflow" );
return;
}
SimObject* object = objectList.last();
objectList.pop_back();
SimObject* object = mObjectList.last();
mObjectList.pop_back();
object->onGroupRemove();
object->mGroup = NULL;
@ -736,9 +736,9 @@ void SimGroup::popObject()
void SimGroup::onRemove()
{
lock();
if( !objectList.empty() )
if( !mObjectList.empty() )
{
objectList.sortId();
mObjectList.sortId();
clear();
}
SimObject::onRemove();
@ -752,10 +752,10 @@ void SimGroup::clear()
lock();
while( size() > 0 )
{
SimObject* object = objectList.last();
SimObject* object = mObjectList.last();
object->onGroupRemove();
objectList.pop_back();
mObjectList.pop_back();
mNameDictionary.remove( object );
object->mGroup = 0;

View file

@ -114,7 +114,7 @@ class SimSet : public SimObject, public TamlChildren
protected:
SimObjectList objectList;
SimObjectList mObjectList;
void *mMutex;
/// Signal that is triggered when objects are added or removed from the set.
@ -144,14 +144,14 @@ class SimSet : public SimObject, public TamlChildren
///
typedef SimObjectList::iterator iterator;
typedef SimObjectList::value_type value;
SimObject* front() { return objectList.front(); }
SimObject* first() { return objectList.first(); }
SimObject* last() { return objectList.last(); }
bool empty() const { return objectList.empty(); }
S32 size() const { return objectList.size(); }
iterator begin() { return objectList.begin(); }
iterator end() { return objectList.end(); }
value operator[] (S32 index) { return objectList[U32(index)]; }
SimObject* front() { return mObjectList.front(); }
SimObject* first() { return mObjectList.first(); }
SimObject* last() { return mObjectList.last(); }
bool empty() const { return mObjectList.empty(); }
S32 size() const { return mObjectList.size(); }
iterator begin() { return mObjectList.begin(); }
iterator end() { return mObjectList.end(); }
value operator[] (S32 index) { return mObjectList[U32(index)]; }
inline iterator find( iterator first, iterator last, SimObject *obj)
{ return T3D::find(first, last, obj); }
@ -163,7 +163,7 @@ class SimSet : public SimObject, public TamlChildren
virtual bool reOrder( SimObject *obj, SimObject *target=0 );
/// Return the object at the given index.
SimObject* at(S32 index) const { return objectList.at(index); }
SimObject* at(S32 index) const { return mObjectList.at(index); }
/// Remove all objects from this set.
virtual void clear();
@ -263,7 +263,7 @@ class SimSet : public SimObject, public TamlChildren
#ifdef TORQUE_DEBUG_GUARD
inline void _setVectorAssoc( const char *file, const U32 line )
{
objectList.setFileAssociation( file, line );
mObjectList.setFileAssociation( file, line );
}
#endif
@ -324,9 +324,9 @@ void SimSet::findObjectByType( Vector<T*> &foundObjects )
// Loop through our child objects.
SimObjectList::iterator itr = objectList.begin();
SimObjectList::iterator itr = mObjectList.begin();
for ( ; itr != objectList.end(); itr++ )
for ( ; itr != mObjectList.end(); itr++ )
{
curObj = dynamic_cast<T*>( *itr );
curSet = dynamic_cast<SimSet*>( *itr );
@ -358,9 +358,9 @@ void SimSet::findObjectByCallback( bool ( *fn )( T* ), Vector<T*> &foundObjects
// Loop through our child objects.
SimObjectList::iterator itr = objectList.begin();
SimObjectList::iterator itr = mObjectList.begin();
for ( ; itr != objectList.end(); itr++ )
for ( ; itr != mObjectList.end(); itr++ )
{
curObj = dynamic_cast<T*>( *itr );
curSet = dynamic_cast<SimSet*>( *itr );

View file

@ -24,6 +24,185 @@
#include "console/consoleInternal.h"
#include "console/stringStack.h"
StringStack::StringStack()
{
mBufferSize = 0;
mBuffer = NULL;
mArgBufferSize = 0;
mArgBuffer = NULL;
mNumFrames = 0;
mStart = 0;
mLen = 0;
mStartStackSize = 0;
mFunctionOffset = 0;
validateBufferSize(8192);
validateArgBufferSize(2048);
dMemset(mBuffer, '\0', mBufferSize);
dMemset(mArgBuffer, '\0', mArgBufferSize);
}
StringStack::~StringStack()
{
if( mBuffer )
dFree( mBuffer );
if( mArgBuffer )
dFree( mArgBuffer );
}
void StringStack::validateBufferSize(U32 size)
{
if(size > mBufferSize)
{
mBufferSize = size + 2048;
mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
}
}
void StringStack::validateArgBufferSize(U32 size)
{
if(size > mArgBufferSize)
{
mArgBufferSize = size + 2048;
mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
}
}
void StringStack::setIntValue(U32 i)
{
validateBufferSize(mStart + 32);
dSprintf(mBuffer + mStart, 32, "%d", i);
mLen = dStrlen(mBuffer + mStart);
}
void StringStack::setFloatValue(F64 v)
{
validateBufferSize(mStart + 32);
dSprintf(mBuffer + mStart, 32, "%g", v);
mLen = dStrlen(mBuffer + mStart);
}
char *StringStack::getReturnBuffer(U32 size)
{
if(size > ReturnBufferSpace)
{
AssertFatal(Con::isMainThread(), "Manipulating return buffer from a secondary thread!");
validateArgBufferSize(size);
return mArgBuffer;
}
else
{
validateBufferSize(mStart + size);
return mBuffer + mStart;
}
}
char *StringStack::getArgBuffer(U32 size)
{
AssertFatal(Con::isMainThread(), "Manipulating console arg buffer from a secondary thread!");
validateBufferSize(mStart + mFunctionOffset + size);
char *ret = mBuffer + mStart + mFunctionOffset;
mFunctionOffset += size;
return ret;
}
void StringStack::clearFunctionOffset()
{
//Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
mFunctionOffset = 0;
}
void StringStack::setStringValue(const char *s)
{
if(!s)
{
mLen = 0;
mBuffer[mStart] = 0;
return;
}
mLen = dStrlen(s);
validateBufferSize(mStart + mLen + 2);
dStrcpy(mBuffer + mStart, s, mBufferSize - mStart);
}
void StringStack::advance()
{
mStartOffsets[mStartStackSize++] = mStart;
mStart += mLen;
mLen = 0;
}
void StringStack::advanceChar(char c)
{
mStartOffsets[mStartStackSize++] = mStart;
mStart += mLen;
mBuffer[mStart] = c;
mBuffer[mStart+1] = 0;
mStart += 1;
mLen = 0;
}
void StringStack::push()
{
advanceChar(0);
}
void StringStack::rewind()
{
mStart = mStartOffsets[--mStartStackSize];
mLen = dStrlen(mBuffer + mStart);
}
void StringStack::rewindTerminate()
{
mBuffer[mStart] = 0;
mStart = mStartOffsets[--mStartStackSize];
mLen = dStrlen(mBuffer + mStart);
}
U32 StringStack::compare()
{
// Figure out the 1st and 2nd item offsets.
U32 oldStart = mStart;
mStart = mStartOffsets[--mStartStackSize];
// Compare current and previous strings.
U32 ret = !dStricmp(mBuffer + mStart, mBuffer + oldStart);
// Put an empty string on the top of the stack.
mLen = 0;
mBuffer[mStart] = 0;
return ret;
}
void StringStack::pushFrame()
{
//Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
mFrameOffsets[mNumFrames++] = mStartStackSize;
mStartOffsets[mStartStackSize++] = mStart;
mStart += ReturnBufferSpace;
validateBufferSize(0);
}
void StringStack::popFrame()
{
//Con::printf("StringStack popFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
mStartStackSize = mFrameOffsets[--mNumFrames];
mStart = mStartOffsets[mStartStackSize];
mLen = 0;
}
void StringStack::clearFrames()
{
//Con::printf("StringStack clearFrames");
mNumFrames = 0;
mStart = 0;
mLen = 0;
mStartStackSize = 0;
mFunctionOffset = 0;
}
void ConsoleValueStack::getArgcArgv(StringTableEntry name, U32 *argc, ConsoleValueRef **in_argv, bool popStackFrame /* = false */)
{

View file

@ -79,105 +79,31 @@ struct StringStack
U32 mArgBufferSize;
char *mArgBuffer;
void validateBufferSize(U32 size)
{
if(size > mBufferSize)
{
mBufferSize = size + 2048;
mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
}
}
void validateBufferSize(U32 size);
void validateArgBufferSize(U32 size);
void validateArgBufferSize(U32 size)
{
if(size > mArgBufferSize)
{
mArgBufferSize = size + 2048;
mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
}
}
StringStack()
{
mBufferSize = 0;
mBuffer = NULL;
mArgBufferSize = 0;
mArgBuffer = NULL;
mNumFrames = 0;
mStart = 0;
mLen = 0;
mStartStackSize = 0;
mFunctionOffset = 0;
validateBufferSize(8192);
validateArgBufferSize(2048);
dMemset(mBuffer, '\0', mBufferSize);
dMemset(mArgBuffer, '\0', mArgBufferSize);
}
~StringStack()
{
if( mBuffer )
dFree( mBuffer );
if( mArgBuffer )
dFree( mArgBuffer );
}
StringStack();
~StringStack();
/// Set the top of the stack to be an integer value.
void setIntValue(U32 i)
{
validateBufferSize(mStart + 32);
dSprintf(mBuffer + mStart, 32, "%d", i);
mLen = dStrlen(mBuffer + mStart);
}
void setIntValue(U32 i);
/// Set the top of the stack to be a float value.
void setFloatValue(F64 v)
{
validateBufferSize(mStart + 32);
dSprintf(mBuffer + mStart, 32, "%g", v);
mLen = dStrlen(mBuffer + mStart);
}
void setFloatValue(F64 v);
/// Return a temporary buffer we can use to return data.
char* getReturnBuffer(U32 size)
{
AssertFatal(Con::isMainThread(), "Manipulating return buffer from a secondary thread!");
validateArgBufferSize(size);
return mArgBuffer;
}
char* getReturnBuffer(U32 size);
/// Return a buffer we can use for arguments.
///
/// This updates the function offset.
char *getArgBuffer(U32 size)
{
AssertFatal(Con::isMainThread(), "Manipulating console arg buffer from a secondary thread!");
validateBufferSize(mStart + mFunctionOffset + size);
char *ret = mBuffer + mStart + mFunctionOffset;
mFunctionOffset += size;
return ret;
}
char *getArgBuffer(U32 size);
/// Clear the function offset.
void clearFunctionOffset()
{
//Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
mFunctionOffset = 0;
}
void clearFunctionOffset();
/// Set a string value on the top of the stack.
void setStringValue(const char *s)
{
if(!s)
{
mLen = 0;
mBuffer[mStart] = 0;
return;
}
mLen = dStrlen(s);
validateBufferSize(mStart + mLen + 2);
dStrcpy(mBuffer + mStart, s, mBufferSize - mStart);
}
void setStringValue(const char *s);
/// Get the top of the stack, as a StringTableEntry.
///
@ -226,33 +152,17 @@ struct StringStack
///
/// @note You should use StringStack::push, not this, if you want to
/// properly push the stack.
void advance()
{
mStartOffsets[mStartStackSize++] = mStart;
mStart += mLen;
mLen = 0;
}
void advance();
/// Advance the start stack, placing a single character, null-terminated strong
/// on the top.
///
/// @note You should use StringStack::push, not this, if you want to
/// properly push the stack.
void advanceChar(char c)
{
mStartOffsets[mStartStackSize++] = mStart;
mStart += mLen;
mBuffer[mStart] = c;
mBuffer[mStart+1] = 0;
mStart += 1;
mLen = 0;
}
void advanceChar(char c);
/// Push the stack, placing a zero-length string on the top.
void push()
{
advanceChar(0);
}
void push();
inline void setLen(U32 newlen)
{
@ -260,64 +170,20 @@ struct StringStack
}
/// Pop the start stack.
void rewind()
{
mStart = mStartOffsets[--mStartStackSize];
mLen = dStrlen(mBuffer + mStart);
}
void rewind();
// Terminate the current string, and pop the start stack.
void rewindTerminate()
{
mBuffer[mStart] = 0;
mStart = mStartOffsets[--mStartStackSize];
mLen = dStrlen(mBuffer + mStart);
}
void rewindTerminate();
/// Compare 1st and 2nd items on stack, consuming them in the process,
/// and returning true if they matched, false if they didn't.
U32 compare()
{
// Figure out the 1st and 2nd item offsets.
U32 oldStart = mStart;
mStart = mStartOffsets[--mStartStackSize];
U32 compare();
// Compare current and previous strings.
U32 ret = !dStricmp(mBuffer + mStart, mBuffer + oldStart);
void pushFrame();
// Put an empty string on the top of the stack.
mLen = 0;
mBuffer[mStart] = 0;
void popFrame();
return ret;
}
void pushFrame()
{
//Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
mFrameOffsets[mNumFrames++] = mStartStackSize;
mStartOffsets[mStartStackSize++] = mStart;
mStart += ReturnBufferSpace;
validateBufferSize(0);
}
void popFrame()
{
//Con::printf("StringStack popFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
mStartStackSize = mFrameOffsets[--mNumFrames];
mStart = mStartOffsets[mStartStackSize];
mLen = 0;
}
void clearFrames()
{
//Con::printf("StringStack clearFrames");
mNumFrames = 0;
mStart = 0;
mLen = 0;
mStartStackSize = 0;
mFunctionOffset = 0;
}
void clearFrames();
/// Get the arguments for a function call from the stack.
void getArgcArgv(StringTableEntry name, U32 *argc, const char ***in_argv, bool popStackFrame = false);