Jump to content

Porting old resources


PaulWeston

Recommended Posts

Hey all,


I'm in the process of porting some old code into 3.7 RC to test, and am having trouble figuring out a few of the changes required...


Can anyone offer any help with these errors?


*****


error C2665: 'Con::addCommand' : none of the 10 overloads could convert all the argument types


code:

void fxGuiSnooper::consoleInit()

{

Con::addCommand("fxGuiSnooper", "setOverlayBitmap", cfxGuiBitmapSetOverlayBitmap, "fxGuiSnooper.setOverlayBitmap(Bitmap)", 3, 3);

}


*****


error C2664: 'String::VToString' : cannot convert parameter 2 from 'U32 *' to 'va_list'


code:

U32 framerate = target->getActualFramerate ();

if (target->mIsSingleFrame)

line += " | [single Frame]";

else

line += " | [FPS: " + String::VToString ("%i", &framerate) + "]";


line += " (Refs: " + String::VToString ("%i", &target->mRefCount) + ")";


*****


The first error (Con::AddCommand) appears in other files as well, where old code has been integrated. 3.7 RC includes Con::AddCommand all over the place and it's fine, just my old code doesn't work. It must be something I have to include with my old code or something, or the syntax is different now, I just can't see it.


The second error I see it's because in 3.7 RC it now passes args as the second parameter for VToString, I'm just unclear on how to convert the above code to use args?


Thanks!

Link to comment
Share on other sites

Con::addCommand has been deprecated for a while now, I thought - either way, using a DefineEngineMethod is the correct way to do it.


Second one I'm not sure about - not familiar with that code. It looks like VToString is possibly an internal method - should you be using ToString instead? And I imagine you don't have to pass the params as a pointer.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the tips...


I was hoping thought that there would be a quick fix, something like just fixing the syntax to match the new way of doing things for VtoString... It looks like now you pass an array list as the parameter for that, whereas before it was just a variable. So I was hoping somebody would just say, oh, just add these few lines to convert that to the new way... :)


In the case of the Con:AddCommand, it may be deprecated but it is still all over the code in other files, and compiles without errors there... Just in this one file it does not recognize the command, where it did in previous T3D version. So I was wondering if it had been moved or something and my file now needs to include some other file it is not including.


Anyhow, I will keep at it, please advise if anyone has any ideas... These are the last changes required to get my project up to 3.7 and we're excited to give it a try.


Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Update...


Got my VString code converted to the new args format, so that one is solved...


However, I have not had any luck converting the following function into a DefineEngineMethod, can anyone please offer any advice?


void fxGuiSnooper::consoleInit()

{

Con::addCommand("fxGuiSnooper", "setOverlayBitmap", cfxGuiBitmapSetOverlayBitmap, "fxGuiSnooper.setOverlayBitmap(Bitmap)", 3, 3);

}


Must confess, have managed to hack away at the engine a lot and integrate a lot of resources and do some basic fixes, but am really not a C+ coder (more of a script guy) and a lot of this stuff confuses me after a bit lol.


So what may seem trivial to some of you can really be out in left field for me - it would be awesome if somebody could recode that for me or get me started with the actual format/syntax... sorry to be a bug :)


Thanks again

Link to comment
Share on other sites

Awesome!!!


Am on my way home and will give it a shot soon.


I was confused about what part went inside the function and what parts made up the function declaration, so now I have a much better idea how that works... I've learned so much from this community, you guys always deliver!


Cheers

P

Link to comment
Share on other sites

OK, getting there, but this next bit is confusing...


For whatever reason, there appear to be 3 separate functions/commands that are named the same, and I am unsure of how everything is being routed through the process..


How would one replace this set of functions with DefineEngineMethod so everything gets passed through correctly?


I have commented out the addCommand but left it for reference. My new DefineEngineMethod is also commented out since it is not compiling due to its structure not being correct yet.


How does the flow work in this code? I see it goes from the addCommand to the static function cfxGuiBitmapSetOverlayBitmap, but then after that it appears to repeat itself or call another function with the same name that is almost identical.


Perhaps this is why DefineEngineMethod was created originally, to shortcut this roundabout way of passing things through?


Thanks again

 



// OLD CODE:

void fxGuiSnooper::consoleInit()
{
  //Con::addCommand("fxGuiSnooper", "setOverlayBitmap",  cfxGuiBitmapSetOverlayBitmap, "fxGuiSnooper.setOverlayBitmap(Bitmap)", 3, 3);
}

static void cfxGuiBitmapSetOverlayBitmap(SimObject *obj, S32, const char **argv)
{
// Fetch HUD Control.
fxGuiSnooper *ctrl = static_cast<fxGuiSnooper*>(obj);

// Set Overlay Bitmap.
ctrl->setOverlayBitmap(argv[2]);
}

ConsoleMethod(fxGuiSnooper,setOverlayBitmap,void,3,3,"Sets Overlay Bitmap.")
{
// Fetch the fxGuiSnooper object.
fxGuiSnooper *Viewport = static_cast<fxGuiSnooper*>(object);

// Set Overlay Bitmap.
Viewport->setOverlayBitmap(argv[2]);
}

void fxGuiSnooper::setOverlayBitmap(const char *name)
{
// Set Overlay Bitmap Name.
mOverlayBitmapName = StringTable->insert(name);

if (*mOverlayBitmapName)
	// Yes, so get Texture Handle.
    mOverlayTextureHandle.set( mOverlayBitmapName, &GFXDefaultGUIProfile, "" );
else
	// No, so reset Texture Handle.
	mOverlayTextureHandle = NULL;

// Update.
setUpdate();
}  


ADDED CODE:

/*
DefineEngineMethod(fxGuiSnooper, setOverlayBitmap, void, (String bitmap), (), "docs")
{
   // contents of cfxGuiBitmapSetOverlayBitmap:

// Fetch HUD Control.
fxGuiSnooper *ctrl = dynamic_cast<fxGuiSnooper*>(object);

// ^ I switched this from static_cast to dynamic_cast, is that correct when moving into DefineEngineMethod?


// Set Overlay Bitmap.
ctrl->setOverlayBitmap(bitmap);

// ^ Which setOverlayBitmap routine is being called here?  Can I remove any excess old functions?
}
*/

Link to comment
Share on other sites

We might need to make some documentation on this, I guess, especially if we actually want to deprecate ConsoleMethod and so on. Did you comment out the code in consoleInit yourself, or was that always commented out? It seems like it and cfxGuiBitmapSetOverlayBitmap duplicate the stuff done in the ConsoleMethod. DefineEngineMethod replaces all three of those (consoleInit, cfxGuiBitmapSetOverlayBitmap, and ConsoleMethod), but of course you still need fxGuiSnooper::setOverlayBitmap because all of these console bindings actually just call that method.


You don't need any cast, IIRC, because DefineEngineMethod does that for you - you should just be able to directly call object->setOverlayBitmap.

Link to comment
Share on other sites

OK, I managed to get it working, thanks for the nudge in the right direction!


In the end it is all so simple lol:


DefineEngineMethod(fxGuiSnooper, setOverlayBitmap, void, (const char* bitmap),,

"docs")

{

object->setOverlayBitmap(bitmap);

}


... And removed the consoleinit, gfxsetoverlaybitmap, and old consolemethod. They were all doing the same thing it appears, as you mentioned above. They are no longer needed with the new DefineEngineMethod. I see now why this route was taken, it is much more efficient.


I had commented out the addCommand in the above example, yes, it was originally there but fails to compile, so I had commented out while I worked on the DefineEngineMethod.


Used this same process to convert a bunch of other AddCommand calls in player.cs and other places, where old resources were using them. They are now DefineEngineMethods and work great.


The more you know!


Cheers

P

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...