From 88106f9032399d926afd3e3d3b5286c3fad204a1 Mon Sep 17 00:00:00 2001 From: "Thomas \"elfprince13\" Dickerson" Date: Fri, 6 Jan 2017 14:50:41 -0500 Subject: [PATCH] Fixed type inference for nulls in console functions --- Engine/source/T3D/aiPlayer.cpp | 6 +++--- Engine/source/T3D/fx/particleEmitterNode.cpp | 2 +- Engine/source/T3D/fx/ribbonNode.cpp | 3 +-- Engine/source/T3D/tsStatic.cpp | 4 ++-- Engine/source/app/badWordFilter.cpp | 2 +- Engine/source/console/consoleTypes.h | 1 + Engine/source/console/engineAPI.h | 9 ++++++--- Engine/source/console/engineFunctions.h | 2 ++ Engine/source/console/enginePrimitives.h | 2 ++ Engine/source/gfx/gfxShader.cpp | 2 +- Engine/source/gfx/video/videoCapture.cpp | 4 ++-- Engine/source/gui/core/guiCanvas.cpp | 2 +- Engine/source/gui/editor/guiEditCtrl.cpp | 4 ++-- Engine/source/gui/editor/guiMenuBar.cpp | 2 +- Engine/source/lighting/lightManager.cpp | 2 +- Engine/source/scene/sceneContainer.cpp | 2 +- Engine/source/sim/actionMap.cpp | 2 +- 17 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Engine/source/T3D/aiPlayer.cpp b/Engine/source/T3D/aiPlayer.cpp index 88b500205..7565f7831 100644 --- a/Engine/source/T3D/aiPlayer.cpp +++ b/Engine/source/T3D/aiPlayer.cpp @@ -1317,7 +1317,7 @@ bool AIPlayer::checkInLos(GameBase* target, bool _useMuzzle, bool _checkEnabled) return hit; } -DefineEngineMethod(AIPlayer, checkInLos, bool, (ShapeBase* obj, bool useMuzzle, bool checkEnabled),(NULL, false, false), +DefineEngineMethod(AIPlayer, checkInLos, bool, (ShapeBase* obj, bool useMuzzle, bool checkEnabled),(nullAsType(), false, false), "@brief Check whether an object is in line of sight.\n" "@obj Object to check. (If blank, it will check the current target).\n" "@useMuzzle Use muzzle position. Otherwise use eye position. (defaults to false).\n" @@ -1366,7 +1366,7 @@ bool AIPlayer::checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled) return (dot > mCos(camFov)); } -DefineEngineMethod(AIPlayer, checkInFoV, bool, (ShapeBase* obj, F32 fov, bool checkEnabled), (NULL, 45.0f, false), +DefineEngineMethod(AIPlayer, checkInFoV, bool, (ShapeBase* obj, F32 fov, bool checkEnabled), (nullAsType(), 45.0f, false), "@brief Check whether an object is within a specified veiw cone.\n" "@obj Object to check. (If blank, it will check the current target).\n" "@fov view angle in degrees.(Defaults to 45)\n" @@ -1440,7 +1440,7 @@ F32 AIPlayer::getTargetDistance(GameBase* target, bool _checkEnabled) return (getPosition() - target->getPosition()).len(); } -DefineEngineMethod(AIPlayer, getTargetDistance, F32, (ShapeBase* obj, bool checkEnabled), (NULL, false), +DefineEngineMethod(AIPlayer, getTargetDistance, F32, (ShapeBase* obj, bool checkEnabled), (nullAsType(), false), "@brief The distance to a given object.\n" "@obj Object to check. (If blank, it will check the current target).\n" "@checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)\n") diff --git a/Engine/source/T3D/fx/particleEmitterNode.cpp b/Engine/source/T3D/fx/particleEmitterNode.cpp index bb362417b..e03e5a1a7 100644 --- a/Engine/source/T3D/fx/particleEmitterNode.cpp +++ b/Engine/source/T3D/fx/particleEmitterNode.cpp @@ -395,7 +395,7 @@ void ParticleEmitterNode::setEmitterDataBlock(ParticleEmitterData* data) } -DefineEngineMethod(ParticleEmitterNode, setEmitterDataBlock, void, (ParticleEmitterData* emitterDatablock), (NULL), +DefineEngineMethod(ParticleEmitterNode, setEmitterDataBlock, void, (ParticleEmitterData* emitterDatablock), (nullAsType()), "Assigns the datablock for this emitter node.\n" "@param emitterDatablock ParticleEmitterData datablock to assign\n" "@tsexample\n" diff --git a/Engine/source/T3D/fx/ribbonNode.cpp b/Engine/source/T3D/fx/ribbonNode.cpp index 2582fbe6f..7e73fbc59 100644 --- a/Engine/source/T3D/fx/ribbonNode.cpp +++ b/Engine/source/T3D/fx/ribbonNode.cpp @@ -39,7 +39,6 @@ ConsoleDocClass( RibbonNodeData, ConsoleDocClass( RibbonNode, "" ); - //----------------------------------------------------------------------------- // RibbonNodeData //----------------------------------------------------------------------------- @@ -299,7 +298,7 @@ void RibbonNode::setRibbonDatablock(RibbonData* data) mRibbonDatablock = data; } -DefineEngineMethod(RibbonNode, setRibbonDatablock, void, (RibbonData* ribbonDatablock), (0), +DefineEngineMethod(RibbonNode, setRibbonDatablock, void, (RibbonData* ribbonDatablock), (nullAsType()), "Assigns the datablock for this ribbon node.\n" "@param ribbonDatablock RibbonData datablock to assign\n" "@tsexample\n" diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index 3997d40dd..0f7b69ef3 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -1256,7 +1256,7 @@ DefineEngineMethod( TSStatic, getTargetCount, S32,(),, // This method is able to change materials per map to with others. The material that is being replaced is being mapped to // unmapped_mat as a part of this transition -DefineEngineMethod( TSStatic, changeMaterial, void, ( const char* mapTo, Material* oldMat, Material* newMat ),("",NULL,NULL), +DefineEngineMethod( TSStatic, changeMaterial, void, ( const char* mapTo, Material* oldMat, Material* newMat ),("",nullAsType(),nullAsType()), "@brief Change one of the materials on the shape.\n\n" "This method changes materials per mapTo with others. The material that " @@ -1323,4 +1323,4 @@ DefineEngineMethod( TSStatic, getModelFile, const char *, (),, ) { return object->getShapeFileName(); -} \ No newline at end of file +} diff --git a/Engine/source/app/badWordFilter.cpp b/Engine/source/app/badWordFilter.cpp index 7f1dd51a6..e267f5032 100644 --- a/Engine/source/app/badWordFilter.cpp +++ b/Engine/source/app/badWordFilter.cpp @@ -254,7 +254,7 @@ DefineEngineFunction(addBadWord, bool, (const char* badWord),, return gBadWordFilter->addBadWord(badWord); } -DefineEngineFunction(filterString, const char *, (const char* baseString, const char* replacementChars), (NULL, NULL), +DefineEngineFunction(filterString, const char *, (const char* baseString, const char* replacementChars), (nullAsType(), nullAsType()), "@brief Replaces the characters in a string with designated text\n\n" "Uses the bad word filter to determine which characters within the string will be replaced.\n\n" diff --git a/Engine/source/console/consoleTypes.h b/Engine/source/console/consoleTypes.h index 8080a8830..8b64d4fa1 100644 --- a/Engine/source/console/consoleTypes.h +++ b/Engine/source/console/consoleTypes.h @@ -39,6 +39,7 @@ #include "console/engineStructs.h" #endif +template constexpr T nullAsType(){ return nullptr; } /// @file /// Legacy TS-based console type definitions. diff --git a/Engine/source/console/engineAPI.h b/Engine/source/console/engineAPI.h index ee1a34c7b..c4976ad55 100644 --- a/Engine/source/console/engineAPI.h +++ b/Engine/source/console/engineAPI.h @@ -547,9 +547,12 @@ namespace engineAPI{ template static IthArgType getRealArgValue(S32 argc, ConsoleValueRef *argv, const _EngineFunctionDefaultArguments< void(RealArgTs...) >& defaultArgs) { - return (startArgc + index) < argc - ? EngineUnmarshallData< IthArgType >()( argv[ startArgc + index ] ) - : std::get(defaultArgs.mArgs); + if((startArgc + index) < argc) + { + return EngineUnmarshallData< IthArgType >()( argv[ startArgc + index ] ); + } else { + return std::get(defaultArgs.mArgs); + } } template diff --git a/Engine/source/console/engineFunctions.h b/Engine/source/console/engineFunctions.h index d0b4fa719..4346b39cf 100644 --- a/Engine/source/console/engineFunctions.h +++ b/Engine/source/console/engineFunctions.h @@ -23,6 +23,8 @@ #ifndef _ENGINEFUNCTIONS_H_ #define _ENGINEFUNCTIONS_H_ +#include + #ifndef _ENGINEEXPORTS_H_ #include "console/engineExports.h" #endif diff --git a/Engine/source/console/enginePrimitives.h b/Engine/source/console/enginePrimitives.h index 72f1899e7..7f0b37670 100644 --- a/Engine/source/console/enginePrimitives.h +++ b/Engine/source/console/enginePrimitives.h @@ -41,6 +41,8 @@ DECLARE_PRIMITIVE_R(S32); DECLARE_PRIMITIVE_R(U32); DECLARE_PRIMITIVE_R(F32); DECLARE_PRIMITIVE_R(F64); +DECLARE_PRIMITIVE_R(U64); +DECLARE_PRIMITIVE_R(S64); DECLARE_PRIMITIVE_R(void*); diff --git a/Engine/source/gfx/gfxShader.cpp b/Engine/source/gfx/gfxShader.cpp index 54f1893e6..1fc35a995 100644 --- a/Engine/source/gfx/gfxShader.cpp +++ b/Engine/source/gfx/gfxShader.cpp @@ -178,7 +178,7 @@ void GFXShader::_unlinkBuffer( GFXShaderConstBuffer *buf ) DefineEngineFunction( addGlobalShaderMacro, void, - ( const char *name, const char *value ), ( NULL ), + ( const char *name, const char *value ), ( nullAsType() ), "Adds a global shader macro which will be merged with the script defined " "macros on every shader. The macro will replace the value of an existing " "macro of the same name. For the new macro to take effect all the shaders " diff --git a/Engine/source/gfx/video/videoCapture.cpp b/Engine/source/gfx/video/videoCapture.cpp index 230baf501..0af46af10 100644 --- a/Engine/source/gfx/video/videoCapture.cpp +++ b/Engine/source/gfx/video/videoCapture.cpp @@ -340,7 +340,7 @@ DefineEngineFunction( stopVideoCapture, void, (),, DefineEngineFunction( playJournalToVideo, void, ( const char *journalFile, const char *videoFile, const char *encoder, F32 framerate, Point2I resolution ), - ( NULL, "THEORA", 30.0f, Point2I::Zero ), + ( nullAsType(), "THEORA", 30.0f, Point2I::Zero ), "Load a journal file and capture it video.\n" "@ingroup Rendering\n" ) { @@ -357,4 +357,4 @@ DefineEngineFunction( playJournalToVideo, void, VIDCAP->waitForCanvas(); Journal::Play( journalFile ); -} \ No newline at end of file +} diff --git a/Engine/source/gui/core/guiCanvas.cpp b/Engine/source/gui/core/guiCanvas.cpp index a3f2344f2..400e50d73 100644 --- a/Engine/source/gui/core/guiCanvas.cpp +++ b/Engine/source/gui/core/guiCanvas.cpp @@ -2147,7 +2147,7 @@ ConsoleDocFragment _popDialog2( "void popDialog();" ); -DefineConsoleMethod( GuiCanvas, popDialog, void, (GuiControl * gui), (NULL), "(GuiControl ctrl=NULL)" +DefineConsoleMethod( GuiCanvas, popDialog, void, (GuiControl * gui), (nullAsType()), "(GuiControl ctrl=NULL)" "@hide") { if (gui) diff --git a/Engine/source/gui/editor/guiEditCtrl.cpp b/Engine/source/gui/editor/guiEditCtrl.cpp index f972ec8ca..5c4c09fb3 100644 --- a/Engine/source/gui/editor/guiEditCtrl.cpp +++ b/Engine/source/gui/editor/guiEditCtrl.cpp @@ -2582,7 +2582,7 @@ DefineConsoleMethod( GuiEditCtrl, moveSelection, void, (S32 dx, S32 dy), , "Move //----------------------------------------------------------------------------- -DefineConsoleMethod( GuiEditCtrl, saveSelection, void, (const char * filename), (NULL), "( string fileName=null ) - Save selection to file or clipboard.") +DefineConsoleMethod( GuiEditCtrl, saveSelection, void, (const char * filename), (nullAsType()), "( string fileName=null ) - Save selection to file or clipboard.") { object->saveSelection( filename ); @@ -2590,7 +2590,7 @@ DefineConsoleMethod( GuiEditCtrl, saveSelection, void, (const char * filename), //----------------------------------------------------------------------------- -DefineConsoleMethod( GuiEditCtrl, loadSelection, void, (const char * filename), (NULL), "( string fileName=null ) - Load selection from file or clipboard.") +DefineConsoleMethod( GuiEditCtrl, loadSelection, void, (const char * filename), (nullAsType()), "( string fileName=null ) - Load selection from file or clipboard.") { object->loadSelection( filename ); diff --git a/Engine/source/gui/editor/guiMenuBar.cpp b/Engine/source/gui/editor/guiMenuBar.cpp index 4a9a4cefa..ea16d4728 100644 --- a/Engine/source/gui/editor/guiMenuBar.cpp +++ b/Engine/source/gui/editor/guiMenuBar.cpp @@ -216,7 +216,7 @@ DefineEngineMethod(GuiMenuBar, addMenu, void, (const char* menuText, S32 menuId) } DefineEngineMethod(GuiMenuBar, addMenuItem, void, (const char* targetMenu, const char* menuItemText, S32 menuItemId, const char* accelerator, int checkGroup, const char *cmd), - ("","",0,NULL,-1,""), + ("","",0,nullAsType(),-1,""), "@brief Adds a menu item to the specified menu. The menu argument can be either the text of a menu or its id.\n\n" "@param menu Menu name or menu Id to add the new item to.\n" "@param menuItemText Text for the new menu item.\n" diff --git a/Engine/source/lighting/lightManager.cpp b/Engine/source/lighting/lightManager.cpp index f53f5284d..2f8ddd5ee 100644 --- a/Engine/source/lighting/lightManager.cpp +++ b/Engine/source/lighting/lightManager.cpp @@ -442,7 +442,7 @@ DefineEngineFunction( setLightManager, bool, ( const char *name ),, return gClientSceneGraph->setLightManager( name ); } -DefineEngineFunction( lightScene, bool, ( const char *completeCallbackFn, const char *mode ), ( NULL, NULL ), +DefineEngineFunction( lightScene, bool, ( const char *completeCallbackFn, const char *mode ), ( nullAsType(), nullAsType() ), "Will generate static lighting for the scene if supported by the active light manager.\n\n" "If mode is \"forceAlways\", the lightmaps will be regenerated regardless of whether " "lighting cache files can be written to. If mode is \"forceWritable\", then the lightmaps " diff --git a/Engine/source/scene/sceneContainer.cpp b/Engine/source/scene/sceneContainer.cpp index f5a271794..fbcd485aa 100644 --- a/Engine/source/scene/sceneContainer.cpp +++ b/Engine/source/scene/sceneContainer.cpp @@ -1602,7 +1602,7 @@ DefineEngineFunction( containerSearchCurrRadiusDist, F32, ( bool useClientContai //TODO: make RayInfo an API type DefineEngineFunction( containerRayCast, const char*, - ( Point3F start, Point3F end, U32 mask, SceneObject *pExempt, bool useClientContainer ), ( NULL, false ), + ( Point3F start, Point3F end, U32 mask, SceneObject *pExempt, bool useClientContainer ), ( nullAsType(), false ), "@brief Cast a ray from start to end, checking for collision against items matching mask.\n\n" "If pExempt is specified, then it is temporarily excluded from collision checks (For " diff --git a/Engine/source/sim/actionMap.cpp b/Engine/source/sim/actionMap.cpp index e4455d458..a1b5c6ac2 100644 --- a/Engine/source/sim/actionMap.cpp +++ b/Engine/source/sim/actionMap.cpp @@ -1991,7 +1991,7 @@ DefineEngineMethod( ActionMap, unbindObj, bool, ( const char* device, const char return object->processUnbind( device, action, simObject ); } -DefineEngineMethod( ActionMap, save, void, ( const char* fileName, bool append ), ( NULL, false ), +DefineEngineMethod( ActionMap, save, void, ( const char* fileName, bool append ), ( nullAsType(), false ), "@brief Saves the ActionMap to a file or dumps it to the console.\n\n" "@param fileName The file path to save the ActionMap to. If a filename is not specified " " the ActionMap will be dumped to the console.\n"