diff --git a/README-zh_CN.md b/README-zh_CN.md index 5d9e5f2cb4..4ddbd83886 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -141,7 +141,7 @@ make build ARCH=x86-64-modern 如果您已经开始使用 Ubuntu 或任何基于 Ubuntu 的 Linux 发行版,则必须通过以 root 身份运行以下命令来安装 Qt: ```shell -sudo apt-get install qt5-default qtmultimedia5-dev qtcreator +sudo apt-get install qt6-base-dev qt6-multimedia-dev qtcreator ``` 使用 Qt Creator 打开 `src/ui/qt/CMakeLists.txt` ,或者运行: diff --git a/README.md b/README.md index b2741b2166..bba5e52710 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ When reporting an issue or a bug, please tell us which version and compiler you If you have started using Ubuntu or any Ubuntu-based Linux distribution, you must install Qt by running the following command as root: ```shell -sudo apt-get install qt5-default qtmultimedia5-dev qtcreator +sudo apt-get install qt6-base-dev qt6-multimedia-dev qtcreator ``` Use Qt Creator to open `src/ui/qt/CMakeLists.txt` , or run diff --git a/src/bitboard.h b/src/bitboard.h index aa50c6d95c..8ddc44a1ec 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -143,20 +143,28 @@ constexpr Bitboard file_bb(Square s) /// popcount() counts the number of non-zero bits in a bitboard -inline int popcount(Bitboard b) noexcept +inline int generic_popcount(Bitboard b) noexcept { -#ifdef DO_NOT_USE_POPCNT - union { Bitboard bb; uint16_t u[2]; } v = {b}; - return PopCnt16[v.u[0]] + PopCnt16[v.u[1]]; +} + +inline int popcount(Bitboard b) noexcept +{ +#ifdef DO_NOT_USE_POPCNT + + return generic_popcount(b); #elif defined(_MSC_VER) || defined(__INTEL_COMPILER) +#if defined(_M_X64) || defined(_M_IX86) return _mm_popcnt_u32(b); +#else + return generic_popcount(b); +#endif #else // Assumed gcc or compatible compiler diff --git a/src/misc.cpp b/src/misc.cpp index c5503983a6..eaa9d8b17b 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -361,10 +361,13 @@ void prefetch(void *addr) __asm__(""); #endif -#if defined(__INTEL_COMPILER) || defined(_MSC_VER) +#if defined(__INTEL_COMPILER) || \ + (defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64)) _mm_prefetch(static_cast(addr), _MM_HINT_T0); -#else +#elif defined(__GNUC__) || defined(__clang__) __builtin_prefetch(addr); +#else + (void)addr; #endif } diff --git a/src/perfect/perfect_platform.h b/src/perfect/perfect_platform.h index f80efaf7c1..ebb09c292a 100644 --- a/src/perfect/perfect_platform.h +++ b/src/perfect/perfect_platform.h @@ -37,7 +37,22 @@ #define STRCPY(destination, destination_size, source) \ strcpy_s(destination, destination_size, source) + +#if defined(_M_ARM) || defined(_M_ARM64) +// TODO: See generic_popcount() +inline int popcnt_software(uint32_t x) noexcept +{ + int count = 0; + while (x) { + count += x & 1; + x >>= 1; + } + return count; +} +#define POPCNT(x) popcnt_software(x) +#else #define POPCNT(x) __popcnt(x) +#endif #else // _WIN32 diff --git a/src/types.h b/src/types.h index de8e03587b..7c92856c08 100644 --- a/src/types.h +++ b/src/types.h @@ -74,11 +74,15 @@ #define IS_64BIT #endif -#if defined(USE_POPCNT) && (defined(__INTEL_COMPILER) || defined(_MSC_VER)) +#if defined(USE_POPCNT) && \ + (defined(__INTEL_COMPILER) || \ + (defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64))) #include // Intel and Microsoft header for _mm_popcnt_u64() #endif -#if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER)) +#if !defined(NO_PREFETCH) && \ + (defined(__INTEL_COMPILER) || \ + (defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64))) #include // Intel and Microsoft header for _mm_prefetch() #endif diff --git a/src/ui/qt/.gitignore b/src/ui/qt/.gitignore index fa97a8d4e9..ed538f9c09 100644 --- a/src/ui/qt/.gitignore +++ b/src/ui/qt/.gitignore @@ -8,7 +8,8 @@ **/install_manifest.txt JSON/ -# Ignore all files generated by Qt Creator +# Ignore all files generated by Qt +.qt .cache *.prev qtcsettings.cmake diff --git a/src/ui/qt/CMakeLists.txt b/src/ui/qt/CMakeLists.txt index 7bef90c1bb..2bc80548d6 100644 --- a/src/ui/qt/CMakeLists.txt +++ b/src/ui/qt/CMakeLists.txt @@ -1,15 +1,19 @@ cmake_minimum_required(VERSION 3.10) project(mill-pro) +# Set C++ standard set(CMAKE_CXX_STANDARD 17) -find_package(Qt5 REQUIRED COMPONENTS Core Gui Multimedia Widgets) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Multimedia Widgets) +# Include directories include_directories(${CMAKE_SOURCE_DIR} ../../../include ../.. ../../test) include_directories(../../perfect) -qt5_add_resources(RESOURCES_RCC ${RESOURCES}) +# Add resource files +qt_add_resources(RESOURCES_RCC ${RESOURCES}) +# Source grouping file(GLOB SOURCES_CORE ../../*.cpp ../../*.h ../../../include/*.h) source_group("Source Files\\Core" FILES ${SOURCES_CORE}) @@ -25,8 +29,12 @@ source_group("Source Files\\Perfect" FILES ${SOURCES_PERFECT}) file(GLOB FORMS *.ui) file(GLOB RESOURCE_FILES *.rc *.qrc) +# Compiler flags if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4") + if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + # Add ARM64-specific flags or settings + endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdiagnostics-color=auto -Wno-deprecated -Wno-unused-parameter") else() @@ -46,12 +54,13 @@ set(all_sources list(APPEND all_sources ${SOURCES_PERFECT}) +# Link libraries and set properties for automatic Qt handling add_executable(${PROJECT_NAME} ${all_sources}) if(MSVC) target_link_libraries(${PROJECT_NAME} shlwapi) endif() -target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Widgets) +target_link_libraries(${PROJECT_NAME} Qt6::Core Qt6::Gui Qt6::Multimedia Qt6::Widgets) set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON) diff --git a/src/ui/qt/boarditem.cpp b/src/ui/qt/boarditem.cpp index f21050ed22..41eb758aea 100644 --- a/src/ui/qt/boarditem.cpp +++ b/src/ui/qt/boarditem.cpp @@ -149,7 +149,7 @@ void BoardItem::drawBoard(QPainter *painter) { #ifndef QT_MOBILE_APP_UI QColor shadowColor(128, 42, 42); - shadowColor.setAlphaF(0.3); + shadowColor.setAlphaF(0.3f); painter->fillRect(boundingRect(), QBrush(shadowColor)); #endif /* ! QT_MOBILE_APP_UI */ @@ -260,7 +260,7 @@ void BoardItem::drawPolarCoordinates(QPainter *painter) painter->setFont(font); for (int r = 0; r < RANK_NB; r++) { - QString text('1' + r); + QString text(QChar('1' + r)); painter->drawText(points[(FILE_NB - 1) * RANK_NB + r], text); } } diff --git a/src/ui/qt/build.bat b/src/ui/qt/build.bat index 01a9f6f0b1..2edf56d9d5 100755 --- a/src/ui/qt/build.bat +++ b/src/ui/qt/build.bat @@ -1,11 +1,46 @@ +@echo off +setlocal + +:: Clean repository git clean -fdx -cmake . +:: Detect system architecture and set Qt6_DIR accordingly +if exist "%ProgramFiles%\Arm" ( + set "Qt6_DIR=C:\Qt\6.7.1\msvc2019_arm64\lib\cmake\Qt6" +) else ( + set "Qt6_DIR=C:\Qt\6.7.1\msvc2019_64\lib\cmake\Qt6" +) + +:: Detect Visual Studio version +set "vsver=" +for /f "tokens=*" %%i in ('dir "C:\Program Files\Microsoft Visual Studio\" /b /ad-h') do ( + if "%%i"=="2019" ( + set "vsver=Visual Studio 16 2019" + ) else if "%%i"=="2022" ( + set "vsver=Visual Studio 17 2022" + ) +) + +if not defined vsver ( + echo "No suitable Visual Studio version found." + exit /b 1 +) + +:: Set system architecture based on previous detection +if exist "%ProgramFiles%\Arm" ( + set "arch=ARM64" +) else ( + set "arch=X64" +) + +:: Generate project files +cmake -G "%vsver%" -A %arch% . -cmake --build . --target mill-pro -windeployqt "Debug\mill-pro.exe" +:: Build and deploy Debug version +cmake --build . --target mill-pro --config Debug +C:\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\windeployqt "Debug\mill-pro.exe" +:: Build and deploy Release version cmake --build . --target mill-pro --config Release -windeployqt "Release\mill-pro.exe" +C:\Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\windeployqt "Release\mill-pro.exe" -# cov-build --dir cov-int cmake --build . --target mill-pro diff --git a/src/ui/qt/build.sh b/src/ui/qt/build.sh index bf51523dcf..ad55fa25d2 100755 --- a/src/ui/qt/build.sh +++ b/src/ui/qt/build.sh @@ -1,14 +1,46 @@ +#!/bin/bash +set -e + +# Clean repository git clean -fdx -cmake . +# Detect Qt installation and set Qt6_DIR +Qt6_BIN=$(dirname "$(which qmake 2>/dev/null)") +Qt6_DIR="${Qt6_BIN%/bin}" + +if [[ -z "$Qt6_DIR" ]]; then + echo "Qt6 installation not found." + exit 1 +fi + +# Detect system architecture +ARCH=$(uname -m) +if [[ "$ARCH" == "arm64" || "$ARCH" == "aarch64" ]]; then + ARCH="ARM64" +else + ARCH="x86_64" +fi -cmake --build . --target mill-pro -#windeployqt "Debug/mill-pro" +# Detect compiler version +if command -v gcc > /devontinue; then + GCC_VER=$(gcc -dumpversion) + echo "GCC version $GCC_VER detected." +elif command -v clang > /dev/null; then + CLANG_VER=$(clang --version | grep version | awk '{print $3}') + echo "Clang version $CLANG_VER detected." +else + echo "No suitable compiler found." + exit 1 +fi -cmake --build . --target mill-pro --config Release -#windeployqt "Release/mill-pro" +# Generate project files for Debug +cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="$Qt6_DIR" -DCMAKE_BUILD_TYPE=Debug $EXTRA_CMAKE_FLAGS -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=Debug . -# cmake .. -G "Xcode" -DCMAKE_PREFIX_PATH=~/Qt5.12.12/5.12.12/clang_64 -DCMAKE_OSX_ARCHITECTURES=x86_64 +# Build and deploy Debug version +cmake --build . --target mill-pro --config Debug -j -# cov-build --dir cov-int cmake --build . --target mill-pro +# Generate project files for Release +cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="$Qt6_DIR" -DCMAKE_BUILD_TYPE=Release $EXTRA_CMAKE_FLAGS -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=Release . +# Build and deploy Release version +cmake --build . --target mill-pro --config Release -j diff --git a/src/ui/qt/pieceitem.cpp b/src/ui/qt/pieceitem.cpp index e28bc69f2c..9e54d5a2ed 100644 --- a/src/ui/qt/pieceitem.cpp +++ b/src/ui/qt/pieceitem.cpp @@ -52,7 +52,7 @@ PieceItem::PieceItem(QGraphicsItem *parent) #endif /* QT_MOBILE_APP_UI */ removeLineColor = QColor(227, 23, 13); - removeLineColor.setAlphaF(0.9); + removeLineColor.setAlphaF(0.9f); } PieceItem::~PieceItem() = default; diff --git a/src/ui/qt/winmain.cpp b/src/ui/qt/winmain.cpp index b35abc72b0..9310f342f4 100644 --- a/src/ui/qt/winmain.cpp +++ b/src/ui/qt/winmain.cpp @@ -48,7 +48,9 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QTranslator translator; - translator.load("mill-pro-qt_zh_CN"); + if (!translator.load("mill-pro-qt_zh_CN")) { + qWarning() << "Failed to load translation file."; + } a.installTranslator(&translator); MillGameWindow w; w.show();