From 6550aef05dafd70cab6f512d1750271c9ad85e23 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 28 May 2021 12:59:37 -0400 Subject: [PATCH] Update C++ style linting --- examples/core/core_3d_camera_first_person.cpp | 15 ++++++------- examples/core/core_basic_window.cpp | 2 +- examples/core/core_drop_files.cpp | 4 +--- examples/core/core_loading_thread.cpp | 3 ++- examples/core/core_random_values.cpp | 3 +-- examples/core/core_world_screen.cpp | 15 ++++++++----- examples/models/models_billboard.cpp | 4 +--- examples/multiple/Player.cpp | 3 +-- examples/multiple/main.cpp | 4 +--- examples/shapes/shapes_logo_raylib.cpp | 2 +- examples/text/text_raylib_fonts.cpp | 2 +- examples/textures/textures_bunnymark.cpp | 8 +++---- examples/textures/textures_image_drawing.cpp | 22 +++++++++++-------- examples/textures/textures_image_loading.cpp | 2 +- include/Functions.hpp | 3 +++ include/Sound.hpp | 6 ++--- projects/CMake/main.cpp | 2 +- 17 files changed, 52 insertions(+), 48 deletions(-) diff --git a/examples/core/core_3d_camera_first_person.cpp b/examples/core/core_3d_camera_first_person.cpp index 5696e92..e7f4a09 100644 --- a/examples/core/core_3d_camera_first_person.cpp +++ b/examples/core/core_3d_camera_first_person.cpp @@ -34,16 +34,15 @@ int main() { raylib::Vector3 positions[MAX_COLUMNS] = { 0 }; raylib::Color colors[MAX_COLUMNS] = { 0 }; - for (int i = 0; i < MAX_COLUMNS; i++) - { - heights[i] = (float)GetRandomValue(1, 12); + for (int i = 0; i < MAX_COLUMNS; i++) { + heights[i] = static_cast(GetRandomValue(1, 12)); positions[i] = raylib::Vector3(GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15)); colors[i] = raylib::Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30); } - camera.SetMode(CAMERA_FIRST_PERSON); // Set a first person camera mode + camera.SetMode(CAMERA_FIRST_PERSON); // Set a first person camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop @@ -61,7 +60,7 @@ int main() { camera.BeginMode(); { - DrawPlane(Vector3{ 0.0f, 0.0f, 0.0f }, Vector2{ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground + DrawPlane(Vector3{ 0.0f, 0.0f, 0.0f }, Vector2{ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground DrawCube(Vector3{ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall DrawCube(Vector3{ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall DrawCube(Vector3{ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall @@ -74,8 +73,8 @@ int main() { } camera.EndMode(); - DrawRectangle( 10, 10, 220, 70, raylib::Color::SkyBlue().Fade(0.5f)); - DrawRectangleLines( 10, 10, 220, 70, BLUE); + DrawRectangle(10, 10, 220, 70, raylib::Color::SkyBlue().Fade(0.5f)); + DrawRectangleLines(10, 10, 220, 70, BLUE); DrawText("First person camera default controls:", 20, 20, 10, BLACK); DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); diff --git a/examples/core/core_basic_window.cpp b/examples/core/core_basic_window.cpp index 6fd81c5..68a1709 100644 --- a/examples/core/core_basic_window.cpp +++ b/examples/core/core_basic_window.cpp @@ -36,7 +36,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core/core_drop_files.cpp b/examples/core/core_drop_files.cpp index 63dc257..ab4d4ac 100644 --- a/examples/core/core_drop_files.cpp +++ b/examples/core/core_drop_files.cpp @@ -30,9 +30,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - if (IsFileDropped()) { - droppedFiles = raylib::GetDroppedFiles(); - } + droppedFiles = raylib::GetDroppedFiles(); //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core/core_loading_thread.cpp b/examples/core/core_loading_thread.cpp index eecacb8..c095f10 100644 --- a/examples/core/core_loading_thread.cpp +++ b/examples/core/core_loading_thread.cpp @@ -11,12 +11,13 @@ * *******************************************************************************/ -#include "raylib-cpp.hpp" #include // C++11 standard library threads #include // C++ atomic data types #include // For: chrono::steady_clock::now() #include // May be thrown by thread c'tor +#include "raylib-cpp.hpp" + // Using C++ std::atomic_bool (aka. std::atomic) for synchronization. // n.b. A plain built-in type can't be used for inter-thread synchronization std::atomic_bool dataLoaded{false}; diff --git a/examples/core/core_random_values.cpp b/examples/core/core_random_values.cpp index 1b7a144..c4e0677 100644 --- a/examples/core/core_random_values.cpp +++ b/examples/core/core_random_values.cpp @@ -33,8 +33,7 @@ int main() { framesCounter++; // Every two seconds (120 frames) a new random value is generated - if (((framesCounter/120)%2) == 1) - { + if (((framesCounter / 120) % 2) == 1) { randValue = GetRandomValue(-8, 5); framesCounter = 0; } diff --git a/examples/core/core_world_screen.cpp b/examples/core/core_world_screen.cpp index 83ac092..62b2a97 100644 --- a/examples/core/core_world_screen.cpp +++ b/examples/core/core_world_screen.cpp @@ -30,16 +30,16 @@ int main() { Vector3 cubePosition; Vector2 cubeScreenPosition; - camera.SetMode(CAMERA_FREE); // Set a free camera mode + camera.SetMode(CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!window.ShouldClose()) { // Detect window close button or ESC key + while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - camera.Update(); // Update camera + camera.Update(); // Update camera // Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera); @@ -60,8 +60,13 @@ int main() { } camera.EndMode(); - DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, cubeScreenPosition.y, 20, BLACK); - DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))/2, 25, 20, GRAY); + DrawText("Enemy: 100 / 100", + cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20) / 2, + cubeScreenPosition.y, 20, + BLACK); + DrawText("Text is always on top of the cube", + (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, + 25, 20, GRAY); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/models/models_billboard.cpp b/examples/models/models_billboard.cpp index bebd21b..4ea0244 100644 --- a/examples/models/models_billboard.cpp +++ b/examples/models/models_billboard.cpp @@ -25,8 +25,7 @@ int main() { raylib::Vector3(0.0f, 2.0f, 0.0f), raylib::Vector3(0.0f, 1.0f, 0.0f), 45.0f, - CAMERA_PERSPECTIVE - ); + CAMERA_PERSPECTIVE); raylib::Texture2D bill("resources/billboard.png"); // Our texture billboard raylib::Vector3 billPosition(0.0f, 2.0f, 0.0f); // Position where draw billboard @@ -47,7 +46,6 @@ int main() { //---------------------------------------------------------------------------------- BeginDrawing(); { - window.ClearBackground(RAYWHITE); camera.BeginMode(); diff --git a/examples/multiple/Player.cpp b/examples/multiple/Player.cpp index 4ae9b45..f923d3a 100644 --- a/examples/multiple/Player.cpp +++ b/examples/multiple/Player.cpp @@ -1,7 +1,6 @@ +#include "Player.hpp" #include "raylib-cpp.hpp" -#include "./Player.hpp" - Player::Player() { position = Rectangle{ GetScreenWidth() / 2.0f - 50, diff --git a/examples/multiple/main.cpp b/examples/multiple/main.cpp index a1a06e0..863f327 100644 --- a/examples/multiple/main.cpp +++ b/examples/multiple/main.cpp @@ -1,7 +1,6 @@ +#include "Player.hpp" #include "raylib-cpp.hpp" -#include "./Player.hpp" - int main() { raylib::Window window(640, 480); SetTargetFPS(60); @@ -16,5 +15,4 @@ int main() { } window.EndDrawing(); } - } diff --git a/examples/shapes/shapes_logo_raylib.cpp b/examples/shapes/shapes_logo_raylib.cpp index 134f228..82bd59a 100644 --- a/examples/shapes/shapes_logo_raylib.cpp +++ b/examples/shapes/shapes_logo_raylib.cpp @@ -28,7 +28,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw diff --git a/examples/text/text_raylib_fonts.cpp b/examples/text/text_raylib_fonts.cpp index bf0e066..be354aa 100644 --- a/examples/text/text_raylib_fonts.cpp +++ b/examples/text/text_raylib_fonts.cpp @@ -74,7 +74,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw diff --git a/examples/textures/textures_bunnymark.cpp b/examples/textures/textures_bunnymark.cpp index 05fbf25..ae3264a 100644 --- a/examples/textures/textures_bunnymark.cpp +++ b/examples/textures/textures_bunnymark.cpp @@ -20,15 +20,15 @@ #include class Bunny { -public: + public: Bunny() { position = GetMousePosition(); - speed.x = (float)GetRandomValue(-250, 250)/60.0f; - speed.y = (float)GetRandomValue(-250, 250)/60.0f; + speed.x = static_cast(GetRandomValue(-250, 250)) / 60.0f; + speed.y = static_cast(GetRandomValue(-250, 250)) / 60.0f; color = raylib::Color( GetRandomValue(50, 240), GetRandomValue(80, 240), - GetRandomValue(100, 240), 255); + GetRandomValue(100, 240)); } void Update(const raylib::Texture2D& texBunny) { diff --git a/examples/textures/textures_image_drawing.cpp b/examples/textures/textures_image_drawing.cpp index 4e2496f..70fcc82 100644 --- a/examples/textures/textures_image_drawing.cpp +++ b/examples/textures/textures_image_drawing.cpp @@ -13,8 +13,7 @@ #include "raylib-cpp.hpp" -int main(void) -{ +int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; @@ -34,9 +33,9 @@ int main(void) // Draw one image over the other with a scaling of 1.5f parrots .Draw(cat, - raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()), + raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()), raylib::Rectangle(30, 40, cat.GetWidth() * 1.5f, cat.GetHeight() * 1.5f)) - .Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image + .Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image // Load custom font for frawing on image raylib::Font font("resources/custom_jupiter_crash.png"); @@ -53,7 +52,7 @@ int main(void) while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw @@ -62,11 +61,16 @@ int main(void) { window.ClearBackground(RAYWHITE); - texture.Draw(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40); - darkGray.DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height); + texture.Draw(screenWidth / 2 - texture.width / 2, + screenHeight / 2 - texture.height / 2 - 40); + darkGray.DrawRectangleLines(screenWidth / 2 - texture.width / 2, + screenHeight / 2 - texture.height / 2 - 40, + texture.width, texture.height); - darkGray.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10); - darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10); + darkGray.DrawText("We are drawing only one texture from various images composed!", + 240, 350, 10); + darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", + 190, 370, 10); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/textures/textures_image_loading.cpp b/examples/textures/textures_image_loading.cpp index 5ab7e21..68b019e 100644 --- a/examples/textures/textures_image_loading.cpp +++ b/examples/textures/textures_image_loading.cpp @@ -27,7 +27,7 @@ int main() { while (!window.ShouldClose()) { // Detect window close button or ESC key // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw diff --git a/include/Functions.hpp b/include/Functions.hpp index d1dab21..b48dce9 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -162,6 +162,9 @@ RLCPPAPI inline bool ChangeDirectory(const std::string& dir) { * Get dropped files names */ RLCPPAPI std::vector GetDroppedFiles() { + if (!::IsFileDropped()) { + return std::vector(); + } int count; char** files = ::GetDroppedFiles(&count); std::vector output(files, files + count); diff --git a/include/Sound.hpp b/include/Sound.hpp index 29b9184..cbc19da 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -44,8 +44,8 @@ class Sound : public ::Sound { /** * Update sound buffer with new data */ - inline Sound& Update(const void *data, int sampleCount) { - ::UpdateSound(*this, data, sampleCount); + inline Sound& Update(const void *data, int samplesCount) { + ::UpdateSound(*this, data, samplesCount); return *this; } @@ -53,7 +53,7 @@ class Sound : public ::Sound { * Update sound buffer with new data, assuming it's the same sample count. */ inline Sound& Update(const void *data) { - ::UpdateSound(*this, data, sampleCount); + ::UpdateSound(*this, data, static_cast(sampleCount)); return *this; } diff --git a/projects/CMake/main.cpp b/projects/CMake/main.cpp index 257de99..0392760 100644 --- a/projects/CMake/main.cpp +++ b/projects/CMake/main.cpp @@ -37,7 +37,7 @@ int main() { { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + // Update your variables here //---------------------------------------------------------------------------------- // Draw