diff --git a/CMakeLists.txt b/CMakeLists.txt index 38058e9..6f83bfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,4 @@ add_executable(${ProjectName} ${SRC_FILES}) target_include_directories(${ProjectName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED) -target_link_libraries(${ProjectName} sfml-graphics sfml-audio) - -# Generates compile_commands.json in build folder, which clangd will pick up -# Without this, clangd might assume the wrong C++ version -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) \ No newline at end of file +target_link_libraries(${ProjectName} sfml-graphics sfml-audio) \ No newline at end of file diff --git a/build/.gitignore b/build/.gitignore index bf0629d..26a7d55 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -2,4 +2,8 @@ CMakeFiles cmake_install.cmake CMakeCache.txt compile_commands.json -Makefile \ No newline at end of file +Makefile +septadrop +septadrop_1.0_amd64/usr/bin/septadrop +septadrop_1.0_amd64.deb +.cmake \ No newline at end of file diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..deaef61 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,6 @@ +# DCMAKE_EXPORT_COMPILE_COMMANDS=ON generates compile_commands.json in build folder, +# which clangd will pick up +# Without this, clangd might assume the wrong C++ version +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. +python3 packer.py +cmake --build . \ No newline at end of file diff --git a/build/linux/debian.sh b/build/debian.sh similarity index 100% rename from build/linux/debian.sh rename to build/debian.sh diff --git a/build/linux/.gitignore b/build/linux/.gitignore deleted file mode 100644 index 00ca04a..0000000 --- a/build/linux/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -septadrop -septadrop_1.0_amd64/usr/bin/septadrop -septadrop_1.0_amd64.deb \ No newline at end of file diff --git a/build/linux/build.sh b/build/linux/build.sh deleted file mode 100755 index b7fdccf..0000000 --- a/build/linux/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -cmake ../.. -cd .. -python3 packer.py -cd linux -cmake --build . \ No newline at end of file diff --git a/build/linux/run.sh b/build/run.sh similarity index 100% rename from build/linux/run.sh rename to build/run.sh diff --git a/build/linux/septadrop_1.0_amd64/DEBIAN/control b/build/septadrop_1.0_amd64/DEBIAN/control similarity index 100% rename from build/linux/septadrop_1.0_amd64/DEBIAN/control rename to build/septadrop_1.0_amd64/DEBIAN/control diff --git a/build/linux/septadrop_1.0_amd64/usr/share/applications/septadrop.desktop b/build/septadrop_1.0_amd64/usr/share/applications/septadrop.desktop similarity index 100% rename from build/linux/septadrop_1.0_amd64/usr/share/applications/septadrop.desktop rename to build/septadrop_1.0_amd64/usr/share/applications/septadrop.desktop diff --git a/build/linux/septadrop_1.0_amd64/usr/share/icons/septadrop-icon.xpm b/build/septadrop_1.0_amd64/usr/share/icons/septadrop-icon.xpm similarity index 100% rename from build/linux/septadrop_1.0_amd64/usr/share/icons/septadrop-icon.xpm rename to build/septadrop_1.0_amd64/usr/share/icons/septadrop-icon.xpm diff --git a/build/windows/.gitignore b/build/windows/.gitignore deleted file mode 100644 index 9637d08..0000000 --- a/build/windows/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -SFML-2.5.1 -septadrop.exe \ No newline at end of file diff --git a/build/windows/build.sh b/build/windows/build.sh deleted file mode 100755 index 3274433..0000000 --- a/build/windows/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -if [[ ! -e SFML-2.5.1 ]]; then - DOWNLOAD=TARGET=SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit - wget https://www.sfml-dev.org/files/${DOWNLOAD}.zip - unzip ${DOWNLOAD}.zip - rm ${DOWNLOAD}.zip -fi -cmake SFML-2.5.1/ -DCMAKE_TOOLCHAIN_FILE=mingw-w64-x86_64.cmake ../.. -cd .. -python3 packer.py -cd windows -cmake --build . diff --git a/build/windows/mingw-w64-x86_64.cmake b/build/windows/mingw-w64-x86_64.cmake deleted file mode 100644 index b4ee2e9..0000000 --- a/build/windows/mingw-w64-x86_64.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# Sample toolchain file for building for Windows from an Ubuntu Linux system. -# -# Typical usage: -# *) install cross compiler: `sudo apt-get install mingw-w64` -# *) cd build -# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake .. - -set(CMAKE_SYSTEM_NAME Windows) -set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) - -# cross compilers to use for C, C++ and Fortran -set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) -set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) -set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) - -# target environment on the build host system -set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) - -# modify default behavior of FIND_XXX() commands -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# currently disfunctional, need to set up static linking(?) and not use DLLs -# also set SFML_PATH relative to project directory -set(SFML_PATH "/home/elnu/Projects/septadrop/build/windows/SFML-2.5.1") -set(SFML_INCLUDE_DIR "${SFML_PATH}/include") -include_directories(${SFML_PATH}/include) -set(SFML_LIBRARY_DIR "${SFML_PATH}/lib") -link_directories(${SFML_PATH}/lib) -set(SFML_DIR "${SFML_PATH}/lib/cmake/SFML") - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED 20) diff --git a/include/Block.hpp b/include/Block.hpp index 1ba2a83..d6cb2b8 100644 --- a/include/Block.hpp +++ b/include/Block.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "BlockType.hpp" class Block { public: diff --git a/include/BlockType.hpp b/include/BlockType.hpp index 31495d3..534cfc0 100644 --- a/include/BlockType.hpp +++ b/include/BlockType.hpp @@ -7,7 +7,7 @@ class BlockType { public: TileType* tile_type; std::vector> grid; - unsigned int width, height, starting_line; + uint width, height, starting_line; bool rotate; BlockType(TileType* _tile_type, const std::vector> _grid, bool _rotate = true); diff --git a/include/NumberRenderer.hpp b/include/NumberRenderer.hpp index 68118ca..7ea4953 100644 --- a/include/NumberRenderer.hpp +++ b/include/NumberRenderer.hpp @@ -12,7 +12,7 @@ class NumberRenderer { sf::IntRect _comma_rect, std::initializer_list _numeral_rects ); - void render(sf::RenderWindow* window, unsigned int number, int x, int y); + void render(sf::RenderWindow* window, uint number, int x, int y); private: sf::Sprite sprite; }; \ No newline at end of file diff --git a/src/BlockType.cpp b/src/BlockType.cpp index 73ef429..b5ea17a 100644 --- a/src/BlockType.cpp +++ b/src/BlockType.cpp @@ -7,9 +7,9 @@ BlockType::BlockType(TileType* _tile_type, const std::vector> // Used for alignment in "next block" area width = 0; starting_line = 0; - for (unsigned int y = 0; y < grid.size(); y++) { + for (uint y = 0; y < grid.size(); y++) { bool has_content = false; - for (unsigned int x = 0; x < grid[y].size(); x++) { + for (uint x = 0; x < grid[y].size(); x++) { if (grid[y][x]) { width = std::max({width, x + 1}); has_content = true; diff --git a/src/Main.cpp b/src/Main.cpp index 5d3721a..ce78189 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -28,11 +28,11 @@ #include #include -unsigned int get_level(int lines) { +uint get_level(int lines) { return std::min(lines / LINES_PER_LEVEL, 15); } -unsigned int get_update_interval(int level) { +uint get_update_interval(int level) { // From Tetris Worlds, see https://harddrop.com/wiki/Tetris_Worlds#Gravity return pow(0.8 - (level - 1) * 0.007, level - 1) * 1000; } @@ -97,7 +97,7 @@ int main() bool paused = false; bool paused_from_lost_focus = false; sf::Clock update_clock, move_clock, pause_clock; - unsigned int pause_offset = 0; + uint pause_offset = 0; sf::RectangleShape paused_clear; paused_clear.setFillColor(sf::Color(81, 62, 69)); @@ -133,19 +133,19 @@ int main() std::fstream highscore_file(highscore_file_path); std::string highscore_string; highscore_file >> highscore_string; - unsigned int highscore = std::stoi(highscore_string); - unsigned int point_gcd = gcd(POINTS_1_LINE, gcd(POINTS_2_LINES, gcd(POINTS_3_LINES, POINTS_4_LINES))); + uint highscore = std::stoi(highscore_string); + uint point_gcd = gcd(POINTS_1_LINE, gcd(POINTS_2_LINES, gcd(POINTS_3_LINES, POINTS_4_LINES))); if (highscore % point_gcd != 0) { std::cout << "It seems your system is misconfigured. Please see this guide for fixing the issue: https://www.youtube.com/watch?v=dQw4w9WgXcQ" << std::endl; return 0; } - unsigned int score = 0; - unsigned int lines = 0; - unsigned int blocks = 0; - unsigned int tiles = 0; + uint score = 0; + uint lines = 0; + uint blocks = 0; + uint tiles = 0; - unsigned int update_interval = get_update_interval(0); + uint update_interval = get_update_interval(0); // https://sfxr.me/#57uBnWWZeyDTsBRrJsAp2Vwd76cMVrdeRQ7DirNQW5XekKxcrCUNx47Zggh7Uqw4R5FdeUpyk362uhjWmpNHmqxE7JBp3EkxDxfJ1VjzMRpuSHieW6B5iyVFM sf::SoundBuffer rotate_buffer; @@ -273,7 +273,7 @@ int main() continue; } - bool is_update_frame = update_clock.getElapsedTime().asMilliseconds() - pause_offset > (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) ? std::min({update_interval, (unsigned int)MAX_FAST_FORWARD_INTERVAL}) : update_interval); + bool is_update_frame = update_clock.getElapsedTime().asMilliseconds() - pause_offset > (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) ? std::min({update_interval, (uint)MAX_FAST_FORWARD_INTERVAL}) : update_interval); if (is_update_frame) { update_clock.restart(); } @@ -370,8 +370,8 @@ int main() auto next_block_tiles = next_block.get_tiles(); // This is assuming the next block spawns unrotated. // Refactoring is needed if random rotations are added - unsigned int x_offset = next_block.type->width * TILE_SIZE / 2; - unsigned int y_offset = (next_block.type->height + next_block.type->starting_line * 2) * TILE_SIZE / 2; + uint x_offset = next_block.type->width * TILE_SIZE / 2; + uint y_offset = (next_block.type->height + next_block.type->starting_line * 2) * TILE_SIZE / 2; for (auto tile : next_block_tiles) { sprite.setTextureRect(next_block.type->tile_type->texture_rect); sprite.setPosition( @@ -400,7 +400,7 @@ int main() for (auto tile : block.get_tiles()) { grid[tile.y][tile.x] = block.type->tile_type; } - unsigned int cleared_lines = 0; + uint cleared_lines = 0; // Check for completed rows for (int y = 0; y < GRID_HEIGHT; y++) { bool completed = true; @@ -420,7 +420,7 @@ int main() } cleared_lines++; } - unsigned int scored; + uint scored; switch (cleared_lines) { case 0: scored = 0; diff --git a/src/NumberRenderer.cpp b/src/NumberRenderer.cpp index 55b1c3e..cdcc768 100644 --- a/src/NumberRenderer.cpp +++ b/src/NumberRenderer.cpp @@ -18,13 +18,13 @@ NumberRenderer::NumberRenderer( } } -void NumberRenderer::render(sf::RenderWindow* window, unsigned int number, int x, int y) { +void NumberRenderer::render(sf::RenderWindow* window, uint number, int x, int y) { auto number_string = std::to_string(number); std::string numeral_string; numeral_string.push_back(number_string.back()); auto numeral_rect = numeral_rects[std::stoi(numeral_string)]; int x_offset = -numeral_rect.width; - unsigned int digits = number_string.length(); + uint digits = number_string.length(); for (int i = digits - 1; i >= 0; i--) { char numeral_string[] = {number_string[i]}; auto numeral_rect = numeral_rects[std::stoi(numeral_string)];