Merge branch 'master' into console-func-refactor

Conflicts:
	Engine/source/app/net/net.cpp
	Engine/source/console/astNodes.cpp
	Engine/source/console/compiledEval.cpp
	Engine/source/console/console.h
	Engine/source/console/consoleInternal.h
	Engine/source/console/engineAPI.h
This commit is contained in:
Daniel Buckmaster 2014-10-14 14:40:17 +11:00
commit b507dc9555
6487 changed files with 315149 additions and 609761 deletions

View file

@ -1910,8 +1910,7 @@ extern int isatty (int );
b->yy_bs_column = 0;
}
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
errno = oerrno;
}
@ -2355,7 +2354,7 @@ void CMDerror(char *format, ...)
char tempBuf[BUFMAX];
va_list args;
va_start( args, format );
#ifdef TORQUE_OS_WIN32
#ifdef TORQUE_OS_WIN
_vsnprintf( tempBuf, BUFMAX, format, args );
#else
vsnprintf( tempBuf, BUFMAX, format, args );

View file

@ -245,7 +245,7 @@ void CMDerror(char *format, ...)
char tempBuf[BUFMAX];
va_list args;
va_start( args, format );
#ifdef TORQUE_OS_WIN32
#ifdef TORQUE_OS_WIN
_vsnprintf( tempBuf, BUFMAX, format, args );
#else
vsnprintf( tempBuf, BUFMAX, format, args );

View file

@ -348,7 +348,7 @@ bool SimXMLDocument::pushFirstChildElement(const char* rName)
TiXmlElement* pElement;
if(!m_paNode.empty())
{
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -412,7 +412,7 @@ bool SimXMLDocument::pushChildElement(S32 index)
TiXmlElement* pElement;
if(!m_paNode.empty())
{
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -472,7 +472,7 @@ bool SimXMLDocument::nextSiblingElement(const char* rName)
{
return false;
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement*& pElement = m_paNode[iLastElement];
if(!pElement)
{
@ -506,7 +506,7 @@ const char* SimXMLDocument::elementValue()
{
return StringTable->insert("");
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -547,7 +547,7 @@ const char* SimXMLDocument::attribute(const char* rAttribute)
{
return StringTable->insert("");
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -597,7 +597,7 @@ bool SimXMLDocument::attributeExists(const char* rAttribute)
{
return false;
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -630,7 +630,7 @@ const char* SimXMLDocument::firstAttribute()
{
return StringTable->insert("");
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -667,7 +667,7 @@ const char* SimXMLDocument::lastAttribute()
{
return StringTable->insert("");
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -766,7 +766,7 @@ void SimXMLDocument::setAttribute(const char* rAttribute, const char* rVal)
return;
}
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pElement = m_paNode[iLastElement];
if(!pElement)
{
@ -798,7 +798,7 @@ void SimXMLDocument::setObjectAttributes(const char* objectID)
if( pObject == NULL )
return;
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pElement = m_paNode[iLastElement];
if(!pElement)
return;
@ -925,7 +925,7 @@ void SimXMLDocument::pushNewElement(const char* rName)
}
else
{
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iFinalElement];
if(!pNode)
{
@ -975,7 +975,7 @@ void SimXMLDocument::addNewElement(const char* rName)
return;
}
const int iParentElement = m_paNode.size() - 2;
const S32 iParentElement = m_paNode.size() - 2;
if(iParentElement < 0)
{
pStackTop = dynamic_cast<TiXmlElement*>
@ -1002,7 +1002,7 @@ void SimXMLDocument::addNewElement(const char* rName)
}
// Overwrite top stack position.
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
m_paNode[iFinalElement] = pStackTop;
//pNode = pStackTop;
}
@ -1091,7 +1091,7 @@ const char* SimXMLDocument::readComment( S32 index )
// Push the first element found under the current element of the given name
if(!m_paNode.empty())
{
const int iLastElement = m_paNode.size() - 1;
const S32 iLastElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iLastElement];
if(!pNode)
{
@ -1159,7 +1159,7 @@ void SimXMLDocument::addText(const char* text)
if(m_paNode.empty())
return;
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iFinalElement];
if(!pNode)
return;
@ -1204,7 +1204,7 @@ const char* SimXMLDocument::getText()
if(m_paNode.empty())
return "";
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlNode* pNode = m_paNode[iFinalElement];
if(!pNode)
return "";
@ -1264,7 +1264,7 @@ void SimXMLDocument::removeText()
if(m_paNode.empty())
return;
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iFinalElement];
if(!pNode)
return;
@ -1300,7 +1300,7 @@ void SimXMLDocument::addData(const char* text)
if(m_paNode.empty())
return;
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlElement* pNode = m_paNode[iFinalElement];
if(!pNode)
return;
@ -1346,7 +1346,7 @@ const char* SimXMLDocument::getData()
if(m_paNode.empty())
return "";
const int iFinalElement = m_paNode.size() - 1;
const S32 iFinalElement = m_paNode.size() - 1;
TiXmlNode* pNode = m_paNode[iFinalElement];
if(!pNode)
return "";

View file

@ -76,7 +76,7 @@ S32 QSORT_CALLBACK ArrayObject::_valueNumCompare( const void* a, const void* b )
F32 bCol = dAtof(eb->value);
F32 result = aCol - bCol;
S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0);
return ( smDecreasing ? res : -res );
return ( smDecreasing ? -res : res );
}
S32 QSORT_CALLBACK ArrayObject::_keyCompare( const void* a, const void* b )
@ -95,7 +95,7 @@ S32 QSORT_CALLBACK ArrayObject::_keyNumCompare( const void* a, const void* b )
const char* bCol = eb->key;
F32 result = dAtof(aCol) - dAtof(bCol);
S32 res = result < 0 ? -1 : (result > 0 ? 1 : 0);
return ( smDecreasing ? res : -res );
return ( smDecreasing ? -res : res );
}
S32 QSORT_CALLBACK ArrayObject::_keyFunctionCompare( const void* a, const void* b )
@ -107,7 +107,7 @@ S32 QSORT_CALLBACK ArrayObject::_keyFunctionCompare( const void* a, const void*
S32 result = dAtoi( Con::execute( 3, argv ) );
S32 res = result < 0 ? -1 : ( result > 0 ? 1 : 0 );
return ( smDecreasing ? res : -res );
return ( smDecreasing ? -res : res );
}
S32 QSORT_CALLBACK ArrayObject::_valueFunctionCompare( const void* a, const void* b )
@ -119,7 +119,7 @@ S32 QSORT_CALLBACK ArrayObject::_valueFunctionCompare( const void* a, const void
S32 result = dAtoi( Con::execute( 3, argv ) );
S32 res = result < 0 ? -1 : ( result > 0 ? 1 : 0 );
return ( smDecreasing ? res : -res );
return ( smDecreasing ? -res : res );
}

View file

@ -27,6 +27,7 @@ class ExprEvalState;
class Namespace;
class SimObject;
class SimGroup;
class CodeStream;
/// Enable this #define if you are seeing the message "precompile size mismatch" in the console.
/// This will help track down which node type is causing the error. It could be
@ -78,15 +79,13 @@ struct StmtNode
/// @name Breaking
/// @{
void addBreakCount();
void addBreakLine(U32 ip);
void addBreakLine(CodeStream &codeStream);
/// @}
/// @name Compilation
/// @{
virtual U32 precompileStmt(U32 loopCount) = 0;
virtual U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint) = 0;
virtual U32 compileStmt(CodeStream &codeStream, U32 ip) = 0;
virtual void setPackage(StringTableEntry packageName);
/// @}
};
@ -102,27 +101,26 @@ struct BreakStmtNode : StmtNode
{
static BreakStmtNode *alloc( S32 lineNumber );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(BreakStmtNode);
};
struct ContinueStmtNode : StmtNode
{
static ContinueStmtNode *alloc( S32 lineNumber );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(ContinueStmtNode);
};
/// A mathematical expression.
struct ExprNode : StmtNode
{
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
virtual U32 precompile(TypeReq type) = 0;
virtual U32 compile(U32 *codeStream, U32 ip, TypeReq type) = 0;
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type) = 0;
virtual TypeReq getPreferredType() = 0;
};
@ -131,8 +129,8 @@ struct ReturnStmtNode : StmtNode
ExprNode *expr;
static ReturnStmtNode *alloc( S32 lineNumber, ExprNode *expr );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(ReturnStmtNode);
};
@ -148,8 +146,8 @@ struct IfStmtNode : StmtNode
static IfStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagateThrough );
void propagateSwitchExpr(ExprNode *left, bool string);
ExprNode *getSwitchOR(ExprNode *left, ExprNode *list, bool string);
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(IfStmtNode);
};
@ -166,8 +164,8 @@ struct LoopStmtNode : StmtNode
bool integer;
static LoopStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *initExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(LoopStmtNode);
};
@ -191,8 +189,7 @@ struct IterStmtNode : StmtNode
static IterStmtNode* alloc( S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter );
U32 precompileStmt( U32 loopCount );
U32 compileStmt( U32* codeStream, U32 ip, U32 continuePoint, U32 breakPoint );
U32 compileStmt( CodeStream &codeStream, U32 ip );
};
/// A binary mathematical expression (ie, left op right).
@ -206,8 +203,8 @@ struct BinaryExprNode : ExprNode
struct FloatBinaryExprNode : BinaryExprNode
{
static FloatBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatBinaryExprNode);
};
@ -219,8 +216,8 @@ struct ConditionalExprNode : ExprNode
ExprNode *falseExpr;
bool integer;
static ConditionalExprNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr );
virtual U32 precompile(TypeReq type);
virtual U32 compile(U32 *codeStream, U32 ip, TypeReq type);
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
virtual TypeReq getPreferredType();
DBG_STMT_TYPE(ConditionalExprNode);
};
@ -233,8 +230,8 @@ struct IntBinaryExprNode : BinaryExprNode
static IntBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
void getSubTypeOperand();
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntBinaryExprNode);
};
@ -243,18 +240,18 @@ struct StreqExprNode : BinaryExprNode
{
bool eq;
static StreqExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, bool eq );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StreqExprNode);
};
struct StrcatExprNode : BinaryExprNode
{
int appendChar;
static StrcatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, int appendChar );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
S32 appendChar;
static StrcatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar );
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StrcatExprNode);
};
@ -263,8 +260,8 @@ struct CommaCatExprNode : BinaryExprNode
{
static CommaCatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(CommaCatExprNode);
};
@ -276,8 +273,8 @@ struct IntUnaryExprNode : ExprNode
bool integer;
static IntUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntUnaryExprNode);
};
@ -288,8 +285,8 @@ struct FloatUnaryExprNode : ExprNode
ExprNode *expr;
static FloatUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatUnaryExprNode);
};
@ -300,8 +297,8 @@ struct VarNode : ExprNode
ExprNode *arrayIndex;
static VarNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(VarNode);
};
@ -312,8 +309,8 @@ struct IntNode : ExprNode
U32 index; // if it's converted to float/string
static IntNode *alloc( S32 lineNumber, S32 value );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntNode);
};
@ -324,8 +321,8 @@ struct FloatNode : ExprNode
U32 index;
static FloatNode *alloc( S32 lineNumber, F64 value );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatNode);
};
@ -339,8 +336,8 @@ struct StrConstNode : ExprNode
bool doc; // Specifies that this string is a documentation block.
static StrConstNode *alloc( S32 lineNumber, char *str, bool tag, bool doc = false );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StrConstNode);
};
@ -352,8 +349,8 @@ struct ConstantNode : ExprNode
U32 index;
static ConstantNode *alloc( S32 lineNumber, StringTableEntry value );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(ConstantNode);
};
@ -366,8 +363,8 @@ struct AssignExprNode : ExprNode
TypeReq subType;
static AssignExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssignExprNode);
};
@ -390,8 +387,8 @@ struct AssignOpExprNode : ExprNode
TypeReq subType;
static AssignOpExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssignOpExprNode);
};
@ -403,8 +400,8 @@ struct TTagSetStmtNode : StmtNode
ExprNode *stringExpr;
static TTagSetStmtNode *alloc( S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(TTagSetStmtNode);
};
@ -413,8 +410,8 @@ struct TTagDerefNode : ExprNode
ExprNode *expr;
static TTagDerefNode *alloc( S32 lineNumber, ExprNode *expr );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(TTagDerefNode);
};
@ -424,8 +421,8 @@ struct TTagExprNode : ExprNode
StringTableEntry tag;
static TTagExprNode *alloc( S32 lineNumber, StringTableEntry tag );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(TTagExprNode);
};
@ -443,8 +440,8 @@ struct FuncCallExprNode : ExprNode
};
static FuncCallExprNode *alloc( S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FuncCallExprNode);
};
@ -456,8 +453,8 @@ struct AssertCallExprNode : ExprNode
U32 messageIndex;
static AssertCallExprNode *alloc( S32 lineNumber, ExprNode *testExpr, const char *message );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssertCallExprNode);
};
@ -476,8 +473,8 @@ struct SlotAccessNode : ExprNode
StringTableEntry slotName;
static SlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAccessNode);
};
@ -496,8 +493,8 @@ struct InternalSlotAccessNode : ExprNode
bool recurse;
static InternalSlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(InternalSlotAccessNode);
};
@ -510,8 +507,8 @@ struct SlotAssignNode : ExprNode
U32 typeID;
static SlotAssignNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID = -1 );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAssignNode);
};
@ -526,8 +523,8 @@ struct SlotAssignOpNode : ExprNode
TypeReq subType;
static SlotAssignOpNode *alloc( S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr );
U32 precompile(TypeReq type);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAssignOpNode);
};
@ -546,10 +543,10 @@ struct ObjectDeclNode : ExprNode
bool isSingleton;
static ObjectDeclNode *alloc( S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton );
U32 precompile(TypeReq type);
U32 precompileSubObject(bool);
U32 compile(U32 *codeStream, U32 ip, TypeReq type);
U32 compileSubObject(U32 *codeStream, U32 ip, bool);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
U32 compileSubObject(CodeStream &codeStream, U32 ip, bool);
TypeReq getPreferredType();
DBG_STMT_TYPE(ObjectDeclNode);
};
@ -571,18 +568,13 @@ struct FunctionDeclStmtNode : StmtNode
U32 argc;
static FunctionDeclStmtNode *alloc( S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts );
U32 precompileStmt(U32 loopCount);
U32 compileStmt(U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileStmt(CodeStream &codeStream, U32 ip);
void setPackage(StringTableEntry packageName);
DBG_STMT_TYPE(FunctionDeclStmtNode);
};
extern StmtNode *gStatementList;
extern void createFunction(const char *fnName, VarNode *args, StmtNode *statements);
extern ExprEvalState gEvalState;
extern bool lookupFunction(const char *fnName, VarNode **args, StmtNode **statements);
typedef const char *(*cfunc)(S32 argc, char **argv);
extern bool lookupCFunction(const char *fnName, cfunc *f);
extern ExprEvalState gEvalState;;
#endif

View file

@ -149,7 +149,7 @@ StreqExprNode *StreqExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *r
return ret;
}
StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, int appendChar )
StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar )
{
StrcatExprNode *ret = (StrcatExprNode *) consoleAlloc(sizeof(StrcatExprNode));
constructInPlace(ret);

File diff suppressed because it is too large Load diff

View file

@ -2059,12 +2059,6 @@ yydestruct (yymsg, yytype, yyvaluep)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
default:
break;
}
}

View file

@ -33,7 +33,6 @@
using namespace Compiler;
bool CodeBlock::smInFunction = false;
U32 CodeBlock::smBreakLineCount = 0;
CodeBlock * CodeBlock::smCodeBlockList = NULL;
CodeBlock * CodeBlock::smCurrentCodeBlock = NULL;
ConsoleParser *CodeBlock::smCurrentParser = NULL;
@ -403,14 +402,14 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st)
for(U32 i = 0; i < size; i++)
st.read(&functionFloats[i]);
}
U32 codeSize;
st.read(&codeSize);
U32 codeLength;
st.read(&codeLength);
st.read(&lineBreakPairCount);
U32 totSize = codeSize + lineBreakPairCount * 2;
U32 totSize = codeLength + lineBreakPairCount * 2;
code = new U32[totSize];
for(i = 0; i < codeSize; i++)
for(i = 0; i < codeLength; i++)
{
U8 b;
st.read(&b);
@ -420,10 +419,10 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st)
code[i] = b;
}
for(i = codeSize; i < totSize; i++)
for(i = codeLength; i < totSize; i++)
st.read(&code[i]);
lineBreakPairs = code + codeSize;
lineBreakPairs = code + codeLength;
// StringTable-ize our identifiers.
U32 identCount;
@ -456,6 +455,8 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st)
bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, const char *inScript, bool overrideNoDso)
{
AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
// This will return true, but return value is ignored
char *script;
chompUTF8BOM( inScript, &script );
@ -464,7 +465,7 @@ bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, con
consoleAllocReset();
STEtoU32 = compileSTEtoU32;
STEtoCode = compileSTEtoCode;
gStatementList = NULL;
@ -497,17 +498,23 @@ bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, con
resetTables();
smInFunction = false;
smBreakLineCount = 0;
setBreakCodeBlock(this);
CodeStream codeStream;
U32 lastIp;
if(gStatementList)
codeSize = precompileBlock(gStatementList, 0) + 1;
{
lastIp = compileBlock(gStatementList, codeStream, 0) + 1;
}
else
{
codeSize = 1;
lineBreakPairCount = smBreakLineCount;
code = new U32[codeSize + smBreakLineCount * 2];
lineBreakPairs = code + codeSize;
lastIp = 0;
}
codeStream.emit(OP_RETURN);
codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
lineBreakPairCount = codeStream.getNumLineBreaks();
// Write string table data...
getGlobalStringTable().write(st);
@ -517,18 +524,10 @@ bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, con
getGlobalFloatTable().write(st);
getFunctionFloatTable().write(st);
smBreakLineCount = 0;
U32 lastIp;
if(gStatementList)
lastIp = compileBlock(gStatementList, code, 0, 0, 0);
else
lastIp = 0;
if(lastIp != codeSize - 1)
if(lastIp != codeSize)
Con::errorf(ConsoleLogEntry::General, "CodeBlock::compile - precompile size mismatch, a precompile/compile function pair is probably mismatched.");
code[lastIp++] = OP_RETURN;
U32 totSize = codeSize + smBreakLineCount * 2;
U32 totSize = codeSize + codeStream.getNumLineBreaks() * 2;
st.write(codeSize);
st.write(lineBreakPairCount);
@ -559,13 +558,15 @@ bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, con
}
const char *CodeBlock::compileExec(StringTableEntry fileName, const char *inString, bool noCalls, int setFrame)
const char *CodeBlock::compileExec(StringTableEntry fileName, const char *inString, bool noCalls, S32 setFrame)
{
AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
// Check for a UTF8 script file
char *string;
chompUTF8BOM( inString, &string );
STEtoU32 = evalSTEtoU32;
STEtoCode = evalSTEtoCode;
consoleAllocReset();
name = fileName;
@ -617,12 +618,11 @@ const char *CodeBlock::compileExec(StringTableEntry fileName, const char *inStri
resetTables();
smInFunction = false;
smBreakLineCount = 0;
setBreakCodeBlock(this);
CodeStream codeStream;
U32 lastIp = compileBlock(gStatementList, codeStream, 0);
codeSize = precompileBlock(gStatementList, 0) + 1;
lineBreakPairCount = smBreakLineCount;
lineBreakPairCount = codeStream.getNumLineBreaks();
globalStrings = getGlobalStringTable().build();
globalStringsMaxLen = getGlobalStringTable().totalLen;
@ -632,20 +632,18 @@ const char *CodeBlock::compileExec(StringTableEntry fileName, const char *inStri
globalFloats = getGlobalFloatTable().build();
functionFloats = getFunctionFloatTable().build();
code = new U32[codeSize + lineBreakPairCount * 2];
lineBreakPairs = code + codeSize;
smBreakLineCount = 0;
U32 lastIp = compileBlock(gStatementList, code, 0, 0, 0);
code[lastIp++] = OP_RETURN;
codeStream.emit(OP_RETURN);
codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
//dumpInstructions(0, false);
consoleAllocReset();
if(lineBreakPairCount && fileName)
calcBreakList();
if(lastIp != codeSize)
if(lastIp+1 != codeSize)
Con::warnf(ConsoleLogEntry::General, "precompile size mismatch, precompile: %d compile: %d", codeSize, lastIp);
return exec(0, fileName, NULL, 0, 0, noCalls, NULL, setFrame);
@ -674,7 +672,7 @@ String CodeBlock::getFunctionArgs( U32 ip )
U32 fnArgc = code[ ip + 5 ];
for( U32 i = 0; i < fnArgc; ++ i )
{
StringTableEntry var = U32toSTE( code[ ip + i + 6 ] );
StringTableEntry var = CodeToSTE(code, ip + (i*2) + 6);
if( i != 0 )
str.append( ", " );
@ -696,41 +694,52 @@ String CodeBlock::getFunctionArgs( U32 ip )
void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
{
U32 ip = startIp;
smInFunction = false;
U32 endFuncIp = 0;
while( ip < codeSize )
{
if (ip > endFuncIp)
{
smInFunction = false;
}
switch( code[ ip ++ ] )
{
case OP_FUNC_DECL:
{
StringTableEntry fnName = U32toSTE(code[ip]);
StringTableEntry fnNamespace = U32toSTE(code[ip+1]);
StringTableEntry fnPackage = U32toSTE(code[ip+2]);
bool hasBody = bool(code[ip+3]);
U32 newIp = code[ ip + 4 ];
U32 argc = code[ ip + 5 ];
StringTableEntry fnName = CodeToSTE(code, ip);
StringTableEntry fnNamespace = CodeToSTE(code, ip+2);
StringTableEntry fnPackage = CodeToSTE(code, ip+4);
bool hasBody = bool(code[ip+6]);
U32 newIp = code[ ip + 7 ];
U32 argc = code[ ip + 8 ];
endFuncIp = newIp;
Con::printf( "%i: OP_FUNC_DECL name=%s nspace=%s package=%s hasbody=%i newip=%i argc=%i",
ip - 1, fnName, fnNamespace, fnPackage, hasBody, newIp, argc );
// Skip args.
ip += 6 + argc;
ip += 9 + (argc * 2);
smInFunction = true;
break;
}
case OP_CREATE_OBJECT:
{
StringTableEntry objParent = U32toSTE(code[ip ]);
bool isDataBlock = code[ip + 1];
bool isInternal = code[ip + 2];
bool isSingleton = code[ip + 3];
U32 lineNumber = code[ip + 4];
U32 failJump = code[ip + 5];
StringTableEntry objParent = CodeToSTE(code, ip);
bool isDataBlock = code[ip + 2];
bool isInternal = code[ip + 3];
bool isSingleton = code[ip + 4];
U32 lineNumber = code[ip + 5];
U32 failJump = code[ip + 6];
Con::printf( "%i: OP_CREATE_OBJECT objParent=%s isDataBlock=%i isInternal=%i isSingleton=%i lineNumber=%i failJump=%i",
ip - 1, objParent, isDataBlock, isInternal, isSingleton, lineNumber, failJump );
ip += 6;
ip += 7;
break;
}
@ -977,19 +986,19 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_SETCURVAR:
{
StringTableEntry var = U32toSTE(code[ip]);
StringTableEntry var = CodeToSTE(code, ip);
Con::printf( "%i: OP_SETCURVAR var=%s", ip - 1, var );
ip++;
ip += 2;
break;
}
case OP_SETCURVAR_CREATE:
{
StringTableEntry var = U32toSTE(code[ip]);
StringTableEntry var = CodeToSTE(code, ip);
Con::printf( "%i: OP_SETCURVAR_CREATE var=%s", ip - 1, var );
ip++;
ip += 2;
break;
}
@ -1074,9 +1083,10 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_SETCURFIELD:
{
StringTableEntry curField = U32toSTE(code[ip]);
StringTableEntry curField = CodeToSTE(code, ip);
Con::printf( "%i: OP_SETCURFIELD field=%s", ip - 1, curField );
++ ip;
ip += 2;
break;
}
case OP_SETCURFIELD_ARRAY:
@ -1199,7 +1209,7 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_LOADIMMED_FLT:
{
F64 val = functionFloats[ code[ ip ] ];
F64 val = (smInFunction ? functionFloats : globalFloats)[ code[ ip ] ];
Con::printf( "%i: OP_LOADIMMED_FLT val=%f", ip - 1, val );
++ ip;
break;
@ -1207,7 +1217,7 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_TAG_TO_STR:
{
const char* str = functionStrings + code[ ip ];
const char* str = (smInFunction ? functionStrings : globalStrings) + code[ ip ];
Con::printf( "%i: OP_TAG_TO_STR str=%s", ip - 1, str );
++ ip;
break;
@ -1215,7 +1225,7 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_LOADIMMED_STR:
{
const char* str = functionStrings + code[ ip ];
const char* str = (smInFunction ? functionStrings : globalStrings) + code[ ip ];
Con::printf( "%i: OP_LOADIMMED_STR str=%s", ip - 1, str );
++ ip;
break;
@ -1223,7 +1233,7 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_DOCBLOCK_STR:
{
const char* str = functionStrings + code[ ip ];
const char* str = (smInFunction ? functionStrings : globalStrings) + code[ ip ];
Con::printf( "%i: OP_DOCBLOCK_STR str=%s", ip - 1, str );
++ ip;
break;
@ -1231,37 +1241,37 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_LOADIMMED_IDENT:
{
StringTableEntry str = U32toSTE( code[ ip ] );
StringTableEntry str = CodeToSTE(code, ip);
Con::printf( "%i: OP_LOADIMMED_IDENT str=%s", ip - 1, str );
++ ip;
ip += 2;
break;
}
case OP_CALLFUNC_RESOLVE:
{
StringTableEntry fnNamespace = U32toSTE(code[ip+1]);
StringTableEntry fnName = U32toSTE(code[ip]);
StringTableEntry fnNamespace = CodeToSTE(code, ip+2);
StringTableEntry fnName = CodeToSTE(code, ip);
U32 callType = code[ip+2];
Con::printf( "%i: OP_CALLFUNC_RESOLVE name=%s nspace=%s callType=%s", ip - 1, fnName, fnNamespace,
callType == FuncCallExprNode::FunctionCall ? "FunctionCall"
: callType == FuncCallExprNode::MethodCall ? "MethodCall" : "ParentCall" );
ip += 3;
ip += 5;
break;
}
case OP_CALLFUNC:
{
StringTableEntry fnNamespace = U32toSTE(code[ip+1]);
StringTableEntry fnName = U32toSTE(code[ip]);
U32 callType = code[ip+2];
StringTableEntry fnNamespace = CodeToSTE(code, ip+2);
StringTableEntry fnName = CodeToSTE(code, ip);
U32 callType = code[ip+4];
Con::printf( "%i: OP_CALLFUNC name=%s nspace=%s callType=%s", ip - 1, fnName, fnNamespace,
callType == FuncCallExprNode::FunctionCall ? "FunctionCall"
: callType == FuncCallExprNode::MethodCall ? "MethodCall" : "ParentCall" );
ip += 3;
ip += 5;
break;
}
@ -1341,7 +1351,7 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_ASSERT:
{
const char* message = functionStrings + code[ ip ];
const char* message = (smInFunction ? functionStrings : globalStrings) + code[ ip ];
Con::printf( "%i: OP_ASSERT message=%s", ip - 1, message );
++ ip;
break;
@ -1355,31 +1365,34 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
case OP_ITER_BEGIN:
{
StringTableEntry varName = U32toSTE( code[ ip ] );
U32 failIp = code[ ip + 1 ];
StringTableEntry varName = CodeToSTE(code, ip);
U32 failIp = code[ ip + 2 ];
Con::printf( "%i: OP_ITER_BEGIN varName=%s failIp=%i", varName, failIp );
Con::printf( "%i: OP_ITER_BEGIN varName=%s failIp=%i", ip - 1, varName, failIp );
++ ip;
ip += 3;
break;
}
case OP_ITER_BEGIN_STR:
{
StringTableEntry varName = U32toSTE( code[ ip ] );
U32 failIp = code[ ip + 1 ];
StringTableEntry varName = CodeToSTE(code, ip);
U32 failIp = code[ ip + 2 ];
Con::printf( "%i: OP_ITER_BEGIN varName=%s failIp=%i", varName, failIp );
Con::printf( "%i: OP_ITER_BEGIN varName=%s failIp=%i", ip - 1, varName, failIp );
ip += 2;
ip += 3;
break;
}
case OP_ITER:
{
U32 breakIp = code[ ip ];
Con::printf( "%i: OP_ITER breakIp=%i", breakIp );
Con::printf( "%i: OP_ITER breakIp=%i", ip - 1, breakIp );
++ ip;
break;
}
case OP_ITER_END:
@ -1393,4 +1406,6 @@ void CodeBlock::dumpInstructions( U32 startIp, bool upToReturn )
break;
}
}
smInFunction = false;
}

View file

@ -40,7 +40,6 @@ private:
static CodeBlock* smCurrentCodeBlock;
public:
static U32 smBreakLineCount;
static bool smInFunction;
static Compiler::ConsoleParser * smCurrentParser;
@ -131,7 +130,7 @@ public:
/// -1 a new frame is created. If the index is out of range the
/// top stack frame is used.
const char *compileExec(StringTableEntry fileName, const char *script,
bool noCalls, int setFrame = -1 );
bool noCalls, S32 setFrame = -1 );
/// Executes the existing code in the CodeBlock. The return string is any
/// result of the code executed, if any, or an empty string.

View file

@ -45,6 +45,9 @@
#include "materials/materialManager.h"
#endif
// Uncomment to optimize function calls at the expense of potential invalid package lookups
//#define COMPILER_OPTIMIZE_FUNCTION_CALLS
using namespace Compiler;
enum EvalConstants {
@ -444,8 +447,8 @@ ConsoleValueRef CodeBlock::exec(U32 ip, const char *functionName, Namespace *thi
if(argv)
{
// assume this points into a function decl:
U32 fnArgc = code[ip + 5];
thisFunctionName = U32toSTE(code[ip]);
U32 fnArgc = code[ip + 2 + 6];
thisFunctionName = CodeToSTE(code, ip);
S32 wantedArgc = getMin(argc-1, fnArgc); // argv[0] is func name
if(gEvalState.traceOn)
{
@ -481,7 +484,7 @@ ConsoleValueRef CodeBlock::exec(U32 ip, const char *functionName, Namespace *thi
for(i = 0; i < wantedArgc; i++)
{
StringTableEntry var = U32toSTE(code[ip + i + 6]);
StringTableEntry var = CodeToSTE(code, ip + (2 + 6 + 1) + (i * 2));
gEvalState.setCurVarNameCreate(var);
ConsoleValueRef ref = argv[i+1];
@ -495,7 +498,7 @@ ConsoleValueRef CodeBlock::exec(U32 ip, const char *functionName, Namespace *thi
else
gEvalState.setStringVariable(argv[i+1]);
}
ip = ip + fnArgc + 6;
ip = ip + (fnArgc * 2) + (2 + 6 + 1);
curFloatTable = functionFloats;
curStringTable = functionStrings;
curStringTableLen = functionStringsMaxLen;
@ -600,11 +603,11 @@ breakContinue:
case OP_FUNC_DECL:
if(!noCalls)
{
fnName = U32toSTE(code[ip]);
fnNamespace = U32toSTE(code[ip+1]);
fnPackage = U32toSTE(code[ip+2]);
bool hasBody = ( code[ ip + 3 ] & 0x01 ) != 0;
U32 lineNumber = code[ ip + 3 ] >> 1;
fnName = CodeToSTE(code, ip);
fnNamespace = CodeToSTE(code, ip+2);
fnPackage = CodeToSTE(code, ip+4);
bool hasBody = ( code[ ip + 6 ] & 0x01 ) != 0;
U32 lineNumber = code[ ip + 6 ] >> 1;
Namespace::unlinkPackages();
ns = Namespace::find(fnNamespace, fnPackage);
@ -627,18 +630,18 @@ breakContinue:
//Con::printf("Adding function %s::%s (%d)", fnNamespace, fnName, ip);
}
ip = code[ip + 4];
ip = code[ip + 7];
break;
case OP_CREATE_OBJECT:
{
// Read some useful info.
objParent = U32toSTE(code[ip ]);
bool isDataBlock = code[ip + 1];
bool isInternal = code[ip + 2];
bool isSingleton = code[ip + 3];
U32 lineNumber = code[ip + 4];
failJump = code[ip + 5];
objParent = CodeToSTE(code, ip);
bool isDataBlock = code[ip + 2];
bool isInternal = code[ip + 3];
bool isSingleton = code[ip + 4];
U32 lineNumber = code[ip + 5];
failJump = code[ip + 6];
// If we don't allow calls, we certainly don't allow creating objects!
// Moved this to after failJump is set. Engine was crashing when
@ -692,6 +695,15 @@ breakContinue:
// IF we aren't looking at a local/internal object, then check if
// this object already exists in the global space
AbstractClassRep* rep = AbstractClassRep::findClassRep( objectName );
if (rep != NULL) {
Con::errorf(ConsoleLogEntry::General, "%s: Cannot name object [%s] the same name as a script class.",
getFileLine(ip), objectName);
ip = failJump;
STR.popFrame();
break;
}
SimObject *obj = Sim::findObject( (const char*)objectName );
if (obj /*&& !obj->isLocalName()*/)
{
@ -916,7 +928,7 @@ breakContinue:
}
// Advance the IP past the create info...
ip += 6;
ip += 7;
break;
}
@ -1298,8 +1310,8 @@ breakContinue:
break;
case OP_SETCURVAR:
var = U32toSTE(code[ip]);
ip++;
var = CodeToSTE(code, ip);
ip += 2;
// If a variable is set, then these must be NULL. It is necessary
// to set this here so that the vector parser can appropriately
@ -1318,8 +1330,8 @@ breakContinue:
break;
case OP_SETCURVAR_CREATE:
var = U32toSTE(code[ip]);
ip++;
var = CodeToSTE(code, ip);
ip += 2;
// See OP_SETCURVAR
prevField = NULL;
@ -1448,9 +1460,9 @@ breakContinue:
// Save the previous field for parsing vector fields.
prevField = curField;
dStrcpy( prevFieldArray, curFieldArray );
curField = U32toSTE(code[ip]);
curField = CodeToSTE(code, ip);
curFieldArray[0] = 0;
ip++;
ip += 2;
break;
case OP_SETCURFIELD_ARRAY:
@ -1646,29 +1658,41 @@ breakContinue:
break;
case OP_LOADIMMED_IDENT:
STR.setStringValue(U32toSTE(code[ip++]));
STR.setStringValue(CodeToSTE(code, ip));
ip += 2;
break;
case OP_CALLFUNC_RESOLVE:
// This deals with a function that is potentially living in a namespace.
fnNamespace = U32toSTE(code[ip+1]);
fnName = U32toSTE(code[ip]);
fnNamespace = CodeToSTE(code, ip+2);
fnName = CodeToSTE(code, ip);
// Try to look it up.
ns = Namespace::find(fnNamespace);
nsEntry = ns->lookup(fnName);
if(!nsEntry)
{
ip+= 3;
ip+= 5;
Con::warnf(ConsoleLogEntry::General,
"%s: Unable to find function %s%s%s",
getFileLine(ip-4), fnNamespace ? fnNamespace : "",
getFileLine(ip-7), fnNamespace ? fnNamespace : "",
fnNamespace ? "::" : "", fnName);
STR.popFrame();
CSTK.popFrame();
break;
}
#ifdef COMPILER_OPTIMIZE_FUNCTION_CALLS
// Now fall through to OP_CALLFUNC...
// Now, rewrite our code a bit (ie, avoid future lookups) and fall
// through to OP_CALLFUNC
#ifdef TORQUE_CPU_X64
*((U64*)(code+ip+2)) = ((U64)nsEntry);
#else
code[ip+2] = ((U32)nsEntry);
#endif
code[ip-1] = OP_CALLFUNC;
#endif
case OP_CALLFUNC:
{
@ -1678,7 +1702,7 @@ breakContinue:
// or just on the object.
S32 routingId = 0;
fnName = U32toSTE(code[ip]);
fnName = CodeToSTE(code, ip);
//if this is called from inside a function, append the ip and codeptr
if( gEvalState.getStackDepth() > 0 )
@ -1687,9 +1711,9 @@ breakContinue:
gEvalState.getCurrentFrame().ip = ip - 1;
}
U32 callType = code[ip+2];
U32 callType = code[ip+4];
ip += 3;
ip += 5;
CSTK.getArgcArgv(fnName, &callArgc, &callArgv);
const char *componentReturnValue = "";
@ -1698,9 +1722,16 @@ breakContinue:
{
if( !nsEntry )
{
// We must not have come from OP_CALLFUNC_RESOLVE, so figure out
// our own entry.
#ifdef COMPILER_OPTIMIZE_FUNCTION_CALLS
#ifdef TORQUE_CPU_X64
nsEntry = ((Namespace::Entry *) *((U64*)(code+ip-3)));
#else
nsEntry = ((Namespace::Entry *) *(code+ip-3));
#endif
#else
nsEntry = Namespace::global()->lookup( fnName );
#endif
ns = NULL;
}
ns = NULL;
}
@ -1762,7 +1793,7 @@ breakContinue:
{
if(!noCalls && !( routingId == MethodOnComponent ) )
{
Con::warnf(ConsoleLogEntry::General,"%s: Unknown command %s.", getFileLine(ip-4), fnName);
Con::warnf(ConsoleLogEntry::General,"%s: Unknown command %s.", getFileLine(ip-6), fnName);
if(callType == FuncCallExprNode::MethodCall)
{
Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
@ -1815,16 +1846,16 @@ breakContinue:
// which is useful behavior when debugging so I'm ifdefing this out for debug builds.
if(nsEntry->mToolOnly && ! Con::isCurrentScriptToolScript())
{
Con::errorf(ConsoleLogEntry::Script, "%s: %s::%s - attempting to call tools only function from outside of tools.", getFileLine(ip-4), nsName, fnName);
Con::errorf(ConsoleLogEntry::Script, "%s: %s::%s - attempting to call tools only function from outside of tools.", getFileLine(ip-6), nsName, fnName);
}
else
#endif
if((nsEntry->mMinArgs && S32(callArgc) < nsEntry->mMinArgs) || (nsEntry->mMaxArgs && S32(callArgc) > nsEntry->mMaxArgs))
{
Con::warnf(ConsoleLogEntry::Script, "%s: %s::%s - wrong number of arguments (got %i, expected min %i and max %i).",
getFileLine(ip-4), nsName, fnName,
getFileLine(ip-6), nsName, fnName,
callArgc, nsEntry->mMinArgs, nsEntry->mMaxArgs);
Con::warnf(ConsoleLogEntry::Script, "%s: usage: %s", getFileLine(ip-4), nsEntry->mUsage);
Con::warnf(ConsoleLogEntry::Script, "%s: usage: %s", getFileLine(ip-6), nsEntry->mUsage);
STR.popFrame();
CSTK.popFrame();
}
@ -1892,7 +1923,7 @@ breakContinue:
case Namespace::Entry::VoidCallbackType:
nsEntry->cb.mVoidCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
if( code[ ip ] != OP_STR_TO_NONE && Con::getBoolVariable( "$Con::warnVoidAssignment", true ) )
Con::warnf(ConsoleLogEntry::General, "%s: Call to %s in %s uses result of void function call.", getFileLine(ip-4), fnName, functionName);
Con::warnf(ConsoleLogEntry::General, "%s: Call to %s in %s uses result of void function call.", getFileLine(ip-6), fnName, functionName);
STR.popFrame();
CSTK.popFrame();
@ -2029,8 +2060,8 @@ breakContinue:
case OP_ITER_BEGIN:
{
StringTableEntry varName = U32toSTE( code[ ip ] );
U32 failIp = code[ ip + 1 ];
StringTableEntry varName = CodeToSTE(code, ip);
U32 failIp = code[ ip + 2 ];
IterStackRecord& iter = iterStack[ _ITER ];
@ -2065,7 +2096,7 @@ breakContinue:
STR.push();
ip += 2;
ip += 3;
break;
}

View file

@ -23,7 +23,6 @@
#include "platform/platform.h"
#include "console/console.h"
#include "console/telnetDebugger.h"
#include "platform/event.h"
#include "console/ast.h"
#include "core/tAlgorithm.h"
@ -61,29 +60,27 @@ namespace Compiler
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
DataChunker gConsoleAllocator;
CompilerIdentTable gIdentTable;
CodeBlock *gCurBreakBlock;
//------------------------------------------------------------
CodeBlock *getBreakCodeBlock() { return gCurBreakBlock; }
void setBreakCodeBlock(CodeBlock *cb) { gCurBreakBlock = cb; }
//------------------------------------------------------------
U32 evalSTEtoU32(StringTableEntry ste, U32)
void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
{
return *((U32 *) &ste);
#ifdef TORQUE_CPU_X64
*(U64*)(ptr) = (U64)ste;
#else
*ptr = (U32)ste;
#endif
}
U32 compileSTEtoU32(StringTableEntry ste, U32 ip)
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
{
if(ste)
getIdentTable().add(ste, ip);
return 0;
*ptr = 0;
*(ptr+1) = 0;
}
U32 (*STEtoU32)(StringTableEntry ste, U32 ip) = evalSTEtoU32;
void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
//------------------------------------------------------------
@ -287,3 +284,131 @@ void CompilerIdentTable::write(Stream &st)
st.write(el->ip);
}
}
//-------------------------------------------------------------------------
U8 *CodeStream::allocCode(U32 sz)
{
U8 *ptr = NULL;
if (mCodeHead)
{
const U32 bytesLeft = BlockSize - mCodeHead->size;
if (bytesLeft > sz)
{
ptr = mCodeHead->data + mCodeHead->size;
mCodeHead->size += sz;
return ptr;
}
}
CodeData *data = new CodeData;
data->data = (U8*)dMalloc(BlockSize);
data->size = sz;
data->next = NULL;
if (mCodeHead)
mCodeHead->next = data;
mCodeHead = data;
if (mCode == NULL)
mCode = data;
return data->data;
}
//-------------------------------------------------------------------------
void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
{
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
U32 fixStart = mFixStack[mFixStack.size()-1];
for (U32 i=fixStart; i<mFixList.size(); i += 2)
{
FixType type = (FixType)mFixList[i+1];
U32 fixedIp = 0;
bool valid = true;
switch (type)
{
case FIXTYPE_LOOPBLOCKSTART:
fixedIp = loopBlockStart;
break;
case FIXTYPE_BREAK:
fixedIp = breakPoint;
break;
case FIXTYPE_CONTINUE:
fixedIp = continuePoint;
break;
default:
//Con::warnf("Address %u fixed as %u", mFixList[i], mFixList[i+1]);
valid = false;
break;
}
if (valid)
{
patch(mFixList[i], fixedIp);
}
}
}
//-------------------------------------------------------------------------
void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
{
// Alloc stream
U32 numLineBreaks = getNumLineBreaks();
*stream = new U32[mCodePos + (numLineBreaks * 2)];
dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2));
*size = mCodePos;
// Dump chunks & line breaks
U32 outBytes = mCodePos * sizeof(U32);
U8 *outPtr = *((U8**)stream);
for (CodeData *itr = mCode; itr != NULL; itr = itr->next)
{
U32 bytesToCopy = itr->size > outBytes ? outBytes : itr->size;
dMemcpy(outPtr, itr->data, bytesToCopy);
outPtr += bytesToCopy;
outBytes -= bytesToCopy;
}
*lineBreaks = *stream + mCodePos;
dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size());
// Apply patches on top
for (U32 i=0; i<mPatchList.size(); i++)
{
PatchEntry &e = mPatchList[i];
(*stream)[e.addr] = e.value;
}
}
//-------------------------------------------------------------------------
void CodeStream::reset()
{
mCodePos = 0;
mFixStack.clear();
mFixLoopStack.clear();
mFixList.clear();
mBreakLines.clear();
// Pop down to one code block
CodeData *itr = mCode ? mCode->next : NULL;
while (itr != NULL)
{
CodeData *next = itr->next;
dFree(itr->data);
dFree(itr);
itr = next;
}
if (mCode)
{
mCode->size = 0;
mCode->next = NULL;
mCodeHead = mCode;
}
}

View file

@ -24,6 +24,12 @@
#ifndef _COMPILER_H_
#define _COMPILER_H_
//#define DEBUG_CODESTREAM
#ifdef DEBUG_CODESTREAM
#include <stdio.h>
#endif
class Stream;
class DataChunker;
@ -31,6 +37,9 @@ class DataChunker;
#include "console/ast.h"
#include "console/codeBlock.h"
#ifndef _TVECTOR_H_
#include "core/util/tVector.h"
#endif
namespace Compiler
{
@ -49,7 +58,7 @@ namespace Compiler
OP_JMPIFF,
OP_JMPIF,
OP_JMPIFNOT_NP,
OP_JMPIF_NP,
OP_JMPIF_NP, // 10
OP_JMP,
OP_RETURN,
// fixes a bug when not explicitly returning a value
@ -63,7 +72,7 @@ namespace Compiler
OP_CMPLT,
OP_CMPLE,
OP_CMPNE,
OP_XOR,
OP_XOR, // 20
OP_MOD,
OP_BITAND,
OP_BITOR,
@ -74,7 +83,7 @@ namespace Compiler
OP_SHR,
OP_SHL,
OP_AND,
OP_OR,
OP_OR, // 30
OP_ADD,
OP_SUB,
@ -87,7 +96,7 @@ namespace Compiler
OP_SETCURVAR_ARRAY,
OP_SETCURVAR_ARRAY_CREATE,
OP_LOADVAR_UINT,
OP_LOADVAR_UINT,// 40
OP_LOADVAR_FLT,
OP_LOADVAR_STR,
OP_LOADVAR_VAR,
@ -102,7 +111,7 @@ namespace Compiler
OP_SETCUROBJECT_INTERNAL,
OP_SETCURFIELD,
OP_SETCURFIELD_ARRAY,
OP_SETCURFIELD_ARRAY, // 50
OP_SETCURFIELD_TYPE,
OP_LOADFIELD_UINT,
@ -115,7 +124,7 @@ namespace Compiler
OP_STR_TO_UINT,
OP_STR_TO_FLT,
OP_STR_TO_NONE,
OP_STR_TO_NONE, // 60
OP_FLT_TO_UINT,
OP_FLT_TO_STR,
OP_FLT_TO_NONE,
@ -127,7 +136,7 @@ namespace Compiler
OP_LOADIMMED_UINT,
OP_LOADIMMED_FLT,
OP_TAG_TO_STR,
OP_LOADIMMED_STR,
OP_LOADIMMED_STR, // 70
OP_DOCBLOCK_STR,
OP_LOADIMMED_IDENT,
@ -139,7 +148,7 @@ namespace Compiler
OP_ADVANCE_STR_COMMA,
OP_ADVANCE_STR_NUL,
OP_REWIND_STR,
OP_TERMINATE_REWIND_STR,
OP_TERMINATE_REWIND_STR, // 80
OP_COMPARE_STR,
OP_PUSH, // String
@ -156,14 +165,14 @@ namespace Compiler
OP_ITER, ///< Enter foreach loop.
OP_ITER_END, ///< End foreach loop.
OP_INVALID
OP_INVALID // 90
};
//------------------------------------------------------------
F64 consoleStringToNumber(const char *str, StringTableEntry file = 0, U32 line = 0);
U32 precompileBlock(StmtNode *block, U32 loopCount);
U32 compileBlock(StmtNode *block, U32 *codeStream, U32 ip, U32 continuePoint, U32 breakPoint);
U32 compileBlock(StmtNode *block, CodeStream &codeStream, U32 ip);
//------------------------------------------------------------
@ -227,15 +236,19 @@ namespace Compiler
//------------------------------------------------------------
inline StringTableEntry U32toSTE(U32 u)
inline StringTableEntry CodeToSTE(U32 *code, U32 ip)
{
return *((StringTableEntry *) &u);
#ifdef TORQUE_CPU_X64
return (StringTableEntry)(*((U64*)(code+ip)));
#else
return (StringTableEntry)(*(code+ip));
#endif
}
extern U32 (*STEtoU32)(StringTableEntry ste, U32 ip);
U32 evalSTEtoU32(StringTableEntry ste, U32);
U32 compileSTEtoU32(StringTableEntry ste, U32 ip);
extern void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr);
void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
CompilerStringTable *getCurrentStringTable();
CompilerStringTable &getGlobalStringTable();
@ -253,9 +266,6 @@ namespace Compiler
void precompileIdent(StringTableEntry ident);
CodeBlock *getBreakCodeBlock();
void setBreakCodeBlock(CodeBlock *cb);
/// Helper function to reset the float, string, and ident tables to a base
/// starting state.
void resetTables();
@ -266,4 +276,170 @@ namespace Compiler
extern bool gSyntaxError;
};
/// Utility class to emit and patch bytecode
class CodeStream
{
public:
enum FixType
{
// For loops
FIXTYPE_LOOPBLOCKSTART,
FIXTYPE_BREAK,
FIXTYPE_CONTINUE
};
enum Constants
{
BlockSize = 16384,
};
protected:
typedef struct PatchEntry
{
U32 addr; ///< Address to patch
U32 value; ///< Value to place at addr
PatchEntry() {;}
PatchEntry(U32 a, U32 v) : addr(a), value(v) {;}
} PatchEntry;
typedef struct CodeData
{
U8 *data; ///< Allocated data (size is BlockSize)
U32 size; ///< Bytes used in data
CodeData *next; ///< Next block
};
/// @name Emitted code
/// {
CodeData *mCode;
CodeData *mCodeHead;
U32 mCodePos;
/// }
/// @name Code fixing stacks
/// {
Vector<U32> mFixList;
Vector<U32> mFixStack;
Vector<bool> mFixLoopStack;
Vector<PatchEntry> mPatchList;
/// }
Vector<U32> mBreakLines; ///< Line numbers
public:
CodeStream() : mCode(0), mCodeHead(NULL), mCodePos(0)
{
}
~CodeStream()
{
reset();
if (mCode)
{
dFree(mCode->data);
delete mCode;
}
}
U8 *allocCode(U32 sz);
inline U32 emit(U32 code)
{
U32 *ptr = (U32*)allocCode(4);
*ptr = code;
#ifdef DEBUG_CODESTREAM
printf("code[%u] = %u\n", mCodePos, code);
#endif
return mCodePos++;
}
inline void patch(U32 addr, U32 code)
{
#ifdef DEBUG_CODESTREAM
printf("patch[%u] = %u\n", addr, code);
#endif
mPatchList.push_back(PatchEntry(addr, code));
}
inline U32 emitSTE(const char *code)
{
U64 *ptr = (U64*)allocCode(8);
*ptr = 0;
Compiler::STEtoCode(code, mCodePos, (U32*)ptr);
#ifdef DEBUG_CODESTREAM
printf("code[%u] = %s\n", mCodePos, code);
#endif
mCodePos += 2;
return mCodePos-2;
}
inline U32 tell()
{
return mCodePos;
}
inline bool inLoop()
{
for (U32 i=0; i<mFixLoopStack.size(); i++)
{
if (mFixLoopStack[i])
return true;
}
return false;
}
inline U32 emitFix(FixType type)
{
U32 *ptr = (U32*)allocCode(4);
*ptr = (U32)type;
#ifdef DEBUG_CODESTREAM
printf("code[%u] = [FIX:%u]\n", mCodePos, (U32)type);
#endif
mFixList.push_back(mCodePos);
mFixList.push_back((U32)type);
return mCodePos++;
}
inline void pushFixScope(bool isLoop)
{
mFixStack.push_back(mFixList.size());
mFixLoopStack.push_back(isLoop);
}
inline void popFixScope()
{
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
U32 newSize = mFixStack[mFixStack.size()-1];
while (mFixList.size() > newSize)
mFixList.pop_back();
mFixStack.pop_back();
mFixLoopStack.pop_back();
}
void fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint);
inline void addBreakLine(U32 lineNumber, U32 ip)
{
mBreakLines.push_back(lineNumber);
mBreakLines.push_back(ip);
}
inline U32 getNumLineBreaks()
{
return mBreakLines.size() / 2;
}
void emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks);
void reset();
};
#endif

View file

@ -249,7 +249,7 @@ static bool active = false;
static bool newLogFile;
static const char *logFileName;
static const int MaxCompletionBufferSize = 4096;
static const S32 MaxCompletionBufferSize = 4096;
static char completionBuffer[MaxCompletionBufferSize];
static char tabBuffer[MaxCompletionBufferSize] = {0};
static SimObjectPtr<SimObject> tabObject;
@ -1430,8 +1430,9 @@ const char *getFormattedData(S32 type, const char *data, const EnumTable *tbl, B
Con::setData(type, variable, 0, 1, &data, tbl, flag);
const char* formattedVal = Con::getData(type, variable, 0, tbl, flag);
char* returnBuffer = Con::getReturnBuffer(2048);
dSprintf(returnBuffer, 2048, "%s\0", formattedVal );
static const U32 bufSize = 2048;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%s\0", formattedVal );
cbt->deleteNativeVariable(variable);

View file

@ -364,8 +364,9 @@ namespace Con
/// 09/12/07 - CAF - 43->44 remove newmsg operator
/// 09/27/07 - RDB - 44->45 Patch from Andreas Kirsch: Added opcode to support correct void return
/// 01/13/09 - TMS - 45->46 Added script assert
/// 10/11/12 - JU - 46->47 Added opcodes to reduce reliance on strings in function calls
DSOVersion = 47,
/// 09/07/14 - jamesu - 46->47 64bit support
/// 10/14/14 - jamesu - 47->48 Added opcodes to reduce reliance on strings in function calls
DSOVersion = 48,
MaxLineLength = 512, ///< Maximum length of a line of console input.
MaxDataTypes = 256 ///< Maximum number of registered data types.
@ -888,7 +889,7 @@ namespace Con
extern void expandEscape(char *dest, const char *src);
extern bool collapseEscape(char *buf);
extern S32 HashPointer(StringTableEntry ptr);
extern U32 HashPointer(StringTableEntry ptr);
/// Extended information about a console function.

View file

@ -223,7 +223,7 @@ void Namespace::printNamespaceEntries(Namespace * g, bool dumpScript, bool dumpE
// Iterate through the methods of the namespace...
for(Entry *ewalk = g->mEntryList; ewalk; ewalk = ewalk->mNext)
{
int eType = ewalk->mType;
S32 eType = ewalk->mType;
const char * funcName = ewalk->mFunctionName;
if( ( eType == Entry::ConsoleFunctionType ) && !dumpScript )

View file

@ -30,7 +30,6 @@
#include "core/strings/unicode.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "core/util/journal/journal.h"
#include "core/util/uuid.h"
@ -76,7 +75,8 @@ DefineConsoleFunction( strformat, const char*, ( const char* format, const char*
"@ingroup Strings\n"
"@see http://en.wikipedia.org/wiki/Printf" )
{
char* pBuffer = Con::getReturnBuffer(64);
static const U32 bufSize = 64;
char* pBuffer = Con::getReturnBuffer(bufSize);
const char *pch = format;
pBuffer[0] = '\0';
@ -100,7 +100,7 @@ DefineConsoleFunction( strformat, const char*, ( const char* format, const char*
case 'u':
case 'x':
case 'X':
dSprintf( pBuffer, 64, format, dAtoi( value ) );
dSprintf( pBuffer, bufSize, format, dAtoi( value ) );
break;
case 'e':
@ -108,7 +108,7 @@ DefineConsoleFunction( strformat, const char*, ( const char* format, const char*
case 'f':
case 'g':
case 'G':
dSprintf( pBuffer, 64, format, dAtof( value ) );
dSprintf( pBuffer, bufSize, format, dAtof( value ) );
break;
default:
@ -260,7 +260,7 @@ DefineConsoleFunction( strstr, S32, ( const char* string, const char* substring
//-----------------------------------------------------------------------------
DefineConsoleFunction( strpos, S32, ( const char* haystack, const char* needle, int offset ), ( 0 ),
DefineConsoleFunction( strpos, S32, ( const char* haystack, const char* needle, S32 offset ), ( 0 ),
"Find the start of @a needle in @a haystack searching from left to right beginning at the given offset.\n"
"@param haystack The string to search.\n"
"@param needle The string to search for.\n"
@ -480,7 +480,7 @@ DefineConsoleFunction( strreplace, const char*, ( const char* source, const char
if(!scan)
{
dStrcpy(ret + dstp, source + scanp);
return ret;
break;
}
U32 len = scan - (source + scanp);
dStrncpy(ret + dstp, source + scanp, len);
@ -1585,15 +1585,22 @@ DefineEngineFunction( gotoWebPage, void, ( const char* address ),,
//-----------------------------------------------------------------------------
DefineEngineFunction( displaySplashWindow, bool, (),,
DefineEngineFunction( displaySplashWindow, bool, (const char* path), ("art/gui/splash.bmp"),
"Display a startup splash window suitable for showing while the engine still starts up.\n\n"
"@note This is currently only implemented on Windows.\n\n"
"@return True if the splash window could be successfully initialized.\n\n"
"@ingroup Platform" )
{
return Platform::displaySplashWindow();
return Platform::displaySplashWindow(path);
}
DefineEngineFunction( closeSplashWindow, void, (),,
"Close our startup splash window.\n\n"
"@note This is currently only implemented on Windows.\n\n"
"@ingroup Platform" )
{
Platform::closeSplashWindow();
}
//-----------------------------------------------------------------------------
DefineEngineFunction( getWebDeployment, bool, (),,
@ -2028,8 +2035,10 @@ DefineEngineFunction( exec, bool, ( const char* fileName, bool noCalls, bool jou
//}
// If we had a DSO, let's check to see if we should be reading from it.
if(compiled && dsoFile != NULL && (scriptFile == NULL|| (scriptModifiedTime - dsoModifiedTime) > Torque::Time(0)))
{
//MGT: fixed bug with dsos not getting recompiled correctly
//Note: Using Nathan Martin's version from the forums since its easier to read and understand
if(compiled && dsoFile != NULL && (scriptFile == NULL|| (dsoModifiedTime >= scriptModifiedTime)))
{ //MGT: end
compiledStream = FileStream::createAndOpen( nameBuffer, Torque::FS::File::Read );
if (compiledStream)
{

View file

@ -261,9 +261,9 @@ void Dictionary::deleteVariables(const char *varString)
}
}
S32 HashPointer(StringTableEntry ptr)
U32 HashPointer(StringTableEntry ptr)
{
return (S32)(((dsize_t)ptr) >> 2);
return (U32)(((dsize_t)ptr) >> 2);
}
Dictionary::Entry *Dictionary::lookup(StringTableEntry name)

View file

@ -175,7 +175,7 @@ bool ConsoleLogger::detach()
mStream.close();
// Remove this object from the list of active loggers
for( int i = 0; i < mActiveLoggers.size(); i++ )
for( S32 i = 0; i < mActiveLoggers.size(); i++ )
{
if( mActiveLoggers[i] == this )
{

View file

@ -29,6 +29,7 @@
#include "core/color.h"
#include "console/simBase.h"
#include "math/mRect.h"
#include "core/strings/stringUnit.h"
//-----------------------------------------------------------------------------
// TypeString
@ -288,8 +289,9 @@ ImplementConsoleTypeCasters( TypeS8, S8 )
ConsoleGetType( TypeS8 )
{
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%d", *((U8 *) dptr) );
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%d", *((U8 *) dptr) );
return returnBuffer;
}
@ -309,8 +311,9 @@ ImplementConsoleTypeCasters(TypeS32, S32)
ConsoleGetType( TypeS32 )
{
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%d", *((S32 *) dptr) );
static const U32 bufSize = 512;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%d", *((S32 *) dptr) );
return returnBuffer;
}
@ -388,8 +391,9 @@ ImplementConsoleTypeCasters(TypeF32, F32)
ConsoleGetType( TypeF32 )
{
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%g", *((F32 *) dptr) );
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%g", *((F32 *) dptr) );
return returnBuffer;
}
ConsoleSetType( TypeF32 )
@ -486,8 +490,9 @@ ImplementConsoleTypeCasters( TypeBoolVector, Vector< bool > )
ConsoleGetType( TypeBoolVector )
{
Vector<bool> *vec = (Vector<bool>*)dptr;
char* returnBuffer = Con::getReturnBuffer(1024);
S32 maxReturn = 1024;
static const U32 bufSize = 1024;
char* returnBuffer = Con::getReturnBuffer(bufSize);
S32 maxReturn = bufSize;
returnBuffer[0] = '\0';
S32 returnLeng = 0;
for (Vector<bool>::iterator itr = vec->begin(); itr < vec->end(); itr++)
@ -567,9 +572,20 @@ ImplementConsoleTypeCasters( TypeColorF, ColorF )
ConsoleGetType( TypeColorF )
{
ColorF * color = (ColorF*)dptr;
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%g %g %g %g", color->red, color->green, color->blue, color->alpha);
// Fetch color.
const ColorF* color = (ColorF*)dptr;
// Fetch stock color name.
StringTableEntry colorName = StockColor::name( *color );
// Write as color name if was found.
if ( colorName != StringTable->EmptyString() )
return colorName;
// Format as color components.
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%g %g %g %g", color->red, color->green, color->blue, color->alpha);
return(returnBuffer);
}
@ -578,6 +594,22 @@ ConsoleSetType( TypeColorF )
ColorF *tmpColor = (ColorF *) dptr;
if(argc == 1)
{
// Is only a single argument passed?
if ( StringUnit::getUnitCount( argv[0], " " ) == 1 )
{
// Is this a stock color name?
if ( !StockColor::isColor(argv[0]) )
{
// No, so warn.
Con::warnf( "TypeColorF() - Invalid single argument of '%s' could not be interpreted as a stock color name. Using default.", argv[0] );
}
// Set stock color (if it's invalid we'll get the default.
tmpColor->set( argv[0] );
return;
}
tmpColor->set(0, 0, 0, 1);
F32 r,g,b,a;
S32 args = dSscanf(argv[0], "%g %g %g %g", &r, &g, &b, &a);
@ -602,7 +634,7 @@ ConsoleSetType( TypeColorF )
tmpColor->alpha = dAtof(argv[3]);
}
else
Con::printf("Color must be set as { r, g, b [,a] }");
Con::printf("Color must be set as { r, g, b [,a] }, { r g b [b] } or { stockColorName }");
}
//-----------------------------------------------------------------------------
@ -613,9 +645,20 @@ ImplementConsoleTypeCasters( TypeColorI, ColorI )
ConsoleGetType( TypeColorI )
{
ColorI *color = (ColorI *) dptr;
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%d %d %d %d", color->red, color->green, color->blue, color->alpha);
// Fetch color.
ColorI* color = (ColorI*)dptr;
// Fetch stock color name.
StringTableEntry colorName = StockColor::name( *color );
// Write as color name if was found.
if ( colorName != StringTable->EmptyString() )
return colorName;
// Format as color components.
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%d %d %d %d", color->red, color->green, color->blue, color->alpha);
return returnBuffer;
}
@ -624,6 +667,22 @@ ConsoleSetType( TypeColorI )
ColorI *tmpColor = (ColorI *) dptr;
if(argc == 1)
{
// Is only a single argument passed?
if ( StringUnit::getUnitCount( argv[0], " " ) == 1 )
{
// Is this a stock color name?
if ( !StockColor::isColor(argv[0]) )
{
// No, so warn.
Con::warnf( "TypeColorF() - Invalid single argument of '%s' could not be interpreted as a stock color name. Using default.", argv[0] );
}
// Set stock color (if it's invalid we'll get the default.
tmpColor->set( argv[0] );
return;
}
tmpColor->set(0, 0, 0, 255);
S32 r,g,b,a;
S32 args = dSscanf(argv[0], "%d %d %d %d", &r, &g, &b, &a);
@ -648,7 +707,7 @@ ConsoleSetType( TypeColorI )
tmpColor->alpha = dAtoi(argv[3]);
}
else
Con::printf("Color must be set as { r, g, b [,a] }");
Con::printf("Color must be set as { r, g, b [,a] }, { r g b [b] } or { stockColorName }");
}
//-----------------------------------------------------------------------------
@ -670,8 +729,9 @@ ConsoleSetType( TypeSimObjectName )
ConsoleGetType( TypeSimObjectName )
{
SimObject **obj = (SimObject**)dptr;
char* returnBuffer = Con::getReturnBuffer(128);
dSprintf(returnBuffer, 128, "%s", *obj && (*obj)->getName() ? (*obj)->getName() : "");
static const U32 bufSize = 128;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%s", *obj && (*obj)->getName() ? (*obj)->getName() : "");
return returnBuffer;
}
@ -738,8 +798,9 @@ ConsoleType( int, TypeTerrainMaterialIndex, S32 )
ConsoleGetType( TypeTerrainMaterialIndex )
{
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%d", *((S32 *) dptr) );
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%d", *((S32 *) dptr) );
return returnBuffer;
}
@ -800,8 +861,9 @@ ConsoleType( RectF, TypeRectUV, RectF )
ConsoleGetType( TypeRectUV )
{
RectF *rect = (RectF *) dptr;
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%g %g %g %g", rect->point.x, rect->point.y,
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%g %g %g %g", rect->point.x, rect->point.y,
rect->extent.x, rect->extent.y);
return returnBuffer;
}

View file

@ -255,7 +255,7 @@ namespace Con {
mXML->pushNewElement("EnumTables");
// write out the used EnumTables
for (int i = 0; i < enumTables.size(); i++)
for (S32 i = 0; i < enumTables.size(); i++)
{
mXML->pushNewElement("EnumTable");
@ -267,7 +267,7 @@ namespace Con {
mXML->pushNewElement("Enums");
for (int j = 0; j < table->size; j++)
for (S32 j = 0; j < table->size; j++)
{
mXML->pushNewElement("Enum");

View file

@ -211,8 +211,9 @@ class BitfieldConsoleBaseType : public ConsoleBaseType
virtual const char* getData( void* dptr, const EnumTable*, BitSet32 )
{
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "0x%08x", *((S32 *) dptr) );
static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "0x%08x", *((S32 *) dptr) );
return returnBuffer;
}
virtual void setData( void* dptr, S32 argc, const char** argv, const EnumTable*, BitSet32 )

View file

@ -76,6 +76,7 @@
// Disable some VC warnings that are irrelevant to us.
#pragma warning( push )
#pragma warning( disable : 4510 ) // default constructor could not be generated; all the Args structures are never constructed by us
#pragma warning( disable : 4610 ) // can never be instantiated; again Args is never constructed by us
@ -557,7 +558,7 @@ struct _EngineTrampoline< R( A, B, C, D, E, F, G ) >
}
typename EngineTypeTraits< G >::ValueType g() const
{
return EngineTypeTraits< F >::ArgumentToValue(
return EngineTypeTraits< G >::ArgumentToValue(
*( reinterpret_cast< const typename EngineTypeTraits< G >::ArgumentValueType* >
( &data[ sizeof( typename EngineTypeTraits< A >::ArgumentValueType ) +
sizeof( typename EngineTypeTraits< B >::ArgumentValueType ) +
@ -1072,7 +1073,7 @@ struct _EngineFunctionTrampoline< R( A, B, C, D, E, F, G, H ) > : public _Engine
{
static R jmp( R ( *fn )( A, B, C, D, E, F, G, H ), const typename _EngineFunctionTrampolineBase< R( A, B, C, D, E, F, G, H ) >::Args& args )
{
return R( fn( args.a, args.b, args.c, args.d, args.e, args.f, args.g, args.h ) );
return R( fn( args.a(), args.b(), args.c(), args.d(), args.e(), args.f(), args.g(), args.h() ) );
}
};
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
@ -1398,14 +1399,14 @@ struct _EngineConsoleThunkCountArgs
// Encapsulation of a legacy console function invocation.
template< int startArgc, typename T >
template< S32 startArgc, typename T >
struct _EngineConsoleThunk {};
template< int startArgc, typename R >
template< S32 startArgc, typename R >
struct _EngineConsoleThunk< startArgc, R() >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 0;
static const S32 NUM_ARGS = 0;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )(), const _EngineFunctionDefaultArguments< void() >& )
{
return _EngineConsoleThunkReturnValue( fn() );
@ -1416,11 +1417,11 @@ struct _EngineConsoleThunk< startArgc, R() >
return _EngineConsoleThunkReturnValue( ( frame->*fn )() );
}
};
template< int startArgc >
template< S32 startArgc >
struct _EngineConsoleThunk< startArgc, void() >
{
typedef void ReturnType;
static const int NUM_ARGS = 0;
static const S32 NUM_ARGS = 0;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )(), const _EngineFunctionDefaultArguments< void() >& )
{
fn();
@ -1432,11 +1433,11 @@ struct _EngineConsoleThunk< startArgc, void() >
}
};
template< int startArgc, typename R, typename A >
template< S32 startArgc, typename R, typename A >
struct _EngineConsoleThunk< startArgc, R( A ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 1 + startArgc;
static const S32 NUM_ARGS = 1 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A ), const _EngineFunctionDefaultArguments< void( A ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1449,11 +1450,11 @@ struct _EngineConsoleThunk< startArgc, R( A ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a ) );
}
};
template< int startArgc, typename A >
template< S32 startArgc, typename A >
struct _EngineConsoleThunk< startArgc, void( A ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 1 + startArgc;
static const S32 NUM_ARGS = 1 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A ), const _EngineFunctionDefaultArguments< void( A ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1467,11 +1468,11 @@ struct _EngineConsoleThunk< startArgc, void( A ) >
}
};
template< int startArgc, typename R, typename A, typename B >
template< S32 startArgc, typename R, typename A, typename B >
struct _EngineConsoleThunk< startArgc, R( A, B ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 2 + startArgc;
static const S32 NUM_ARGS = 2 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B ), const _EngineFunctionDefaultArguments< void( A, B ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1486,11 +1487,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b ) );
}
};
template< int startArgc, typename A, typename B >
template< S32 startArgc, typename A, typename B >
struct _EngineConsoleThunk< startArgc, void( A, B ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 2 + startArgc;
static const S32 NUM_ARGS = 2 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B ), const _EngineFunctionDefaultArguments< void( A, B ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1506,11 +1507,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C >
template< S32 startArgc, typename R, typename A, typename B, typename C >
struct _EngineConsoleThunk< startArgc, R( A, B, C ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 3 + startArgc;
static const S32 NUM_ARGS = 3 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C ), const _EngineFunctionDefaultArguments< void( A, B, C ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1527,11 +1528,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c ) );
}
};
template< int startArgc, typename A, typename B, typename C >
template< S32 startArgc, typename A, typename B, typename C >
struct _EngineConsoleThunk< startArgc, void( A, B, C ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 3 + startArgc;
static const S32 NUM_ARGS = 3 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C ), const _EngineFunctionDefaultArguments< void( A, B, C ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1549,11 +1550,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 4 + startArgc;
static const S32 NUM_ARGS = 4 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D ), const _EngineFunctionDefaultArguments< void( A, B, C, D ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1572,11 +1573,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D >
template< S32 startArgc, typename A, typename B, typename C, typename D >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 4 + startArgc;
static const S32 NUM_ARGS = 4 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D ), const _EngineFunctionDefaultArguments< void( A, B, C, D ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1596,11 +1597,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 5 + startArgc;
static const S32 NUM_ARGS = 5 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1621,11 +1622,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 5 + startArgc;
static const S32 NUM_ARGS = 5 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1647,11 +1648,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 6 + startArgc;
static const S32 NUM_ARGS = 6 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1674,11 +1675,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 6 + startArgc;
static const S32 NUM_ARGS = 6 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1702,11 +1703,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 7 + startArgc;
static const S32 NUM_ARGS = 7 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F, G ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1731,11 +1732,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f, g ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 7 + startArgc;
static const S32 NUM_ARGS = 7 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F, G ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1761,11 +1762,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 8 + startArgc;
static const S32 NUM_ARGS = 8 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F, G, H ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1792,11 +1793,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f, g, h ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 8 + startArgc;
static const S32 NUM_ARGS = 8 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F, G, H ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1824,11 +1825,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 9 + startArgc;
static const S32 NUM_ARGS = 9 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F, G, H, I ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1857,11 +1858,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f, g, h, i ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H, I ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 9 + startArgc;
static const S32 NUM_ARGS = 9 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F, G, H, I ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1891,11 +1892,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H, I ) >
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I, J ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 10 + startArgc;
static const S32 NUM_ARGS = 10 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F, G, H, I, J ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I, J ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1926,11 +1927,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I, J ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f, g, h, i, j ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H, I, J ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 10 + startArgc;
static const S32 NUM_ARGS = 10 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F, G, H, I, J ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I, J ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1961,11 +1962,11 @@ struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H, I, J ) >
( frame->*fn )( a, b, c, d, e, f, g, h, i, j );
}
};
template< int startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
template< S32 startArgc, typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I, J, K ) >
{
typedef typename _EngineConsoleThunkType< R >::ReturnType ReturnType;
static const int NUM_ARGS = 11 + startArgc;
static const S32 NUM_ARGS = 11 + startArgc;
static ReturnType thunk( S32 argc, ConsoleValueRef *argv, R ( *fn )( A, B, C, D, E, F, G, H, I, J, K ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I, J, K ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -1998,11 +1999,11 @@ struct _EngineConsoleThunk< startArgc, R( A, B, C, D, E, F, G, H, I, J, K ) >
return _EngineConsoleThunkReturnValue( ( frame->*fn )( a, b, c, d, e, f, g, h, i, j, k ) );
}
};
template< int startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
template< S32 startArgc, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
struct _EngineConsoleThunk< startArgc, void( A, B, C, D, E, F, G, H, I, J, K ) >
{
typedef void ReturnType;
static const int NUM_ARGS = 11 + startArgc;
static const S32 NUM_ARGS = 11 + startArgc;
static void thunk( S32 argc, ConsoleValueRef *argv, void ( *fn )( A, B, C, D, E, F, G, H, I, J, K ), const _EngineFunctionDefaultArguments< void( A, B, C, D, E, F, G, H, I, J, K ) >& defaultArgs )
{
A a = ( startArgc < argc ? EngineUnmarshallData< A >()( argv[ startArgc ] ) : A( defaultArgs.a ) );
@ -2547,79 +2548,79 @@ struct _EngineCallbackHelper
R call() const
{
typedef R( FunctionType )( EngineObject* );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis ) );
}
template< typename R, typename A >
R call( A a ) const
{
typedef R( FunctionType )( EngineObject*, A );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a ) );
}
template< typename R, typename A, typename B >
R call( A a, B b ) const
{
typedef R( FunctionType )( EngineObject*, A, B );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b ) );
}
template< typename R, typename A, typename B, typename C >
R call( A a, B b, C c ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c ) );
}
template< typename R, typename A, typename B, typename C, typename D >
R call( A a, B b, C c, D d ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E >
R call( A a, B b, C c, D d, E e ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F >
R call( A a, B b, C c, D d, E e, F f ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G >
R call( A a, B b, C c, D d, E e, F f, G g ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
R call( A a, B b, C c, D d, E e, F f, G g, H h ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G, H );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g, h ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g, h ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I >
R call( A a, B b, C c, D d, E e, F f, G g, H h, I i ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G, H, I );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g, h, i ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g, h, i ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J >
R call( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G, H, I, J );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g, h, i, j ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g, h, i, j ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
R call( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G, H, I, J, K );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g, h, i, j, k ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g, h, i, j, k ) );
}
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K, typename L >
R call( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l ) const
{
typedef R( FunctionType )( EngineObject*, A, B, C, D, E, F, G, H, I, J, K, L l );
return R( reinterpret_cast< FunctionType* >( mFn )( mThis, a, b, c, d, e, f, g, h, i, j, k, l ) );
return R( reinterpret_cast< FunctionType* >( const_cast<void*>(mFn) )( mThis, a, b, c, d, e, f, g, h, i, j, k, l ) );
}
};
@ -2808,7 +2809,6 @@ struct _EngineConsoleCallbackHelper
// Re-enable some VC warnings we disabled for this file.
#pragma warning( default : 4510 )
#pragma warning( default : 4610 )
#pragma warning( pop ) // 4510 and 4610
#endif // !_ENGINEAPI_H_

View file

@ -307,7 +307,7 @@ static void dumpNamespaceEntries( Stream &stream, Namespace *g, bool callbacks =
// Go through all the entries in the namespace.
for ( Namespace::Entry *ewalk = g->mEntryList; ewalk; ewalk = ewalk->mNext )
{
int eType = ewalk->mType;
S32 eType = ewalk->mType;
// We do not dump script defined functions... only engine exports.
if( eType == Namespace::Entry::ConsoleFunctionType

View file

@ -333,7 +333,7 @@ struct _EngineTypeTraits< R( A, B, C, D, E, F, G, H, I, J, K ) > : public _Engin
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K >
struct _EngineTypeTraits< R( A, B, C, D, E, F, G, H, I, J, K, ... ) > : public _EngineFunctionTypeTraits< T( R )( T( A ), T( B ), T( C ), T( D ), T( E ), T( F ), T( G ), T( H ), T( I ), T( J ), T( K ), ... ) > {};
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K, typename L >
struct _EngineTypeTraits< R( A, B, C, D, E, F, G, H, I, J, K, L ) > : public _EngineFunctionTypeTraits< T( R )( T( A ), T( B ), T( C ), T( D ), T( E ), T( F ), T( G ), T( H ), T( I ), T( J ), T( J ), T( L ) ) > {};
struct _EngineTypeTraits< R( A, B, C, D, E, F, G, H, I, J, K, L ) > : public _EngineFunctionTypeTraits< T( R )( T( A ), T( B ), T( C ), T( D ), T( E ), T( F ), T( G ), T( H ), T( I ), T( J ), T( K ), T( L ) ) > {};
template< typename R, typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I, typename J, typename K, typename L >
struct _EngineTypeTraits< R( A, B, C, D, E, F, G, H, I, J, K, L, ... ) > : public _EngineFunctionTypeTraits< T( R )( T( A ), T( B ), T( C ), T( D ), T( E ), T( F ), T( G ), T( H ), T( I ), T( J ), T( K ), T( L ), ... ) > {};

View file

@ -27,7 +27,6 @@
#include "console/ast.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "torqueConfig.h"
#include "core/frameAllocator.h"
@ -600,10 +599,10 @@ DefineEngineFunction(fileExt, String, ( const char* fileName ),,
}
DefineEngineFunction(fileBase, String, ( const char* fileName ),,
"@brief Get the base of a file name (removes extension)\n\n"
"@brief Get the base of a file name (removes extension and path)\n\n"
"@param fileName Name and path of file to check\n"
"@return String containing the file name, minus extension\n"
"@return String containing the file name, minus extension and path\n"
"@ingroup FileSystem")
{
@ -627,10 +626,10 @@ DefineEngineFunction(fileBase, String, ( const char* fileName ),,
}
DefineEngineFunction(fileName, String, ( const char* fileName ),,
"@brief Get the file name of a file (removes extension and path)\n\n"
"@brief Get only the file name of a path and file name string (removes path)\n\n"
"@param fileName Name and path of file to check\n"
"@return String containing the file name, minus extension and path\n"
"@return String containing the file name, minus the path\n"
"@ingroup FileSystem")
{
S32 pathLen = dStrlen( fileName );
@ -696,8 +695,9 @@ DefineEngineFunction(makeFullPath, String, ( const char* path, const char* cwd )
"@return String containing non-relative directory of path\n"
"@ingroup FileSystem")
{
char *buf = Con::getReturnBuffer(512);
Platform::makeFullPathName(path, buf, 512, dStrlen(cwd) > 1 ? cwd : NULL);
static const U32 bufSize = 512;
char *buf = Con::getReturnBuffer(buf);
Platform::makeFullPathName(path, buf, bufSize, dStrlen(cwd) > 1 ? cwd : NULL);
return buf;
}
@ -722,8 +722,9 @@ DefineEngineFunction(pathConcat, String, ( const char* path, const char* file),,
"@return String containing concatenated file name and path\n"
"@ingroup FileSystem")
{
char *buf = Con::getReturnBuffer(1024);
Platform::makeFullPathName(file, buf, 1024, path);
static const U32 bufSize = 1024;
char *buf = Con::getReturnBuffer(buf);
Platform::makeFullPathName(file, buf, bufSize, path);
return buf;
}

View file

@ -344,8 +344,9 @@ ConsoleFunction(expandFilename, const char*, 2, 2, "(string filename)"
"@ingroup FileSystem")
{
TORQUE_UNUSED(argc);
char* ret = Con::getReturnBuffer( 1024 );
Con::expandScriptFilename(ret, 1024, argv[1]);
static const U32 bufSize = 1024;
char* ret = Con::getReturnBuffer( bufSize );
Con::expandScriptFilename(ret, bufSize, argv[1]);
return ret;
}
@ -355,8 +356,9 @@ ConsoleFunction(expandOldFilename, const char*, 2, 2, "(string filename)"
"@ingroup FileSystem")
{
TORQUE_UNUSED(argc);
char* ret = Con::getReturnBuffer( 1024 );
Con::expandOldScriptFilename(ret, 1024, argv[1]);
static const U32 bufSize = 1024;
char* ret = Con::getReturnBuffer( bufSize );
Con::expandOldScriptFilename(ret, bufSize, argv[1]);
return ret;
}
@ -368,8 +370,9 @@ ConsoleToolFunction(collapseFilename, const char*, 2, 2, "(string filename)"
"@internal Editor use only")
{
TORQUE_UNUSED(argc);
char* ret = Con::getReturnBuffer( 1024 );
Con::collapseScriptFilename(ret, 1024, argv[1]);
static const U32 bufSize = 1024;
char* ret = Con::getReturnBuffer( bufSize );
Con::collapseScriptFilename(ret, bufSize, argv[1]);
return ret;
}

View file

@ -27,6 +27,10 @@
#include "console/simBase.h"
#include "console/engineAPI.h"
//-----------------------------------------------------------------------------
// ScriptObject
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(ScriptObject);
ConsoleDocClass( ScriptObject,
@ -83,23 +87,103 @@ void ScriptObject::onRemove()
}
//-----------------------------------------------------------------------------
// Script group placeholder
// ScriptTickObject
//-----------------------------------------------------------------------------
class ScriptGroup : public SimGroup
IMPLEMENT_CONOBJECT(ScriptTickObject);
ConsoleDocClass( ScriptTickObject,
"@brief A ScriptObject that responds to tick and frame events.\n\n"
"ScriptTickObject is a ScriptObject that adds callbacks for tick and frame events. Use "
"setProcessTicks() to enable or disable the onInterpolateTick() and onProcessTick() callbacks. "
"The callOnAdvanceTime property determines if the onAdvanceTime() callback is called.\n\n"
"@see ScriptObject\n"
"@ingroup Console\n"
"@ingroup Scripting"
);
IMPLEMENT_CALLBACK( ScriptTickObject, onInterpolateTick, void, ( F32 delta ), ( delta ),
"This is called every frame, but only if the object is set to process ticks.\n"
"@param delta The time delta for this frame.\n"
);
IMPLEMENT_CALLBACK( ScriptTickObject, onProcessTick, void, (), (),
"Called once every 32ms if this object is set to process ticks.\n"
);
IMPLEMENT_CALLBACK( ScriptTickObject, onAdvanceTime, void, ( F32 timeDelta ), ( timeDelta ),
"This is called every frame regardless if the object is set to process ticks, but only "
"if the callOnAdvanceTime property is set to true.\n"
"@param timeDelta The time delta for this frame.\n"
"@see callOnAdvanceTime\n"
);
ScriptTickObject::ScriptTickObject()
{
typedef SimGroup Parent;
public:
ScriptGroup();
bool onAdd();
void onRemove();
mCallOnAdvanceTime = false;
}
DECLARE_CONOBJECT(ScriptGroup);
void ScriptTickObject::initPersistFields()
{
addField("callOnAdvanceTime", TypeBool, Offset(mCallOnAdvanceTime, ScriptTickObject), "Call the onAdvaceTime() callback.");
DECLARE_CALLBACK(void, onAdd, (SimObjectId ID) );
DECLARE_CALLBACK(void, onRemove, (SimObjectId ID));
};
Parent::initPersistFields();
}
bool ScriptTickObject::onAdd()
{
if (!Parent::onAdd())
return false;
return true;
}
void ScriptTickObject::onRemove()
{
Parent::onRemove();
}
void ScriptTickObject::interpolateTick( F32 delta )
{
onInterpolateTick_callback(delta);
}
void ScriptTickObject::processTick()
{
onProcessTick_callback();
}
void ScriptTickObject::advanceTime( F32 timeDelta )
{
if(mCallOnAdvanceTime)
{
onAdvanceTime_callback(timeDelta);
}
}
DefineEngineMethod( ScriptTickObject, setProcessTicks, void, ( bool tick ),,
"@brief Sets this object as either tick processing or not.\n\n"
"@param tick This object's onInterpolateTick() and onProcessTick() callbacks are called if set to true.\n\n")
{
object->setProcessTicks(tick);
}
DefineEngineMethod( ScriptTickObject, isProcessingTicks, bool, ( ),,
"@brief Is this object wanting to receive tick notifications.\n\n"
"If this object is set to receive tick notifications then its onInterpolateTick() and "
"onProcessTick() callbacks are called.\n"
"@return True if object wants tick notifications\n\n" )
{
return object->isProcessingTicks();
}
//-----------------------------------------------------------------------------
// ScriptGroup
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(ScriptGroup);
@ -157,7 +241,6 @@ bool ScriptGroup::onAdd()
return false;
// Call onAdd in script!
//Con::executef(this, "onAdd", Con::getIntArg(getId()));
onAdd_callback(getId());
return true;
}
@ -165,7 +248,6 @@ bool ScriptGroup::onAdd()
void ScriptGroup::onRemove()
{
// Call onRemove in script!
//Con::executef(this, "onRemove", Con::getIntArg(getId()));
onRemove_callback(getId());
Parent::onRemove();

View file

@ -27,8 +27,12 @@
#include "console/consoleInternal.h"
#endif
#ifndef _ITICKABLE_H_
#include "core/iTickable.h"
#endif
//-----------------------------------------------------------------------------
// Script object placeholder
// ScriptObject
//-----------------------------------------------------------------------------
class ScriptObject : public SimObject
@ -46,4 +50,51 @@ public:
DECLARE_CALLBACK(void, onRemove, (SimObjectId ID));
};
//-----------------------------------------------------------------------------
// ScriptTickObject
//-----------------------------------------------------------------------------
class ScriptTickObject : public ScriptObject, public virtual ITickable
{
typedef ScriptObject Parent;
protected:
bool mCallOnAdvanceTime;
public:
ScriptTickObject();
static void initPersistFields();
bool onAdd();
void onRemove();
virtual void interpolateTick( F32 delta );
virtual void processTick();
virtual void advanceTime( F32 timeDelta );
DECLARE_CONOBJECT(ScriptTickObject);
DECLARE_CALLBACK(void, onInterpolateTick, (F32 delta) );
DECLARE_CALLBACK(void, onProcessTick, () );
DECLARE_CALLBACK(void, onAdvanceTime, (F32 timeDelta) );
};
//-----------------------------------------------------------------------------
// ScriptGroup
//-----------------------------------------------------------------------------
class ScriptGroup : public SimGroup
{
typedef SimGroup Parent;
public:
ScriptGroup();
bool onAdd();
void onRemove();
DECLARE_CONOBJECT(ScriptGroup);
DECLARE_CALLBACK(void, onAdd, (SimObjectId ID) );
DECLARE_CALLBACK(void, onRemove, (SimObjectId ID));
};
#endif

View file

@ -25,7 +25,7 @@
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
extern S32 HashPointer(StringTableEntry e);
extern U32 HashPointer(StringTableEntry e);
SimNameDictionary::SimNameDictionary()
{

View file

@ -2663,7 +2663,7 @@ DefineConsoleMethod( SimObject, getDynamicFieldCount, S32, (),,
//-----------------------------------------------------------------------------
DefineConsoleMethod( SimObject, getDynamicField, const char*, ( int index ),,
DefineConsoleMethod( SimObject, getDynamicField, const char*, ( S32 index ),,
"Get a value of a dynamic field by index.\n"
"@param index The index of the dynamic field.\n"
"@return The value of the dynamic field at the given index or \"\"." )
@ -2680,11 +2680,12 @@ DefineConsoleMethod( SimObject, getDynamicField, const char*, ( int index ),,
++itr;
}
char* buffer = Con::getReturnBuffer(256);
static const U32 bufSize = 256;
char* buffer = Con::getReturnBuffer(bufSize);
if (*itr)
{
SimFieldDictionary::Entry* entry = *itr;
dSprintf(buffer, 256, "%s\t%s", entry->slotName, entry->value);
dSprintf(buffer, bufSize, "%s\t%s", entry->slotName, entry->value);
return buffer;
}
@ -2702,7 +2703,7 @@ DefineConsoleMethod( SimObject, getFieldCount, S32, (),,
const AbstractClassRep::Field* f;
U32 numDummyEntries = 0;
for(int i = 0; i < list.size(); i++)
for(S32 i = 0; i < list.size(); i++)
{
f = &list[i];
@ -2716,7 +2717,7 @@ DefineConsoleMethod( SimObject, getFieldCount, S32, (),,
//-----------------------------------------------------------------------------
DefineConsoleMethod( SimObject, getField, const char*, ( int index ),,
DefineConsoleMethod( SimObject, getField, const char*, ( S32 index ),,
"Retrieve the value of a static field by index.\n"
"@param index The index of the static field.\n"
"@return The value of the static field with the given index or \"\"." )

View file

@ -781,7 +781,7 @@ class SimObject: public ConsoleObject
void setCanSaveDynamicFields( bool bCanSave ) { mCanSaveFieldDictionary = bCanSave; }
/// Get whether fields created at runtime should be saved. Default is true.
bool getCanSaveDynamicFields( bool bCanSave ) { return mCanSaveFieldDictionary;}
bool getCanSaveDynamicFields( ) { return mCanSaveFieldDictionary;}
/// Return the object that this object is copying fields from.
SimObject* getCopySource() const { return mCopySource; }

View file

@ -25,7 +25,6 @@
#include "console/engineAPI.h"
#include "core/strings/stringFunctions.h"
#include "platform/event.h"
#include "core/util/journal/process.h"
#include "core/module.h"

View file

@ -26,9 +26,6 @@
#ifndef _CONSOLE_H_
#include "console/console.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#include "platform/platformNet.h"
/// Telnet admin console.

View file

@ -25,7 +25,6 @@
#include "core/frameAllocator.h"
#include "console/console.h"
#include "platform/event.h"
#include "core/stringTable.h"
#include "console/consoleInternal.h"
#include "console/ast.h"

View file

@ -127,7 +127,7 @@ public:
void breakProcess();
virtual void executionStopped(CodeBlock *code, U32 lineNumber);
void executionStopped(CodeBlock *code, U32 lineNumber);
void send(const char *s);
void setDebugParameters(S32 port, const char *password, bool waitForClient);
void processConsoleLine(const char *consoleLine);

View file

@ -0,0 +1,108 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2014 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.
//-----------------------------------------------------------------------------
#ifdef TORQUE_TESTS_ENABLED
#include "testing/unitTesting.h"
#include "platform/platform.h"
#include "console/simBase.h"
#include "console/consoleTypes.h"
#include "console/runtimeClassRep.h"
class RuntimeRegisteredSimObject : public SimObject
{
typedef SimObject Parent;
protected:
bool mFoo;
public:
RuntimeRegisteredSimObject() : mFoo(false) {};
DECLARE_RUNTIME_CONOBJECT(RuntimeRegisteredSimObject);
static void initPersistFields();
};
IMPLEMENT_RUNTIME_CONOBJECT(RuntimeRegisteredSimObject);
void RuntimeRegisteredSimObject::initPersistFields()
{
addField("fooField", TypeBool, Offset(mFoo, RuntimeRegisteredSimObject));
}
TEST(Console, RuntimeClassRep)
{
// First test to make sure that the test class is not registered (don't
// know how it could be, but that's programming for you). Stop the test if
// it is.
ASSERT_TRUE(!RuntimeRegisteredSimObject::dynRTClassRep.isRegistered())
<< "RuntimeRegisteredSimObject class was already registered with the console";
// This should not be able to find the class, and return null (this may
// AssertWarn as well).
ConsoleObject *conobj = ConsoleObject::create("RuntimeRegisteredSimObject");
EXPECT_TRUE(conobj == NULL)
<< "Unregistered AbstractClassRep returned non-NULL value! That is really bad!";
// Register with console system.
RuntimeRegisteredSimObject::dynRTClassRep.consoleRegister();
// Make sure that the object knows it's registered.
EXPECT_TRUE(RuntimeRegisteredSimObject::dynRTClassRep.isRegistered())
<< "RuntimeRegisteredSimObject class failed console registration";
// Now try again to create the instance.
conobj = ConsoleObject::create("RuntimeRegisteredSimObject");
EXPECT_TRUE(conobj != NULL)
<< "AbstractClassRep::create method failed!";
// Cast the instance, and test it.
RuntimeRegisteredSimObject *rtinst =
dynamic_cast<RuntimeRegisteredSimObject *>(conobj);
EXPECT_TRUE(rtinst != NULL)
<< "Casting failed for some reason";
// Register it with a name.
rtinst->registerObject("_utRRTestObject");
EXPECT_TRUE(rtinst->isProperlyAdded())
<< "registerObject failed on test object";
// Now execute some script on it.
Con::evaluate("_utRRTestObject.fooField = true;");
// Test to make sure field worked.
EXPECT_TRUE(dAtob(rtinst->getDataField(StringTable->insert("fooField"), NULL)))
<< "Set property failed on instance.";
// BALETED
rtinst->deleteObject();
// Unregister the type.
RuntimeRegisteredSimObject::dynRTClassRep.consoleUnRegister();
// And make sure we can't create another one.
conobj = ConsoleObject::create("RuntimeRegisteredSimObject");
EXPECT_TRUE(conobj == NULL)
<< "Unregistration of type failed";
}
#endif