Browse Source

3 more scriptbinding conversions

Charlie Patterson 12 years ago
parent
commit
54d2c78da5

+ 4 - 0
engine/compilers/VisualStudio 2012/Torque 2D.vcxproj

@@ -838,6 +838,7 @@
     <ClInclude Include="..\..\source\graphics\TextureDictionary.h" />
     <ClInclude Include="..\..\source\graphics\TextureHandle.h" />
     <ClInclude Include="..\..\source\graphics\TextureManager.h" />
+    <ClInclude Include="..\..\source\graphics\TextureManager_ScriptBinding.h" />
     <ClInclude Include="..\..\source\graphics\TextureObject.h" />
     <ClInclude Include="..\..\source\gui\containers\guiGridCtrl.h" />
     <ClInclude Include="..\..\source\gui\guiArrayCtrl.h" />
@@ -887,6 +888,7 @@
     <ClInclude Include="..\..\source\io\memstream.h" />
     <ClInclude Include="..\..\source\io\resizeStream.h" />
     <ClInclude Include="..\..\source\io\resource\resourceManager.h" />
+    <ClInclude Include="..\..\source\io\resource\resourceManager_ScriptBinding.h" />
     <ClInclude Include="..\..\source\io\stream.h" />
     <ClInclude Include="..\..\source\io\streamObject.h" />
     <ClInclude Include="..\..\source\io\streamObject_ScriptBinding.h" />
@@ -935,6 +937,8 @@
     <ClInclude Include="..\..\source\network\netObject_ScriptBinding.h" />
     <ClInclude Include="..\..\source\network\netStringTable.h" />
     <ClInclude Include="..\..\source\network\networkProcessList.h" />
+    <ClInclude Include="..\..\source\network\RemoteCommandEvent.h" />
+    <ClInclude Include="..\..\source\network\RemoteCommandEvent_ScriptBinding.h" />
     <ClInclude Include="..\..\source\network\serverQuery.h" />
     <ClInclude Include="..\..\source\network\serverQuery_ScriptBinding.h" />
     <ClInclude Include="..\..\source\network\tcpObject.h" />

+ 12 - 0
engine/compilers/VisualStudio 2012/Torque 2D.vcxproj.filters

@@ -2892,6 +2892,18 @@
     <ClInclude Include="..\..\source\debug\telnetDebugger_ScriptBinding.h">
       <Filter>debug</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\source\network\RemoteCommandEvent_ScriptBinding.h">
+      <Filter>network</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\source\network\RemoteCommandEvent.h">
+      <Filter>network</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\source\io\resource\resourceManager_ScriptBinding.h">
+      <Filter>io\resource</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\source\graphics\TextureManager_ScriptBinding.h">
+      <Filter>graphics</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\source\math\mMath_ASM.asm">

+ 2 - 43
engine/source/graphics/TextureManager.cc

@@ -34,6 +34,8 @@
 #include "memory/safeDelete.h"
 #include "math/mMath.h"
 
+#include "TextureManager_ScriptBinding.h"
+
 //---------------------------------------------------------------------------------------------------------------------
 
 S32 TextureManager::mMasterTextureKeyIndex = 0;
@@ -73,34 +75,6 @@ static const char* extArray[EXT_ARRAY_SIZE] = { "", ".jpg", ".png"};
 
 //---------------------------------------------------------------------------------------------------------------------
 
-ConsoleFunction(setOpenGLTextureCompressionHint, void, 2, 2, " ( hint ) Use the setOpenGLTextureCompressionHint function to select the OpenGL texture compression method.\n"
-    "@param hint \"GL_DONT_CARE\", \"GL_FASTEST\", or \"GL_NICEST\". (Please refer to an OpenGL text for information on what these mean).\n"
-    "@return No return value")
-{
-    GLenum newHint        = GL_DONT_CARE;
-    const char* newString = "GL_DONT_CARE";
-
-    if (!dStricmp(argv[1], "GL_FASTEST"))
-    {
-        newHint = GL_FASTEST;
-        newString = "GL_FASTEST";
-    }
-    else if (!dStricmp(argv[1], "GL_NICEST"))
-    {
-        newHint = GL_NICEST;
-        newString = "GL_NICEST";
-    }
-
-    TextureManager::mTextureCompressionHint = newHint;
-
-#if !defined(TORQUE_OS_IOS)
-    if (dglDoesSupportTextureCompression())
-        glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, TextureManager::mTextureCompressionHint);
-#endif
-}
-
-//--------------------------------------------------------------------------------------------------------------------
-
 struct EventCallbackEntry
 {
     TextureManager::TextureEventCallback callback;
@@ -298,14 +272,6 @@ void TextureManager::flush()
 
 //--------------------------------------------------------------------------------------------------------------------
 
-ConsoleFunction( flushTextureCache, void, 1, 1, "() Use the flushTextureCache function to flush the texture cache.\n"
-                                                "@return No return value.\n")
-{
-    TextureManager::flush();
-}
-
-//--------------------------------------------------------------------------------------------------------------------
-
 StringTableEntry TextureManager::getUniqueTextureKey( void )
 {
     char textureKeyBuffer[32];
@@ -921,13 +887,6 @@ GBitmap *TextureManager::loadBitmap( const char* pTextureKey, bool recurse, bool
 
 //--------------------------------------------------------------------------------------------------------------------
 
-ConsoleFunction( dumpTextureManagerMetrics, void, 1, 1, "() Dump the texture manager metrics." )
-{
-    return TextureManager::dumpMetrics();
-}
-
-//--------------------------------------------------------------------------------------------------------------------
-
 void TextureManager::dumpMetrics( void )
 {
     S32 textureResidentCount = 0;

BIN
engine/source/graphics/TextureManager_ScriptBinding.h


+ 70 - 0
engine/source/graphics/TextureManager_ScriptBinding_o.h

@@ -0,0 +1,70 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+/*! @defgroup TextureManagerFunctions Texture Manager
+	@ingroup TorqueScriptFunctions
+	@{
+*/
+
+ConsoleFunction(setOpenGLTextureCompressionHint, void, 2, 2, " ( hint ) Use the setOpenGLTextureCompressionHint function to select the OpenGL texture compression method.\n"
+    "@param hint \"GL_DONT_CARE\", \"GL_FASTEST\", or \"GL_NICEST\". (Please refer to an OpenGL text for information on what these mean).\n"
+    "@return No return value")
+{
+    GLenum newHint        = GL_DONT_CARE;
+    const char* newString = "GL_DONT_CARE";
+
+    if (!dStricmp(argv[1], "GL_FASTEST"))
+    {
+        newHint = GL_FASTEST;
+        newString = "GL_FASTEST";
+    }
+    else if (!dStricmp(argv[1], "GL_NICEST"))
+    {
+        newHint = GL_NICEST;
+        newString = "GL_NICEST";
+    }
+
+    TextureManager::mTextureCompressionHint = newHint;
+
+#if !defined(TORQUE_OS_IOS)
+    if (dglDoesSupportTextureCompression())
+        glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, TextureManager::mTextureCompressionHint);
+#endif
+}
+
+//--------------------------------------------------------------------------------------------------------------------
+
+ConsoleFunction( flushTextureCache, void, 1, 1, "() Use the flushTextureCache function to flush the texture cache.\n"
+                                                "@return No return value.\n")
+{
+    TextureManager::flush();
+}
+
+//--------------------------------------------------------------------------------------------------------------------
+
+ConsoleFunction( dumpTextureManagerMetrics, void, 1, 1, "() Dump the texture manager metrics." )
+{
+    return TextureManager::dumpMetrics();
+}
+
+
+/*! @} */ // group TextureManagerFunctions

+ 2 - 68
engine/source/io/resource/resourceManager.cc

@@ -39,6 +39,8 @@
 
 #include "memory/safeDelete.h"
 
+#include "resourceManager_ScriptBinding.h"
+
 ResManager *ResourceManager = NULL;
 
 const char *ResManager::smExcludedDirectories = ".svn;CVS";
@@ -198,15 +200,6 @@ void ResManager::dumpResources (const bool onlyLoaded)
    }
 }
 
-ConsoleFunction(dumpResources, void, 2, 2, "(onlyLoaded?) Use the dumpLoadedResources function to dump a listing of the currently in-use resources to the console. This will include such things as sound files, font files, etc.\n"
-                                                                "For this to work, the engine must have been compiled with TORQUE_DEBUG defined.\n"
-                                                                "@return No return value.\n"
-                                                                "@sa purgeResources")
-{
-    const bool onlyLoaded = argc == 2 ? dAtob(argv[1]) : true;
-    ResourceManager->dumpResources(onlyLoaded);
-}
-
 #endif
 
 //------------------------------------------------------------------------------
@@ -541,14 +534,6 @@ void ResManager::addPath(const char *path, bool ignoreZips )
    searchPath(path, true, ignoreZips );
 }
 
-ConsoleFunction(addResPath, void, 2, 3, "(path, [ignoreZips=false]) Add a path to the resource manager")
-{
-   if( argc > 2 )
-      ResourceManager->addPath(argv[1], dAtob(argv[2]));
-   else
-      ResourceManager->addPath(argv[1]);
-}
-
 void ResManager::removePath(const char *path)
 {
    ResourceObject *rwalk = resourceList.nextResource, *rtemp;
@@ -568,11 +553,6 @@ void ResManager::removePath(const char *path)
    }
 }
 
-ConsoleFunction(removeResPath, void, 2, 2, "(pathExpression) Remove a path from the resource manager. Path is an expression as in findFirstFile()")
-{
-   ResourceManager->removePath(argv[1]);
-}
-
 void ResManager::setModPaths (U32 numPaths, const char **paths)
 {
    // [tom, 10/28/2006] If we're using a VFS, we don't want to do this
@@ -644,39 +624,6 @@ const char * ResManager::getModPaths ()
 
 //------------------------------------------------------------------------------
 
-// Mod paths aren't used in tools applications.  
-// See : addResPath/removeResPath console functions
-ConsoleFunction( setModPaths, void, 2, 2, "( path ) Use the setModPaths function to set the current mod path to the value specified in path.\n"
-                                                                "@param path A string containing a semi-colon (;) separated list of game and mod paths.\n"
-                                                                "@return No return value.\n"
-                                                                "@sa getModPaths")
-{
-   char buf[512];
-   dStrncpy(buf, argv[1], sizeof(buf) - 1);
-   buf[511] = '\0';
-
-   Vector<char *> paths;
-   char* temp = dStrtok( buf, ";" );
-   while ( temp )
-   {
-      if ( temp[0] )
-         paths.push_back(temp);
-      
-      temp = dStrtok( NULL, ";" );
-   }
-
-   ResourceManager->setModPaths( paths.size(), (const char**) paths.address() );
-}
-
-ConsoleFunction( getModPaths, const char*, 1, 1, "() Use the getModPaths function to get the current mod path information.\n"
-                                                                "@return Returns a string equivalent to the complete current mod path, that is all pads that are visible to the file manager.\n"
-                                                                "@sa setModPaths")
-{
-   return( ResourceManager->getModPaths() );
-}
-
-//------------------------------------------------------------------------------
-
 S32 ResManager::getSize (const char *fileName)
 {
    ResourceObject * ro = find (fileName);
@@ -1123,13 +1070,6 @@ void ResManager::purge ()
    while (found);
 }
 
-ConsoleFunction( purgeResources, void, 1, 1, "() Use the purgeResources function to purge all game resources.\n"
-                                                                "@return No return value.\n"
-                                                                "@sa clearTextureHolds, dumpResourceStats, dumpTextureStats, flushTextureCache")
-{
-   ResourceManager->purge();
-}
-
 //------------------------------------------------------------------------------
 
 void ResManager::purge (ResourceObject * obj)
@@ -1364,9 +1304,3 @@ bool ResManager::openFileForWrite (FileStream & stream, const char *fileName, U3
    ro->compressedFileSize = 0;
    return true;
 }
-
-ConsoleFunction(isUsingVFS, bool, 1, 1, "()\n"
-                "@return Returns true if using Virtual File System")
-{
-   return ResourceManager->isUsingVFS();
-}

BIN
engine/source/io/resource/resourceManager_ScriptBinding.h


+ 104 - 0
engine/source/io/resource/resourceManager_ScriptBinding_o.h

@@ -0,0 +1,104 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+ConsoleFunctionGroupBegin( Net, "Functions for use with the network; tagged strings and remote commands.");
+
+/*! @defgroup NetworkFunctions Network
+	@ingroup TorqueScriptFunctions
+	@{
+*/
+
+
+
+#ifdef TORQUE_DEBUG
+
+ConsoleFunction(dumpResources, void, 2, 2, "(onlyLoaded?) Use the dumpLoadedResources function to dump a listing of the currently in-use resources to the console. This will include such things as sound files, font files, etc.\n"
+                                                                "For this to work, the engine must have been compiled with TORQUE_DEBUG defined.\n"
+                                                                "@return No return value.\n"
+                                                                "@sa purgeResources")
+{
+    const bool onlyLoaded = argc == 2 ? dAtob(argv[1]) : true;
+    ResourceManager->dumpResources(onlyLoaded);
+}
+
+#endif
+
+ConsoleFunction(addResPath, void, 2, 3, "(path, [ignoreZips=false]) Add a path to the resource manager")
+{
+   if( argc > 2 )
+      ResourceManager->addPath(argv[1], dAtob(argv[2]));
+   else
+      ResourceManager->addPath(argv[1]);
+}
+
+
+ConsoleFunction(removeResPath, void, 2, 2, "(pathExpression) Remove a path from the resource manager. Path is an expression as in findFirstFile()")
+{
+   ResourceManager->removePath(argv[1]);
+}
+
+// Mod paths aren't used in tools applications.  
+// See : addResPath/removeResPath console functions
+ConsoleFunction( setModPaths, void, 2, 2, "( path ) Use the setModPaths function to set the current mod path to the value specified in path.\n"
+                                                                "@param path A string containing a semi-colon (;) separated list of game and mod paths.\n"
+                                                                "@return No return value.\n"
+                                                                "@sa getModPaths")
+{
+   char buf[512];
+   dStrncpy(buf, argv[1], sizeof(buf) - 1);
+   buf[511] = '\0';
+
+   Vector<char *> paths;
+   char* temp = dStrtok( buf, ";" );
+   while ( temp )
+   {
+      if ( temp[0] )
+         paths.push_back(temp);
+      
+      temp = dStrtok( NULL, ";" );
+   }
+
+   ResourceManager->setModPaths( paths.size(), (const char**) paths.address() );
+}
+
+ConsoleFunction( getModPaths, const char*, 1, 1, "() Use the getModPaths function to get the current mod path information.\n"
+                                                                "@return Returns a string equivalent to the complete current mod path, that is all pads that are visible to the file manager.\n"
+                                                                "@sa setModPaths")
+{
+   return( ResourceManager->getModPaths() );
+}
+
+ConsoleFunction( purgeResources, void, 1, 1, "() Use the purgeResources function to purge all game resources.\n"
+                                                                "@return No return value.\n"
+                                                                "@sa clearTextureHolds, dumpResourceStats, dumpTextureStats, flushTextureCache")
+{
+   ResourceManager->purge();
+}
+
+ConsoleFunction(isUsingVFS, bool, 1, 1, "()\n"
+                "@return Returns true if using Virtual File System")
+{
+   return ResourceManager->isUsingVFS();
+}
+
+
+/*! @} */ // group NetworkFunctions

+ 3 - 241
engine/source/network/RemoteCommandEvent.cc

@@ -30,141 +30,14 @@
 #include "network/netObject.h"
 #include "game/gameConnection.h"
 #include "network/serverQuery.h"
+#include "network/RemoteCommandEvent.h"
+
+#include "RemoteCommandEvent_ScriptBinding.h"
 
 //----------------------------------------------------------------
 // remote procedure call console functions
 //----------------------------------------------------------------
 
-class RemoteCommandEvent : public NetEvent
-{
-public:
-   enum {
-      MaxRemoteCommandArgs = 20,
-      CommandArgsBits = 5
-   };
-
-private:
-   S32 mArgc;
-   char *mArgv[MaxRemoteCommandArgs + 1];
-   NetStringHandle mTagv[MaxRemoteCommandArgs + 1];
-   static char mBuf[1024];
-public:
-   RemoteCommandEvent(S32 argc=0, const char **argv=NULL, NetConnection *conn = NULL)
-   {
-      mArgc = argc;
-      for(S32 i = 0; i < argc; i++)
-      {
-         if(argv[i][0] == StringTagPrefixByte)
-         {
-            char buffer[256];
-            mTagv[i+1] = NetStringHandle(dAtoi(argv[i]+1));
-            if(conn)
-            {
-               dSprintf(buffer + 1, sizeof(buffer) - 1, "%d", conn->getNetSendId(mTagv[i+1]));
-               buffer[0] = StringTagPrefixByte;
-               mArgv[i+1] = dStrdup(buffer);
-            }
-         }
-         else
-            mArgv[i+1] = dStrdup(argv[i]);
-      }
-   }
-
-#ifdef TORQUE_DEBUG_NET
-   const char *getDebugName()
-   {
-      static char buffer[256];
-      dSprintf(buffer, sizeof(buffer), "%s [%s]", getClassName(), gNetStringTable->lookupString(dAtoi(mArgv[1] + 1)) );
-      return buffer;
-   }
-#endif
-
-   ~RemoteCommandEvent()
-   {
-      for(S32 i = 0; i < mArgc; i++)
-         dFree(mArgv[i+1]);
-   }
-
-   virtual void pack(NetConnection* conn, BitStream *bstream)
-   {
-      bstream->writeInt(mArgc, CommandArgsBits);
-      // write it out reversed... why?
-      // automatic string substitution with later arguments -
-      // handled automatically by the system.
-
-      for(S32 i = 0; i < mArgc; i++)
-         conn->packString(bstream, mArgv[i+1]);
-   }
-
-   virtual void write(NetConnection* conn, BitStream *bstream)
-   {
-      pack(conn, bstream);
-   }
-
-   virtual void unpack(NetConnection* conn, BitStream *bstream)
-   {
-
-      mArgc = bstream->readInt(CommandArgsBits);
-      // read it out backwards
-      for(S32 i = 0; i < mArgc; i++)
-      {
-         conn->unpackString(bstream, mBuf);
-         mArgv[i+1] = dStrdup(mBuf);
-      }
-   }
-
-   virtual void process(NetConnection *conn)
-   {
-      static char idBuf[10];
-
-      // de-tag the command name
-
-      for(S32 i = mArgc - 1; i >= 0; i--)
-      {
-         char *arg = mArgv[i+1];
-         if(*arg == StringTagPrefixByte)
-         {
-            // it's a tag:
-            U32 localTag = dAtoi(arg + 1);
-            NetStringHandle tag = conn->translateRemoteStringId(localTag);
-            NetStringTable::expandString( tag,
-                                          mBuf,
-                                          sizeof(mBuf),
-                                          (mArgc - 1) - i,
-                                          (const char**)(mArgv + i + 2) );
-            dFree(mArgv[i+1]);
-            mArgv[i+1] = dStrdup(mBuf);
-         }
-      }
-      const char *rmtCommandName = dStrchr(mArgv[1], ' ') + 1;
-      if(conn->isConnectionToServer())
-      {
-         dStrcpy(mBuf, "clientCmd");
-         dStrcat(mBuf, rmtCommandName);
-
-         char *temp = mArgv[1];
-         mArgv[1] = mBuf;
-
-         Con::execute(mArgc, (const char **) mArgv+1);
-         mArgv[1] = temp;
-      }
-      else
-      {
-         dStrcpy(mBuf, "serverCmd");
-         dStrcat(mBuf, rmtCommandName);
-         char *temp = mArgv[1];
-
-         dSprintf(idBuf, sizeof(idBuf), "%d", conn->getId());
-         mArgv[0] = mBuf;
-         mArgv[1] = idBuf;
-
-         Con::execute(mArgc+1, (const char **) mArgv);
-         mArgv[1] = temp;
-      }
-   }
-
-   DECLARE_CONOBJECT(RemoteCommandEvent);
-};
 char RemoteCommandEvent::mBuf[1024];
 
 IMPLEMENT_CO_NETEVENT_V1(RemoteCommandEvent);
@@ -188,114 +61,3 @@ static void sendRemoteCommand(NetConnection *conn, S32 argc, const char **argv)
    RemoteCommandEvent *cevt = new RemoteCommandEvent(argc, argv, conn);
    conn->postNetEvent(cevt);
 }
-
-ConsoleFunctionGroupBegin( Net, "Functions for use with the network; tagged strings and remote commands.");
-
-ConsoleFunction( commandToServer, void, 2, RemoteCommandEvent::MaxRemoteCommandArgs + 1, "( func [ , arg1, ... , argn ] ) Use the commandToServer function to issue a remote procedure call the server.\n"
-                                                                "All arguments may be in tagged or non-tagged format. See 'Remote Procedure Call Samples' below\n"
-                                                                "@param func The suffix of the remote procedure name to be executed on the client.\n"
-                                                                "@param arg1 ... argn - Optional arguments to be passed to the remote procedure.\n"
-                                                                "@return No return value.")
-{
-   NetConnection *conn = NetConnection::getConnectionToServer();
-   if(!conn)
-      return;
-   sendRemoteCommand(conn, argc - 1, argv + 1);
-}
-
-ConsoleFunction( commandToClient, void, 3, RemoteCommandEvent::MaxRemoteCommandArgs + 2, "( client, func [ , arg1, ... , argn ] ) Use the commandToClient function to issue a remote procedure call on a client.\n"
-                                                                "All arguments (excluding client) may be in tagged or non-tagged format. See 'Remote Procedure Call Samples' below\n"
-                                                                "@param client The numeric ID of a client gameConnection.\n"
-                                                                "@param func The suffix of the remote procedure name to be executed on the client.\n"
-                                                                "@param arg1 ... argn - Optional arguments to be passed to the remote procedure.\n"
-                                                                "@return No return value.")
-{
-   NetConnection *conn;
-   if(!Sim::findObject(argv[1], conn))
-      return;
-   sendRemoteCommand(conn, argc - 2, argv + 2);
-}
-
-ConsoleFunction(removeTaggedString, void, 2, 2, "( tag ) Use the removeTaggedSTring function to remove a previously tagged string from the NetStringTable.\n"
-                                                                "@param tag A number tag ID.\n"
-                                                                "@return No return value")
-{
-   gNetStringTable->removeString(dAtoi(argv[1]+1), true);
-}
-
-ConsoleFunction( addTaggedString, const char*, 2, 2, "( string ) Use the addTaggedString function to tag a new string and add it to the NetStringTable.\n"
-                                                                "@param string The string to tagged and placed in the NetStringTable. Tagging ignores case, so tagging the same string (excluding case differences) will be ignored as a duplicated tag.\n"
-                                                                "@return Returns a string (containing a numeric value) equivalent to the string ID for the newly tagged string")
-{
-   NetStringHandle s(argv[1]);
-   gNetStringTable->incStringRefScript(s.getIndex());
-
-   char *ret = Con::getReturnBuffer(10);
-   ret[0] = StringTagPrefixByte;
-   dSprintf(ret + 1, 9, "%d", s.getIndex());
-   return ret;
-}
-
-ConsoleFunction( getTaggedString, const char*, 2, 2, "( tag ) Use the getTaggedString function to convert a tag to a string. This is not the same a detag() which can only be used within the context of a function that receives a tag. This function can be used any time and anywhere to convert a tag to a string.\n"
-                                                                "@param tag A numeric tag ID.\n"
-                                                                "@return Returns the string corresponding to the tag ID")
-{
-   const char *indexPtr = argv[1];
-   if (*indexPtr == StringTagPrefixByte)
-      indexPtr++;
-   return gNetStringTable->lookupString(dAtoi(indexPtr));
-}
-
-ConsoleFunction( buildTaggedString, const char*, 2, 11, "( format , <arg1, ...arg9> ) Use the buildTaggedString function to build a tagged string using the specified format.\n"
-                                                                "@param enable A boolean value. If set to true, network packet logging is enabled, otherwise it is disabled.\n"
-                                                                "@return No return value")
-{
-   const char *indexPtr = argv[1];
-   if (*indexPtr == StringTagPrefixByte)
-      indexPtr++;
-   const char *fmtString = gNetStringTable->lookupString(dAtoi(indexPtr));
-   char *strBuffer = Con::getReturnBuffer(512);
-   const char *fmtStrPtr = fmtString;
-   char *strBufPtr = strBuffer;
-   S32 strMaxLength = 511;
-   if (!fmtString)
-      goto done;
-
-   //build the string
-   while (*fmtStrPtr)
-   {
-      //look for an argument tag
-      if (*fmtStrPtr == '%')
-      {
-         if (fmtStrPtr[1] >= '1' && fmtStrPtr[1] <= '9')
-         {
-            S32 argIndex = S32(fmtStrPtr[1] - '0') + 1;
-            if (argIndex >= argc)
-               goto done;
-            const char *argStr = argv[argIndex];
-            if (!argStr)
-               goto done;
-            S32 strLength = dStrlen(argStr);
-            if (strLength > strMaxLength)
-               goto done;
-            dStrcpy(strBufPtr, argStr);
-            strBufPtr += strLength;
-            strMaxLength -= strLength;
-            fmtStrPtr += 2;
-            continue;
-         }
-      }
-
-      //if we don't continue, just copy the character
-      if (strMaxLength <= 0)
-         goto done;
-      *strBufPtr++ = *fmtStrPtr++;
-      strMaxLength--;
-   }
-
-done:
-   *strBufPtr = '\0';
-   return strBuffer;
-}
-
-ConsoleFunctionGroupEnd( Net );

+ 159 - 0
engine/source/network/RemoteCommandEvent.h

@@ -0,0 +1,159 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#ifndef _H_REMOTECOMMANDEVENT
+#define _H_REMOTECOMMANDEVENT
+
+class RemoteCommandEvent : public NetEvent
+{
+public:
+   enum {
+      MaxRemoteCommandArgs = 20,
+      CommandArgsBits = 5
+   };
+
+private:
+   S32 mArgc;
+   char *mArgv[MaxRemoteCommandArgs + 1];
+   NetStringHandle mTagv[MaxRemoteCommandArgs + 1];
+   static char mBuf[1024];
+public:
+   RemoteCommandEvent(S32 argc=0, const char **argv=NULL, NetConnection *conn = NULL)
+   {
+      mArgc = argc;
+      for(S32 i = 0; i < argc; i++)
+      {
+         if(argv[i][0] == StringTagPrefixByte)
+         {
+            char buffer[256];
+            mTagv[i+1] = NetStringHandle(dAtoi(argv[i]+1));
+            if(conn)
+            {
+               dSprintf(buffer + 1, sizeof(buffer) - 1, "%d", conn->getNetSendId(mTagv[i+1]));
+               buffer[0] = StringTagPrefixByte;
+               mArgv[i+1] = dStrdup(buffer);
+            }
+         }
+         else
+            mArgv[i+1] = dStrdup(argv[i]);
+      }
+   }
+
+#ifdef TORQUE_DEBUG_NET
+   const char *getDebugName()
+   {
+      static char buffer[256];
+      dSprintf(buffer, sizeof(buffer), "%s [%s]", getClassName(), gNetStringTable->lookupString(dAtoi(mArgv[1] + 1)) );
+      return buffer;
+   }
+#endif
+
+   ~RemoteCommandEvent()
+   {
+      for(S32 i = 0; i < mArgc; i++)
+         dFree(mArgv[i+1]);
+   }
+
+   virtual void pack(NetConnection* conn, BitStream *bstream)
+   {
+      bstream->writeInt(mArgc, CommandArgsBits);
+      // write it out reversed... why?
+      // automatic string substitution with later arguments -
+      // handled automatically by the system.
+
+      for(S32 i = 0; i < mArgc; i++)
+         conn->packString(bstream, mArgv[i+1]);
+   }
+
+   virtual void write(NetConnection* conn, BitStream *bstream)
+   {
+      pack(conn, bstream);
+   }
+
+   virtual void unpack(NetConnection* conn, BitStream *bstream)
+   {
+
+      mArgc = bstream->readInt(CommandArgsBits);
+      // read it out backwards
+      for(S32 i = 0; i < mArgc; i++)
+      {
+         conn->unpackString(bstream, mBuf);
+         mArgv[i+1] = dStrdup(mBuf);
+      }
+   }
+
+   virtual void process(NetConnection *conn)
+   {
+      static char idBuf[10];
+
+      // de-tag the command name
+
+      for(S32 i = mArgc - 1; i >= 0; i--)
+      {
+         char *arg = mArgv[i+1];
+         if(*arg == StringTagPrefixByte)
+         {
+            // it's a tag:
+            U32 localTag = dAtoi(arg + 1);
+            NetStringHandle tag = conn->translateRemoteStringId(localTag);
+            NetStringTable::expandString( tag,
+                                          mBuf,
+                                          sizeof(mBuf),
+                                          (mArgc - 1) - i,
+                                          (const char**)(mArgv + i + 2) );
+            dFree(mArgv[i+1]);
+            mArgv[i+1] = dStrdup(mBuf);
+         }
+      }
+      const char *rmtCommandName = dStrchr(mArgv[1], ' ') + 1;
+      if(conn->isConnectionToServer())
+      {
+         dStrcpy(mBuf, "clientCmd");
+         dStrcat(mBuf, rmtCommandName);
+
+         char *temp = mArgv[1];
+         mArgv[1] = mBuf;
+
+         Con::execute(mArgc, (const char **) mArgv+1);
+         mArgv[1] = temp;
+      }
+      else
+      {
+         dStrcpy(mBuf, "serverCmd");
+         dStrcat(mBuf, rmtCommandName);
+         char *temp = mArgv[1];
+
+         dSprintf(idBuf, sizeof(idBuf), "%d", conn->getId());
+         mArgv[0] = mBuf;
+         mArgv[1] = idBuf;
+
+         Con::execute(mArgc+1, (const char **) mArgv);
+         mArgv[1] = temp;
+      }
+   }
+
+   DECLARE_CONOBJECT(RemoteCommandEvent);
+};
+
+void sendRemoteCommand(NetConnection *conn, S32 argc, const char **argv);
+
+#endif

BIN
engine/source/network/RemoteCommandEvent_ScriptBinding.h


+ 139 - 0
engine/source/network/RemoteCommandEvent_ScriptBinding_o.h

@@ -0,0 +1,139 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+/*! @defgroup TelnetDebuggerFunctions Telnet Debugger
+	@ingroup TorqueScriptFunctions
+	@{
+*/
+
+ConsoleFunctionGroupBegin( Net, "Functions for use with the network; tagged strings and remote commands.");
+
+ConsoleFunction( commandToServer, void, 2, RemoteCommandEvent::MaxRemoteCommandArgs + 1, "( func [ , arg1, ... , argn ] ) Use the commandToServer function to issue a remote procedure call the server.\n"
+                                                                "All arguments may be in tagged or non-tagged format. See 'Remote Procedure Call Samples' below\n"
+                                                                "@param func The suffix of the remote procedure name to be executed on the client.\n"
+                                                                "@param arg1 ... argn - Optional arguments to be passed to the remote procedure.\n"
+                                                                "@return No return value.")
+{
+   NetConnection *conn = NetConnection::getConnectionToServer();
+   if(!conn)
+      return;
+   sendRemoteCommand(conn, argc - 1, argv + 1);
+}
+
+ConsoleFunction( commandToClient, void, 3, RemoteCommandEvent::MaxRemoteCommandArgs + 2, "( client, func [ , arg1, ... , argn ] ) Use the commandToClient function to issue a remote procedure call on a client.\n"
+                                                                "All arguments (excluding client) may be in tagged or non-tagged format. See 'Remote Procedure Call Samples' below\n"
+                                                                "@param client The numeric ID of a client gameConnection.\n"
+                                                                "@param func The suffix of the remote procedure name to be executed on the client.\n"
+                                                                "@param arg1 ... argn - Optional arguments to be passed to the remote procedure.\n"
+                                                                "@return No return value.")
+{
+   NetConnection *conn;
+   if(!Sim::findObject(argv[1], conn))
+      return;
+   sendRemoteCommand(conn, argc - 2, argv + 2);
+}
+
+ConsoleFunction(removeTaggedString, void, 2, 2, "( tag ) Use the removeTaggedSTring function to remove a previously tagged string from the NetStringTable.\n"
+                                                                "@param tag A number tag ID.\n"
+                                                                "@return No return value")
+{
+   gNetStringTable->removeString(dAtoi(argv[1]+1), true);
+}
+
+ConsoleFunction( addTaggedString, const char*, 2, 2, "( string ) Use the addTaggedString function to tag a new string and add it to the NetStringTable.\n"
+                                                                "@param string The string to tagged and placed in the NetStringTable. Tagging ignores case, so tagging the same string (excluding case differences) will be ignored as a duplicated tag.\n"
+                                                                "@return Returns a string (containing a numeric value) equivalent to the string ID for the newly tagged string")
+{
+   NetStringHandle s(argv[1]);
+   gNetStringTable->incStringRefScript(s.getIndex());
+
+   char *ret = Con::getReturnBuffer(10);
+   ret[0] = StringTagPrefixByte;
+   dSprintf(ret + 1, 9, "%d", s.getIndex());
+   return ret;
+}
+
+ConsoleFunction( getTaggedString, const char*, 2, 2, "( tag ) Use the getTaggedString function to convert a tag to a string. This is not the same a detag() which can only be used within the context of a function that receives a tag. This function can be used any time and anywhere to convert a tag to a string.\n"
+                                                                "@param tag A numeric tag ID.\n"
+                                                                "@return Returns the string corresponding to the tag ID")
+{
+   const char *indexPtr = argv[1];
+   if (*indexPtr == StringTagPrefixByte)
+      indexPtr++;
+   return gNetStringTable->lookupString(dAtoi(indexPtr));
+}
+
+ConsoleFunction( buildTaggedString, const char*, 2, 11, "( format , <arg1, ...arg9> ) Use the buildTaggedString function to build a tagged string using the specified format.\n"
+                                                                "@param enable A boolean value. If set to true, network packet logging is enabled, otherwise it is disabled.\n"
+                                                                "@return No return value")
+{
+   const char *indexPtr = argv[1];
+   if (*indexPtr == StringTagPrefixByte)
+      indexPtr++;
+   const char *fmtString = gNetStringTable->lookupString(dAtoi(indexPtr));
+   char *strBuffer = Con::getReturnBuffer(512);
+   const char *fmtStrPtr = fmtString;
+   char *strBufPtr = strBuffer;
+   S32 strMaxLength = 511;
+   if (!fmtString)
+      goto done;
+
+   //build the string
+   while (*fmtStrPtr)
+   {
+      //look for an argument tag
+      if (*fmtStrPtr == '%')
+      {
+         if (fmtStrPtr[1] >= '1' && fmtStrPtr[1] <= '9')
+         {
+            S32 argIndex = S32(fmtStrPtr[1] - '0') + 1;
+            if (argIndex >= argc)
+               goto done;
+            const char *argStr = argv[argIndex];
+            if (!argStr)
+               goto done;
+            S32 strLength = dStrlen(argStr);
+            if (strLength > strMaxLength)
+               goto done;
+            dStrcpy(strBufPtr, argStr);
+            strBufPtr += strLength;
+            strMaxLength -= strLength;
+            fmtStrPtr += 2;
+            continue;
+         }
+      }
+
+      //if we don't continue, just copy the character
+      if (strMaxLength <= 0)
+         goto done;
+      *strBufPtr++ = *fmtStrPtr++;
+      strMaxLength--;
+   }
+
+done:
+   *strBufPtr = '\0';
+   return strBuffer;
+}
+
+ConsoleFunctionGroupEnd( Net );
+
+/*! @} */ // group TelnetDebuggerFunctions