Game Development Community

DefineEngineMethod > ConsoleFunction ?

by Steve Acaster · in Torque 3D Professional · 08/05/2010 (10:29 pm) · 6 replies

Not being able to speak Borg, I was just wondering what the change behind many of the ConsoleFunctions being superceded by awfully similar looking DefineEngineMethods was?

Just curious ...

#1
08/05/2010 (11:30 pm)
The ConsoleXXX macros required every single function to do all its string->value conversions by hand. Among other things (docs, default values, etc.) the DefineEngineXXX macros do all the work for you.

Example:

ConsoleFunction( myFunction, const char*, 1, 2, "( Point3F p ) - Do something" )
{
   Point3F p;
   dSscanf( argv[ 1 ], "%g %g %g", &p.x, &p.y, &p.z );
   doSomethingWith( p );
   
   char* buffer = Con::getReturnBuffer( 64 );
   dSprintf( buffer, 64, "%g %g %g", p.x, p.y, p.z );
   return buffer;
}

becomes

DefineEngineFunction( myFunction, Point3F, ( const Point3F& p ), (),
   "Do something" )
{
   doSomethingWith( p );
   return p;
}

This, for example, also supplies accurate type information for the docs. The ConsoleFunction has a generic "string" return type whereas the DefineEngineFunction has an accurate Point3F return type.

However, there's quite a bit more to it.

//Edit: extended the example a bit
#2
08/05/2010 (11:40 pm)
Ah, to add some to the "why?", the biggest drive here has been the docs and since they required pretty much going over all ConsoleFunctions and ConsoleMethods in the system, we used that opportunity to update this part of the codebase. A big advantage of engineAPI, too, is that it hides all the internals of the interop system whereas the console macros pushed them all onto the users. This means that with engineAPI the interop system can be changed or completely switched out without any of the engine functions or methods being affected.
#3
08/06/2010 (12:15 am)
I love the new DefineEngineFunction system, so eloquent in simplicity and such beauty of design. It is logical just by looking at it.

The old ConsoleFunction system always managed to confuse me and send me seeking documentation and simple examples. I am not exactly a supper clever C'coder.

doSomethingWith( p ); I say flush it.
#4
08/06/2010 (12:25 am)
Curiosity satisfied! :)
Wasn't too much hassle for this non-coder to port his custom cpp hacks over.

rofl @ Caylo!
#5
08/06/2010 (2:46 am)
Yea... the new macros rock. So much simpler to work with... less error prone... and totally allows us to make massive changes under the hood without disturbing user code.
#6
08/06/2010 (7:00 am)
I agree this is clearly a good approach. and I would say that I appreciate that now we can declare some method/function like C++ one without the datob & so one functions!!!