Replaced a ton of ConsoleMethods with the DefineConsoleMethod Macro.

This commit is contained in:
Vincent Gee 2014-11-03 22:42:51 -05:00
parent 378a933894
commit acb192e2a5
133 changed files with 1716 additions and 2087 deletions

View file

@ -571,21 +571,22 @@ DefineEngineMethod( SimXMLDocument, attribute, const char*, ( const char* attrib
}
// These two methods don't make a lot of sense the way TS works. Leaving them in for backwards-compatibility.
ConsoleMethod( SimXMLDocument, attributeF32, F32, 3, 3, "(string attributeName)"
DefineConsoleMethod( SimXMLDocument, attributeF32, F32, (const char * attributeName), , "(string attributeName)"
"@brief Get float attribute from the current Element on the stack.\n\n"
"@param attributeName Name of attribute to retrieve.\n"
"@return The value of the given attribute in the form of a float.\n"
"@deprecated Use attribute().")
{
return dAtof( object->attribute( argv[2] ) );
return dAtof( object->attribute( attributeName ) );
}
ConsoleMethod(SimXMLDocument, attributeS32, S32, 3, 3, "(string attributeName)"
DefineConsoleMethod(SimXMLDocument, attributeS32, S32, (const char * attributeName), , "(string attributeName)"
"@brief Get int attribute from the current Element on the stack.\n\n"
"@param attributeName Name of attribute to retrieve.\n"
"@return The value of the given attribute in the form of an integer.\n"
"@deprecated Use attribute().")
{
return dAtoi( object->attribute( argv[2] ) );
return dAtoi( object->attribute( attributeName ) );
}
// -----------------------------------------------------------------------------

View file

@ -275,7 +275,7 @@ bool useTimestamp = false;
ConsoleFunctionGroupBegin( Clipboard, "Miscellaneous functions to control the clipboard and clear the console.");
ConsoleFunction( cls, void, 1, 1, "()"
DefineConsoleFunction( cls, void, (), , "()"
"@brief Clears the console output.\n\n"
"@ingroup Console")
{
@ -285,18 +285,18 @@ ConsoleFunction( cls, void, 1, 1, "()"
consoleLog.setSize(0);
};
ConsoleFunction( getClipboard, const char*, 1, 1, "()"
DefineConsoleFunction( getClipboard, const char*, (), , "()"
"@brief Get text from the clipboard.\n\n"
"@internal")
{
return Platform::getClipboard();
};
ConsoleFunction( setClipboard, bool, 2, 2, "(string text)"
DefineConsoleFunction( setClipboard, bool, (const char* text), , "(string text)"
"@brief Set the system clipboard.\n\n"
"@internal")
{
return Platform::setClipboard(argv[1]);
return Platform::setClipboard(text);
};
ConsoleFunctionGroupEnd( Clipboard );

View file

@ -1179,7 +1179,7 @@ static bool isInSet(char c, const char *set)
return false;
}
ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, string delimiters ) "
DefineConsoleFunction( nextToken, const char*, ( const char* str1, const char* token, const char* delim), , "( string str, string token, string delimiters ) "
"Tokenize a string using a set of delimiting characters.\n"
"This function first skips all leading charaters in @a str that are contained in @a delimiters. "
"From that position, it then scans for the next character in @a str that is contained in @a delimiters and stores all characters "
@ -1207,12 +1207,7 @@ ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, str
"@endtsexample\n\n"
"@ingroup Strings" )
{
char buffer[4096];
dStrncpy(buffer, argv[1], 4096);
char *str = buffer;
const char *token = argv[2];
const char *delim = argv[3];
char *str = (char *)str1;
if( str )
{
// skip over any characters that are a member of delim
@ -1242,9 +1237,7 @@ ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, str
str++;
}
char *ret = Con::getReturnBuffer(dStrlen(str)+1);
dStrncpy(ret, str, dStrlen(str)+1);
return ret;
return str;
}
//=============================================================================
@ -1289,7 +1282,7 @@ DefineEngineFunction( detag, const char*, ( const char* str ),,
return str;
}
ConsoleFunction(getTag, const char *, 2, 2, "(string textTagString)"
DefineConsoleFunction( getTag, const char*, ( const char* textTagString ), , "( string textTagString ) "
"@brief Extracts the tag from a tagged string\n\n"
"Should only be used within the context of a function that receives a tagged "
@ -1303,26 +1296,24 @@ ConsoleFunction(getTag, const char *, 2, 2, "(string textTagString)"
"@see detag()\n"
"@ingroup Networking")
{
TORQUE_UNUSED(argc);
if(argv[1][0] == StringTagPrefixByte)
if(textTagString[0] == StringTagPrefixByte)
{
const char *arg = argv[1];
const char * space = dStrchr(argv[1], ' ');
const char * space = dStrchr(textTagString, ' ');
U32 len;
U64 len;
if(space)
len = space - arg;
len = space - textTagString;
else
len = dStrlen(arg) + 1;
len = dStrlen(textTagString) + 1;
char * ret = Con::getReturnBuffer(len);
dStrncpy(ret, arg + 1, len - 1);
dStrncpy(ret, textTagString + 1, len - 1);
ret[len - 1] = 0;
return(ret);
}
else
return(argv[1]);
return(textTagString);
}
@ -1512,13 +1503,12 @@ DefineConsoleFunction( quit, void, ( ),,
//-----------------------------------------------------------------------------
#ifdef TORQUE_DEMO_PURCHASE
ConsoleFunction( realQuit, void, 1, 1, "" )
DefineConsoleFunction( realQuit, void, (), , "")
{
TORQUE_UNUSED(argc); TORQUE_UNUSED(argv);
Platform::postQuitMessage(0);
}
#endif
//-----------------------------------------------------------------------------
@ -2185,87 +2175,86 @@ DefineEngineFunction( exec, bool, ( const char* fileName, bool noCalls, bool jou
return ret;
}
ConsoleFunction(eval, const char *, 2, 2, "eval(consoleString)")
DefineConsoleFunction( eval, const char*, ( const char* consoleString ), , "eval(consoleString)" )
{
TORQUE_UNUSED(argc);
return Con::evaluate(argv[1], false, NULL);
return Con::evaluate(consoleString, false, NULL);
}
ConsoleFunction(getVariable, const char *, 2, 2, "(string varName)\n"
DefineConsoleFunction( getVariable, const char*, ( const char* varName ), , "(string varName)\n"
"@brief Returns the value of the named variable or an empty string if not found.\n\n"
"@varName Name of the variable to search for\n"
"@return Value contained by varName, \"\" if the variable does not exist\n"
"@ingroup Scripting")
{
return Con::getVariable(argv[1]);
return Con::getVariable(varName);
}
ConsoleFunction(setVariable, void, 3, 3, "(string varName, string value)\n"
DefineConsoleFunction( setVariable, void, ( const char* varName, const char* value ), , "(string varName, string value)\n"
"@brief Sets the value of the named variable.\n\n"
"@param varName Name of the variable to locate\n"
"@param value New value of the variable\n"
"@return True if variable was successfully found and set\n"
"@ingroup Scripting")
{
return Con::setVariable(argv[1], argv[2]);
return Con::setVariable(varName, value);
}
ConsoleFunction(isFunction, bool, 2, 2, "(string funcName)"
DefineConsoleFunction( isFunction, bool, ( const char* funcName ), , "(string funcName)"
"@brief Determines if a function exists or not\n\n"
"@param funcName String containing name of the function\n"
"@return True if the function exists, false if not\n"
"@ingroup Scripting")
{
return Con::isFunction(argv[1]);
return Con::isFunction(funcName);
}
ConsoleFunction(getFunctionPackage, const char*, 2, 2, "(string funcName)"
DefineConsoleFunction( getFunctionPackage, const char*, ( const char* funcName ), , "(string funcName)"
"@brief Provides the name of the package the function belongs to\n\n"
"@param funcName String containing name of the function\n"
"@return The name of the function's package\n"
"@ingroup Packages")
{
Namespace::Entry* nse = Namespace::global()->lookup( StringTable->insert( argv[1] ) );
Namespace::Entry* nse = Namespace::global()->lookup( StringTable->insert( funcName ) );
if( !nse )
return "";
return nse->mPackage;
}
ConsoleFunction(isMethod, bool, 3, 3, "(string namespace, string method)"
DefineConsoleFunction( isMethod, bool, ( const char* nameSpace, const char* method ), , "(string namespace, string method)"
"@brief Determines if a class/namespace method exists\n\n"
"@param namespace Class or namespace, such as Player\n"
"@param method Name of the function to search for\n"
"@return True if the method exists, false if not\n"
"@ingroup Scripting\n")
{
Namespace* ns = Namespace::find( StringTable->insert( argv[1] ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( argv[2] ) );
Namespace* ns = Namespace::find( StringTable->insert( nameSpace ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( method ) );
if( !nse )
return false;
return true;
}
ConsoleFunction(getMethodPackage, const char*, 3, 3, "(string namespace, string method)"
DefineConsoleFunction( getMethodPackage, const char*, ( const char* nameSpace, const char* method ), , "(string namespace, string method)"
"@brief Provides the name of the package the method belongs to\n\n"
"@param namespace Class or namespace, such as Player\n"
"@param method Name of the funciton to search for\n"
"@return The name of the method's package\n"
"@ingroup Packages")
{
Namespace* ns = Namespace::find( StringTable->insert( argv[1] ) );
Namespace* ns = Namespace::find( StringTable->insert( nameSpace ) );
if( !ns )
return "";
Namespace::Entry* nse = ns->lookup( StringTable->insert( argv[2] ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( method ) );
if( !nse )
return "";
return nse->mPackage;
}
ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
DefineConsoleFunction( isDefined, bool, ( const char* varName, const char* varValue ), ("") , "(string varName)"
"@brief Determines if a variable exists and contains a value\n"
"@param varName Name of the variable to search for\n"
"@return True if the variable was defined in script, false if not\n"
@ -2274,13 +2263,13 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
"@endtsexample\n\n"
"@ingroup Scripting")
{
if(dStrlen(argv[1]) == 0)
if(dStrlen(varName) == 0)
{
Con::errorf("isDefined() - did you forget to put quotes around the variable name?");
return false;
}
StringTableEntry name = StringTable->insert(argv[1]);
StringTableEntry name = StringTable->insert(varName);
// Deal with <var>.<value>
if (dStrchr(name, '.'))
@ -2331,7 +2320,7 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (!value)
{
obj->setDataField(valName, 0, argv[2]);
obj->setDataField(valName, 0, varValue);
return false;
}
@ -2350,8 +2339,11 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
{
if (dStrlen(value) > 0)
return true;
else if (argc > 2)
obj->setDataField(valName, 0, argv[2]);
else if (dStrcmp(varValue,"")!=0)
{
obj->setDataField(valName, 0, varValue);
}
}
}
}
@ -2365,8 +2357,10 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (ent)
return true;
else if (argc > 2)
gEvalState.getCurrentFrame().setVariable(name, argv[2]);
else if (dStrcmp (varValue,"")!=0)
{
gEvalState.getCurrentFrame().setVariable(name, varValue);
}
}
else
Con::errorf("%s() - no local variable frame.", __FUNCTION__);
@ -2378,16 +2372,20 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (ent)
return true;
else if (argc > 2)
gEvalState.globalVars.setVariable(name, argv[2]);
else if (dStrcmp( varValue,"") != 0)
{
gEvalState.globalVars.setVariable(name, varValue);
}
}
else
{
// Is it an object?
if (dStrcmp(argv[1], "0") && dStrcmp(argv[1], "") && (Sim::findObject(argv[1]) != NULL))
if (dStrcmp(varName, "0") && dStrcmp(varName, "") && (Sim::findObject(varName) != NULL))
return true;
else if (argc > 2)
Con::errorf("%s() - can't assign a value to a variable of the form \"%s\"", __FUNCTION__, (const char*)argv[1]);
else if (varValue != "")
{
Con::errorf("%s() - can't assign a value to a variable of the form \"%s\"", __FUNCTION__, varValue);
}
}
return false;
@ -2395,39 +2393,39 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
//-----------------------------------------------------------------------------
ConsoleFunction( isCurrentScriptToolScript, bool, 1, 1,
"() Returns true if the calling script is a tools script.\n"
DefineConsoleFunction( isCurrentScriptToolScript, bool, (), , "()"
"Returns true if the calling script is a tools script.\n"
"@hide")
{
return Con::isCurrentScriptToolScript();
}
ConsoleFunction(getModNameFromPath, const char *, 2, 2, "(string path)"
DefineConsoleFunction( getModNameFromPath, const char *, ( const char* path ), , "(string path)"
"@brief Attempts to extract a mod directory from path. Returns empty string on failure.\n\n"
"@param File path of mod folder\n"
"@note This is no longer relevant in Torque 3D (which does not use mod folders), should be deprecated\n"
"@internal")
{
StringTableEntry modPath = Con::getModNameFromPath(argv[1]);
StringTableEntry modPath = Con::getModNameFromPath(path);
return modPath ? modPath : "";
}
//-----------------------------------------------------------------------------
ConsoleFunction( pushInstantGroup, void, 1, 2, "([group])"
DefineConsoleFunction( pushInstantGroup, void, ( String group ),("") , "([group])"
"@brief Pushes the current $instantGroup on a stack "
"and sets it to the given value (or clears it).\n\n"
"@note Currently only used for editors\n"
"@ingroup Editors\n"
"@internal")
{
if( argc > 1 )
Con::pushInstantGroup( (const char*)argv[ 1 ] );
if( group.size() > 0 )
Con::pushInstantGroup( group );
else
Con::pushInstantGroup();
}
ConsoleFunction( popInstantGroup, void, 1, 1, "()"
DefineConsoleFunction( popInstantGroup, void, (), , "()"
"@brief Pop and restore the last setting of $instantGroup off the stack.\n\n"
"@note Currently only used for editors\n\n"
"@ingroup Editors\n"
@ -2438,11 +2436,11 @@ ConsoleFunction( popInstantGroup, void, 1, 1, "()"
//-----------------------------------------------------------------------------
ConsoleFunction(getPrefsPath, const char *, 1, 2, "([relativeFileName])"
DefineConsoleFunction( getPrefsPath, const char *, ( const char* relativeFileName ), , "([relativeFileName])"
"@note Appears to be useless in Torque 3D, should be deprecated\n"
"@internal")
{
const char *filename = Platform::getPrefsPath(argc > 1 ? (const char*)argv[1] : NULL);
const char *filename = Platform::getPrefsPath(relativeFileName);
if(filename == NULL || *filename == 0)
return "";

View file

@ -225,7 +225,7 @@ void ConsoleLogger::log( const char *consoleLine )
//-----------------------------------------------------------------------------
ConsoleMethod( ConsoleLogger, attach, bool, 2, 2, "() Attaches the logger to the console and begins writing to file"
DefineConsoleMethod( ConsoleLogger, attach, bool, (), , "() Attaches the logger to the console and begins writing to file"
"@tsexample\n"
"// Create the logger\n"
"// Will automatically start writing to testLogging.txt with normal priority\n"
@ -247,7 +247,7 @@ ConsoleMethod( ConsoleLogger, attach, bool, 2, 2, "() Attaches the logger to the
//-----------------------------------------------------------------------------
ConsoleMethod( ConsoleLogger, detach, bool, 2, 2, "() Detaches the logger from the console and stops writing to file"
DefineConsoleMethod( ConsoleLogger, detach, bool, (), , "() Detaches the logger from the console and stops writing to file"
"@tsexample\n"
"// Create the logger\n"
"// Will automatically start writing to testLogging.txt with normal priority\n"

View file

@ -21,6 +21,7 @@
//-----------------------------------------------------------------------------
#include "console/consoleInternal.h"
#include "console/engineAPI.h"
#include "console/consoleObject.h"
#include "console/SimXMLDocument.h"
@ -313,7 +314,7 @@ namespace Con {
}; // namespace Con
ConsoleFunction(consoleExportXML, const char*, 1, 1, "Exports console definition XML representation")
DefineConsoleFunction( consoleExportXML, const char*, (), ,"Exports console definition XML representation" )
{
Con::XMLExport xmlExport;
String xml;

View file

@ -245,6 +245,19 @@ struct EngineUnmarshallData< F32 >
}
};
template<>
struct EngineUnmarshallData< U8 >
{
U8 operator()( ConsoleValueRef &ref ) const
{
return (U8)((S32)ref);
}
U8 operator()( const char* str ) const
{
return dAtoui( str );
}
};
template<>
struct EngineUnmarshallData< const char* >
{
const char* operator()( const char* str ) const

View file

@ -22,6 +22,7 @@
#include "core/strings/stringUnit.h"
#include "console/fieldBrushObject.h"
#include "console/engineAPI.h"
// Prefix added to dynamic-fields when they're used to store any copied static-fields when peristing.
#define INTERNAL_FIELD_PREFIX "_fieldBrush_"
@ -122,12 +123,12 @@ static char* suppressSpaces(const char* in_pname)
//-----------------------------------------------------------------------------
// Query Groups.
//-----------------------------------------------------------------------------
ConsoleMethod(FieldBrushObject, queryGroups, const char*, 3, 3, "(simObject) Query available static-field groups for selected object./\n"
DefineConsoleMethod(FieldBrushObject, queryGroups, const char*, (const char* simObjName), , "(simObject) Query available static-field groups for selected object./\n"
"@param simObject Object to query static-field groups on.\n"
"@return Space-seperated static-field group list.")
{
// Fetch selected object.
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( argv[2] ) );
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( simObjName ) );
// Valid object?
if ( pSimObject == NULL )
@ -190,13 +191,13 @@ ConsoleMethod(FieldBrushObject, queryGroups, const char*, 3, 3, "(simObject) Que
//-----------------------------------------------------------------------------
// Query Fields.
//-----------------------------------------------------------------------------
ConsoleMethod(FieldBrushObject, queryFields, const char*, 3, 4, "(simObject, [groupList]) Query available static-fields for selected object./\n"
DefineConsoleMethod(FieldBrushObject, queryFields, const char*, (const char* simObjName, const char* groupList), (""), "(simObject, [groupList]) Query available static-fields for selected object./\n"
"@param simObject Object to query static-fields on.\n"
"@param groupList groups to filter static-fields against.\n"
"@return Space-seperated static-field list.")
{
// Fetch selected object.
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( argv[2] ) );
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( simObjName ) );
// Valid object?
if ( pSimObject == NULL )
@ -215,7 +216,7 @@ ConsoleMethod(FieldBrushObject, queryFields, const char*, 3, 4, "(simObject, [gr
const AbstractClassRep::FieldList& staticFields = pSimObject->getFieldList();
// Did we specify a groups list?
if ( argc < 4 )
if (dStrcmp (groupList,"")==0 )
{
// No, so return all fields...
@ -263,7 +264,6 @@ ConsoleMethod(FieldBrushObject, queryFields, const char*, 3, 4, "(simObject, [gr
// Group List.
Vector<StringTableEntry> groups;
// Yes, so fetch group list.
const char* groupList = argv[3];
// Yes, so calculate group Count.
const U32 groupCount = StringUnit::getUnitCount( groupList, " \t\n" );
@ -366,13 +366,13 @@ ConsoleMethod(FieldBrushObject, queryFields, const char*, 3, 4, "(simObject, [gr
//-----------------------------------------------------------------------------
// Copy Fields.
//-----------------------------------------------------------------------------
ConsoleMethod(FieldBrushObject, copyFields, void, 3, 4, "(simObject, [fieldList]) Copy selected static-fields for selected object./\n"
DefineConsoleMethod(FieldBrushObject, copyFields, void, (const char* simObjName, const char* pFieldList), (""), "(simObject, [fieldList]) Copy selected static-fields for selected object./\n"
"@param simObject Object to copy static-fields from.\n"
"@param fieldList fields to filter static-fields against.\n"
"@return No return value.")
{
// Fetch selected object.
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( argv[2] ) );
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( simObjName ) );
// Valid object?
if ( pSimObject == NULL )
@ -383,7 +383,6 @@ ConsoleMethod(FieldBrushObject, copyFields, void, 3, 4, "(simObject, [fieldList]
}
// Fetch field list.
const char* pFieldList = (argc > 3 ) ? (const char*)argv[3] : NULL;
// Copy Fields.
object->copyFields( pSimObject, pFieldList );
@ -501,12 +500,12 @@ void FieldBrushObject::copyFields( SimObject* pSimObject, const char* fieldList
//-----------------------------------------------------------------------------
// Paste Fields.
//-----------------------------------------------------------------------------
ConsoleMethod(FieldBrushObject, pasteFields, void, 3, 3, "(simObject) Paste copied static-fields to selected object./\n"
DefineConsoleMethod(FieldBrushObject, pasteFields, void, (const char* simObjName), , "(simObject) Paste copied static-fields to selected object./\n"
"@param simObject Object to paste static-fields to.\n"
"@return No return value.")
{
// Fetch selected object.
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( argv[2] ) );
SimObject* pSimObject = dynamic_cast<SimObject*>( Sim::findObject( simObjName ) );
// Valid object?
if ( pSimObject == NULL )

View file

@ -23,6 +23,7 @@
#include "persistenceManager.h"
#include "console/simSet.h"
#include "console/consoleTypes.h"
#include "console/engineAPI.h"
#include "core/stream/fileStream.h"
#include "gui/core/guiTypes.h"
#include "materials/customMaterialDefinition.h"
@ -2189,22 +2190,22 @@ void PersistenceManager::deleteObjectsFromFile(const char* fileName)
clearAll();
}
ConsoleMethod( PersistenceManager, deleteObjectsFromFile, void, 3, 3, "( fileName )"
DefineConsoleMethod( PersistenceManager, deleteObjectsFromFile, void, ( const char * fileName ), , "( fileName )"
"Delete all of the objects that are created from the given file." )
{
// Delete Objects.
object->deleteObjectsFromFile( argv[2] );
object->deleteObjectsFromFile( fileName );
}
ConsoleMethod( PersistenceManager, setDirty, void, 3, 4, "(SimObject object, [filename])"
DefineConsoleMethod( PersistenceManager, setDirty, void, ( const char * objName, const char * fileName ), (""), "(SimObject object, [filename])"
"Mark an existing SimObject as dirty (will be written out when saveDirty() is called).")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (objName != "")
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("setDirty(): Invalid SimObject: %s", objName);
return;
}
}
@ -2213,28 +2214,28 @@ ConsoleMethod( PersistenceManager, setDirty, void, 3, 4, "(SimObject object, [fi
if( dirtyObject == Sim::getRootGroup() )
{
Con::errorf( "%s(): Cannot save RootGroup", (const char*)argv[ 0 ] );
Con::errorf( "%s(): Cannot save RootGroup", objName );
return;
}
if (dirtyObject)
{
if (argc == 4 && argv[3][0])
object->setDirty(dirtyObject, argv[3]);
if (dStrcmp( fileName,"")!=0)
object->setDirty(dirtyObject, fileName);
else
object->setDirty(dirtyObject);
}
}
ConsoleMethod( PersistenceManager, removeDirty, void, 3, 3, "(SimObject object)"
DefineConsoleMethod( PersistenceManager, removeDirty, void, ( const char * objName ), , "(SimObject object)"
"Remove a SimObject from the dirty list.")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (dStrcmp( objName,"")!=0)
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("%s(): Invalid SimObject: %s", object->getName(),objName);
return;
}
}
@ -2243,15 +2244,15 @@ ConsoleMethod( PersistenceManager, removeDirty, void, 3, 3, "(SimObject object)"
object->removeDirty(dirtyObject);
}
ConsoleMethod( PersistenceManager, isDirty, bool, 3, 3, "(SimObject object)"
DefineConsoleMethod( PersistenceManager, isDirty, bool, ( const char * objName ), , "(SimObject object)"
"Returns true if the SimObject is on the dirty list.")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (dStrcmp ( objName,"")!=0)
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("%s(): Invalid SimObject: %s", object->getName(), objName);
return false;
}
}
@ -2262,25 +2263,24 @@ ConsoleMethod( PersistenceManager, isDirty, bool, 3, 3, "(SimObject object)"
return false;
}
ConsoleMethod( PersistenceManager, hasDirty, bool, 2, 2, "()"
DefineConsoleMethod( PersistenceManager, hasDirty, bool, (), , "()"
"Returns true if the manager has dirty objects to save." )
{
return object->hasDirty();
}
ConsoleMethod( PersistenceManager, getDirtyObjectCount, S32, 2, 2, "()"
DefineConsoleMethod( PersistenceManager, getDirtyObjectCount, S32, (), , "()"
"Returns the number of dirty objects." )
{
return object->getDirtyList().size();
}
ConsoleMethod( PersistenceManager, getDirtyObject, S32, 3, 3, "( index )"
DefineConsoleMethod( PersistenceManager, getDirtyObject, S32, (S32 index), , "( index )"
"Returns the ith dirty object." )
{
const S32 index = dAtoi( argv[2] );
if ( index < 0 || index >= object->getDirtyList().size() )
{
Con::warnf( "PersistenceManager::getDirtyObject() - Index (%s) out of range.", (const char*)argv[2] );
Con::warnf( "PersistenceManager::getDirtyObject() - Index (%s) out of range.", index );
return 0;
}
@ -2291,7 +2291,7 @@ ConsoleMethod( PersistenceManager, getDirtyObject, S32, 3, 3, "( index )"
return ( dirtyObject.getObject() ) ? dirtyObject.getObject()->getId() : 0;
}
ConsoleMethod( PersistenceManager, listDirty, void, 2, 2, "()"
DefineConsoleMethod( PersistenceManager, listDirty, void, (), , "()"
"Prints the dirty list to the console.")
{
const PersistenceManager::DirtyList dirtyList = object->getDirtyList();
@ -2319,21 +2319,21 @@ ConsoleMethod( PersistenceManager, listDirty, void, 2, 2, "()"
}
}
ConsoleMethod( PersistenceManager, saveDirty, bool, 2, 2, "()"
DefineConsoleMethod( PersistenceManager, saveDirty, bool, (), , "()"
"Saves all of the SimObject's on the dirty list to their respective files.")
{
return object->saveDirty();
}
ConsoleMethod( PersistenceManager, saveDirtyObject, bool, 3, 3, "(SimObject object)"
DefineConsoleMethod( PersistenceManager, saveDirtyObject, bool, (const char * objName), , "(SimObject object)"
"Save a dirty SimObject to it's file.")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (dStrcmp ( objName, "")!=0)
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("%s(): Invalid SimObject: %s", object->getName(), objName);
return false;
}
}
@ -2343,51 +2343,51 @@ ConsoleMethod( PersistenceManager, saveDirtyObject, bool, 3, 3, "(SimObject obje
return false;
}
ConsoleMethod( PersistenceManager, clearAll, void, 2, 2, "()"
DefineConsoleMethod( PersistenceManager, clearAll, void, (), , "()"
"Clears all the tracked objects without saving them." )
{
object->clearAll();
}
ConsoleMethod( PersistenceManager, removeObjectFromFile, void, 3, 4, "(SimObject object, [filename])"
DefineConsoleMethod( PersistenceManager, removeObjectFromFile, void, (const char * objName, const char * filename),("") , "(SimObject object, [filename])"
"Remove an existing SimObject from a file (can optionally specify a different file than \
the one it was created in.")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (dStrcmp ( objName , "")!=0)
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("%s(): Invalid SimObject: %s", object->getName(), objName);
return;
}
}
if (dirtyObject)
{
if (argc == 4 && argv[3][0])
object->removeObjectFromFile(dirtyObject, argv[3]);
if (dStrcmp( filename,"")!=0)
object->removeObjectFromFile(dirtyObject, filename);
else
object->removeObjectFromFile(dirtyObject);
}
}
ConsoleMethod( PersistenceManager, removeField, void, 4, 4, "(SimObject object, string fieldName)"
DefineConsoleMethod( PersistenceManager, removeField, void, (const char * objName, const char * fieldName), , "(SimObject object, string fieldName)"
"Remove a specific field from an object declaration.")
{
SimObject *dirtyObject = NULL;
if (argv[2][0])
if (dStrcmp(objName,"")!=0)
{
if (!Sim::findObject(argv[2], dirtyObject))
if (!Sim::findObject(objName, dirtyObject))
{
Con::printf("%s(): Invalid SimObject: %s", (const char*)argv[0], (const char*)argv[2]);
Con::printf("%s(): Invalid SimObject: %s", object->getName(), objName);
return;
}
}
if (dirtyObject)
{
if (argv[3][0])
object->addRemoveField(dirtyObject, argv[3]);
if (fieldName != "")
object->addRemoveField(dirtyObject, fieldName);
}
}

View file

@ -21,7 +21,7 @@
//-----------------------------------------------------------------------------
#include "console/console.h"
#include "console/engineAPI.h"
#include "console/sim.h"
#include "console/simEvents.h"
#include "console/simObject.h"
@ -86,23 +86,21 @@ namespace Sim
ConsoleFunctionGroupBegin ( SimFunctions, "Functions relating to Sim.");
ConsoleFunction(nameToID, S32, 2, 2, "nameToID(object)")
DefineConsoleFunction( nameToID, S32, (const char * objectName), ,"nameToID(object)")
{
TORQUE_UNUSED(argc);
SimObject *obj = Sim::findObject(argv[1]);
SimObject *obj = Sim::findObject(objectName);
if(obj)
return obj->getId();
else
return -1;
}
ConsoleFunction(isObject, bool, 2, 2, "isObject(object)")
DefineConsoleFunction( isObject, bool, (const char * objectName), ,"isObject(object)")
{
TORQUE_UNUSED(argc);
if (!dStrcmp(argv[1], "0") || !dStrcmp(argv[1], ""))
if (!dStrcmp(objectName, "0") || !dStrcmp(objectName, ""))
return false;
else
return (Sim::findObject(argv[1]) != NULL);
return (Sim::findObject(objectName) != NULL);
}
ConsoleDocFragment _spawnObject1(
@ -135,23 +133,14 @@ ConsoleDocFragment _spawnObject1(
"bool spawnObject(class [, dataBlock, name, properties, script]);"
);
ConsoleFunction(spawnObject, S32, 3, 6, "spawnObject(class [, dataBlock, name, properties, script])"
DefineConsoleFunction( spawnObject, S32, ( const char * spawnClass
, const char * spawnDataBlock
, const char * spawnName
, const char * spawnProperties
, const char * spawnScript
),("","","","","") ,"spawnObject(class [, dataBlock, name, properties, script])"
"@hide")
{
String spawnClass((const char*)argv[1]);
String spawnDataBlock;
String spawnName;
String spawnProperties;
String spawnScript;
if (argc >= 3)
spawnDataBlock = (const char*)argv[2];
if (argc >= 4)
spawnName = (const char*)argv[3];
if (argc >= 5)
spawnProperties = (const char*)argv[4];
if (argc >= 6)
spawnScript = (const char*)argv[5];
SimObject* spawnObject = Sim::spawnObject(spawnClass, spawnDataBlock, spawnName, spawnProperties, spawnScript);
@ -161,35 +150,35 @@ ConsoleFunction(spawnObject, S32, 3, 6, "spawnObject(class [, dataBlock, name, p
return -1;
}
ConsoleFunction(cancel,void,2,2,"cancel(eventId)")
DefineConsoleFunction( cancel, void, (S32 eventId), ,"cancel(eventId)")
{
Sim::cancelEvent(dAtoi(argv[1]));
Sim::cancelEvent(eventId);
}
ConsoleFunction(cancelAll,void,2,2,"cancelAll(objectId): cancel pending events on the specified object. Events will be automatically cancelled if object is deleted.")
DefineConsoleFunction( cancelAll, void, (const char * objectId), ,"cancelAll(objectId): cancel pending events on the specified object. Events will be automatically cancelled if object is deleted.")
{
Sim::cancelPendingEvents(Sim::findObject(argv[1]));
Sim::cancelPendingEvents(Sim::findObject(objectId));
}
ConsoleFunction(isEventPending, bool, 2, 2, "isEventPending(%scheduleId);")
DefineConsoleFunction( isEventPending, bool, (S32 scheduleId), ,"isEventPending(%scheduleId);")
{
return Sim::isEventPending(dAtoi(argv[1]));
return Sim::isEventPending(scheduleId);
}
ConsoleFunction(getEventTimeLeft, S32, 2, 2, "getEventTimeLeft(scheduleId) Get the time left in ms until this event will trigger.")
DefineConsoleFunction( getEventTimeLeft, S32, (S32 scheduleId), ,"getEventTimeLeft(scheduleId) Get the time left in ms until this event will trigger.")
{
return Sim::getEventTimeLeft(dAtoi(argv[1]));
return Sim::getEventTimeLeft(scheduleId);
}
ConsoleFunction(getScheduleDuration, S32, 2, 2, "getScheduleDuration(%scheduleId);")
DefineConsoleFunction( getScheduleDuration, S32, (S32 scheduleId), ,"getScheduleDuration(%scheduleId);" )
{
TORQUE_UNUSED(argc); S32 ret = Sim::getScheduleDuration(dAtoi(argv[1]));
S32 ret = Sim::getScheduleDuration(scheduleId);
return ret;
}
ConsoleFunction(getTimeSinceStart, S32, 2, 2, "getTimeSinceStart(%scheduleId);")
DefineConsoleFunction( getTimeSinceStart, S32, (S32 scheduleId), ,"getTimeSinceStart(%scheduleId);" )
{
TORQUE_UNUSED(argc); S32 ret = Sim::getTimeSinceStart(dAtoi(argv[1]));
S32 ret = Sim::getTimeSinceStart(scheduleId);
return ret;
}
@ -214,7 +203,7 @@ ConsoleFunction(schedule, S32, 4, 0, "schedule(time, refobject|0, command, <arg1
return ret;
}
ConsoleFunction(getUniqueName, const char*, 2, 2,
DefineConsoleFunction( getUniqueName, const char*, (const char * baseName), ,
"( String baseName )\n"
"@brief Returns a unique unused SimObject name based on a given base name.\n\n"
"@baseName Name to conver to a unique string if another instance exists\n"
@ -222,7 +211,7 @@ ConsoleFunction(getUniqueName, const char*, 2, 2,
"@ingroup Editors\n"
"@internal")
{
String outName = Sim::getUniqueName( argv[1] );
String outName = Sim::getUniqueName( baseName );
if ( outName.isEmpty() )
return NULL;
@ -233,7 +222,7 @@ ConsoleFunction(getUniqueName, const char*, 2, 2,
return buffer;
}
ConsoleFunction(getUniqueInternalName, const char*, 4, 4,
DefineConsoleFunction( getUniqueInternalName, const char*, (const char * baseName, const char * setString, bool searchChildren), ,
"( String baseName, SimSet set, bool searchChildren )\n"
"@brief Returns a unique unused internal name within the SimSet/Group based on a given base name.\n\n"
"@note Currently only used by editors\n"
@ -241,13 +230,13 @@ ConsoleFunction(getUniqueInternalName, const char*, 4, 4,
"@internal")
{
SimSet *set;
if ( !Sim::findObject( argv[2], set ) )
if ( !Sim::findObject( setString, set ) )
{
Con::errorf( "getUniqueInternalName() - invalid parameter for SimSet." );
return NULL;
}
String outName = Sim::getUniqueInternalName( argv[1], set, dAtob(argv[3]) );
String outName = Sim::getUniqueInternalName( baseName, set, searchChildren );
if ( outName.isEmpty() )
return NULL;
@ -258,13 +247,12 @@ ConsoleFunction(getUniqueInternalName, const char*, 4, 4,
return buffer;
}
ConsoleFunction( isValidObjectName, bool, 2, 2, "( string name )"
DefineConsoleFunction( isValidObjectName, bool, (const char * name), , "( string name )"
"@brief Return true if the given name makes for a valid object name.\n\n"
"@param name Name of object\n"
"@return True if name is allowed, false if denied (usually because it starts with a number, _, or invalid character"
"@ingroup Console")
{
const char* name = argv[ 1 ];
return Sim::isValidObjectName( name );
}

View file

@ -23,6 +23,7 @@
#include "console/simPersistSet.h"
#include "console/simPersistID.h"
#include "console/consoleTypes.h"
#include "console/engineAPI.h"
IMPLEMENT_CONOBJECT( SimPersistSet );
@ -186,7 +187,7 @@ void SimPersistSet::addObject( SimObject* object )
//-----------------------------------------------------------------------------
ConsoleMethod( SimPersistSet, resolvePersistentIds, void, 2, 2, "() - Try to bind unresolved persistent IDs in the set." )
DefineConsoleMethod( SimPersistSet, resolvePersistentIds, void, (), , "() - Try to bind unresolved persistent IDs in the set." )
{
object->resolvePIDs();
}

View file

@ -25,6 +25,7 @@
#include "core/stringTable.h"
#include "console/console.h"
#include "console/engineAPI.h"
#include "core/stream/fileStream.h"
#include "sim/actionMap.h"
#include "core/fileObject.h"
@ -950,7 +951,7 @@ DefineEngineMethod( SimSet, clear, void, (),,
//-----------------------------------------------------------------------------
//UNSAFE; don't want this in the new API
ConsoleMethod( SimSet, deleteAllObjects, void, 2, 2, "() Delete all objects in the set." )
DefineConsoleMethod( SimSet, deleteAllObjects, void, (), , "() Delete all objects in the set." )
{
object->deleteAllObjects();
}
@ -1022,7 +1023,7 @@ DEFINE_CALLIN( fnSimSet_getCountRecursive, getCountRecursive, SimSet, U32, ( Sim
return set->sizeRecursive();
}
ConsoleMethod( SimSet, getFullCount, S32, 2, 2, "() Get the number of direct and indirect child objects contained in the set.\n"
DefineConsoleMethod( SimSet, getFullCount, S32, (), , "() Get the number of direct and indirect child objects contained in the set.\n"
"@return The number of objects contained in the set as well as in other sets contained directly or indirectly in the set." )
{
return object->sizeRecursive();
@ -1118,10 +1119,10 @@ DefineEngineMethod( SimSet, pushToBack, void, ( SimObject* obj ),,
//-----------------------------------------------------------------------------
ConsoleMethod( SimSet, sort, void, 3, 3, "( string callbackFunction ) Sort the objects in the set using the given comparison function.\n"
DefineConsoleMethod( SimSet, sort, void, ( const char * callbackFunction ), , "( string callbackFunction ) Sort the objects in the set using the given comparison function.\n"
"@param callbackFunction Name of a function that takes two object arguments A and B and returns -1 if A is less, 1 if B is less, and 0 if both are equal." )
{
object->scriptSort( (const char*)argv[2] );
object->scriptSort( callbackFunction );
}
//-----------------------------------------------------------------------------

View file

@ -25,6 +25,7 @@
#include "core/frameAllocator.h"
#include "console/console.h"
#include "console/engineApi.h"
#include "core/stringTable.h"
#include "console/consoleInternal.h"
#include "console/ast.h"
@ -112,24 +113,25 @@ MODULE_END;
// BRKCLR file line - sent when a breakpoint cannot be moved to a breakable line on the client.
//
ConsoleFunction( dbgSetParameters, void, 3, 4, "(int port, string password, bool waitForClient)"
DefineConsoleFunction( dbgSetParameters, void, (S32 port, const char * password, bool waitForClient ), (false), "( int port, string password, bool waitForClient )"
"Open a debug server port on the specified port, requiring the specified password, "
"and optionally waiting for the debug client to connect.\n"
"@internal Primarily used for Torsion and other debugging tools")
{
if (TelDebugger)
TelDebugger->setDebugParameters(dAtoi(argv[1]), argv[2], argc > 3 ? dAtob(argv[3]) : false );
{
TelDebugger->setDebugParameters(port, password, waitForClient );
}
}
ConsoleFunction( dbgIsConnected, bool, 1, 1, "()"
DefineConsoleFunction( dbgIsConnected, bool, (), , "()"
"Returns true if a script debugging client is connected else return false.\n"
"@internal Primarily used for Torsion and other debugging tools")
{
return TelDebugger && TelDebugger->isConnected();
}
ConsoleFunction( dbgDisconnect, void, 1, 1, "()"
DefineConsoleFunction( dbgDisconnect, void, (), , "()"
"Forcibly disconnects any attached script debugging client.\n"
"@internal Primarily used for Torsion and other debugging tools")
{