Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced a ton of ConsoleMethods with the DefineConsoleMethod Macro. #887

Closed

Conversation

Winterleaf
Copy link
Contributor

Cleaned up the ConsoleMethods and converted them to DefineConsoleMethods. Mainly the ConsoleMethods left are the ones that take a variable amount of parameters. They will need to be cleaned up in a later pass.

@crabmusket crabmusket added this to the 3.7 milestone Nov 4, 2014
@crabmusket
Copy link
Contributor

Awesome work, and thanks for the PR! This is a big step forwards.

Ubuntu fails because of including engineApi.h from telnetDebugger.cpp. Correct include is engineAPI.h.

static const U32 bufSize = 256;
char *returnBuffer = Con::getReturnBuffer( bufSize );
dSprintf( returnBuffer, bufSize, "%f %f %f", movePoint.x, movePoint.y, movePoint.z );
char *returnBuffer = Con::getReturnBuffer( 256 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Erm... This change and several others in this PR are undoing proper return buffersize handling. They need to be fixed.

@crabmusket
Copy link
Contributor

Thanks @dottools for the detailed review! Hadn't gotten around to it myself. I'm curious whether all those == ""s actually work because of the StringTable. But they're still bad style and I agree with changing them. dStrcmp is probably faster as in this case it is O(1) not O(n), I believe.

@dottools
Copy link

dottools commented Nov 4, 2014

Yeah... I wouldn't trust "" to point to the same memory location at all times since it is per compiler and compiler settings specific as to how that'll work. Not to mention with optimizations you just can't trust "" to be in the same memory location as another empty string ("") used in another source file.

An idea to tackle this situation, Andrew Mac suggested introducing a new dStrcmpEmpty() function to make it more uniform to test "" against const char* C strings. Both him and James Urquhart suggested a more simpler and faster approach to checking an empty string. So I took those ideas and came up with a C macro for comparing against empty strings:

#define dStrcmpEmpty(_var)  (*_var == '\0')

// Usage examples
if(dStrcmpEmpty(MissionAreaName))
{
   // MissionAreaName is an empty string
}
if(!dStrcmpEmpty(MissionAreaName))
{
   // MissionAreaName is not an empty string
}

I'm sure somebody could also come up with a C++ inlined template variant with type safety to ensure only variables of type const char* are used with it. I'm not that in-depth with C++ templates myself to come up with one. :)

Anyway, there's probably other problems I haven't spotted that hopefully others will take the initiative to review this PR as well, so we can make sure no other problems are left unnoticed.

@Winterleaf
Copy link
Contributor Author

I’m going to be updating the pr here in a bit

(I removed some quoted text. @eightyeight)

@crabmusket
Copy link
Contributor

@dottools if it's only applicable to const char*... isn't that the opposite of when to use a template :P? Good idea on the empty cmp function though.

@Winterleaf seems like WaypointTesm has slipped in there, and there are still some instances of == "".

@Winterleaf
Copy link
Contributor Author

So what failed on this in linux? I have no idea how to read the log.

@Winterleaf
Copy link
Contributor Author

All fixed now! Let me know if you all find anything else with it.

{
if ( argc < 4 )
if ( delimiter == "" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

@crabmusket
Copy link
Contributor

@Winterleaf note that I'd prefer all these strinc comparisons to use dStrcmp. Which, I think you did for the last batch :).

@Winterleaf
Copy link
Contributor Author

Fixed

DefineEngineFunction(calcExplosionCoverage, F32, (Point3F pos, S32 id, U32 covMask),(Point3F(0.0f,0.0f,0.0f), NULL, NULL),
//I could possible see a use with passing in a null covMask, but even that
//sounds flaky because it will be 100 percent if your saying not to take
//any thing in consideration for coverage. So I'm removing these defaults they are just bad.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment and add it to the GitHub issue (either in the description or as a comment). It will be recoverable using git blame if someone notices that the defaults have changed, and if nobody notices then they don't need to know that there used to be defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exactly do you do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use git blame?

@crabmusket
Copy link
Contributor

Resubmitted with merge and fixes.

@crabmusket crabmusket closed this Dec 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants