From f9cd778b3b9b9ad8d585b5e70ff5e373a0b7b7f2 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Wed, 24 Dec 2014 10:04:44 +1100 Subject: [PATCH] Fixed tricky overloaded sfx* functions. --- .../source/gui/controls/guiTreeViewCtrl.cpp | 2 +- .../gui/worldEditor/guiDecalEditorCtrl.cpp | 13 +++--- Engine/source/sfx/sfxSystem.cpp | 44 ++++++++++--------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index 6e84e398f..4b2fed88f 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -5137,7 +5137,7 @@ DefineConsoleMethod(GuiTreeViewCtrl, getSelectedItemList,const char*, (), ,"retu //the start of the buffer where we want to write char* buffPart = buff+len; //the size of the remaining buffer (-1 cause dStrlen doesn't count the \0) - S32 size = 1024-len-1; + S32 size = bufSize-len-1; //write it: if(size < 1) { diff --git a/Engine/source/gui/worldEditor/guiDecalEditorCtrl.cpp b/Engine/source/gui/worldEditor/guiDecalEditorCtrl.cpp index 8da96bbda..ab6b377e2 100644 --- a/Engine/source/gui/worldEditor/guiDecalEditorCtrl.cpp +++ b/Engine/source/gui/worldEditor/guiDecalEditorCtrl.cpp @@ -817,15 +817,14 @@ DefineConsoleMethod( GuiDecalEditorCtrl, getDecalCount, S32, (), , "getDecalCoun DefineConsoleMethod( GuiDecalEditorCtrl, getDecalTransform, const char*, ( U32 id ), , "getDecalTransform()" ) { - DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id]; + DecalInstance *decalInstance = gDecalManager->mDecalInstanceVec[id]; - if( decalInstance == NULL ) - return ""; + if( decalInstance == NULL ) + return ""; - static const U32 bufSize = 256; - char* returnBuffer = Con::getReturnBuffer(bufSize); - returnBuffer[0] = 0; - + static const U32 bufSize = 256; + char* returnBuffer = Con::getReturnBuffer(bufSize); + returnBuffer[0] = 0; if ( decalInstance ) { diff --git a/Engine/source/sfx/sfxSystem.cpp b/Engine/source/sfx/sfxSystem.cpp index 0eb12e2e9..502e16733 100644 --- a/Engine/source/sfx/sfxSystem.cpp +++ b/Engine/source/sfx/sfxSystem.cpp @@ -1443,7 +1443,7 @@ static ConsoleDocFragment _sfxCreateSource4( NULL, "SFXSound sfxCreateSource( SFXDescription description, string filename, float x, float y, float z );" ); -DefineConsoleFunction( sfxCreateSource, S32, ( const char * SFXType, const char * filename, const char * x, const char * y, const char * z ), ("", "", "", ""), +DefineConsoleFunction( sfxCreateSource, S32, ( const char * sfxType, const char * arg0, const char * arg1, const char * arg2, const char * arg3 ), ("", "", "", ""), "( SFXTrack track | ( SFXDescription description, string filename ) [, float x, float y, float z ] ) " "Creates a new paused sound source using a profile or a description " "and filename. The return value is the source which must be " @@ -1451,13 +1451,13 @@ DefineConsoleFunction( sfxCreateSource, S32, ( const char * SFXType, const char "@hide" ) { SFXDescription* description = NULL; - SFXTrack* track = dynamic_cast< SFXTrack* >( Sim::findObject( SFXType ) ); + SFXTrack* track = dynamic_cast< SFXTrack* >( Sim::findObject( sfxType ) ); if ( !track ) { - description = dynamic_cast< SFXDescription* >( Sim::findObject( SFXType ) ); + description = dynamic_cast< SFXDescription* >( Sim::findObject( sfxType ) ); if ( !description ) { - Con::printf( "Unable to locate sound track/description '%s'", SFXType ); + Con::printf( "Unable to locate sound track/description '%s'", sfxType ); return 0; } } @@ -1466,20 +1466,22 @@ DefineConsoleFunction( sfxCreateSource, S32, ( const char * SFXType, const char if ( track ) { - if ( dStrIsEmpty(x) ) + // In this overloaded use of the function, arg0..arg2 are x, y, and z. + if ( dStrIsEmpty(arg0) ) { source = SFX->createSource( track ); } else { MatrixF transform; - transform.set( EulerF(0,0,0), Point3F( dAtof(x), dAtof(y), dAtof(z)) ); + transform.set( EulerF(0,0,0), Point3F( dAtof(arg0), dAtof(arg1), dAtof(arg2)) ); source = SFX->createSource( track, &transform ); } } else if ( description ) { - SFXProfile* tempProfile = new SFXProfile( description, StringTable->insert( filename ), true ); + // In this use, arg0 is the filename, and arg1..arg3 are x, y, and z. + SFXProfile* tempProfile = new SFXProfile( description, StringTable->insert( arg0), true ); if( !tempProfile->registerObject() ) { Con::errorf( "sfxCreateSource - unable to create profile" ); @@ -1487,14 +1489,14 @@ DefineConsoleFunction( sfxCreateSource, S32, ( const char * SFXType, const char } else { - if ( dStrIsEmpty(x) ) + if ( dStrIsEmpty(arg1) ) { source = SFX->createSource( tempProfile ); } else { MatrixF transform; - transform.set(EulerF(0,0,0), Point3F( dAtof(x),dAtof(y),dAtof(z) )); + transform.set(EulerF(0,0,0), Point3F( dAtof(arg1), dAtof(arg2), dAtof(arg3) )); source = SFX->createSource( tempProfile, &transform ); } @@ -1656,19 +1658,19 @@ static ConsoleDocFragment _sPlayOnce4( "SFXSource sfxPlayOnce( SFXDescription description, string filename, float x, float y, float z, float fadeInTime=-1 );" ); -DefineConsoleFunction( sfxPlayOnce, S32, ( const char * SFXType, const char * filename, const char * x, const char * y, const char * z, F32 fadeInTime ), ("", "", "", -1.0f), +DefineConsoleFunction( sfxPlayOnce, S32, ( const char * sfxType, const char * arg0, const char * arg1, const char * arg2, const char * arg3, const char* arg4 ), ("", "", "", "", "-1.0f"), "SFXSource sfxPlayOnce( ( SFXTrack track | SFXDescription description, string filename ) [, float x, float y, float z, float fadeInTime=-1 ] ) " "Create a new play-once source for the given profile or description+filename and start playback of the source.\n" "@hide" ) { SFXDescription* description = NULL; - SFXTrack* track = dynamic_cast< SFXTrack* >( Sim::findObject( SFXType ) ); + SFXTrack* track = dynamic_cast< SFXTrack* >( Sim::findObject( sfxType ) ); if( !track ) { - description = dynamic_cast< SFXDescription* >( Sim::findObject( SFXType ) ); + description = dynamic_cast< SFXDescription* >( Sim::findObject( sfxType ) ); if( !description ) { - Con::errorf( "sfxPlayOnce - Unable to locate sound track/description '%s'", SFXType ); + Con::errorf( "sfxPlayOnce - Unable to locate sound track/description '%s'", sfxType ); return 0; } } @@ -1676,20 +1678,22 @@ DefineConsoleFunction( sfxPlayOnce, S32, ( const char * SFXType, const char * fi SFXSource* source = NULL; if( track ) { - if (dStrIsEmpty(x)) + // In this overloaded use, arg0..arg2 are x, y, z, and arg3 is the fadeInTime. + if (dStrIsEmpty(arg0)) { source = SFX->playOnce( track ); } else { MatrixF transform; - transform.set( EulerF( 0, 0, 0 ), Point3F( dAtof( x ), dAtof( y ),dAtof( z ) ) ); - source = SFX->playOnce( track, &transform, NULL, fadeInTime ); + transform.set( EulerF( 0, 0, 0 ), Point3F( dAtof( arg0 ), dAtof( arg1 ),dAtof( arg2 ) ) ); + source = SFX->playOnce( track, &transform, NULL, dAtof( arg3 ) ); } } else if( description ) { - SFXProfile* tempProfile = new SFXProfile( description, StringTable->insert( filename ), true ); + // In this overload, arg0 is the filename, arg1..arg3 are x, y, z, and arg4 is fadeInTime. + SFXProfile* tempProfile = new SFXProfile( description, StringTable->insert( arg0 ), true ); if( !tempProfile->registerObject() ) { Con::errorf( "sfxPlayOnce - unable to create profile" ); @@ -1697,13 +1701,13 @@ DefineConsoleFunction( sfxPlayOnce, S32, ( const char * SFXType, const char * fi } else { - if (dStrIsEmpty(x)) + if (dStrIsEmpty(arg1)) source = SFX->playOnce( tempProfile ); else { MatrixF transform; - transform.set( EulerF( 0, 0, 0 ), Point3F( dAtof( x ), dAtof( y ),dAtof( z ) ) ); - source = SFX->playOnce( tempProfile, &transform, NULL, fadeInTime ); + transform.set( EulerF( 0, 0, 0 ), Point3F( dAtof( arg1 ), dAtof( arg2 ),dAtof( arg3 ) ) ); + source = SFX->playOnce( tempProfile, &transform, NULL, dAtof( arg4 ) ); } // Set profile to auto-delete when SFXSource releases its reference.