mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-06 14:00:39 +00:00
Merge branch 'development' into defineconsolemethod
Conflicts: Engine/source/materials/materialDefinition.cpp
This commit is contained in:
commit
ae284a89ec
129 changed files with 3742 additions and 1038 deletions
|
|
@ -470,11 +470,11 @@ ConsoleValueRef CodeBlock::exec(U32 ip, const char *functionName, Namespace *thi
|
|||
dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
|
||||
"%s(", thisFunctionName);
|
||||
}
|
||||
for (i = 0; i < wantedArgc; i++)
|
||||
for(i = 0; i < wantedArgc; i++)
|
||||
{
|
||||
dStrcat(traceBuffer, argv[i + 1]);
|
||||
if (i != wantedArgc - 1)
|
||||
dStrcat(traceBuffer, ", ");
|
||||
dStrcat(traceBuffer, argv[i+1]);
|
||||
if(i != wantedArgc - 1)
|
||||
dStrcat(traceBuffer, ", ");
|
||||
}
|
||||
dStrcat(traceBuffer, ")");
|
||||
Con::printf("%s", traceBuffer);
|
||||
|
|
@ -533,9 +533,16 @@ ConsoleValueRef CodeBlock::exec(U32 ip, const char *functionName, Namespace *thi
|
|||
}
|
||||
}
|
||||
|
||||
// Reset the console stack frame which at this point will contain
|
||||
// either nothing or argv[] which we just copied
|
||||
CSTK.resetFrame();
|
||||
bool doResetValueStack = !gEvalState.mResetLocked;
|
||||
gEvalState.mResetLocked = true;
|
||||
|
||||
if (gEvalState.mShouldReset)
|
||||
{
|
||||
// Ensure all stacks are clean in case anything became unbalanced during the previous execution
|
||||
STR.clearFrames();
|
||||
CSTK.clearFrames();
|
||||
gEvalState.mShouldReset = false;
|
||||
}
|
||||
|
||||
// Grab the state of the telenet debugger here once
|
||||
// so that the push and pop frames are always balanced.
|
||||
|
|
@ -1817,7 +1824,7 @@ breakContinue:
|
|||
ConsoleValueRef ret;
|
||||
if(nsEntry->mFunctionOffset)
|
||||
ret = nsEntry->mCode->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage);
|
||||
|
||||
|
||||
STR.popFrame();
|
||||
// Functions are assumed to return strings, so look ahead to see if we can skip the conversion
|
||||
if(code[ip] == OP_STR_TO_UINT)
|
||||
|
|
@ -1837,7 +1844,7 @@ breakContinue:
|
|||
}
|
||||
else
|
||||
STR.setStringValue((const char*)ret);
|
||||
|
||||
|
||||
// This will clear everything including returnValue
|
||||
CSTK.popFrame();
|
||||
STR.clearFunctionOffset();
|
||||
|
|
@ -2219,15 +2226,7 @@ execFinished:
|
|||
Con::printf("%s", traceBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete[] globalStrings;
|
||||
globalStringsMaxLen = 0;
|
||||
|
||||
delete[] globalFloats;
|
||||
globalStrings = NULL;
|
||||
globalFloats = NULL;
|
||||
}
|
||||
smCurrentCodeBlock = saveCodeBlock;
|
||||
if(saveCodeBlock && saveCodeBlock->name)
|
||||
{
|
||||
|
|
@ -2235,6 +2234,13 @@ execFinished:
|
|||
Con::gCurrentRoot = saveCodeBlock->modPath;
|
||||
}
|
||||
|
||||
// Mark the reset flag for the next run if we've finished execution
|
||||
if (doResetValueStack)
|
||||
{
|
||||
gEvalState.mShouldReset = true;
|
||||
gEvalState.mResetLocked = false;
|
||||
}
|
||||
|
||||
decRefCount();
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
|
|
|
|||
|
|
@ -796,6 +796,8 @@ ExprEvalState::ExprEvalState()
|
|||
currentVariable = NULL;
|
||||
mStackDepth = 0;
|
||||
stack.reserve( 64 );
|
||||
mShouldReset = false;
|
||||
mResetLocked = false;
|
||||
}
|
||||
|
||||
ExprEvalState::~ExprEvalState()
|
||||
|
|
|
|||
|
|
@ -468,6 +468,8 @@ public:
|
|||
bool traceOn;
|
||||
|
||||
U32 mStackDepth;
|
||||
bool mShouldReset; ///< Designates if the value stack should be reset
|
||||
bool mResetLocked; ///< mShouldReset will be set at the end
|
||||
|
||||
ExprEvalState();
|
||||
~ExprEvalState();
|
||||
|
|
|
|||
|
|
@ -29,19 +29,23 @@ extern U32 HashPointer(StringTableEntry e);
|
|||
|
||||
SimNameDictionary::SimNameDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
hashTable = NULL;
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
}
|
||||
|
||||
SimNameDictionary::~SimNameDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
delete[] hashTable;
|
||||
#endif
|
||||
Mutex::destroyMutex(mutex);
|
||||
}
|
||||
|
||||
void SimNameDictionary::insert(SimObject* obj)
|
||||
{
|
||||
if(!obj->objectName)
|
||||
if(!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
SimObject* checkForDup = find(obj->objectName);
|
||||
|
|
@ -50,7 +54,7 @@ void SimNameDictionary::insert(SimObject* obj)
|
|||
Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->objectName);
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
if(!hashTable)
|
||||
{
|
||||
hashTable = new SimObject *[DefaultTableSize];
|
||||
|
|
@ -95,12 +99,15 @@ void SimNameDictionary::insert(SimObject* obj)
|
|||
hashTable = newHashTable;
|
||||
hashTableSize = newHashTableSize;
|
||||
}
|
||||
|
||||
#else
|
||||
root[obj->objectName] = obj;
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
SimObject* SimNameDictionary::find(StringTableEntry name)
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
// NULL is a valid lookup - it will always return NULL
|
||||
if(!hashTable)
|
||||
return NULL;
|
||||
|
|
@ -121,15 +128,22 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
|
|||
|
||||
Mutex::unlockMutex(mutex);
|
||||
return NULL;
|
||||
#else
|
||||
Mutex::lockMutex(mutex);
|
||||
StringDictDef::iterator it = root.find(name);
|
||||
SimObject* f = (it == root.end() ? NULL : it->second);
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimNameDictionary::remove(SimObject* obj)
|
||||
{
|
||||
if(!obj->objectName)
|
||||
if(!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
while(*walk)
|
||||
{
|
||||
|
|
@ -144,7 +158,11 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
}
|
||||
walk = &((*walk)->nextNameObject);
|
||||
}
|
||||
|
||||
#else
|
||||
const char* name = obj->objectName;
|
||||
if (root.find(name) != root.end())
|
||||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
|
|
@ -152,28 +170,31 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
|
||||
SimManagerNameDictionary::SimManagerNameDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
hashTable = new SimObject *[DefaultTableSize];
|
||||
hashTableSize = DefaultTableSize;
|
||||
hashEntryCount = 0;
|
||||
|
||||
dMemset( hashTable, 0, sizeof( hashTable[ 0 ] ) * hashTableSize );
|
||||
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
}
|
||||
|
||||
SimManagerNameDictionary::~SimManagerNameDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
delete[] hashTable;
|
||||
#endif
|
||||
Mutex::destroyMutex(mutex);
|
||||
}
|
||||
|
||||
void SimManagerNameDictionary::insert(SimObject* obj)
|
||||
{
|
||||
if(!obj->objectName)
|
||||
if(!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = HashPointer(obj->objectName) % hashTableSize;
|
||||
obj->nextManagerNameObject = hashTable[idx];
|
||||
hashTable[idx] = obj;
|
||||
|
|
@ -209,7 +230,9 @@ void SimManagerNameDictionary::insert(SimObject* obj)
|
|||
hashTable = newHashTable;
|
||||
hashTableSize = newHashTableSize;
|
||||
}
|
||||
|
||||
#else
|
||||
root[obj->objectName] = obj;
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
|
|
@ -219,6 +242,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = HashPointer(name) % hashTableSize;
|
||||
SimObject *walk = hashTable[idx];
|
||||
while(walk)
|
||||
|
|
@ -230,16 +254,23 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
}
|
||||
walk = walk->nextManagerNameObject;
|
||||
}
|
||||
|
||||
Mutex::unlockMutex(mutex);
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
StringDictDef::iterator it = root.find(name);
|
||||
SimObject* f = (it == root.end() ? NULL : it->second);
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimManagerNameDictionary::remove(SimObject* obj)
|
||||
{
|
||||
if(!obj->objectName)
|
||||
if(!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
|
|
@ -256,7 +287,11 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
}
|
||||
walk = &((*walk)->nextManagerNameObject);
|
||||
}
|
||||
|
||||
#else
|
||||
StringTableEntry name = obj->objectName;
|
||||
if (root.find(name) != root.end())
|
||||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +300,9 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
|
||||
SimIdDictionary::SimIdDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
}
|
||||
|
||||
|
|
@ -274,22 +311,29 @@ SimIdDictionary::~SimIdDictionary()
|
|||
Mutex::destroyMutex(mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimIdDictionary::insert(SimObject* obj)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = obj->getId() & TableBitMask;
|
||||
obj->nextIdObject = table[idx];
|
||||
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
|
||||
table[idx] = obj;
|
||||
|
||||
#else
|
||||
root[obj->getId()] = obj;
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
SimObject* SimIdDictionary::find(S32 id)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = id & TableBitMask;
|
||||
SimObject *walk = table[idx];
|
||||
while(walk)
|
||||
|
|
@ -301,22 +345,32 @@ SimObject* SimIdDictionary::find(S32 id)
|
|||
}
|
||||
walk = walk->nextIdObject;
|
||||
}
|
||||
|
||||
Mutex::unlockMutex(mutex);
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
SimObjectIdDictDef::iterator it = root.find(id);
|
||||
SimObject* f = (it == root.end() ? NULL : it->second);
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimIdDictionary::remove(SimObject* obj)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &table[obj->getId() & TableBitMask];
|
||||
while(*walk && *walk != obj)
|
||||
walk = &((*walk)->nextIdObject);
|
||||
if(*walk)
|
||||
*walk = obj->nextIdObject;
|
||||
|
||||
#else
|
||||
root.erase(obj->getId());
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,38 @@
|
|||
#include "platform/threads/mutex.h"
|
||||
#endif
|
||||
|
||||
#include "torqueConfig.h"
|
||||
|
||||
class SimObject;
|
||||
|
||||
#ifdef USE_NEW_SIMDICTIONARY
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifndef _SIM_H_
|
||||
#include "console/sim.h"
|
||||
#endif
|
||||
|
||||
struct StringTableEntryHash
|
||||
{
|
||||
inline size_t operator()(StringTableEntry val) const
|
||||
{
|
||||
return (size_t)val;
|
||||
}
|
||||
};
|
||||
|
||||
struct StringTableEntryEq
|
||||
{
|
||||
inline bool operator()(StringTableEntry s1, StringTableEntry s2) const
|
||||
{
|
||||
return s1 == s2;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<StringTableEntry, SimObject*, StringTableEntryHash, StringTableEntryEq> StringDictDef;
|
||||
typedef std::unordered_map<SimObjectId, SimObject*> SimObjectIdDictDef;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Map of names to SimObjects
|
||||
///
|
||||
|
|
@ -42,6 +72,7 @@ class SimObject;
|
|||
/// for fast removal of an object given object*
|
||||
class SimNameDictionary
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -50,6 +81,9 @@ class SimNameDictionary
|
|||
SimObject **hashTable; // hash the pointers of the names...
|
||||
S32 hashTableSize;
|
||||
S32 hashEntryCount;
|
||||
#else
|
||||
StringDictDef root;
|
||||
#endif
|
||||
|
||||
void *mutex;
|
||||
|
||||
|
|
@ -64,6 +98,7 @@ public:
|
|||
|
||||
class SimManagerNameDictionary
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -72,6 +107,9 @@ class SimManagerNameDictionary
|
|||
SimObject **hashTable; // hash the pointers of the names...
|
||||
S32 hashTableSize;
|
||||
S32 hashEntryCount;
|
||||
#else
|
||||
StringDictDef root;
|
||||
#endif
|
||||
|
||||
void *mutex;
|
||||
|
||||
|
|
@ -91,12 +129,16 @@ public:
|
|||
/// for fast removal of an object given object*
|
||||
class SimIdDictionary
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 4096,
|
||||
TableBitMask = 4095
|
||||
};
|
||||
SimObject *table[DefaultTableSize];
|
||||
#else
|
||||
SimObjectIdDictDef root;
|
||||
#endif
|
||||
|
||||
void *mutex;
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ ConsoleValue* ConsoleValueStack::pop()
|
|||
|
||||
void ConsoleValueStack::pushFrame()
|
||||
{
|
||||
//Con::printf("CSTK pushFrame");
|
||||
//Con::printf("CSTK pushFrame[%i] (%i)", mFrame, mStackPos);
|
||||
mStackFrames[mFrame++] = mStackPos;
|
||||
}
|
||||
|
||||
|
|
@ -181,6 +181,12 @@ void ConsoleValueStack::resetFrame()
|
|||
//Con::printf("CSTK resetFrame to %i", mStackPos);
|
||||
}
|
||||
|
||||
void ConsoleValueStack::clearFrames()
|
||||
{
|
||||
mStackPos = 0;
|
||||
mFrame = 0;
|
||||
}
|
||||
|
||||
void ConsoleValueStack::popFrame()
|
||||
{
|
||||
//Con::printf("CSTK popFrame");
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ struct StringStack
|
|||
mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
void validateArgBufferSize(U32 size)
|
||||
{
|
||||
if(size > mArgBufferSize)
|
||||
|
|
@ -82,6 +83,7 @@ struct StringStack
|
|||
mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
StringStack()
|
||||
{
|
||||
mBufferSize = 0;
|
||||
|
|
@ -95,6 +97,8 @@ struct StringStack
|
|||
mFunctionOffset = 0;
|
||||
validateBufferSize(8192);
|
||||
validateArgBufferSize(2048);
|
||||
dMemset(mBuffer, '\0', mBufferSize);
|
||||
dMemset(mArgBuffer, '\0', mArgBufferSize);
|
||||
}
|
||||
~StringStack()
|
||||
{
|
||||
|
|
@ -141,6 +145,7 @@ struct StringStack
|
|||
/// Clear the function offset.
|
||||
void clearFunctionOffset()
|
||||
{
|
||||
//Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
|
||||
mFunctionOffset = 0;
|
||||
}
|
||||
|
||||
|
|
@ -262,9 +267,9 @@ struct StringStack
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void pushFrame()
|
||||
{
|
||||
//Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
|
||||
mFrameOffsets[mNumFrames++] = mStartStackSize;
|
||||
mStartOffsets[mStartStackSize++] = mStart;
|
||||
mStart += ReturnBufferSpace;
|
||||
|
|
@ -273,11 +278,22 @@ struct StringStack
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
/// Get the arguments for a function call from the stack.
|
||||
void getArgcArgv(StringTableEntry name, U32 *argc, const char ***in_argv, bool popStackFrame = false);
|
||||
};
|
||||
|
|
@ -309,6 +325,7 @@ public:
|
|||
void popFrame();
|
||||
|
||||
void resetFrame();
|
||||
void clearFrames();
|
||||
|
||||
void getArgcArgv(StringTableEntry name, U32 *argc, ConsoleValueRef **in_argv, bool popStackFrame = false);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue