17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 12:39:18 +02:00
Files
maszyna/editor/tests/CMakeLists.txt
maj00r 366645ef59 Plan tool: cofanie, złącza, przejścia rozjazdowe, and a demo to open
What the plan tool was missing was not geometry but the ordinary business of
editing: taking a mistake back, dividing what is drawn, and seeing what the next
click will do before making it.

Cofanie. The document is plain data, so a step is a copy of it. What counts as one
step is decided by watching the document - a fingerprint over the tracks, turnouts
and catalogue - rather than by dressing every edit with a call: a frame that
changes anything opens a step, and the step closes when the drawing settles. That
is what makes a drag, or a number typed digit by digit, one step and not thirty,
and nothing can be forgotten on the way in. Ctrl+Z / Ctrl+Y; the scene editor
listens for the same keys, so it hands them over while the plan has the keyboard.

Złącze i wycięcie. `insert_joint` divides whichever element a station lands in and
leaves one chain: the ground does not move, the curvature at the new joint is the
one that was always there, and the fit reads the chain the same way afterwards. It
is refused on a straight, because two straights end to end are one straight and the
skeleton will not read that, and under a turnout, which is one piece of geometry on
one element. `cut_track` takes a piece out and does leave two tracks - a gap is the
ground between them, not a hole in a chain.

Przejście rozjazdowe. A turnout may now stand against another one: where it stands
is then worked out from that one's frog, not authored, so moving either carries the
other with it and a trapez stays shut. The frog has to land on the line leaving the
other frog - not on the track's axis, which is 1,469 m further on for a 1:9 - so
the station is settled by laying the turnout and walking it along until it does.

Drawing is a tool now, not what a click happens to do: until Rysuj is on, a click
picks what is under it. With it on, the cursor at the growing end shows the corner
and the straight the next click would lay, worked out by the same fit_corner the
click itself uses. A chain only grows at a loose end, and the first element of a
track is put down by two clicks instead of landing on the plan's zero.

Also here: the curvature strip under the panel, pikietaż in the rows and at the
cursor, how far the laid axis runs from the clicks it was drawn from, the file
format saying which frame and which units it is in (v9), plans chosen from the
directory instead of typed, and editor/samples/demo.m0s - two parallel tracks and a
trapez - with the generator that wrote it and a test that opens it and demands it
lays clean.
2026-09-14 16:35:36 +02:00

56 lines
2.2 KiB
CMake

# Unit tests for the plan library (the geometry and the solver behind the track
# layout tool). They are off by default: switched on, the interface units are
# compiled a second time into a small library of their own, because a test
# executable can only import modules from a target it links, and linking the game
# would drag the whole simulator in. The code under test needs nothing but a
# C++20 compiler - no glm, no engine, no imgui.
option(EU07_EDITOR_PLAN_TESTS "Build the editor plan library unit tests" OFF)
if (NOT EU07_EDITOR_PLAN_TESTS)
return()
endif()
enable_testing()
set(PLAN_INTERFACES
../plan_segment.cppm
../plan_turnout_geometry.cppm
../plan_model.cppm
../plan_solution.cppm
../plan_chain.cppm
../plan_join.cppm
../plan_layout.cppm
../plan_render.cppm
../plan_sketch.cppm
../plan_tilecache.cppm
../plan_document_io.cppm
../plan_scn_export.cppm
../plan_scene.cppm
../plan_track_renderer.cppm
../plan_rail_renderer.cppm)
file(GLOB PLAN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../plan_*.cpp")
add_library(editor_plan STATIC ${PLAN_SOURCES})
target_sources(editor_plan
PUBLIC FILE_SET CXX_MODULES
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/..
FILES ${PLAN_INTERFACES})
set_target_properties(editor_plan PROPERTIES
CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON FOLDER "editor")
foreach(name chain hold lines graph format turnout tile_cache split)
add_executable(editor_plan_test_${name} test_${name}.cpp)
target_link_libraries(editor_plan_test_${name} PRIVATE editor_plan)
target_include_directories(editor_plan_test_${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(editor_plan_test_${name} PROPERTIES
CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF FOLDER "editor")
# the sample plan is a fixture: the format test opens the very file the editor ships
target_compile_definitions(editor_plan_test_${name}
PRIVATE EU07_PLAN_SAMPLES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../samples")
add_test(NAME plan_${name} COMMAND editor_plan_test_${name})
endforeach()
# test_scn.cpp and test_join.cpp are missing: they were never committed, along
# with the join module those two exercised (see the stub in plan_join.cpp).