Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,24 @@ target_link_libraries(checkmate_core PUBLIC
Qt6::Core Qt6::Gui Qt6::Network Qt6::Qml Qt6::Quick Qt6::QuickControls2 Qt6::DBus Qt6::Quick3D Qt6::Concurrent)
target_compile_options(checkmate_core PUBLIC -Wall -Wextra)

# The version comes from the release, never from the code: a tag's tarball
# unpacks as checkmate-<version>, and a checkout asks git.
get_filename_component(source_dir_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
if(source_dir_name MATCHES "^checkmate-([0-9][0-9.]*)$")
set(CHECKMATE_VERSION "${CMAKE_MATCH_1}")
else()
execute_process(COMMAND git describe --tags --always --dirty
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE CHECKMATE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
string(REGEX REPLACE "^v" "" CHECKMATE_VERSION "${CHECKMATE_VERSION}")
if(NOT CHECKMATE_VERSION)
set(CHECKMATE_VERSION dev)
endif()
endif()

add_executable(checkmate src/main.cpp src/resources.qrc)
target_link_libraries(checkmate PRIVATE checkmate_core)
target_compile_definitions(checkmate PRIVATE CHECKMATE_VERSION="${CHECKMATE_VERSION}")

# The tests load the real Main.qml, so they carry the resources too.
enable_testing()
Expand All @@ -33,6 +49,12 @@ find_program(XVFB_RUN xvfb-run REQUIRED)
add_test(NAME checkmate_tests COMMAND ${XVFB_RUN} -a $<TARGET_FILE:checkmate_tests>)
set_tests_properties(checkmate_tests PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen;QT_QUICK_BACKEND=rhi;QSG_RHI_BACKEND=opengl;LIBGL_ALWAYS_SOFTWARE=1")

# --version answers without a display. A checkout without tags reports git's commit or "dev" rather than a number.
add_test(NAME checkmate_version_without_display
COMMAND ${CMAKE_COMMAND} -E env --unset=QT_QPA_PLATFORM --unset=WAYLAND_DISPLAY --unset=DISPLAY
$<TARGET_FILE:checkmate> --version)
set_tests_properties(checkmate_version_without_display PROPERTIES PASS_REGULAR_EXPRESSION "^Checkmate [0-9a-z]")

# `cmake --install build --prefix ~/.local` puts the app in the launcher
# before it is packaged; a package installs the same files under /usr.
include(GNUInstallDirs)
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
int main(int argc, char *argv[]) {
const std::string command = argc > 1 ? argv[1] : "open";
if (command == "--help" || command == "--version") {
std::cout << (command == "--version" ? "Checkmate 0.1.0\n" : "Checkmate — 3D chess\nUsage: checkmate [open | inspect | export | legal [FEN] | --help | --version]\nHeadless commands accept --json. export prints PGN to stdout.\n");
std::cout << (command == "--version" ? "Checkmate " CHECKMATE_VERSION "\n" : "Checkmate — 3D chess\nUsage: checkmate [open | inspect | export | legal [FEN] | --help | --version]\nHeadless commands accept --json. export prints PGN to stdout.\n");
return 0;
}
if (command == "inspect" || command == "export" || command == "legal") return runCli(argc,argv);
Expand All @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
qmlRegisterType<SculptGeometry>("Checkmate", 1, 0, "SculptGeometry");
qmlRegisterType<SurfaceTexture>("Checkmate",1,0,"SurfaceTexture");
app.setApplicationName("checkmate");
app.setApplicationVersion("0.1.0");
app.setApplicationVersion(CHECKMATE_VERSION);

// Matches the window to checkmate.desktop, so the compositor (Wayland app_id)
// and the launcher pick up the installed icon. The compiled-in copy covers
Expand Down
47 changes: 27 additions & 20 deletions tests/checkmate_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,20 @@ private slots:
QTest::qWait(150);
for (int set=0;set<4;++set) {
backend.setPieceSet(set);
QTest::qWait(60);
for (float x : {-4.55f,4.55f}) for (float z : {-4.55f,4.55f}) {
QVector3D point;
QVERIFY(QMetaObject::invokeMethod(view,"mapFrom3DScene",Q_RETURN_ARG(QVector3D,point),Q_ARG(QVector3D,QVector3D(x,0,z))));
QVERIFY2(point.x()>=0 && point.x()<=board->width() && point.y()>=0 && point.y()<=board->height(),
qPrintable(QString("set %1 at %2x%3: corner %4,%5 lands at %6,%7").arg(set).arg(size.width()).arg(size.height())
.arg(x).arg(z).arg(point.x()).arg(point.y())));
}
// The view answers from the last frame it drew, and a slow renderer takes its time over one.
QString stray;
auto framed=[&] {
stray.clear();
for (float x : {-4.55f,4.55f}) for (float z : {-4.55f,4.55f}) {
QVector3D point;
if (!QMetaObject::invokeMethod(view,"mapFrom3DScene",Q_RETURN_ARG(QVector3D,point),Q_ARG(QVector3D,QVector3D(x,0,z)))) return false;
if (point.x()<0 || point.x()>board->width() || point.y()<0 || point.y()>board->height())
stray=QString("set %1 at %2x%3: corner %4,%5 lands at %6,%7").arg(set).arg(size.width()).arg(size.height())
.arg(x).arg(z).arg(point.x()).arg(point.y());
}
return stray.isEmpty();
};
QTRY_VERIFY2_WITH_TIMEOUT(framed(),qPrintable(stray),10000);
Comment on lines +837 to +850

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Camera checks can skip sets

After setPieceSet(), framed() runs immediately and can accept the previous set's already-valid projection. The loop can then advance without drawing the selected set, including set 2's different camera. This leaves a gap where a change that crops the board could pass the test. Wait for a new frame after each set change, then poll the corners.

}
}
backend.setPieceSet(0);
Expand Down Expand Up @@ -933,14 +939,15 @@ private slots:
auto *pawn=window->findChild<QObject *>("figure-20");
QVERIFY(pawn);
QVERIFY(backend.move(12,28));
QTest::qWait(160);
QVERIFY(pawn->property("lift").toDouble()>0);
QVERIFY(pawn->property("z").toDouble()>.5);
QVERIFY(pawn->property("z").toDouble()<2.5);
// A slow renderer may draw the whole journey in a frame or two, so nothing is sampled in mid-air:
// the journey has started, it is aimed up the board, and it ends on the square.
QVERIFY(pawn->findChild<QObject *>("leap")->property("running").toBool());
QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9);
QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),.5f),5000);
backend.undo();
// Quick 3D coordinates use float precision, including the final animation setter.
QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),2.5f),1500);
QTRY_COMPARE_WITH_TIMEOUT(pawn->property("lift").toDouble(),0.0,1500);
QTRY_VERIFY_WITH_TIMEOUT(qFuzzyCompare(pawn->property("z").toFloat(),2.5f),8000);
QTRY_COMPARE_WITH_TIMEOUT(pawn->property("lift").toDouble(),0.0,8000);
auto *leap=pawn->findChild<QObject *>("leap");
auto *perk=pawn->findChild<QObject *>("perk");
QVERIFY(leap && perk);
Expand Down Expand Up @@ -970,16 +977,16 @@ private slots:
pawn->setProperty("wiggle",8.0);
QVERIFY(backend.move(12,28));
QVERIFY(leap->property("running").toBool());
QTRY_VERIFY(qAbs(pawn->property("lean").toDouble())>2);
QVERIFY(pawn->property("lift").toDouble()>0);
QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9);
QVERIFY(leap->property("height").toDouble()>0);
// A captured piece waits for its captor, then goes.
QVERIFY(backend.move(51,35));
auto *taken=window->findChild<QObject *>("figure-"+QString::number(backend.position().board[35].id));
QVERIFY(taken);
QVERIFY(backend.move(28,35));
QCOMPARE(taken->property("presence").toDouble(),1.0);
QTRY_COMPARE_WITH_TIMEOUT(taken->property("presence").toDouble(),0.0,2500);
QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),2500);
QTRY_COMPARE_WITH_TIMEOUT(taken->property("presence").toDouble(),0.0,8000);
QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),8000);
QCOMPARE(pawn->property("lean").toDouble(),0.0);
QCOMPARE(pawn->property("stretch").toDouble(),1.0);
QCOMPARE(pawn->property("lift").toDouble(),0.0);
Expand Down Expand Up @@ -1014,8 +1021,8 @@ private slots:
QTRY_VERIFY(qAbs(neighbour->property("look").toDouble())>5);
QVERIFY(backend.move(12,28));
QVERIFY(leap->property("running").toBool());
QTRY_VERIFY(qAbs(pawn->property("lean").toDouble())>2);
QVERIFY(pawn->property("lift").toDouble()>0);
QVERIFY(qAbs(pawn->property("leanZ").toDouble())>.9);
QVERIFY(leap->property("height").toDouble()>0);
QTRY_VERIFY_WITH_TIMEOUT(!leap->property("running").toBool(),2000);
QVERIFY(qFuzzyCompare(pawn->property("z").toFloat(),.5f));
QCOMPARE(pawn->property("lean").toDouble(),0.0);
Expand Down
Loading