-
Notifications
You must be signed in to change notification settings - Fork 81
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
Adding Clang Format file #1284
Adding Clang Format file #1284
Conversation
What is the status here? |
I don't think we have agreement on what the format should be, and if you run Clang-format on the entire code tree it will reformat everything. I think we'd need to have an agreement that we run this on files individually as needed - and not the entire tree. plClient also has it's own formatting file set. I'd be fine with just closing this PR down and if people are fine with the formatting file in the client maybe we roll that up at some point. |
Right, the old code is all over the place in terms of code style. Ideally, what we want is for this to match the H'uru Plasma Code Style, which is mostly documented here. My suggestions were attempts to bring the clang-format rules in line with the style guideline. |
Let me look at this again in since I'm looking at applying clang-format to the Metal code. It would be a good chance to at least apply the style to a "clean" section of the code that won't cause a bunch of needless churn. |
46c24e0
to
9551150
Compare
I'm skimming through the Metal PR to see what the results look like. I still see some code style problems, but I'm not sure if clang-format can handle this, so I'm just going to make a note of it.
static const uint kFaceMapping[] = {
1, // kLeftFace
0, // kRightFace
4, // kFrontFace
5, // kBackFace
2, // kTopFace
3 // kBottomFace
}; is good, but static const float fullFrameCoords[16] = {
//first pair is vertex, second pair is texture
-1, -1, 0, 1,
1, -1, 1, 1,
-1, 1, 0, 0,
1, 1, 1, 0}; is not good.
is good, but
is not good. |
Lemme take a look. I'll try to make changes on the Metal PR - and if they look good, bring them back here. |
I've updated the format and also applied it to the Metal source. (I can see there are some embarrassing copy/paste mixups with the DX or OpenGL pipelines that the format is messing with, I'll clean those up on the Metal pipeline side.) |
I'm seeing some odd stuff in if (src.fFlags & hsMatrix44::kIsIdent)
{
memcpy(dst, &matrix_identity_float4x4, sizeof(float) * 16);
} else
{
memcpy(dst, &src.fMap, sizeof(matrix_float4x4));
} should be if (src.fFlags & hsMatrix44::kIsIdent) {
memcpy(dst, &matrix_identity_float4x4, sizeof(float) * 16);
} else {
memcpy(dst, &src.fMap, sizeof(matrix_float4x4));
} or just drop the curly brackets altogether. In class plMetalFragmentShader : public plMetalShader
{
protected: should be class plMetalFragmentShader : public plMetalShader
{
protected: In for (auto& layer : layerStates)
{
layer.clampFlag = hsGMatState::hsGMatClampFlags(-1);
} should be: for (auto& layer : layerStates) {
layer.clampFlag = hsGMatState::hsGMatClampFlags(-1);
} or just drop the curly brackets altogether. |
Ah, I meant more stuff like DX specific comments that are still hanging out in Metal headers. I'll take a look at this stuff. Clang format should be able to enforce that... |
Clang-format is currently doing something weird here. The existing rule is:
This means if you have a multiline control statement, a brace is allowed to break. Otherwise a brace is not allowed to break. It should be enforcing that the braces are on the same line. But it's not. If I change that value to I can change to Never. Just thought I'd note the oddity here. |
Adding Clang format file based on Google Style. This is useful for the Metal code which wasn't really written with respect for conventions, so this will allow automatic enforcement of code style to make the pull request easier. There are two changes made to Google Style:
Clang format can be invoked using the following commands:
Dry run:
clang-format --dry-run -style=file plMetalDevice.cpp
Apply changes in place:
clang-format -style=file -i plMetalDevice.cpp
This does not automatically invoke clang-format as part of builds. There are several CMake plugins to do so (and even plugins for some IDEs.)