Skip to content

Commit

Permalink
Update clang-format config
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Oct 14, 2023
1 parent 2c82148 commit 76e7153
Show file tree
Hide file tree
Showing 157 changed files with 3,363 additions and 2,315 deletions.
137 changes: 89 additions & 48 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,58 +1,99 @@
---
Language: Cpp
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: "true"
AlignConsecutiveDeclarations: "false"
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Right
AlignOperands: "true"
AlignTrailingComments: "true"
AllowShortBlocksOnASingleLine: "true"
AllowShortCaseLabelsOnASingleLine: "true"
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: "true"
AllowShortLoopsOnASingleLine: "true"
AlwaysBreakAfterDefinitionReturnType: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: "false"
AlwaysBreakTemplateDeclarations: "true"
BinPackArguments: "true"
BinPackParameters: "true"
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: "true"
BreakBeforeTernaryOperators: "true"
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: After
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: "true"
ColumnLimit: "120"
CompactNamespaces: "false"
ConstructorInitializerAllOnOneLineOrOnePerLine: "true"
Cpp11BracedListStyle: "true"
DisableFormat: "false"
FixNamespaceComments: "true"
IndentCaseLabels: "true"
IndentWrappedFunctionNames: "false"
KeepEmptyLinesAtTheStartOfBlocks: "true"
MaxEmptyLinesToKeep: "1"
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 92
CompactNamespaces: false
Cpp11BracedListStyle: true
DisableFormat: false
FixNamespaceComments: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
LambdaBodyIndentation: OuterScope
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PackConstructorInitializers: CurrentLine
PointerAlignment: Left
ReflowComments: "true"
SortIncludes: "true"
SortUsingDeclarations: "true"
SpaceAfterTemplateKeyword: "false"
SpaceBeforeAssignmentOperators: "true"
ReferenceAlignment: Left
ReflowComments: true
SeparateDefinitionBlocks: Always
SortIncludes: CaseInsensitive
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: "false"
SpacesBeforeTrailingComments: "2"
SpacesInAngles: "false"
SpacesInCStyleCastParentheses: "false"
SpacesInContainerLiterals: "false"
SpacesInParentheses: "false"
SpacesInSquareBrackets: "false"
Standard: Cpp11
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesBeforeTrailingComments: 2
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
UseTab: Never
---
Language: Proto
---
Language: ObjC
BasedOnStyle: WebKit
ColumnLimit: "120"
QualifierAlignment: Custom
QualifierOrder: ["inline", "static", "constexpr", "type", "const", "volatile"]
25 changes: 13 additions & 12 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Checks: >
*-,
boost-*,
bugprone-*,
-bugprone-macro-parentheses,
cert-*,
-cert-err58-cpp,
-cert-oop54-cpp,
clang-analyzer-*,
Expand All @@ -15,39 +18,35 @@ Checks: >
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
hicpp-*,
-hicpp-special-member-functions,
-hicpp-no-array-decay,
-hicpp-signed-bitwise,
misc-*,
modernize-*,
-modernize-avoid-bind,
-modernize-use-trailing-return-type,
performance-*,
readability-*,
-readability-identifier-naming,
-readability-const-return-type,
-readability-identifier-length,
-readability-magic-numbers,
readability-identifier-naming,
-readability-uppercase-literal-suffix,
-*non-private-member-variables-in-classes,
-*-avoid-c-arrays
-*-named-parameter,
-*-non-private-member-variables-in-classes,
-*-special-member-functions,
WarningsAsErrors: "*"
FormatStyle: none
CheckOptions:
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: cppcoreguidelines-avoid-do-while.IgnoreMacros
value: true
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberCase
Expand All @@ -60,6 +59,8 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: "^tag_invoke$"
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
- key: readability-identifier-naming.IgnoreMainLikeFunctions
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: check-case-conflict
- id: check-added-large-files

# - repo: https://github.com/pre-commit/mirrors-clang-format
# rev: v17.0.2
# hooks:
# - id: clang-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.2
hooks:
- id: clang-format
28 changes: 21 additions & 7 deletions src/app/playground/cxx_stb_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,44 @@ int main(int, char**)

stbi_set_flip_vertically_on_load(1);
buffer = stbi_load(path, &width, &height, &bpp, 0);
if (buffer == nullptr) { MOCI_ERROR("stbi load error"); }
if (buffer == nullptr) {
MOCI_ERROR("stbi load error");
}

MOCI_INFO("Width: {}", width);
MOCI_INFO("Height: {}", height);
MOCI_INFO("BPP: {}", bpp);

// Resize
auto const newSize = 512;
std::vector<stbi_uc> outBuffer {};
std::vector<stbi_uc> outBuffer{};
outBuffer.resize(newSize * newSize * bpp);
if (stbir_resize_uint8(buffer, width, height, 0, outBuffer.data(), newSize, newSize, 0, bpp) == 0)
{
if (stbir_resize_uint8(
buffer,
width,
height,
0,
outBuffer.data(),
newSize,
newSize,
0,
bpp
)
== 0) {
MOCI_ERROR("stbi resize error");
}

// Write
auto const outPath = "test.png";
if (stbi_write_png(outPath, newSize, newSize, bpp, outBuffer.data(), newSize * bpp) == 0)
{
if (stbi_write_png(outPath, newSize, newSize, bpp, outBuffer.data(), newSize * bpp)
== 0) {
MOCI_ERROR("stbi write error");
}

// Cleanup
if (buffer != nullptr) { stbi_image_free(buffer); }
if (buffer != nullptr) {
stbi_image_free(buffer);
}

return EXIT_SUCCESS;
}
33 changes: 17 additions & 16 deletions src/app/playground/freetype_atlas/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ struct glyph_info
int main(int argc, char** argv)
{
auto const arguments = std::span<char*>(argv, argc);
if (argc < 3)
{
if (argc < 3) {
printf("usage: %s <font> <size>\n", arguments[0]);
return 1;
}
Expand All @@ -36,9 +35,12 @@ int main(int argc, char** argv)

// quick and dirty max texture size estimate

int max_dim = (1 + (face->size->metrics.height >> 6)) * static_cast<int>(ceilf(sqrtf(NUM_GLYPHS)));
int max_dim = (1 + (face->size->metrics.height >> 6))
* static_cast<int>(ceilf(sqrtf(NUM_GLYPHS)));
int tex_width = 1;
while (tex_width < max_dim) { tex_width <<= 1; }
while (tex_width < max_dim) {
tex_width <<= 1;
}
int tex_height = tex_width;

// render glyphs to atlas
Expand All @@ -47,26 +49,26 @@ int main(int argc, char** argv)
int pen_x = 0;
int pen_y = 0;

std::array<glyph_info, NUM_GLYPHS> info {};
std::array<glyph_info, NUM_GLYPHS> info{};

auto index = 0;
for (auto& glyph : info)
{
FT_Load_Char(face, index, FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT);
for (auto& glyph : info) {
FT_Load_Char(
face,
index,
FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT
);
index++;

FT_Bitmap* bmp = &face->glyph->bitmap;

if (pen_x + static_cast<int>(bmp->width) >= tex_width)
{
if (pen_x + static_cast<int>(bmp->width) >= tex_width) {
pen_x = 0;
pen_y += ((face->size->metrics.height >> 6) + 1);
}

for (int row = 0; row < static_cast<int>(bmp->rows); ++row)
{
for (int col = 0; col < static_cast<int>(bmp->width); ++col)
{
for (int row = 0; row < static_cast<int>(bmp->rows); ++row) {
for (int col = 0; col < static_cast<int>(bmp->width); ++col) {
int x = pen_x + col;
int y = pen_y + row;
pixels[y * tex_width + x] = bmp->buffer[row * bmp->pitch + col];
Expand All @@ -92,8 +94,7 @@ int main(int argc, char** argv)
// write png

char* png_data = (char*)calloc(tex_width * tex_height * 4, 1);
for (int i = 0; i < (tex_width * tex_height); ++i)
{
for (int i = 0; i < (tex_width * tex_height); ++i) {
png_data[i * 4 + 0] |= pixels[i];
png_data[i * 4 + 1] |= pixels[i];
png_data[i * 4 + 2] |= pixels[i];
Expand Down
17 changes: 9 additions & 8 deletions src/app/playground/gl_extensions/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

auto main() -> int
{
if (auto success = glfwInit(); success == GLFW_FALSE)
{
if (auto success = glfwInit(); success == GLFW_FALSE) {
std::fprintf(stderr, "Failed to initialize glfw\n");
return EXIT_FAILURE;
}
Expand All @@ -16,20 +15,22 @@ auto main() -> int
glfwHideWindow(window);
glfwMakeContextCurrent(window);

if (auto err = glewInit() != GLEW_OK; err)
{
if (auto err = glewInit() != GLEW_OK; err) {
auto const* msg = glewGetErrorString(err);
std::fprintf(stderr, "Failed to initialize glew: %s\n", reinterpret_cast<char const*>(msg));
std::fprintf(
stderr,
"Failed to initialize glew: %s\n",
reinterpret_cast<char const*>(msg)
);
return EXIT_FAILURE;
}

GLint n = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
std::printf("num: %d\n", n);

for (GLint i = 0; i < n; i++)
{
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
for (GLint i = 0; i < n; i++) {
char const* extension = (char const*)glGetStringi(GL_EXTENSIONS, i);
printf("Ext %d: %s\n", i, extension);
}

Expand Down
Loading

0 comments on commit 76e7153

Please sign in to comment.