Eliminate ConsoleFunction and ConsoleMethod, replace with DefineEngineStringlyVariadic

This commit is contained in:
Lukas Joergensen 2018-04-20 22:09:58 +02:00
parent 6b524ae58a
commit 7d91d0a577
18 changed files with 112 additions and 84 deletions

View file

@ -130,7 +130,7 @@ static inline F32 moveClamp(F32 v)
//-----------------------------------------------------------------------------
/// Construct and connect an AI connection object
ConsoleFunction(aiConnect, S32 , 2, 20, "(...)"
DefineEngineStringlyVariadicFunction(aiConnect, S32 , 2, 20, "(...)"
"@brief Creates a new AIConnection, and passes arguments to its onConnect script callback.\n\n"
"@returns The newly created AIConnection\n"
"@see GameConnection for parameter information\n"

View file

@ -326,7 +326,7 @@ DefineEngineMethod( GameConnection, setJoinPassword, void, (const char* password
object->setJoinPassword(password);
}
ConsoleMethod(GameConnection, setConnectArgs, void, 3, 17,
DefineEngineStringlyVariadicMethod(GameConnection, setConnectArgs, void, 3, 17,
"(const char* args) @brief On the client, pass along a variable set of parameters to the server.\n\n"
"Once the connection is established with the server, the server calls its onConnect() method "

View file

@ -452,7 +452,7 @@ const char* afxCamera::getMode()
static char buffer[100];
ConsoleMethod(afxCamera, setOrbitMode, void, 7, 8,
DefineEngineStringlyVariadicMethod(afxCamera, setOrbitMode, void, 7, 8,
"(GameBase orbitObject, TransformF mat, float minDistance, float maxDistance, float curDistance, bool ownClientObject)"
"Set the camera to orbit around some given object.\n\n"
"@param orbitObject Object we want to orbit.\n"

View file

@ -2633,29 +2633,29 @@ DefineEngineMethod(afxMagicSpell, getImpactedObject, S32, (),,
return (imp_obj) ? imp_obj->getId() : -1;
}
ConsoleMethod(afxMagicSpell, setTimeFactor, void, 3, 4, "(F32 factor) or (string phase, F32 factor)"
"Sets the time-factor for the spell, either overall or for a specific phrase.\n\n"
"@ingroup AFX")
DefineEngineStringlyVariadicMethod(afxMagicSpell, setTimeFactor, void, 3, 4, "(F32 factor) or (string phase, F32 factor)"
"Sets the time-factor for the spell, either overall or for a specific phrase.\n\n"
"@ingroup AFX")
{
if (argc == 3)
object->setTimeFactor(dAtof(argv[2]));
else
{
if (dStricmp(argv[2], "overall") == 0)
object->setTimeFactor(dAtof(argv[3]));
else if (dStricmp(argv[2], "casting") == 0)
object->setTimeFactor(afxMagicSpell::CASTING_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "launch") == 0)
object->setTimeFactor(afxMagicSpell::LAUNCH_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "delivery") == 0)
object->setTimeFactor(afxMagicSpell::DELIVERY_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "impact") == 0)
object->setTimeFactor(afxMagicSpell::IMPACT_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "linger") == 0)
object->setTimeFactor(afxMagicSpell::LINGER_PHRASE, dAtof(argv[3]));
else
Con::errorf("afxMagicSpell::setTimeFactor() -- unknown spell phrase [%s].", argv[2].getStringValue());
}
if (argc == 3)
object->setTimeFactor(dAtof(argv[2]));
else
{
if (dStricmp(argv[2], "overall") == 0)
object->setTimeFactor(dAtof(argv[3]));
else if (dStricmp(argv[2], "casting") == 0)
object->setTimeFactor(afxMagicSpell::CASTING_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "launch") == 0)
object->setTimeFactor(afxMagicSpell::LAUNCH_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "delivery") == 0)
object->setTimeFactor(afxMagicSpell::DELIVERY_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "impact") == 0)
object->setTimeFactor(afxMagicSpell::IMPACT_PHRASE, dAtof(argv[3]));
else if (dStricmp(argv[2], "linger") == 0)
object->setTimeFactor(afxMagicSpell::LINGER_PHRASE, dAtof(argv[3]));
else
Con::errorf("afxMagicSpell::setTimeFactor() -- unknown spell phrase [%s].", argv[2].getStringValue());
}
}
DefineEngineMethod(afxMagicSpell, interruptStage, void, (),,

View file

@ -860,18 +860,18 @@ DefineEngineFunction(getMaxF, F32, (float a, float b),,
return getMax(a, b);
}
ConsoleFunction(echoThru, const char*, 2, 0, "(string passthru, string text...)"
"Like echo(), but first argument is returned.\n"
"@ingroup AFX")
DefineEngineStringlyVariadicFunction(echoThru, const char*, 2, 0, "(string passthru, string text...)"
"Like echo(), but first argument is returned.\n"
"@ingroup AFX")
{
U32 len = 0;
S32 i;
for(i = 2; i < argc; i++)
for (i = 2; i < argc; i++)
len += dStrlen(argv[i]);
char *ret = Con::getReturnBuffer(len + 1);
ret[0] = 0;
for(i = 2; i < argc; i++)
for (i = 2; i < argc; i++)
dStrcat(ret, argv[i], len + 1);
Con::printf("%s -- [%s]", ret, argv[1].getStringValue());
@ -880,7 +880,7 @@ ConsoleFunction(echoThru, const char*, 2, 0, "(string passthru, string text...)"
return argv[1];
}
ConsoleFunction(warnThru, const char*, 2, 0, "(string passthru, string text...)"
DefineEngineStringlyVariadicFunction(warnThru, const char*, 2, 0, "(string passthru, string text...)"
"Like warn(), but first argument is returned.\n"
"@ingroup AFX")
{
@ -900,7 +900,7 @@ ConsoleFunction(warnThru, const char*, 2, 0, "(string passthru, string text...)"
return argv[1];
}
ConsoleFunction(errorThru, const char*, 2, 0, "(string passthru, string text...)"
DefineEngineStringlyVariadicFunction(errorThru, const char*, 2, 0, "(string passthru, string text...)"
"Like error(), but first argument is returned.\n"
"@ingroup AFX")
{

View file

@ -212,7 +212,7 @@ ConsoleDocClass( RemoteCommandEvent,
ConsoleFunctionGroupBegin( Net, "Functions for use with the network; tagged strings and remote commands.");
ConsoleFunction( commandToServer, void, 2, RemoteCommandEvent::MaxRemoteCommandArgs + 1, "(string func, ...)"
DefineEngineStringlyVariadicFunction( commandToServer, void, 2, RemoteCommandEvent::MaxRemoteCommandArgs + 1, "(string func, ...)"
"@brief Send a command to the server.\n\n"
"@param func Name of the server command being called\n"
@ -255,7 +255,7 @@ ConsoleFunction( commandToServer, void, 2, RemoteCommandEvent::MaxRemoteCommandA
RemoteCommandEvent::sendRemoteCommand(conn, args.count(), args);
}
ConsoleFunction( commandToClient, void, 3, RemoteCommandEvent::MaxRemoteCommandArgs + 2, "(NetConnection client, string func, ...)"
DefineEngineStringlyVariadicFunction( commandToClient, void, 3, RemoteCommandEvent::MaxRemoteCommandArgs + 2, "(NetConnection client, string func, ...)"
"@brief Send a command from the server to the client\n\n"
"@param client The numeric ID of a client GameConnection\n"
@ -349,7 +349,7 @@ DefineEngineFunction(getTaggedString, const char* , (const char *tag), (""),
ConsoleFunction( buildTaggedString, const char*, 2, 11, "(string format, ...)"
DefineEngineStringlyVariadicFunction( buildTaggedString, const char*, 2, 11, "(string format, ...)"
"@brief Build a string using the specified tagged string format.\n\n"
"This function takes an already tagged string (passed in as a tagged string ID) and one "

View file

@ -420,7 +420,7 @@ extern "C" {
}
ConsoleFunction(TestFunction2Args, const char *, 3, 3, "testFunction(arg1, arg2)")
DefineEngineStringlyVariadicFunction(TestFunction2Args, const char *, 3, 3, "testFunction(arg1, arg2)")
{
return "Return Value";
}

View file

@ -1191,11 +1191,6 @@ public:
# define ConsoleFunctionGroupBegin(groupName, usage) \
static ConsoleConstructor cfg_ConsoleFunctionGroup_##groupName##_GroupBegin(NULL,#groupName,usage)
# define ConsoleFunction(name,returnType,minArgs,maxArgs,usage1) \
returnType cf_##name(SimObject *, S32, ConsoleValueRef *argv); \
ConsoleConstructor cc_##name##_obj(NULL,#name,cf_##name,usage1,minArgs,maxArgs); \
returnType cf_##name(SimObject *, S32 argc, ConsoleValueRef *argv)
# define ConsoleToolFunction(name,returnType,minArgs,maxArgs,usage1) \
returnType ctf_##name(SimObject *, S32, ConsoleValueRef *argv); \
ConsoleConstructor cc_##name##_obj(NULL,#name,ctf_##name,usage1,minArgs,maxArgs, true); \
@ -1211,15 +1206,6 @@ public:
# define ConsoleMethodGroupBegin(className, groupName, usage) \
static ConsoleConstructor cc_##className##_##groupName##_GroupBegin(#className,#groupName,usage)
# define ConsoleMethod(className,name,returnType,minArgs,maxArgs,usage1) \
inline returnType cm_##className##_##name(className *, S32, ConsoleValueRef *argv); \
returnType cm_##className##_##name##_caster(SimObject *object, S32 argc, ConsoleValueRef *argv) { \
AssertFatal( dynamic_cast<className*>( object ), "Object passed to " #name " is not a " #className "!" ); \
conmethod_return_##returnType ) cm_##className##_##name(static_cast<className*>(object),argc,argv); \
}; \
ConsoleConstructor cc_##className##_##name##_obj(#className,#name,cm_##className##_##name##_caster,usage1,minArgs,maxArgs); \
inline returnType cm_##className##_##name(className *object, S32 argc, ConsoleValueRef *argv)
# define ConsoleMethodGroupEnd(className, groupName) \
static ConsoleConstructor cc_##className##_##groupName##_GroupEnd(#className,#groupName,NULL)

View file

@ -1200,7 +1200,7 @@ DefineEngineFunction( isValidIP, bool, ( const char* str),,
// Torque won't normally add another string if it already exists with another casing,
// so this forces the addition. It should be called once near the start, such as in main.cs.
ConsoleFunction(addCaseSensitiveStrings,void,2,0,"[string1, string2, ...]"
DefineEngineStringlyVariadicFunction(addCaseSensitiveStrings,void,2,0,"[string1, string2, ...]"
"Adds case sensitive strings to the StringTable.")
{
for(int i = 1; i < argc; i++)
@ -1879,7 +1879,7 @@ DefineEngineFunction( getTag, const char*, ( const char* textTagString ), , "( s
//-----------------------------------------------------------------------------
ConsoleFunction( echo, void, 2, 0, "( string message... ) "
DefineEngineStringlyVariadicFunction( echo, void, 2, 0, "( string message... ) "
"@brief Logs a message to the console.\n\n"
"Concatenates all given arguments to a single string and prints the string to the console. "
"A newline is added automatically after the text.\n\n"
@ -1902,7 +1902,7 @@ ConsoleFunction( echo, void, 2, 0, "( string message... ) "
//-----------------------------------------------------------------------------
ConsoleFunction( warn, void, 2, 0, "( string message... ) "
DefineEngineStringlyVariadicFunction( warn, void, 2, 0, "( string message... ) "
"@brief Logs a warning message to the console.\n\n"
"Concatenates all given arguments to a single string and prints the string to the console as a warning "
"message (in the in-game console, these will show up using a turquoise font by default). "
@ -1926,7 +1926,7 @@ ConsoleFunction( warn, void, 2, 0, "( string message... ) "
//-----------------------------------------------------------------------------
ConsoleFunction( error, void, 2, 0, "( string message... ) "
DefineEngineStringlyVariadicFunction( error, void, 2, 0, "( string message... ) "
"@brief Logs an error message to the console.\n\n"
"Concatenates all given arguments to a single string and prints the string to the console as an error "
"message (in the in-game console, these will show up using a red font by default). "
@ -2236,7 +2236,7 @@ DefineEngineFunction( generateUUID, Torque::UUID, (),,
//-----------------------------------------------------------------------------
ConsoleFunction( call, const char *, 2, 0, "( string functionName, string args... ) "
DefineEngineStringlyVariadicFunction( call, const char *, 2, 0, "( string functionName, string args... ) "
"Apply the given arguments to the specified global function and return the result of the call.\n\n"
"@param functionName The name of the function to call. This function must be in the global namespace, i.e. "
"you cannot call a function in a namespace through #call. Use eval() for that.\n"

View file

@ -855,6 +855,64 @@ public:
); \
static inline returnType _fn ## className ## name ## impl args
# define DefineEngineStringlyVariadicFunction(name,returnType,minArgs,maxArgs,usage) \
static inline returnType _fn ## name ## impl (SimObject *, S32 argc, ConsoleValueRef *argv); \
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \
(S32 argc, const char** argv) \
{ \
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
StringStackConsoleWrapper args(argc, argv); \
return EngineTypeTraits< returnType >::ReturnValue( \
_fn ## name ## impl(NULL, args.count(), args) \
); \
} \
static _EngineFunctionDefaultArguments< void (S32 argc, const char** argv) > _fn ## name ## DefaultArgs; \
static EngineFunctionInfo _fn ## name ## FunctionInfo( \
#name, \
&_SCOPE<>()(), \
usage, \
#returnType " " #name "(S32 argc, const char** argv)", \
"fn" #name, \
TYPE< returnType (S32 argc, const char** argv) >(), \
&_fn ## name ## DefaultArgs, \
( void* ) &fn ## name, \
0 \
); \
ConsoleConstructor cc_##name##_obj(NULL,#name,_fn ## name ## impl,usage,minArgs,maxArgs); \
returnType _fn ## name ## impl(SimObject *, S32 argc, ConsoleValueRef *argv)
# define DefineEngineStringlyVariadicMethod(className, name,returnType,minArgs,maxArgs,usage) \
static inline returnType _fn ## className ## _ ## name ## impl (className* object, S32 argc, ConsoleValueRef* argv); \
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \
(className* object, S32 argc, const char** argv) \
{ \
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
StringStackConsoleWrapper args(argc, argv); \
return EngineTypeTraits< returnType >::ReturnValue( \
_fn ## className ## _ ## name ## impl(object, args.count(), args) \
); \
} \
static _EngineFunctionDefaultArguments< void (className* object, S32 argc, const char** argv) > _fn ## className ## _ ## name ## DefaultArgs; \
static EngineFunctionInfo _fn ## className ## _ ## name ## FunctionInfo( \
#name, \
&_SCOPE<>()(), \
usage, \
#returnType " " #name "(SimObject* object, S32 argc, const char** argv)", \
"fn" #className "_" #name, \
TYPE< returnType (SimObject* object, S32 argc, const char** argv) >(), \
&_fn ## className ## _ ## name ## DefaultArgs, \
( void* ) &fn ## className ## _ ## name, \
0 \
); \
returnType cm_##className##_##name##_caster(SimObject* object, S32 argc, ConsoleValueRef* argv) { \
AssertFatal( dynamic_cast<className*>( object ), "Object passed to " #name " is not a " #className "!" ); \
conmethod_return_##returnType ) _fn ## className ## _ ## name ## impl(static_cast<className*>(object),argc,argv); \
}; \
ConsoleConstructor cc_##className##_##name##_obj(#className,#name,cm_##className##_##name##_caster,usage,minArgs,maxArgs); \
static inline returnType _fn ## className ## _ ## name ## impl(className *object, S32 argc, ConsoleValueRef *argv)
// The following three macros are only temporary. They allow to define engineAPI functions using the framework
// here in this file while being visible only in the new API. When the console interop is removed, these macros
// can be removed and all their uses be replaced with their corresponding versions that now still include support

View file

@ -181,7 +181,7 @@ DefineEngineFunction( getTimeSinceStart, S32, (S32 scheduleId), ,"getTimeSinceSt
return ret;
}
ConsoleFunction(schedule, S32, 4, 0, "schedule(time, refobject|0, command, <arg1...argN>)")
DefineEngineStringlyVariadicFunction(schedule, S32, 4, 0, "schedule(time, refobject|0, command, <arg1...argN>)")
{
U32 timeDelta = U32(dAtof(argv[1]));
SimObject *refObject = Sim::findObject(argv[2]);

View file

@ -2945,7 +2945,7 @@ DefineEngineMethod( SimObject, setFieldType, void, ( const char* fieldName, cons
//-----------------------------------------------------------------------------
ConsoleMethod( SimObject, call, const char*, 3, 0, "( string method, string args... ) Dynamically call a method on an object.\n"
DefineEngineStringlyVariadicMethod( SimObject, call, const char*, 3, 0, "( string method, string args... ) Dynamically call a method on an object.\n"
"@param method Name of method to call.\n"
"@param args Zero or more arguments for the method.\n"
"@return The result of the method call." )
@ -3047,7 +3047,7 @@ DefineEngineMethod( SimObject, delete, void, (),,
//-----------------------------------------------------------------------------
ConsoleMethod( SimObject,schedule, S32, 4, 0, "( float time, string method, string args... ) Delay an invocation of a method.\n"
DefineEngineStringlyVariadicMethod( SimObject,schedule, S32, 4, 0, "( float time, string method, string args... ) Delay an invocation of a method.\n"
"@param time The number of milliseconds after which to invoke the method. This is a soft limit.\n"
"@param method The method to call.\n"
"@param args The arguments with which to call the method.\n"

View file

@ -895,15 +895,7 @@ DefineEngineMethod( SimSet, listObjects, void, (),,
//-----------------------------------------------------------------------------
DEFINE_CALLIN( fnSimSet_add, add, SimSet, void, ( SimSet* set, SimObject* object ),,,
"Add the given object to the set.\n"
"@param object An object." )
{
if( object )
set->addObject( object );
}
ConsoleMethod( SimSet, add, void, 3, 0,
DefineEngineStringlyVariadicMethod( SimSet, add, void, 3, 0,
"( SimObject objects... ) Add the given objects to the set.\n"
"@param objects The objects to add to the set." )
{
@ -919,15 +911,7 @@ ConsoleMethod( SimSet, add, void, 3, 0,
//-----------------------------------------------------------------------------
DEFINE_CALLIN( fnSimSet_remove, remove, SimSet, void, ( SimSet* set, SimObject* object ),,,
"Remove the given object from the set.\n"
"@param object An object." )
{
if( object )
set->removeObject( object );
}
ConsoleMethod( SimSet, remove, void, 3, 0,
DefineEngineStringlyVariadicMethod( SimSet, remove, void, 3, 0,
"( SimObject objects... ) Remove the given objects from the set.\n"
"@param objects The objects to remove from the set." )
{
@ -970,7 +954,7 @@ DefineEngineMethod( SimSet, getRandom, SimObject*, (),,
//-----------------------------------------------------------------------------
ConsoleMethod( SimSet, callOnChildren, void, 3, 0,
DefineEngineStringlyVariadicMethod( SimSet, callOnChildren, void, 3, 0,
"( string method, string args... ) Call a method on all objects contained in the set.\n\n"
"@param method The name of the method to call.\n"
"@param args The arguments to the method.\n\n"
@ -982,7 +966,7 @@ ConsoleMethod( SimSet, callOnChildren, void, 3, 0,
//-----------------------------------------------------------------------------
ConsoleMethod( SimSet, callOnChildrenNoRecurse, void, 3, 0,
DefineEngineStringlyVariadicMethod( SimSet, callOnChildrenNoRecurse, void, 3, 0,
"( string method, string args... ) Call a method on all objects contained in the set.\n\n"
"@param method The name of the method to call.\n"
"@param args The arguments to the method.\n\n"

View file

@ -77,7 +77,7 @@ DefineEngineMethod( GuiFilterCtrl, getValue, const char*, (), , "Return a tuple
return buffer;
}
ConsoleMethod( GuiFilterCtrl, setValue, void, 3, 20, "(f1, f2, ...)"
DefineEngineStringlyVariadicMethod( GuiFilterCtrl, setValue, void, 3, 20, "(f1, f2, ...)"
"Reset the filter to use the specified points, spread equidistantly across the domain."
"@internal")
{

View file

@ -407,7 +407,7 @@ DefineEngineMethod( GuiGraphCtrl, setGraphType, void, ( S32 plotId, GuiGraphType
//-----------------------------------------------------------------------------
ConsoleMethod( GuiGraphCtrl, matchScale, void, 3, GuiGraphCtrl::MaxPlots + 2, "( int plotID1, int plotID2, ... ) "
DefineEngineStringlyVariadicMethod( GuiGraphCtrl, matchScale, void, 3, GuiGraphCtrl::MaxPlots + 2, "( int plotID1, int plotID2, ... ) "
"Set the scale of all specified plots to the maximum scale among them.\n\n"
"@param plotID1 Index of plotting curve.\n"
"@param plotID2 Index of plotting curve." )

View file

@ -3225,7 +3225,7 @@ void WorldEditor::setEditorTool(EditorTool* newTool)
//------------------------------------------------------------------------------
ConsoleMethod( WorldEditor, ignoreObjClass, void, 3, 0, "(string class_name, ...)")
DefineEngineStringlyVariadicMethod( WorldEditor, ignoreObjClass, void, 3, 0, "(string class_name, ...)")
{
object->ignoreObjClass(argc, argv);
}

View file

@ -33,7 +33,7 @@ extern void mInstall_AMD_Math();
extern void mInstall_Library_SSE();
//--------------------------------------
ConsoleFunction( mathInit, void, 1, 10, "( ... )"
DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
"@brief Install the math library with specified extensions.\n\n"
"Possible parameters are:\n\n"
" - 'DETECT' Autodetect math lib settings.\n\n"

View file

@ -2077,7 +2077,7 @@ static ConsoleDocFragment _ActionMapbind2(
"ActionMap",
"bool bind( string device, string action, string flag, string deadZone, string scale, string command );");
ConsoleMethod( ActionMap, bind, bool, 5, 10, "actionMap.bind( device, action, [modifier, spec, mod...], command )"
DefineEngineStringlyVariadicMethod( ActionMap, bind, bool, 5, 10, "actionMap.bind( device, action, [modifier, spec, mod...], command )"
"@hide")
{
StringStackWrapper args(argc - 2, argv + 2);
@ -2126,7 +2126,7 @@ static ConsoleDocFragment _ActionMapbindObj2(
"ActionMap",
"bool bindObj( string device, string action, string flag, string deadZone, string scale, string command, SimObjectID object );");
ConsoleMethod( ActionMap, bindObj, bool, 6, 11, "(device, action, [modifier, spec, mod...], command, object)"
DefineEngineStringlyVariadicMethod( ActionMap, bindObj, bool, 6, 11, "(device, action, [modifier, spec, mod...], command, object)"
"@hide")
{
SimObject* simObject = Sim::findObject(argv[argc - 1]);