From e6bd1ad05728888f38fe480c6d6587334127624c Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 15:34:08 -0500 Subject: [PATCH 1/8] chore: removes unneeded headers --- Makefile | 2 ++ README.md | 11 +++-------- main.cpp | 22 ++++------------------ scripts/install_dependencies.sh | 3 ++- scripts/run_lint.sh | 3 +++ 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 03ac160..89592b2 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ SHELL := /bin/bash CC := gcc TARGET := main SRCS := main.cpp +# `-lstdc++` was added to resolve [this issue](https://stackoverflow.com/questions/33263288/libstdc-dso-missing-from-command-line) +# `-lm` was added to resolve [this issue](https://stackoverflow.com/questions/16006145/ld-undefined-reference-to-symbol-log2glibc-2-2-5) LIBS := -lGL -lGLU -lglut -lIL -lILU -lILUT -lstdc++ -lm all: $(TARGET) diff --git a/README.md b/README.md index ef3a157..142f841 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,9 @@ git clone https://github.com/robert-7/Go-Board-Game.git && cd Go-Board-Game ## Building and Running Building requires the OpenGL and DevIL libraries imported. -To build the binary, simply run `make`. -To run the built binary, simply run `./main`. +To build and run the binary, simply run `make && ./main`. To clean up, run `make clean`. -### Building Gotchas - -* `-lstdc++` was added to resolve [this issue](https://stackoverflow.com/questions/33263288/libstdc-dso-missing-from-command-line) -* `-lm` was added to resolve [this issue](https://stackoverflow.com/questions/16006145/ld-undefined-reference-to-symbol-log2glibc-2-2-5). - ## Linting The repository uses the same commands locally and in CI. After installing the packages above, run: @@ -50,7 +44,8 @@ The repository uses the same commands locally and in CI. After installing the pa ./scripts/run_lint.sh ``` -The script configures CMake, runs clang-tidy, and then runs cppcheck with the same settings used in CI. It can be removed along with the `build` directory when you finish linting. +The script configures CMake, runs clang-tidy, and then runs cppcheck with the same settings used in CI. +It can be removed along with the `build` directory when you finish linting. To run linting automatically before each commit, install [`pre-commit`](https://pre-commit.com/) (e.g., `pip install pre-commit` or `sudo apt install pre-commit`), then enable the hooks once: diff --git a/main.cpp b/main.cpp index d3886d9..e180f6f 100644 --- a/main.cpp +++ b/main.cpp @@ -3,30 +3,16 @@ // #include // #include // Standard library -#include #include #include -#include - -// For Sleep in Windows -// #include -// For Sleep in Linux -#include -// #pragma comment(lib, "ILUT.lib") - -#include - -// For Sleep in Windows -// #include -// For Sleep in Linux -#include -#include +#include // For std::cout +#include // For usleep // includes, graphics +#include #include #include -#include - +// DevIL includes #define ILUT_USE_OPENGL #include #include diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 410fa68..acbb869 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -21,4 +21,5 @@ run_with_sudo apt-get install -y \ cmake \ clang-tidy \ clang-format \ - cppcheck + cppcheck \ + iwyu # enforces include hygiene diff --git a/scripts/run_lint.sh b/scripts/run_lint.sh index d4175f1..b13d09a 100755 --- a/scripts/run_lint.sh +++ b/scripts/run_lint.sh @@ -19,6 +19,9 @@ clang-format --dry-run --Werror "${REPO_ROOT}/main.cpp" # Static analysis with clang-tidy; uses the compile database for accurate diagnostics. clang-tidy "${REPO_ROOT}/main.cpp" -p "${BUILD_DIR}" +# Include-What-You-Use to enforce proper includes; uses the compile database via the helper tool. +iwyu_tool -p "${BUILD_DIR}" "${REPO_ROOT}/main.cpp" + # Cross-check the same sources with cppcheck for complementary warnings. # ignore normalCheckLevelMaxBranches to reduce noise cppcheck --project="${BUILD_DIR}/compile_commands.json" --enable=warning,style,performance --error-exitcode=1 --suppress=normalCheckLevelMaxBranches From 672d1753aaaaa3bd649d322d7fe21dab84b98ab5 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 15:37:40 -0500 Subject: [PATCH 2/8] chore: cleans up headers --- main.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index e180f6f..facee22 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,11 @@ -// OLD INCLUDES/USINGS -// #include -// #include -// #include -// Standard library +// Standard libraries #include #include #include // For std::cout #include // For usleep +#include +#include +#include // includes, graphics #include @@ -21,11 +20,6 @@ ILuint il[3] = {0, 1, 2}; GLuint texture[3] = {0, 1, 2}; -// For the queue -#include -#include -#include - #define GL_CLAMP_TO_EDGE 0x812F // Window settings @@ -115,10 +109,10 @@ void jump_off(int x0, int y0, int color); //! Program entry point int main(int argc, char **argv) { - const int DEFAULT_WINDOW_WIDTH = 512; - const int DEFAULT_WINDOW_HEIGHT = 512; - const int DEFAULT_WINDOW_X = 100; - const int DEFAULT_WINDOW_Y = 100; + const int DEFAULT_WINDOW_WIDTH = 768; + const int DEFAULT_WINDOW_HEIGHT = 768; + const int DEFAULT_WINDOW_X = 256; + const int DEFAULT_WINDOW_Y = 256; const char *WINDOW_TITLE = "Go Board Game"; // initialize GLUT glutInit(&argc, argv); From fc052689ab8afeae77c0d0d12f1d8c9852d8e9c7 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 15:50:34 -0500 Subject: [PATCH 3/8] chore: addresses linting --- .clang-tidy | 3 ++- main.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7756ffa..464e736 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,6 +17,7 @@ Checks: > modernize-deprecated-headers, modernize-loop-convert, modernize-use-stdarray, - modernize-use-using + modernize-use-using, + performance-* WarningsAsErrors: '*' diff --git a/main.cpp b/main.cpp index facee22..1ab536f 100644 --- a/main.cpp +++ b/main.cpp @@ -2,9 +2,9 @@ #include #include #include // For std::cout -#include // For usleep #include #include +#include // For usleep #include // includes, graphics From bd9f973d1511b9d5249547049748fa13af5098d7 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 16:29:39 -0500 Subject: [PATCH 4/8] feat: implements Codex's recommended naming --- .clang-tidy | 36 +++++- main.cpp | 367 ++++++++++++++++++++++++++-------------------------- 2 files changed, 220 insertions(+), 183 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 464e736..2647670 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -18,6 +18,40 @@ Checks: > modernize-loop-convert, modernize-use-stdarray, modernize-use-using, - performance-* + performance-*, + readability-identifier-naming WarningsAsErrors: '*' + +CheckOptions: + # Adopt a consistent C++ naming convention: types PascalCase, functions camelBack, variables lower_case. + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantCase + value: CamelCase + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.UnionCase + value: CamelCase + - key: readability-identifier-naming.TypeAliasCase + value: CamelCase + - key: readability-identifier-naming.FunctionCase + value: lower_case + - key: readability-identifier-naming.MethodCase + value: lower_case + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.VariableCase + value: lower_case + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.GlobalConstantCase + value: lower_case + - key: readability-identifier-naming.StaticConstantCase + value: lower_case + - key: readability-identifier-naming.ConstexprVariableCase + value: lower_case diff --git a/main.cpp b/main.cpp index 1ab536f..ded15aa 100644 --- a/main.cpp +++ b/main.cpp @@ -17,33 +17,33 @@ #include #include -ILuint il[3] = {0, 1, 2}; -GLuint texture[3] = {0, 1, 2}; +ILuint image_ids[3] = {0, 1, 2}; +GLuint textures[3] = {0, 1, 2}; #define GL_CLAMP_TO_EDGE 0x812F // Window settings -int windowID; // Glut window ID (for display) +int window_id; // Glut window ID (for display) // Camera methods void mouse(int button, int state, int x, int y); void motion(int x, int y); // Camera settings -bool updateCamZPos = false; -int lastX = 0; -int lastY = 0; -const float ZOOM_SCALE = 0.01; +bool update_cam_z_pos = false; +int last_x = 0; +int last_y = 0; +const float zoom_scale = 0.01; -constexpr int BOARD_SIZE = 19; -constexpr int BOARD_CENTER = BOARD_SIZE / 2; +constexpr int board_size = 19; +constexpr int board_center = board_size / 2; // Global Constants // Camera initial position -constexpr GLdouble INITIAL_CAM_X = 0.0; -constexpr GLdouble INITIAL_CAM_Y = 0.0; -constexpr GLdouble INITIAL_CAM_Z = -1.5; -constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers +constexpr GLdouble initial_cam_x = 0.0; +constexpr GLdouble initial_cam_y = 0.0; +constexpr GLdouble initial_cam_z = -1.5; +constexpr float pi = 3.14159265358979323846F; // Pi constant for trigonometric helpers struct Camera { GLdouble x; @@ -54,36 +54,36 @@ struct Camera { int wireframe = 0; int lighting = 1; int material = 1; -int pauseBoardRotation_y = 1; -int pauseBoardRotation_x = 1; -int pauseLighting = 0; -int depthTest = 1; -int cullFace = 1; -int smooth = 1; -int enabletexture = 0; - -constexpr int INITIAL_BOARD_ANGLE_X = 45; -constexpr int INITIAL_BOARD_ANGLE_Y = 0; -float angle_x = INITIAL_BOARD_ANGLE_X; -float angle_y = INITIAL_BOARD_ANGLE_Y; -float translatelight = 0; - -Camera camera{INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z}; +int pause_board_rotation_y = 1; +int pause_board_rotation_x = 1; +int pause_lighting = 0; +int depth_test = 1; +int cull_face = 1; +int smooth_shading = 1; +int enable_texture = 0; + +constexpr int initial_board_angle_x = 45; +constexpr int initial_board_angle_y = 0; +float angle_x = initial_board_angle_x; +float angle_y = initial_board_angle_y; +float translate_light = 0; + +Camera camera{initial_cam_x, initial_cam_y, initial_cam_z}; // Behind the Scenes variables -int placex = 0; -int placey = 0; -int col = 1; -float t = 0; -constexpr float TIME_INCREMENT = 0.002; // Depicts how fast time increments. -constexpr int DEFAULT_SLEEP_TIME = 3000; // Default sleep time in microseconds. +int place_x = 0; +int place_y = 0; +int stone_color = 1; +float animation_time = 0; +constexpr float time_increment = 0.002; // Depicts how fast time increments. +constexpr int default_sleep_time = 3000; // Default sleep time in microseconds. // Behind the Scenes -std::array, BOARD_SIZE> board_status{}; -std::array, BOARD_SIZE> liberties_status{}; +std::array, board_size> board_status{}; +std::array, board_size> liberties_status{}; int restart_option = 0; std::queue rm_queue; -std::list> L; +std::list> captured_groups; // float rm_array[1083]; // Holds the objects that will be removed. // int p = 0; // Always points to the last index of rm_array. @@ -93,11 +93,11 @@ void display(); void keyboard(unsigned char, int, int); void init(); void idle(); -void SetImage(); -void DrawSphere(int); -void DrawUnitCube(int); -void ApplyTransformations(float indx, float indy, float z); -void ApplyTransformationGeneral(float indx, float indy, float z); +void set_images(); +void draw_sphere(int color); +void draw_unit_cube(int color); +void apply_transformations(float indx, float indy, float z); +void apply_transformation_general(float indx, float indy, float z); // Behind the Scenes void init_board(); @@ -109,29 +109,29 @@ void jump_off(int x0, int y0, int color); //! Program entry point int main(int argc, char **argv) { - const int DEFAULT_WINDOW_WIDTH = 768; - const int DEFAULT_WINDOW_HEIGHT = 768; - const int DEFAULT_WINDOW_X = 256; - const int DEFAULT_WINDOW_Y = 256; - const char *WINDOW_TITLE = "Go Board Game"; + const int default_window_width = 768; + const int default_window_height = 768; + const int default_window_x = 256; + const int default_window_y = 256; + const char *window_title = "Go Board Game"; // initialize GLUT glutInit(&argc, argv); // set visual glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // set physical window properties - glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); + glutInitWindowSize(default_window_width, default_window_height); // position window on the screen - glutInitWindowPosition(DEFAULT_WINDOW_X, DEFAULT_WINDOW_Y); + glutInitWindowPosition(default_window_x, default_window_y); // create window - windowID = glutCreateWindow(WINDOW_TITLE); + window_id = glutCreateWindow(window_title); ilInit(); iluInit(); ilutInit(); ilutRenderer(ILUT_OPENGL); - ilGenImages(2, il); - glGenTextures(2, texture); + ilGenImages(2, image_ids); + glGenTextures(2, textures); // initialize OpenGL init(); @@ -198,9 +198,9 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) break; case '5': - depthTest = !depthTest; + depth_test = !depth_test; - if (depthTest) { + if (depth_test) { glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); } else { @@ -210,9 +210,9 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) break; case '6': - cullFace = !cullFace; + cull_face = !cull_face; - if (cullFace) { + if (cull_face) { glEnable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); @@ -221,9 +221,9 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) break; case '7': - smooth = !smooth; + smooth_shading = !smooth_shading; - if (smooth) { + if (smooth_shading) { glShadeModel(GL_SMOOTH); } else { glShadeModel(GL_FLAT); @@ -232,9 +232,9 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) break; case '8': - enabletexture = !enabletexture; + enable_texture = !enable_texture; - if (enabletexture) { + if (enable_texture) { glEnable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); @@ -244,58 +244,58 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) case 'o': case 'O': std::cout << "PRESSED O\n"; - pauseBoardRotation_y = !pauseBoardRotation_y; + pause_board_rotation_y = !pause_board_rotation_y; break; case 'p': case 'P': std::cout << "PRESSED P\n"; - pauseBoardRotation_x = !pauseBoardRotation_x; + pause_board_rotation_x = !pause_board_rotation_x; break; case 'a': case 'A': - if (placex > -BOARD_CENTER) { - placex -= 1; + if (place_x > -board_center) { + place_x -= 1; } break; case 'w': case 'W': - if (placey < BOARD_CENTER) { - placey += 1; + if (place_y < board_center) { + place_y += 1; } break; case 's': case 'S': - if (placey > -BOARD_CENTER) { - placey -= 1; + if (place_y > -board_center) { + place_y -= 1; } break; case 'd': case 'D': - if (placex < BOARD_CENTER) { - placex += 1; + if (place_x < board_center) { + place_x += 1; } break; case '\r': - if (board_status[placex + BOARD_CENTER][placey + BOARD_CENTER] != 0) { + if (board_status[place_x + board_center][place_y + board_center] != 0) { std::cout << "YOU CAN'T PLACE A PIECE HERE BECAUSE THERE ALREADY IS A " "PIECE HERE!!!\n"; } else { std::cout << "ENTER KEY PRESSED!!!\n"; - make_move(placex + BOARD_CENTER, placey + BOARD_CENTER, col); - if (col == 1) { - col = 2; + make_move(place_x + board_center, place_y + board_center, stone_color); + if (stone_color == 1) { + stone_color = 2; } else { - col = 1; + stone_color = 1; } } break; @@ -317,17 +317,17 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) if (restart_option) { std::cout << "You pressed 'y'. The game has been restarted.\n"; init_board(); - col = 1; + stone_color = 1; } break; case 'b': case 'B': - col = 2; + stone_color = 2; break; case 'v': case 'V': - col = 1; + stone_color = 1; break; } } @@ -335,15 +335,15 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) // Handles mouse motion events while a button is pressed void motion(int x, int y) { // If the RMB is pressed and dragged then zoom in / out - if (updateCamZPos) { + if (update_cam_z_pos) { // Update camera position while the mouse is dragged - camera.z += (y - lastY) * ZOOM_SCALE; - camera.x += (x - lastX) * ZOOM_SCALE; - lastX = x; - lastY = y; + camera.z += (y - last_y) * zoom_scale; + camera.x += (x - last_x) * zoom_scale; + last_x = x; + last_y = y; // Redraw the scene from updated camera position - glutSetWindow(windowID); + glutSetWindow(window_id); glutPostRedisplay(); } } @@ -353,38 +353,38 @@ void mouse(int button, int state, int x, int y) { // If the RMB is pressed and dragged then zoom in / out if (button == GLUT_RIGHT_BUTTON) { if (state == GLUT_DOWN) { - lastX = x; - lastY = y; - updateCamZPos = true; + last_x = x; + last_y = y; + update_cam_z_pos = true; } else { - updateCamZPos = false; + update_cam_z_pos = false; } } } void idle() { - const float BOARD_ROTATION_STEP = 0.5f; - const float ANGLE_LIMIT = 360.0f; - if (!pauseBoardRotation_y) { - angle_y += BOARD_ROTATION_STEP; - if (angle_y > ANGLE_LIMIT) { - angle_y -= ANGLE_LIMIT; + const float board_rotation_step = 0.5f; + const float angle_limit = 360.0f; + if (!pause_board_rotation_y) { + angle_y += board_rotation_step; + if (angle_y > angle_limit) { + angle_y -= angle_limit; } } - if (!pauseBoardRotation_x) { - angle_x += BOARD_ROTATION_STEP; - if (angle_x > ANGLE_LIMIT) { - angle_x -= ANGLE_LIMIT; + if (!pause_board_rotation_x) { + angle_x += board_rotation_step; + if (angle_x > angle_limit) { + angle_x -= angle_limit; } } /* - if (!pauseLighting) { - translatelight += BOARD_ROTATION_STEP; + if (!pause_lighting) { + translate_light += board_rotation_step; - if (translatelight > 360) { - translatelight -= 360; + if (translate_light > 360) { + translate_light -= 360; } } */ @@ -392,7 +392,7 @@ void idle() { glutPostRedisplay(); } -void lightingFunc() { +void lighting_func() { // Specify light position GLfloat lightposition[4] = {0.0, 0.0, -0.5, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, lightposition); @@ -408,13 +408,13 @@ void lightingFunc() { // GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; glLightfv(GL_LIGHT0, GL_SPECULAR, lightstrength); - GLfloat spread = 90 - 90 * t; + GLfloat spread = 90 - 90 * animation_time; glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, &spread); glEnable(GL_LIGHT0); } -void materialFunc() { +void material_func() { // Add a diffuse component to our board. The diffuse reflection constant // is white (white light source produces white reflection). GLfloat materialdiffuse[4] = {0.5, 0.5, 1.0, 1.0}; @@ -430,42 +430,42 @@ void materialFunc() { glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, materialshininess); } -void DrawSphere(int color) { - float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; +void draw_sphere(int color) { + const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; if (color == 0) { - float colorRed[4] = {1.0, 0.0, 0.0, 0.0}; - glColor4fv(colorRed); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorRed); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_red[4] = {1.0F, 0.0F, 0.0F, 0.0F}; + glColor4fv(color_red); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_red); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } if (color == 1) { - float colorWhite[4] = {1.0, 1.0, 1.0, 1.0}; - glColor4fv(colorWhite); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorWhite); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_white[4] = {1.0F, 1.0F, 1.0F, 1.0F}; + glColor4fv(color_white); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_white); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } if (color == 2) { - float colorBlack[4] = {0.0, 0.0, 0.0, 0.0}; - glColor4fv(colorBlack); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlack); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_black[4] = {0.0F, 0.0F, 0.0F, 0.0F}; + glColor4fv(color_black); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_black); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } if (color == 3) { - float colorGreen[4] = {0.0, 0.0, 1.0, 0.0}; - glColor4fv(colorGreen); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_green[4] = {0.0F, 0.0F, 1.0F, 0.0F}; + glColor4fv(color_green); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } if (color == 4) { - float colorBlue[4] = {0.0, 1.0, 0.0, 0.0}; - glColor4fv(colorBlue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_blue[4] = {0.0F, 1.0F, 0.0F, 0.0F}; + glColor4fv(color_blue); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } glBegin(GL_TRIANGLES); @@ -478,21 +478,21 @@ void DrawSphere(int color) { glEnd(); } -void DrawUnitCube(int color) { +void draw_unit_cube(int color) { if (color == 0) { - glBindTexture(GL_TEXTURE_2D, texture[0]); + glBindTexture(GL_TEXTURE_2D, textures[0]); } else if (color == 3) { - float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; - float colorGreen[4] = {0.0, 0.0, 1.0, 0.0}; - glColor4fv(colorGreen); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorGreen); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; + const GLfloat color_green[4] = {0.0F, 0.0F, 1.0F, 0.0F}; + glColor4fv(color_green); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } else if (color == 4) { - float colorNone[4] = {0.0, 0.0, 0.0, 0.0}; - float colorBlue[4] = {0.0, 1.0, 0.0, 0.0}; - glColor4fv(colorBlue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue); - glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone); + const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; + const GLfloat color_blue[4] = {0.0F, 1.0F, 0.0F, 0.0F}; + glColor4fv(color_blue); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); } glBegin(GL_QUADS); @@ -551,7 +551,7 @@ void DrawUnitCube(int color) { if (color == 0) { glEnd(); - glBindTexture(GL_TEXTURE_2D, texture[1]); + glBindTexture(GL_TEXTURE_2D, textures[1]); glBegin(GL_QUADS); } @@ -568,7 +568,7 @@ void DrawUnitCube(int color) { glEnd(); - usleep(DEFAULT_SLEEP_TIME); + usleep(default_sleep_time); } void display() { @@ -595,10 +595,10 @@ void display() { glPushMatrix(); //////////////////// MOVING LIGHT!!!!! //////////////////// - glTranslatef(2.0F * std::sin(translatelight * 2.0F * PI / 360.0F), 0.0F, 0.0F); + glTranslatef(2.0F * std::sin(translate_light * 2.0F * pi / 360.0F), 0.0F, 0.0F); if (lighting) { - lightingFunc(); + lighting_func(); } glPopMatrix(); @@ -613,10 +613,10 @@ void display() { // Specify material for the board we'll be drawing. if (material) { - materialFunc(); + material_func(); } - DrawUnitCube(0); + draw_unit_cube(0); glPopMatrix(); glPushMatrix(); @@ -628,31 +628,31 @@ void display() { glTranslatef(0.0, 1.0, 0.0); // The centre glPushMatrix(); - ApplyTransformations(placex, placey, 0); - DrawSphere(0); + apply_transformations(place_x, place_y, 0); + draw_sphere(0); glPopMatrix(); for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { if (board_status[i][j] != 0) { glPushMatrix(); - ApplyTransformations(i - 9, j - 9, 0); - DrawSphere(board_status[i][j]); + apply_transformations(i - 9, j - 9, 0); + draw_sphere(board_status[i][j]); glPopMatrix(); } } } // THE REMOVAL OF PIECE PORTION - if (!L.empty()) { - for (const auto &piece : L) { + if (!captured_groups.empty()) { + for (const auto &piece : captured_groups) { jump_off(piece[0], piece[1], piece[2]); } - t += (TIME_INCREMENT * L.size()); + animation_time += (time_increment * captured_groups.size()); } - if (t > 1) { - t = 0; - L.clear(); + if (animation_time > 1) { + animation_time = 0; + captured_groups.clear(); } glPopMatrix(); @@ -665,7 +665,7 @@ void display() { glutSwapBuffers(); } -void ApplyTransformations(float indx, float indy, [[maybe_unused]] float z) { +void apply_transformations(float indx, float indy, [[maybe_unused]] float z) { int i; if (indx < 0) { for (i = 0; i < std::abs(indx); i++) { @@ -692,17 +692,17 @@ We can probably get rid of the first method, but I don't feel like doing that. */ -void ApplyTransformationGeneral(float indx, float indy, float z) { +void apply_transformation_general(float indx, float indy, float z) { glTranslatef(2 * indx, 10 * indy, 2 * z); } -void SetImages() { +void set_images() { ///////////////////// LOAD WOODEN TEXTURE ///////////////////// - ilBindImage(il[0]); + ilBindImage(image_ids[0]); ilLoadImage("images/wooden.jpg"); ilConvertImage(IL_RGB, IL_UNSIGNED_SHORT); - glBindTexture(GL_TEXTURE_2D, texture[0]); + glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -712,11 +712,11 @@ void SetImages() { ilGetData()); ///////////////////// LOAD CHECKERBOARD TEXTURE ///////////////// - ilBindImage(il[1]); + ilBindImage(image_ids[1]); ilLoadImage("images/checkerboard.png"); ilConvertImage(IL_RGB, IL_UNSIGNED_SHORT); - glBindTexture(GL_TEXTURE_2D, texture[1]); + glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -774,53 +774,53 @@ void jump_off(int x0, int z0, int color) { // For now, let's just assume they're all jumping to point (-4,0,-4) int x1 = -4; - float xt = x0 * (1 - t) + x1 * t; + float xt = x0 * (1 - animation_time) + x1 * animation_time; int y0 = 9; - float yt = -y0 * std::pow(t, 2.0F) + y0 * t + y0; + float yt = -y0 * std::pow(animation_time, 2.0F) + y0 * animation_time + y0; int z1 = -4; - float zt = z0 * (1 - t) + z1 * t; + float zt = z0 * (1 - animation_time) + z1 * animation_time; glPushMatrix(); - ApplyTransformationGeneral((xt - 9), (yt - 9), -(zt - 9)); - DrawSphere(color); + apply_transformation_general((xt - 9), (yt - 9), -(zt - 9)); + draw_sphere(color); // Draw Thigh glPushMatrix(); - if (t < 0.1) { - glRotatef(-80 + 80 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + if (animation_time < 0.1) { + glRotatef(-80 + 80 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); } else { glRotatef(-80, 1.0, 0.0, 1.0); } glScalef(2.0 / 5.0, 1.0, 2.0 / 5.0); glTranslatef(0.0, -1.0, 0.0); - DrawUnitCube(3); + draw_unit_cube(3); glScalef(5.0 / 2.0, 1.0, 5.0 / 2.0); // Draw Shin glPushMatrix(); glTranslatef(0, -0.8, 0); - if (t < 0.1) { - glRotatef(90 - 90 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + if (animation_time < 0.1) { + glRotatef(90 - 90 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); } else { glRotatef(90, 1.0, 0.0, 1.0); } glScalef(1.0 / 5.0, 1.0, 1.0 / 5.0); glTranslatef(0, -1.0, 0); - DrawUnitCube(4); + draw_unit_cube(4); glScalef(5.0, 1.0, 5.0); // Draw Ankle glPushMatrix(); glTranslatef(0, -1.0, 0); - if (t < 0.1) { - glRotatef(-100 + 100 * std::sin(t * 10.0F * PI), 1.0, 0.0, 1.0); + if (animation_time < 0.1) { + glRotatef(-100 + 100 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); } else { glRotatef(-100, 1.0, 0.0, 1.0); } glScalef(1.0 / 2.0, 2.0 / 3.0, 1.0 / 2.0); glTranslatef(0, -1.0, 0); - DrawSphere(0); + draw_sphere(0); glPopMatrix(); glPopMatrix(); glPopMatrix(); @@ -843,7 +843,7 @@ void remove_block(int x, int y, int piece) { rm_piece.push_back(x); rm_piece.push_back(y); rm_piece.push_back(piece); - L.push_back(rm_piece); + captured_groups.push_back(rm_piece); remove_block(x - 1, y, piece); remove_block(x + 1, y, piece); @@ -909,12 +909,15 @@ void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - double fovY = 45, aspect = 1.0, zNear = 0.1, zFar = 100; + double fov_y = 45; + double aspect = 1.0; + double z_near = 0.1; + double z_far = 100; - gluPerspective(fovY, // Field of view + gluPerspective(fov_y, // Field of view aspect, // Aspect ratio (width / height) - zNear, // Near plane - zFar); // Far plane + z_near, // Near plane + z_far); // Far plane // initialize modelview matrix glMatrixMode(GL_MODELVIEW); @@ -925,7 +928,7 @@ void init() { glEnable(GL_DEPTH_TEST); // enable depth testing // glEnable(GL_TEXTURE_2D); // enable textures - SetImages(); + set_images(); init_board(); // Create the "Board" } \ No newline at end of file From bf1f14dcbbd6c89635eab75778646d0206c474d2 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 16:31:11 -0500 Subject: [PATCH 5/8] chore: changes EnumConstantCase to UPPER_CASE --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 2647670..d32b0e1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,7 +30,7 @@ CheckOptions: - key: readability-identifier-naming.EnumCase value: CamelCase - key: readability-identifier-naming.EnumConstantCase - value: CamelCase + value: UPPER_CASE - key: readability-identifier-naming.ClassCase value: CamelCase - key: readability-identifier-naming.StructCase From 7df009341b224978a0b580405bc67d2078e280d8 Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 16:43:43 -0500 Subject: [PATCH 6/8] chore: ensures more common naming --- .clang-tidy | 34 +++++++++++++++++++++--------- main.cpp | 60 ++++++++++++++++++++++++++--------------------------- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index d32b0e1..e3489f5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -24,13 +24,9 @@ Checks: > WarningsAsErrors: '*' CheckOptions: - # Adopt a consistent C++ naming convention: types PascalCase, functions camelBack, variables lower_case. + # ===== Types ===== - key: readability-identifier-naming.NamespaceCase value: lower_case - - key: readability-identifier-naming.EnumCase - value: CamelCase - - key: readability-identifier-naming.EnumConstantCase - value: UPPER_CASE - key: readability-identifier-naming.ClassCase value: CamelCase - key: readability-identifier-naming.StructCase @@ -39,19 +35,37 @@ CheckOptions: value: CamelCase - key: readability-identifier-naming.TypeAliasCase value: CamelCase + - key: readability-identifier-naming.EnumCase + value: CamelCase + + # ===== Enum Values ===== + - key: readability-identifier-naming.EnumConstantCase + value: UPPER_CASE + + # ===== Functions & Methods ===== + # (matches typical C++ engine style; avoids collision with OpenGL's mixed conventions) - key: readability-identifier-naming.FunctionCase value: lower_case - key: readability-identifier-naming.MethodCase value: lower_case - - key: readability-identifier-naming.MemberCase - value: lower_case + + # ===== Variables ===== - key: readability-identifier-naming.VariableCase value: lower_case - key: readability-identifier-naming.ParameterCase value: lower_case - - key: readability-identifier-naming.GlobalConstantCase + + # ===== Member Variables ===== + # Strongly recommended for rendering code for clarity + - key: readability-identifier-naming.MemberCase value: lower_case + - key: readability-identifier-naming.PrivateMemberPrefix + value: m_ + + # ===== Constants ===== + - key: readability-identifier-naming.GlobalConstantCase + value: UPPER_CASE - key: readability-identifier-naming.StaticConstantCase - value: lower_case + value: UPPER_CASE - key: readability-identifier-naming.ConstexprVariableCase - value: lower_case + value: UPPER_CASE \ No newline at end of file diff --git a/main.cpp b/main.cpp index ded15aa..1261276 100644 --- a/main.cpp +++ b/main.cpp @@ -33,17 +33,17 @@ void motion(int x, int y); bool update_cam_z_pos = false; int last_x = 0; int last_y = 0; -const float zoom_scale = 0.01; +const float ZOOM_SCALE = 0.01; -constexpr int board_size = 19; -constexpr int board_center = board_size / 2; +constexpr int BOARD_SIZE = 19; +constexpr int BOARD_CENTER = BOARD_SIZE / 2; // Global Constants // Camera initial position -constexpr GLdouble initial_cam_x = 0.0; -constexpr GLdouble initial_cam_y = 0.0; -constexpr GLdouble initial_cam_z = -1.5; -constexpr float pi = 3.14159265358979323846F; // Pi constant for trigonometric helpers +constexpr GLdouble INITIAL_CAM_X = 0.0; +constexpr GLdouble INITIAL_CAM_Y = 0.0; +constexpr GLdouble INITIAL_CAM_Z = -1.5; +constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers struct Camera { GLdouble x; @@ -62,25 +62,25 @@ int cull_face = 1; int smooth_shading = 1; int enable_texture = 0; -constexpr int initial_board_angle_x = 45; -constexpr int initial_board_angle_y = 0; -float angle_x = initial_board_angle_x; -float angle_y = initial_board_angle_y; +constexpr int INITIAL_BOARD_ANGLE_X = 45; +constexpr int INITIAL_BOARD_ANGLE_Y = 0; +float angle_x = INITIAL_BOARD_ANGLE_X; +float angle_y = INITIAL_BOARD_ANGLE_Y; float translate_light = 0; -Camera camera{initial_cam_x, initial_cam_y, initial_cam_z}; +Camera camera{INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z}; // Behind the Scenes variables int place_x = 0; int place_y = 0; int stone_color = 1; float animation_time = 0; -constexpr float time_increment = 0.002; // Depicts how fast time increments. -constexpr int default_sleep_time = 3000; // Default sleep time in microseconds. +constexpr float TIME_INCREMENT = 0.002; // Depicts how fast time increments. +constexpr int DEFAULT_SLEEP_TIME = 3000; // Default sleep time in microseconds. // Behind the Scenes -std::array, board_size> board_status{}; -std::array, board_size> liberties_status{}; +std::array, BOARD_SIZE> board_status{}; +std::array, BOARD_SIZE> liberties_status{}; int restart_option = 0; std::queue rm_queue; std::list> captured_groups; @@ -257,7 +257,7 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) case 'a': case 'A': - if (place_x > -board_center) { + if (place_x > -BOARD_CENTER) { place_x -= 1; } @@ -265,33 +265,33 @@ void keyboard(unsigned char key, [[maybe_unused]] int x, [[maybe_unused]] int y) case 'w': case 'W': - if (place_y < board_center) { + if (place_y < BOARD_CENTER) { place_y += 1; } break; case 's': case 'S': - if (place_y > -board_center) { + if (place_y > -BOARD_CENTER) { place_y -= 1; } break; case 'd': case 'D': - if (place_x < board_center) { + if (place_x < BOARD_CENTER) { place_x += 1; } break; case '\r': - if (board_status[place_x + board_center][place_y + board_center] != 0) { + if (board_status[place_x + BOARD_CENTER][place_y + BOARD_CENTER] != 0) { std::cout << "YOU CAN'T PLACE A PIECE HERE BECAUSE THERE ALREADY IS A " "PIECE HERE!!!\n"; } else { std::cout << "ENTER KEY PRESSED!!!\n"; - make_move(place_x + board_center, place_y + board_center, stone_color); + make_move(place_x + BOARD_CENTER, place_y + BOARD_CENTER, stone_color); if (stone_color == 1) { stone_color = 2; } else { @@ -337,8 +337,8 @@ void motion(int x, int y) { // If the RMB is pressed and dragged then zoom in / out if (update_cam_z_pos) { // Update camera position while the mouse is dragged - camera.z += (y - last_y) * zoom_scale; - camera.x += (x - last_x) * zoom_scale; + camera.z += (y - last_y) * ZOOM_SCALE; + camera.x += (x - last_x) * ZOOM_SCALE; last_x = x; last_y = y; @@ -568,7 +568,7 @@ void draw_unit_cube(int color) { glEnd(); - usleep(default_sleep_time); + usleep(DEFAULT_SLEEP_TIME); } void display() { @@ -595,7 +595,7 @@ void display() { glPushMatrix(); //////////////////// MOVING LIGHT!!!!! //////////////////// - glTranslatef(2.0F * std::sin(translate_light * 2.0F * pi / 360.0F), 0.0F, 0.0F); + glTranslatef(2.0F * std::sin(translate_light * 2.0F * PI / 360.0F), 0.0F, 0.0F); if (lighting) { lighting_func(); @@ -648,7 +648,7 @@ void display() { for (const auto &piece : captured_groups) { jump_off(piece[0], piece[1], piece[2]); } - animation_time += (time_increment * captured_groups.size()); + animation_time += (TIME_INCREMENT * captured_groups.size()); } if (animation_time > 1) { animation_time = 0; @@ -787,7 +787,7 @@ void jump_off(int x0, int z0, int color) { // Draw Thigh glPushMatrix(); if (animation_time < 0.1) { - glRotatef(-80 + 80 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); + glRotatef(-80 + 80 * std::sin(animation_time * 10.0F * PI), 1.0, 0.0, 1.0); } else { glRotatef(-80, 1.0, 0.0, 1.0); } @@ -801,7 +801,7 @@ void jump_off(int x0, int z0, int color) { glTranslatef(0, -0.8, 0); if (animation_time < 0.1) { - glRotatef(90 - 90 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); + glRotatef(90 - 90 * std::sin(animation_time * 10.0F * PI), 1.0, 0.0, 1.0); } else { glRotatef(90, 1.0, 0.0, 1.0); } @@ -814,7 +814,7 @@ void jump_off(int x0, int z0, int color) { glPushMatrix(); glTranslatef(0, -1.0, 0); if (animation_time < 0.1) { - glRotatef(-100 + 100 * std::sin(animation_time * 10.0F * pi), 1.0, 0.0, 1.0); + glRotatef(-100 + 100 * std::sin(animation_time * 10.0F * PI), 1.0, 0.0, 1.0); } else { glRotatef(-100, 1.0, 0.0, 1.0); } From adbcd3e3ceb5339370066a0885a985868b97619b Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 16:53:45 -0500 Subject: [PATCH 7/8] chore: adds modernize-avoid-c-arrays --- .clang-tidy | 18 +++++++++-- main.cpp | 92 ++++++++++++++++++++++++++--------------------------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e3489f5..cb12c75 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ # clang-diagnostic-* : surface compiler-style warnings (unused variables, conversions, etc.) # clang-diagnostic-unused-const-variable : warn on unused 'const' variables # google-build-using-namespace : reject global using-namespace directives +# misc-include-cleaner : ensure proper #includes are present and unused ones are removed # modernize-deprecated-headers : prefer C++ standard headers over legacy C ones # modernize-loop-convert : prefer range-based for loops over traditional loops # modernize-use-stdarray : prefer 'std::array' over C-style arrays @@ -12,8 +13,8 @@ Checks: > clang-analyzer-*, clang-diagnostic-*, - clang-diagnostic-unused-const-variable, google-build-using-namespace, + modernize-avoid-c-arrays, modernize-deprecated-headers, modernize-loop-convert, modernize-use-stdarray, @@ -68,4 +69,17 @@ CheckOptions: - key: readability-identifier-naming.StaticConstantCase value: UPPER_CASE - key: readability-identifier-naming.ConstexprVariableCase - value: UPPER_CASE \ No newline at end of file + value: UPPER_CASE + + + # ===== Modernize tuning ===== + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-use-override.UseOverride + value: '1' + - key: modernize-avoid-c-arrays.CheckCStrings + value: '1' + + # ===== Include cleaner ===== + - key: misc-include-cleaner.StrictMode + value: '0' diff --git a/main.cpp b/main.cpp index 1261276..6d2c3c8 100644 --- a/main.cpp +++ b/main.cpp @@ -17,8 +17,8 @@ #include #include -ILuint image_ids[3] = {0, 1, 2}; -GLuint textures[3] = {0, 1, 2}; +std::array image_ids{0, 1, 2}; +std::array textures{0, 1, 2}; #define GL_CLAMP_TO_EDGE 0x812F @@ -130,8 +130,8 @@ int main(int argc, char **argv) { ilutInit(); ilutRenderer(ILUT_OPENGL); - ilGenImages(2, image_ids); - glGenTextures(2, textures); + ilGenImages(2, image_ids.data()); + glGenTextures(2, textures.data()); // initialize OpenGL init(); @@ -394,19 +394,19 @@ void idle() { void lighting_func() { // Specify light position - GLfloat lightposition[4] = {0.0, 0.0, -0.5, 1.0}; - glLightfv(GL_LIGHT0, GL_POSITION, lightposition); + const std::array light_position{0.0F, 0.0F, -0.5F, 1.0F}; + glLightfv(GL_LIGHT0, GL_POSITION, light_position.data()); // Specify diffuse component. Diffuse component is white. // GLfloat lightdiffuse[4] = {0.0, 0.0, 0.0, 1.0}; - GLfloat lightstrength[4] = {2.0, 2.0, 2.0, 2.0}; - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightstrength); + const std::array light_strength{2.0F, 2.0F, 2.0F, 2.0F}; + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_strength.data()); // Specify specular component. Specular component is green. // TODO: Decide on desired specular component -- IF NEEDED // GLfloat lightspecular[4] = {0.0, 0.0, 0.0, 1.0}; // GLfloat lightspecular[4] = { 0.0, 2.0, 0.0, 1.0 }; - glLightfv(GL_LIGHT0, GL_SPECULAR, lightstrength); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_strength.data()); GLfloat spread = 90 - 90 * animation_time; glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, &spread); @@ -417,55 +417,55 @@ void lighting_func() { void material_func() { // Add a diffuse component to our board. The diffuse reflection constant // is white (white light source produces white reflection). - GLfloat materialdiffuse[4] = {0.5, 0.5, 1.0, 1.0}; - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materialdiffuse); + const std::array material_diffuse{0.5F, 0.5F, 1.0F, 1.0F}; + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse.data()); // Add a specular component to our board. The specular reflection constant // is white (white light source produces white reflection). - GLfloat materialspecular[4] = {1.0, 1.0, 1.0, 1.0}; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialspecular); + const std::array material_specular{1.0F, 1.0F, 1.0F, 1.0F}; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular.data()); // Defines the shinyness (the exponent to the phong model). - GLfloat materialshininess[1] = {100.0}; - glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, materialshininess); + const std::array material_shininess{100.0F}; + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, material_shininess.data()); } void draw_sphere(int color) { - const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; + const std::array color_none{0.0F, 0.0F, 0.0F, 0.0F}; if (color == 0) { - const GLfloat color_red[4] = {1.0F, 0.0F, 0.0F, 0.0F}; - glColor4fv(color_red); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_red); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_red{1.0F, 0.0F, 0.0F, 0.0F}; + glColor4fv(color_red.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_red.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } if (color == 1) { - const GLfloat color_white[4] = {1.0F, 1.0F, 1.0F, 1.0F}; - glColor4fv(color_white); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_white); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_white{1.0F, 1.0F, 1.0F, 1.0F}; + glColor4fv(color_white.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_white.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } if (color == 2) { - const GLfloat color_black[4] = {0.0F, 0.0F, 0.0F, 0.0F}; - glColor4fv(color_black); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_black); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_black{0.0F, 0.0F, 0.0F, 0.0F}; + glColor4fv(color_black.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_black.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } if (color == 3) { - const GLfloat color_green[4] = {0.0F, 0.0F, 1.0F, 0.0F}; - glColor4fv(color_green); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_green{0.0F, 0.0F, 1.0F, 0.0F}; + glColor4fv(color_green.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } if (color == 4) { - const GLfloat color_blue[4] = {0.0F, 1.0F, 0.0F, 0.0F}; - glColor4fv(color_blue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_blue{0.0F, 1.0F, 0.0F, 0.0F}; + glColor4fv(color_blue.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } glBegin(GL_TRIANGLES); @@ -482,17 +482,17 @@ void draw_unit_cube(int color) { if (color == 0) { glBindTexture(GL_TEXTURE_2D, textures[0]); } else if (color == 3) { - const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; - const GLfloat color_green[4] = {0.0F, 0.0F, 1.0F, 0.0F}; - glColor4fv(color_green); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_none{0.0F, 0.0F, 0.0F, 0.0F}; + const std::array color_green{0.0F, 0.0F, 1.0F, 0.0F}; + glColor4fv(color_green.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_green.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } else if (color == 4) { - const GLfloat color_none[4] = {0.0F, 0.0F, 0.0F, 0.0F}; - const GLfloat color_blue[4] = {0.0F, 1.0F, 0.0F, 0.0F}; - glColor4fv(color_blue); - glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue); - glMaterialfv(GL_FRONT, GL_SPECULAR, color_none); + const std::array color_none{0.0F, 0.0F, 0.0F, 0.0F}; + const std::array color_blue{0.0F, 1.0F, 0.0F, 0.0F}; + glColor4fv(color_blue.data()); + glMaterialfv(GL_FRONT, GL_DIFFUSE, color_blue.data()); + glMaterialfv(GL_FRONT, GL_SPECULAR, color_none.data()); } glBegin(GL_QUADS); From c6e0abab45bcbae14df54939c6d217e83e65b79b Mon Sep 17 00:00:00 2001 From: Robert Lech Date: Mon, 10 Nov 2025 17:05:15 -0500 Subject: [PATCH 8/8] chore: additional cleanup --- .clang-tidy | 17 +++++------------ main.cpp | 37 +++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index cb12c75..815041e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,23 +2,17 @@ # Keep checks at tool defaults while treating all warnings as errors. # clang-analyzer-* : enable static analysis passes for deeper bug finding # clang-diagnostic-* : surface compiler-style warnings (unused variables, conversions, etc.) -# clang-diagnostic-unused-const-variable : warn on unused 'const' variables # google-build-using-namespace : reject global using-namespace directives # misc-include-cleaner : ensure proper #includes are present and unused ones are removed -# modernize-deprecated-headers : prefer C++ standard headers over legacy C ones -# modernize-loop-convert : prefer range-based for loops over traditional loops -# modernize-use-stdarray : prefer 'std::array' over C-style arrays -# modernize-use-using : prefer 'using' type alias declarations over 'typedef's -# readability-magic-numbers : discourage use of magic numbers in code +# modernize-* : enforce modern C++ idioms (e.g., avoid C arrays, prefer std::numbers) +# performance-* : flag common performance pitfalls +# readability-identifier-naming : enforce consistent identifier style Checks: > clang-analyzer-*, clang-diagnostic-*, google-build-using-namespace, - modernize-avoid-c-arrays, - modernize-deprecated-headers, - modernize-loop-convert, - modernize-use-stdarray, - modernize-use-using, + misc-include-cleaner, + modernize-*, performance-*, readability-identifier-naming @@ -71,7 +65,6 @@ CheckOptions: - key: readability-identifier-naming.ConstexprVariableCase value: UPPER_CASE - # ===== Modernize tuning ===== - key: modernize-loop-convert.MinConfidence value: reasonable diff --git a/main.cpp b/main.cpp index 6d2c3c8..95714da 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,11 @@ #include #include // For std::cout #include +#if defined(__has_include) +#if __has_include() +#include +#endif +#endif #include #include // For usleep #include @@ -20,7 +25,7 @@ std::array image_ids{0, 1, 2}; std::array textures{0, 1, 2}; -#define GL_CLAMP_TO_EDGE 0x812F +constexpr GLenum GL_CLAMP_TO_EDGE_VALUE = 0x812F; // Window settings int window_id; // Glut window ID (for display) @@ -43,7 +48,11 @@ constexpr int BOARD_CENTER = BOARD_SIZE / 2; constexpr GLdouble INITIAL_CAM_X = 0.0; constexpr GLdouble INITIAL_CAM_Y = 0.0; constexpr GLdouble INITIAL_CAM_Z = -1.5; -constexpr float PI = 3.14159265358979323846F; // Pi constant for trigonometric helpers +#if defined(__cpp_lib_math_constants) +constexpr float PI = std::numbers::pi_v; // Pi constant for trigonometric helpers +#else +constexpr float PI = 3.14159265358979323846F; // NOLINT(modernize-use-std-numbers) +#endif struct Camera { GLdouble x; @@ -68,7 +77,7 @@ float angle_x = INITIAL_BOARD_ANGLE_X; float angle_y = INITIAL_BOARD_ANGLE_Y; float translate_light = 0; -Camera camera{INITIAL_CAM_X, INITIAL_CAM_Y, INITIAL_CAM_Z}; +Camera camera{.x = INITIAL_CAM_X, .y = INITIAL_CAM_Y, .z = INITIAL_CAM_Z}; // Behind the Scenes variables int place_x = 0; @@ -102,13 +111,13 @@ void apply_transformation_general(float indx, float indy, float z); // Behind the Scenes void init_board(); void clear_liberties(); -int make_move(int x, int y, int piece); -int check_liberties(int x, int y, int originx, int originy, int piece); +auto make_move(int x, int y, int piece) -> int; +auto check_liberties(int x, int y, int originx, int originy, int piece) -> int; void remove_block(int x, int y, int piece); void jump_off(int x0, int y0, int color); //! Program entry point -int main(int argc, char **argv) { +auto main(int argc, char **argv) -> int { const int default_window_width = 768; const int default_window_height = 768; const int default_window_x = 256; @@ -705,8 +714,10 @@ void set_images() { glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, + static_cast(GL_CLAMP_TO_EDGE_VALUE)); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, + static_cast(GL_CLAMP_TO_EDGE_VALUE)); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_SHORT, ilGetData()); @@ -719,8 +730,10 @@ void set_images() { glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, + static_cast(GL_CLAMP_TO_EDGE_VALUE)); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, + static_cast(GL_CLAMP_TO_EDGE_VALUE)); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGB, GL_UNSIGNED_SHORT, ilGetData()); @@ -744,7 +757,7 @@ void clear_liberties() { } } -int check_liberties(int x, int y, int originx, int originy, int piece) { +auto check_liberties(int x, int y, int originx, int originy, int piece) -> int { if (x < 0 || x > 18 || y < 0 || y > 18) { return 0; } @@ -852,7 +865,7 @@ void remove_block(int x, int y, int piece) { } } -int make_move(int x, int y, int piece) { +auto make_move(int x, int y, int piece) -> int { board_status[x][y] = piece; clear_liberties(); int other;