Eliminate unnecessary uses of ConsoleFunction

This commit is contained in:
Lukas Joergensen 2018-04-17 21:41:29 +02:00
parent 6be736ff85
commit 2bbc716db6
12 changed files with 103 additions and 158 deletions

View file

@ -2722,33 +2722,32 @@ void GameConnection::resetDatablockCache()
afx_saved_db_cache_CRC = 0xffffffff;
}
ConsoleFunction(resetDatablockCache, void, 1, 1, "resetDatablockCache()")
DefineEngineFunction(resetDatablockCache, void, (),,"")
{
GameConnection::resetDatablockCache();
}
ConsoleFunction(isDatablockCacheSaved, bool, 1, 1, "resetDatablockCache()")
DefineEngineFunction(isDatablockCacheSaved, bool, (),,"")
{
return afx_saved_db_cache;
}
ConsoleFunction(getDatablockCacheCRC, S32, 1, 1, "getDatablockCacheCRC()")
DefineEngineFunction(getDatablockCacheCRC, S32, (),,"")
{
return (S32)afx_saved_db_cache_CRC;
}
ConsoleFunction(extractDatablockCacheCRC, S32, 2, 2, "extractDatablockCacheCRC(filename)")
DefineEngineFunction(extractDatablockCacheCRC, S32, (const char* fileName),,"")
{
FileStream f_stream;
const char* fileName = argv[1];
if(!f_stream.open(fileName, Torque::FS::File::Read))
if (!f_stream.open(fileName, Torque::FS::File::Read))
{
Con::errorf("Failed to open file '%s'.", fileName);
return -1;
}
U32 stream_sz = f_stream.getStreamSize();
if (stream_sz < 4*32)
if (stream_sz < 4 * 32)
{
Con::errorf("File '%s' is not a valid datablock cache.", fileName);
f_stream.close();
@ -2777,17 +2776,16 @@ ConsoleFunction(extractDatablockCacheCRC, S32, 2, 2, "extractDatablockCacheCRC(f
return (S32)crc_code;
}
ConsoleFunction(setDatablockCacheCRC, void, 2, 2, "setDatablockCacheCRC(crc)")
DefineEngineFunction(setDatablockCacheCRC, void, (U32 crc), , "")
{
GameConnection *conn = GameConnection::getConnectionToServer();
if(!conn)
if (!conn)
return;
U32 crc_u = (U32)dAtoi(argv[1]);
conn->setServerCacheCRC(crc_u);
conn->setServerCacheCRC(crc);
}
ConsoleMethod( GameConnection, saveDatablockCache, void, 2, 2, "saveDatablockCache()")
DefineEngineMethod(GameConnection, saveDatablockCache, void, (),, "")
{
if (GameConnection::serverCacheEnabled() && !afx_saved_db_cache)
{
@ -2802,14 +2800,14 @@ ConsoleMethod( GameConnection, saveDatablockCache, void, 2, 2, "saveDatablockCac
Con::expandScriptFilename(filename_buffer, sizeof(filename_buffer), filename.c_str());
Torque::Path givenPath(Torque::Path::CompressPath(filename_buffer));
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(givenPath);
if ( fileRef == NULL )
if (fileRef == NULL)
Con::errorf("saveDatablockCache() failed to get CRC for file '%s'.", filename.c_str());
else
afx_saved_db_cache_CRC = (S32)fileRef->getChecksum();
}
}
ConsoleMethod( GameConnection, loadDatablockCache, void, 2, 2, "loadDatablockCache()")
DefineEngineMethod(GameConnection, loadDatablockCache, void, (),, "")
{
if (GameConnection::clientCacheEnabled())
{
@ -2817,7 +2815,7 @@ ConsoleMethod( GameConnection, loadDatablockCache, void, 2, 2, "loadDatablockCac
}
}
ConsoleMethod( GameConnection, loadDatablockCache_Begin, bool, 2, 2, "loadDatablockCache_Begin()")
DefineEngineMethod(GameConnection, loadDatablockCache_Begin, bool, (),, "")
{
if (GameConnection::clientCacheEnabled())
{
@ -2827,7 +2825,7 @@ ConsoleMethod( GameConnection, loadDatablockCache_Begin, bool, 2, 2, "loadDatabl
return false;
}
ConsoleMethod( GameConnection, loadDatablockCache_Continue, bool, 2, 2, "loadDatablockCache_Continue()")
DefineEngineMethod(GameConnection, loadDatablockCache_Continue, bool, (),, "")
{
if (GameConnection::clientCacheEnabled())
{

View file

@ -584,69 +584,33 @@ DefineEngineFunction(getRandomDir, Point3F, (Point3F axis, float thetaMin, float
return MathUtils::randomDir(axis, thetaMin, thetaMax, phiMin, phiMax);
}
ConsoleFunction( MatrixInverseMulVector, const char*, 3, 3, "(MatrixF xfrm, Point3F vector)"
"@brief Multiply the vector by the affine inverse of the transform.\n\n"
"@ingroup AFX")
DefineEngineFunction(MatrixInverseMulVector, Point3F, (MatrixF xfrm, Point3F vector),,
"@brief Multiply the vector by the affine inverse of the transform.\n\n"
"@ingroup AFX")
{
Point3F pos1(0.0f,0.0f,0.0f);
AngAxisF aa1(Point3F(0.0f,0.0f,0.0f),0.0f);
dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
MatrixF temp1(true);
aa1.setMatrix(&temp1);
temp1.setColumn(3, pos1);
Point3F vec1(0.0f,0.0f,0.0f);
dSscanf(argv[2], "%g %g %g", &vec1.x, &vec1.y, &vec1.z);
temp1.affineInverse();
xfrm.affineInverse();
Point3F result;
temp1.mulV(vec1, &result);
xfrm.mulV(vector, &result);
char* ret = Con::getReturnBuffer(256);
dSprintf(ret, 255, "%g %g %g", result.x, result.y, result.z);
return ret;
return result;
}
ConsoleFunction(moveTransformAbs, const char*, 3, 3, "(MatrixF xfrm, Point3F pos)"
"@brief Move the transform to the new absolute position.\n\n"
"@ingroup AFX")
DefineEngineFunction(moveTransformAbs, MatrixF, (MatrixF xfrm, Point3F pos),,
"@brief Move the transform to the new absolute position.\n\n"
"@ingroup AFX")
{
Point3F pos1(0.0f,0.0f,0.0f);
AngAxisF aa1(Point3F(0.0f,0.0f,0.0f),0.0f);
dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
Point3F pos2(0.0f,0.0f,0.0f);
dSscanf(argv[2], "%g %g %g", &pos2.x, &pos2.y, &pos2.z);
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 255, "%g %g %g %g %g %g %g",
pos2.x, pos2.y, pos2.z,
aa1.axis.x, aa1.axis.y, aa1.axis.z,
aa1.angle);
return returnBuffer;
xfrm.setPosition(pos);
return xfrm;
}
ConsoleFunction(moveTransformRel, const char*, 3, 3, "(MatrixF xfrm, Point3F pos)"
"@brief Move the transform to the new relative position.\n\n"
"@ingroup AFX")
DefineEngineFunction(moveTransformRel, MatrixF, (MatrixF xfrm, Point3F pos),,
"@brief Move the transform to the new relative position.\n\n"
"@ingroup AFX")
{
Point3F pos1(0.0f,0.0f,0.0f);
AngAxisF aa1(Point3F(0.0f,0.0f,0.0f),0.0f);
dSscanf(argv[1], "%g %g %g %g %g %g %g", &pos1.x, &pos1.y, &pos1.z, &aa1.axis.x, &aa1.axis.y, &aa1.axis.z, &aa1.angle);
Point3F pos2(0.0f,0.0f,0.0f);
dSscanf(argv[2], "%g %g %g", &pos2.x, &pos2.y, &pos2.z);
pos2 += pos1;
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 255, "%g %g %g %g %g %g %g",
pos2.x, pos2.y, pos2.z,
aa1.axis.x, aa1.axis.y, aa1.axis.z,
aa1.angle);
return returnBuffer;
pos += xfrm.getPosition();
xfrm.setPosition(pos);
return xfrm;
}
DefineEngineFunction(getFreeTargetPosition, Point3F, (),,

View file

@ -218,8 +218,10 @@ DefineEngineFunction( getRealTime, S32, (), , "()"
return Platform::getRealMilliseconds();
}
ConsoleFunction( getLocalTime, const char *, 1, 1, "Return the current local time as: weekday month day year hour min sec.\n\n"
"Local time is platform defined.")
DefineEngineFunction(getLocalTime, const char*, (),,
"@brief Return the current local time as: weekday month day year hour min sec.\n\n"
"Local time is platform defined."
"@ingroup Platform")
{
Platform::LocalTime lt;
Platform::getLocalTime(lt);

View file

@ -2646,26 +2646,23 @@ DefineEngineFunction( getPrefsPath, const char *, ( const char* relativeFileName
//-----------------------------------------------------------------------------
ConsoleFunction( execPrefs, bool, 2, 4, "( string relativeFileName, bool noCalls=false, bool journalScript=false )"
"@brief Manually execute a special script file that contains game or editor preferences\n\n"
"@param relativeFileName Name and path to file from project folder\n"
"@param noCalls Deprecated\n"
"@param journalScript Deprecated\n"
"@return True if script was successfully executed\n"
"@note Appears to be useless in Torque 3D, should be deprecated\n"
"@ingroup Scripting")
DefineEngineFunction(execPrefs, bool, (const char* relativeFileName, bool noCalls, bool journalScript),(false, false),
"@brief Manually execute a special script file that contains game or editor preferences\n\n"
"@param relativeFileName Name and path to file from project folder\n"
"@param noCalls Deprecated\n"
"@param journalScript Deprecated\n"
"@return True if script was successfully executed\n"
"@note Appears to be useless in Torque 3D, should be deprecated\n"
"@ingroup Scripting")
{
const char *filename = Platform::getPrefsPath(argv[1]);
if(filename == NULL || *filename == 0)
if (relativeFileName == NULL || *relativeFileName == 0)
return false;
// Scripts do this a lot, so we may as well help them out
if(! Platform::isFile(filename) && ! Torque::FS::IsFile(filename))
if (!Platform::isFile(relativeFileName) && !Torque::FS::IsFile(relativeFileName))
return true;
argv[0] = "exec";
argv[1] = filename;
return dAtob(Con::execute(argc, argv));
return Con::executeFile(relativeFileName, noCalls, journalScript);
}
//-----------------------------------------------------------------------------

View file

@ -27,7 +27,7 @@
#include "core/tSimpleHashTable.h"
#include "core/strings/stringFunctions.h"
#include "core/stringTable.h"
#include "console/console.h"
#include "console/engineAPI.h"
#include "console/compiler.h"
@ -342,28 +342,26 @@ bool collapseScriptFilename(char *filename, U32 size, const char *src)
// Console Functions
//-----------------------------------------------------------------------------
ConsoleFunction(expandFilename, const char*, 2, 2, "(string filename)"
"@brief Grabs the full path of a specified file\n\n"
"@param filename Name of the local file to locate\n"
"@return String containing the full filepath on disk\n"
"@ingroup FileSystem")
DefineEngineFunction(expandFilename, const char*, (const char* filename),,
"@brief Grabs the full path of a specified file\n\n"
"@param filename Name of the local file to locate\n"
"@return String containing the full filepath on disk\n"
"@ingroup FileSystem")
{
TORQUE_UNUSED(argc);
static const U32 bufSize = 1024;
char* ret = Con::getReturnBuffer( bufSize );
Con::expandScriptFilename(ret, bufSize, argv[1]);
char* ret = Con::getReturnBuffer(bufSize);
Con::expandScriptFilename(ret, bufSize, filename);
return ret;
}
ConsoleFunction(expandOldFilename, const char*, 2, 2, "(string filename)"
"@brief Retrofits a filepath that uses old Torque style\n\n"
"@return String containing filepath with new formatting\n"
"@ingroup FileSystem")
DefineEngineFunction(expandOldFilename, const char*, (const char* filename),,
"@brief Retrofits a filepath that uses old Torque style\n\n"
"@return String containing filepath with new formatting\n"
"@ingroup FileSystem")
{
TORQUE_UNUSED(argc);
static const U32 bufSize = 1024;
char* ret = Con::getReturnBuffer( bufSize );
Con::expandOldScriptFilename(ret, bufSize, argv[1]);
char* ret = Con::getReturnBuffer(bufSize);
Con::expandOldScriptFilename(ret, bufSize, filename);
return ret;
}

View file

@ -536,80 +536,67 @@ float LinearColorF::sSrgbToLinear[256] =
#endif
//-----------------------------------------------------------------------------
ConsoleFunction( getStockColorCount, S32, 1, 1, "() - Gets a count of available stock colors.\n"
"@return A count of available stock colors." )
DefineEngineFunction(getStockColorCount, S32, (),,
"@brief Gets a count of available stock colors.\n"
"@return A count of available stock colors.")
{
return StockColor::getCount();
}
//-----------------------------------------------------------------------------
ConsoleFunction( getStockColorName, const char*, 2, 2, "(stockColorIndex) - Gets the stock color name at the specified index.\n"
DefineEngineFunction(getStockColorName, const char*, (S32 stockColorIndex),,
"@brief Gets the stock color name at the specified index.\n"
"@param stockColorIndex The zero-based index of the stock color name to retrieve.\n"
"@return The stock color name at the specified index or nothing if the string is invalid." )
"@return The stock color name at the specified index or nothing if the string is invalid.")
{
// Fetch stock color index.
const S32 stockColorIndex = dAtoi(argv[1]);
// Fetch the color item.
const StockColorItem* pColorItem = StockColor::getColorItem( stockColorIndex );
const StockColorItem* pColorItem = StockColor::getColorItem(stockColorIndex);
return pColorItem == NULL ? NULL : pColorItem->getColorName();
}
//-----------------------------------------------------------------------------
ConsoleFunction( isStockColor, bool, 2, 2, "(stockColorName) - Gets whether the specified name is a stock color or not.\n"
DefineEngineFunction(isStockColor, bool, (const char* stockColorName),,
"@brief Gets whether the specified name is a stock color or not.\n"
"@param stockColorName - The stock color name to test for.\n"
"@return Whether the specified name is a stock color or not.\n" )
"@return Whether the specified name is a stock color or not.\n")
{
// Fetch stock color name.
const char* pStockColorName = argv[1];
// Return whether this is a stock color name or not.
return StockColor::isColor( pStockColorName );
return StockColor::isColor(stockColorName);
}
//-----------------------------------------------------------------------------
ConsoleFunction( getStockColorF, const char*, 2, 2, "(stockColorName) - Gets a floating-point-based stock color by name.\n"
DefineEngineFunction(getStockColorF, LinearColorF, (const char* stockColorName),,
"@brief Gets a floating-point-based stock color by name.\n"
"@param stockColorName - The stock color name to retrieve.\n"
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n" )
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n")
{
// Fetch stock color name.
const char* pStockColorName = argv[1];
// Return nothing if stock color name is invalid.
if ( !StockColor::isColor( pStockColorName ) )
if (!StockColor::isColor(stockColorName))
return StringTable->EmptyString();
// Fetch stock color.
const LinearColorF& color = StockColor::colorF( pStockColorName );
const LinearColorF& color = StockColor::colorF(stockColorName);
// Format stock color.
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%g %g %g %g", color.red, color.green, color.blue, color.alpha);
return(returnBuffer);
return color;
}
//-----------------------------------------------------------------------------
ConsoleFunction( getStockColorI, const char*, 2, 2, "(stockColorName) - Gets a byte-based stock color by name.\n"
DefineEngineFunction(getStockColorI, ColorI, (const char* stockColorName),,
"@brief Gets a byte-based stock color by name.\n"
"@param stockColorName - The stock color name to retrieve.\n"
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n" )
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n")
{
// Fetch stock color name.
const char* pStockColorName = argv[1];
// Return nothing if stock color name is invalid.
if ( !StockColor::isColor( pStockColorName ) )
if (!StockColor::isColor(stockColorName))
return StringTable->EmptyString();
// Fetch stock color.
const ColorI& color = StockColor::colorI( pStockColorName );
const ColorI& color = StockColor::colorI(stockColorName);
// Format stock color.
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%d %d %d %d", color.red, color.green, color.blue, color.alpha);
return(returnBuffer);
return color;
}

View file

@ -21,7 +21,7 @@
//-----------------------------------------------------------------------------
#include "core/frameAllocator.h"
#include "console/console.h"
#include "console/engineAPI.h"
U8* FrameAllocator::smBuffer = NULL;
U32 FrameAllocator::smWaterMark = 0;
@ -30,7 +30,7 @@ U32 FrameAllocator::smHighWaterMark = 0;
#ifdef TORQUE_DEBUG
U32 FrameAllocator::smMaxFrameAllocation = 0;
ConsoleFunction(getMaxFrameAllocation, S32, 1,1, "getMaxFrameAllocation();")
DefineEngineFunction(getMaxFrameAllocation, S32, (),,"")
{
return FrameAllocator::getMaxFrameAllocation();
}

View file

@ -222,18 +222,17 @@ ResourceBase ResourceManager::nextResource()
ConsoleFunctionGroupBegin(ResourceManagerFunctions, "Resource management functions.");
ConsoleFunction(resourceDump, void, 1, 1, "()"
"@brief List the currently managed resources\n\n"
"Currently used by editors only, internal\n"
"@ingroup Editors\n"
"@internal")
DefineEngineFunction(resourceDump, void, (),,
"@brief List the currently managed resources\n\n"
"Currently used by editors only, internal\n"
"@ingroup Editors\n"
"@internal")
{
#ifdef TORQUE_DEBUG
ResourceManager::get().dumpToConsole();
#endif
}
DefineEngineFunction( reloadResource, void, ( const char* path ),,
"Force the resource at specified input path to be reloaded\n"
"@param path Path to the resource to be reloaded\n\n"

View file

@ -992,7 +992,7 @@ public:
static GFXGLRegisterDevice pGLRegisterDevice;
ConsoleFunction(cycleResources, void, 1, 1, "")
DefineEngineFunction(cycleResources, void, (),, "")
{
static_cast<GFXGLDevice*>(GFX)->zombify();
static_cast<GFXGLDevice*>(GFX)->resurrect();

View file

@ -508,14 +508,15 @@ bool compiledFileNeedsUpdate(UTF8* filename)
return false;
}
ConsoleFunction(CompileLanguage, void, 2, 3, "(string inputFile, [bool createMap]) Compiles a LSO language file."
DefineEngineFunction(CompileLanguage, void, (const char* inputFile, bool createMap), (false),
"@brief Compiles a LSO language file."
" if createIndex is true, will also create languageMap.cs with"
" the global variables for each string index."
" The input file must follow this example layout:"
" TXT_HELLO_WORLD = Hello world in english!")
{
UTF8 scriptFilenameBuffer[1024];
Con::expandScriptFilename((char*)scriptFilenameBuffer, sizeof(scriptFilenameBuffer), argv[1]);
Con::expandScriptFilename((char*)scriptFilenameBuffer, sizeof(scriptFilenameBuffer), inputFile);
if (!Torque::FS::IsFile(scriptFilenameBuffer))
{
@ -532,7 +533,6 @@ ConsoleFunction(CompileLanguage, void, 2, 3, "(string inputFile, [bool createMap
if (compiledFileNeedsUpdate(scriptFilenameBuffer))
{
bool createMap = argc > 2 ? dAtob(argv[2]) : false;
FileStream *mapStream = NULL;
if (createMap)
{

View file

@ -23,7 +23,7 @@
#include <stdarg.h>
#include "core/strings/stringFunctions.h"
#include "console/console.h"
#include "console/engineAPI.h"
//-------------------------------------- STATIC Declaration
@ -167,8 +167,8 @@ const char* avar(const char *message, ...)
//-----------------------------------------------------------------------------
ConsoleFunction( Assert, void, 3, 3, "(condition, message) - Fatal Script Assertion" )
DefineEngineFunction(Assert, void, (bool condition, const char* message),, "Fatal Script Assertion")
{
// Process Assertion.
AssertISV( dAtob(argv[1]), argv[2] );
// Process Assertion.
AssertISV(condition, message);
}

View file

@ -21,7 +21,7 @@
//-----------------------------------------------------------------------------
#include "platform/platformInput.h"
#include "console/console.h"
#include "console/engineAPI.h"
#include "core/util/journal/process.h"
#include "windowManager/platformWindowMgr.h"
@ -97,16 +97,16 @@ void Input::init()
}
//------------------------------------------------------------------------------
ConsoleFunction( isJoystickDetected, bool, 1, 1, "isJoystickDetected()" )
DefineEngineFunction(isJoystickDetected, bool, (),, "")
{
return( SDL_NumJoysticks() > 0 );
return(SDL_NumJoysticks() > 0);
}
//------------------------------------------------------------------------------
ConsoleFunction( getJoystickAxes, const char*, 2, 2, "getJoystickAxes( instance )" )
DefineEngineFunction(getJoystickAxes, const char*, (const char* instance), , "")
{
// TODO SDL
return( "" );
return("");
}
//------------------------------------------------------------------------------