From 983b7f4ade6f4bf690a4aa275e724da60c0bd9a8 Mon Sep 17 00:00:00 2001 From: Erin Catto Date: Tue, 20 Oct 2026 15:09:15 -0700 Subject: [PATCH] doxygen update improve CMake --- .github/workflows/build.yml | 10 +- CMakeLists.txt | 53 +++-- README.md | 6 +- benchmark/CMakeLists.txt | 10 +- docs/CMakeLists.txt | 24 +- docs/extra.css | 438 +++++++++++++++++++++++++++++++----- docs/instant_scroll.cmake | 19 ++ docs/layout.xml | 238 ++++++++++---------- include/box3d/collision.h | 4 +- shared/CMakeLists.txt | 6 + src/CMakeLists.txt | 114 +++++++--- src/box3d.pc.in | 11 + src/replay.c | 2 +- src/simd.h | 2 +- src/timer.c | 19 +- src/world_snapshot.c | 2 +- test/CMakeLists.txt | 17 +- 17 files changed, 719 insertions(+), 256 deletions(-) create mode 100644 docs/instant_scroll.cmake create mode 100644 src/box3d.pc.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 32b91ed..5831e95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,16 +24,17 @@ jobs: - name: ubuntu-gcc os: ubuntu-latest test: ./bin/test + # Clang jobs pin the image because each Ubuntu image ships a different set of clang versions - name: ubuntu-clang - os: ubuntu-latest - args: '-DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_COMPILER=clang-18 -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread"' + os: ubuntu-26.04 + args: '-DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_C_COMPILER=clang-20 -DCMAKE_C_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-fsanitize=thread -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread"' test: ./bin/test # Runner speed varies about 3x by region and MSan at -O0 can exceed the timeout on the slow ones. # -O1 is the level MSan recommends and Debug keeps asserts. Line buffering shows per test timing. - name: ubuntu-clang-msan - os: ubuntu-latest + os: ubuntu-26.04 timeout: 10 - args: '-DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_COMPILER=clang-18 -DCMAKE_C_FLAGS="-O1 -fsanitize=memory -fsanitize-memory-track-origins=1 -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-O1 -fsanitize=memory -fsanitize-memory-track-origins=1 -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=memory"' + args: '-DCMAKE_CXX_COMPILER=clang++-20 -DCMAKE_C_COMPILER=clang-20 -DCMAKE_C_FLAGS="-O1 -fsanitize=memory -fsanitize-memory-track-origins=1 -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-O1 -fsanitize=memory -fsanitize-memory-track-origins=1 -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=memory"' test: lscpu | grep 'Model name'; nproc; stdbuf -oL ./bin/test msan-options: abort_on_error=1:halt_on_error=1 - name: macos @@ -45,7 +46,6 @@ jobs: msvc: true args: -DBOX3D_SANITIZE=ON test: ./bin/Debug/test - # Box3D is width-4 SIMD only, so this covers the clang-cl toolchain, not AVX2. - name: windows-clang-cl os: windows-latest msvc: true diff --git a/CMakeLists.txt b/CMakeLists.txt index dc3ecb6..10f3b96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.22) -include(CMakeDependentOption) project(box3d VERSION 0.1.0 @@ -18,7 +17,7 @@ message(STATUS "CMake system name: ${CMAKE_SYSTEM_NAME}") message(STATUS "CMake host system processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}") # static link to make leak checking easier (_crtBreakAlloc) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") if (MSVC OR APPLE OR UNIX) option(BOX3D_SANITIZE "Enable sanitizers for some builds" OFF) @@ -61,8 +60,8 @@ if (MSVC OR APPLE OR UNIX) add_link_options(-fsanitize=memory) else() # default to address sanitizer - add_compile_options(-fsanitize=address -fno-omit-frame-pointer) - add_link_options(-fsanitize=address) + add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) + add_link_options(-fsanitize=address -fsanitize=undefined) endif() endif() else() @@ -89,10 +88,22 @@ if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") endif() option(BOX3D_DISABLE_SIMD "Disable SIMD math (slower)" OFF) -option(BOX3D_AVX2 "Compile AVX2 kernels, selected at runtime on x86 CPUs that support them" ON) option(BOX3D_COMPILE_WARNING_AS_ERROR "Compile warnings as errors" OFF) option(BOX3D_DOUBLE_PRECISION "Enable double precision for large worlds" OFF) +# core.h selects the SIMD path from these definitions, so the unit tests and the SAT +# benchmark, which include the src headers, must compile with the same definitions and +# instruction set flags as the library. Selected once here for all of them. +set(BOX3D_SIMD_DEFINITIONS "") +set(BOX3D_SIMD_OPTIONS "") +if (BOX3D_DISABLE_SIMD) + message(STATUS "Box3D SIMD disabled") + set(BOX3D_SIMD_DEFINITIONS BOX3D_DISABLE_SIMD) +elseif (EMSCRIPTEN) + # core.h maps wasm onto the SSE2 path, the intrinsics only compile with simd128 enabled + set(BOX3D_SIMD_OPTIONS -msimd128 -msse2) +endif() + # These are read by the library build, so they must precede add_subdirectory(src), # otherwise the first configure and a re-configure produce different libraries. # Top level only, so they stay hidden from FetchContent consumers. @@ -101,13 +112,6 @@ if(PROJECT_IS_TOP_LEVEL) option(BOX3D_VALIDATE "Enable heavy validation" ON) endif() -# Emscripten maps the SSE2 path onto wasm SIMD128. simd.h is a header included by -# non-library targets like the tests, so these flags must be directory-wide, not -# PRIVATE to the box3d library. -if (EMSCRIPTEN AND NOT BOX3D_DISABLE_SIMD) - add_compile_options(-msimd128 -msse2) -endif() - # Emscripten pthread support. Must precede add_subdirectory(src) so the box3d library # objects are built with the same atomics/bulk-memory features as the executables that # link them, otherwise wasm-ld rejects --shared-memory. Top level only, so a FetchContent @@ -122,17 +126,20 @@ endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set(CMAKE_VERBOSE_MAKEFILE ON) +# Leaving this here for testing +# set(CMAKE_VERBOSE_MAKEFILE ON) -# Needed for samples.exe to find box2d.dll -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") +if(PROJECT_IS_TOP_LEVEL) + # Needed for samples.exe to find box3d.dll + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") -# Collect FetchContent downloads outside the build dir so a clean rebuild reuses them. -# Must precede the first include(FetchContent) -if(NOT FETCHCONTENT_BASE_DIR) - set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/.fetchcontent-cache" - CACHE PATH "Shared FetchContent populate cache") + # Collect FetchContent downloads outside the build dir so a clean rebuild reuses them. + # Must precede the first include(FetchContent) + if(NOT FETCHCONTENT_BASE_DIR) + set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/.fetchcontent-cache" + CACHE PATH "Shared FetchContent populate cache") + endif() endif() include(FetchContent) @@ -159,7 +166,7 @@ if(PROJECT_IS_TOP_LEVEL) message(STATUS "Adding Box3D unit tests") add_subdirectory(test) set_target_properties(test PROPERTIES XCODE_GENERATE_SCHEME TRUE) - else() + elseif(BOX3D_UNIT_TESTS) message(STATUS "Skipping Box3D unit tests") endif() @@ -172,9 +179,11 @@ if(PROJECT_IS_TOP_LEVEL) set_property(TARGET samples PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") endif() + if(APPLE) set_target_properties(samples PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + endif() endif() if(BOX3D_BENCHMARKS) diff --git a/README.md b/README.md index ab36b8c..ba89e27 100644 --- a/README.md +++ b/README.md @@ -147,9 +147,9 @@ You will need a compiler that supports C17 to build the Box3D library. You will need a compiler that supports C++20 to build the samples. -Box3D uses SSE2 and Neon SIMD math to improve performance. SIMD can be disabled by defining `BOX3D_DISABLE_SIMD`. - -On x86, AVX2 kernels are selected at runtime when the CPU supports them. Configure with `-DBOX3D_AVX2=OFF` to disable them. +Box3D uses SSE2, AVX2, and Neon (AArch64) SIMD math to improve performance. This can be disabled by +defining `BOX3D_DISABLE_SIMD`. SSE2 is automatically used as a fallback when the CPU doesn't support +AVX2. ## Documentation diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 73f7210..c3e21cb 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -6,7 +6,15 @@ set(BOX3D_BENCHMARK_FILES add_executable(benchmark ${BOX3D_BENCHMARK_FILES}) -set_target_properties(benchmark PROPERTIES C_STANDARD 17) +set_target_properties(benchmark PROPERTIES + C_STANDARD 17 + C_STANDARD_REQUIRED YES + C_EXTENSIONS NO +) + +if (BOX3D_COMPILE_WARNING_AS_ERROR) + set_target_properties(benchmark PROPERTIES COMPILE_WARNING_AS_ERROR ON) +endif() target_link_libraries(benchmark PRIVATE box3d shared) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 9014cdd..4a65521 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,4 +1,7 @@ -find_package(Doxygen REQUIRED dot) +# https://www.doxygen.nl/manual/markdown.html#markdown_extra +# https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax + +find_package(Doxygen REQUIRED) set(DOXYGEN_PROJECT_NAME "Box3D") set(DOXYGEN_GENERATE_HTML YES) @@ -31,16 +34,25 @@ set(DOXYGEN_DISABLE_INDEX YES) set(DOXYGEN_GENERATE_TREEVIEW YES) set(DOXYGEN_FULL_SIDEBAR NO) +# Only the ## sections in the tree, deeper headings made the manual pages expand into long lists +set(DOXYGEN_TOC_INCLUDE_HEADINGS 2) + # No per-page outline panel on the right set(DOXYGEN_PAGE_OUTLINE_PANEL NO) -# Dark theme baked by doxygen, extra.css only adds the Box3D accent +# Dark theme baked by doxygen, extra.css restyles it in the Box2D grays and accent set(DOXYGEN_HTML_COLORSTYLE DARK) # this tells doxygen to label structs as structs instead of classes set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) set(DOXYGEN_WARN_IF_INCOMPLETE_DOC NO) +# Keep enum values out of the summary tables, b3HexColor alone has over a hundred +set(DOXYGEN_ENUM_VALUES_PER_LINE 0) + +# No Graphviz diagrams, the struct collaboration graphs only repeat the field types +set(DOXYGEN_HAVE_DOT NO) + doxygen_add_docs(doc "${CMAKE_SOURCE_DIR}/include/box3d" "overview.md" @@ -57,4 +69,10 @@ doxygen_add_docs(doc "reading.md" ALL COMMENT "Generate HTML documentation") - \ No newline at end of file + + +# Jump to anchors instead of doxygen's animated scroll +add_custom_command(TARGET doc POST_BUILD + COMMAND ${CMAKE_COMMAND} -DNAVTREE=${CMAKE_CURRENT_BINARY_DIR}/html/navtree.js + -P ${CMAKE_CURRENT_SOURCE_DIR}/instant_scroll.cmake + VERBATIM) diff --git a/docs/extra.css b/docs/extra.css index fb75491..19aecdf 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -1,61 +1,41 @@ /* -Box2D accents on top of doxygen's built-in dark theme (HTML_COLORSTYLE DARK). -Doxygen 1.17 bakes a complete dark palette, so this only restores the Box2D -cyan accent and backs the transparent SVG diagrams. Loaded after doxygen.css, +Box2D look on top of doxygen's built-in dark theme (HTML_COLORSTYLE DARK). +Restores the Box2D cyan accent and grays, backs the transparent SVG diagrams, +and styles screenshots, prose width, and callouts. Loaded after doxygen.css, so plain overrides win by order. */ -/* Box2D cyan for links, symbol cross references, and section headings */ -a, a:link, a:visited, -.contents a:visited, -a.el, a.el:visited, a.code, a.code:visited, a.line, a.line:visited, -a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { - color: #67d8ef; +/* Doxygen's DARK style bakes its colors, so these only feed the overrides below */ +:root { + --b3-page: #292a2d; + --b3-panel: #32363d; + --b3-edge: #3c4048; + --b3-edge-hover: #5f6670; + --b3-text: #D8D8D8; + --b3-muted: #9aa0a6; + --b3-accent: #67d8ef; + --b3-warm: #e5b567; + --b3-plate: #CCCCCC; } -h2.groupheader, -.memtitle { - color: #67d8ef; -} +/* Page */ -h1.glow, h2.glow, h3.glow, h4.glow, h5.glow, h6.glow { - text-shadow: 0 0 15px #67d8ef; -} - -/* SVG diagrams are transparent, so back them with a light plate to stay legible on a dark page */ -.image { - background-color: #CCCCCC; - border: 10px solid #CCCCCC; -} - -img.inline { - background-color: #CCCCCC; - border: 10px solid #CCCCCC; - margin: 0px; -} - -/* Caption sits on the light plate */ -.caption { - padding-top: 10px; - color: black; -} - -/* Cap line length for readability */ -div.contents { - max-width: 1000px; -} - -/* Soften contrast. doxygen 1.17's dark is near black, restore the Box2D grays */ +/* Soften contrast. Doxygen's dark is near black, restore the Box2D grays */ body { - background-color: #292a2d; - color: #D8D8D8; + background-color: var(--b3-page); + color: var(--b3-text); } #titlearea, div.header, #side-nav, #nav-tree { - background-color: #292a2d; + background-color: var(--b3-page); +} + +#titlearea, +div.header { + border-bottom-color: var(--b3-edge); } /* Panels and selection sit one step lighter than the page */ @@ -69,17 +49,371 @@ table.doxtable th, .fieldtable th, th.markdownTableHeadLeft, th.markdownTableHeadRight, th.markdownTableHeadCenter, th.markdownTableHeadNone, table.doxtable tr:nth-child(even) td, .directory tr.even { - background-color: #32363d; + background-color: var(--b3-panel); } .directory tr.odd { - background-color: #292a2d; + background-color: var(--b3-page); } -/* Caution callouts, filled olive box with a full border and real padding */ -blockquote.doxtable { - background-color: #456114; - border: 1px solid #000000; - padding: 12px 16px; - margin: 10px 24px 10px 4px; +/* Cap line length for readability */ +div.contents { + max-width: 1000px; +} + +/* Prose reads best near 75 characters, the reference tables keep the wider cap */ +.textblock { + max-width: 820px; +} + +/* Links and headings */ + +/* Box2D cyan for links, symbol cross references, and section headings */ +a, a:link, a:visited, +.contents a:visited, +a.el, a.el:visited, a.code, a.code:visited, a.line, a.line:visited, +a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { + color: var(--b3-accent); +} + +/* Doxygen bolds internal links only, so prose would mix two link weights */ +.textblock a.el { + font-weight: normal; +} + +.contents a:hover { + text-decoration: underline; +} + +h2.groupheader, +.memtitle { + color: var(--b3-accent); +} + +h1.glow, h2.glow, h3.glow, h4.glow, h5.glow, h6.glow { + text-shadow: 0 0 15px var(--b3-accent); +} + +/* A page's # heading is the title and its ## headings render as h1 at 200% bold, +so the title has to outrank them */ +div.headertitle .title { + font-size: 240%; + font-weight: 600; + line-height: 1.2; +} + +/* Doxygen draws the group underline with side shadows filled in its black page color */ +h2.groupheader { + box-shadow: 12px 0 var(--b3-page), -12px 0 var(--b3-page), 12px 1px var(--b3-edge), -12px 1px var(--b3-edge); +} + +td h2.groupheader { + box-shadow: 13px 0 var(--b3-page), -13px 0 var(--b3-page), 13px 1px var(--b3-edge), -13px 1px var(--b3-edge); +} + +/* Reference members */ + +/* Typedef types left aligned and free to wrap, so a long opaque struct typedef doesn't widen the + column, push the short callback return types right and squeeze the signatures */ +table.memberdecls:has(#header-typedef-members) td.memItemLeft { + text-align: left; + white-space: normal; +} + +/* Member list and field table edges in the border gray instead of navy */ +.mdescLeft, .mdescRight, .memItemLeft, .memItemRight, .memTemplParams, td.ititle, +tr.heading + tr[class^='memitem'] td.memItemLeft, +tr.groupHeader + tr[class^='memitem'] td.memItemLeft, +tr.inherit_header + tr[class^='memitem'] td.memItemLeft, +tr.heading + tr[class^='memitem'] td.memItemRight, +tr.groupHeader + tr[class^='memitem'] td.memItemRight, +tr.inherit_header + tr[class^='memitem'] td.memItemRight, +tr.heading + tr[class^='memitem'] td.memTemplParams, +tr.heading + tr td.ititle, +tr.groupHeader + tr[class^='memitem'] td.memTemplParams, +tr.groupHeader + tr td.ititle, +tr.inherit_header + tr[class^='memitem'] td.memTemplParams, +table.fieldtable, table.memberdecls-inline, +.fieldtable td.fieldtype, .fieldtable td.fieldname, .fieldtable td.fieldinit, .fieldtable td.fielddoc, +.memberdecls-inline th, .fieldtable th { + border-color: var(--b3-edge); +} + +/* The member tab joins its box with a shadow and a strip, both in doxygen's navy */ +.memtitle { + box-shadow: 0 10px 0 -1px var(--b3-panel), 0 2px 8px 0 rgba(0, 0, 0, 0.075); +} + +.memtitle:after { + background: var(--b3-panel); +} + +.memtitle, .memproto, dl.reflist dt, .memdoc, dl.reflist dd { + border-color: var(--b3-edge); +} + +.memberdecls-inline th, .fieldtable th { + background-color: var(--b3-panel); + color: var(--b3-text); +} + +/* Images */ + +/* Doxygen embeds SVG with object. The diagrams are transparent, so back them with a light plate +to stay legible on a dark page */ +.image:has(object) { + background-color: var(--b3-plate); + border: 10px solid var(--b3-plate); +} + +/* Raster images are screenshots, already opaque, so no plate */ +.image:has(img) img { + border: 1px solid var(--b3-edge); + border-radius: 6px; +} + +/* Fit wide images to the page, a link around a screenshot opens it full size */ +.image img, +.image object { + max-width: 100%; + height: auto; +} + +/* Caption sits on the light plate */ +.caption { + padding-top: 10px; + color: black; +} + +.image:has(img) .caption { + color: var(--b3-muted); + font-weight: normal; + font-size: 90%; +} + +/* Callouts */ + +/* Callouts share one panel with an accent edge. +@note and > [!NOTE] give dl.note, @warning and > [!WARNING] give dl.warning, +> [!CAUTION] gives dl.attention, a plain quote like > [!caution]: gives blockquote.doxtable */ +dl.note, dl.remark, dl.warning, dl.attention, dl.important, +blockquote.doxtable { + background-color: var(--b3-panel); + color: var(--b3-text); + border: none; + border-left: 4px solid var(--b3-accent); + border-radius: 4px; + padding: 10px 16px; + margin: 12px 0; +} + +dl.warning, dl.attention, dl.important, +blockquote.doxtable { + border-left-color: var(--b3-warm); +} + +dl.note dt, dl.remark dt { + color: var(--b3-accent); +} + +dl.warning dt, dl.attention dt, dl.important dt, +blockquote.doxtable b:first-child { + color: var(--b3-warm); +} + +blockquote.doxtable p { + margin: 0; +} + +/* Doxygen titles > [!CAUTION] as Attention, overlay the GitHub title in the same font */ +dl.attention dt { + visibility: hidden; + position: relative; +} + +dl.attention dt::after { + content: "Caution"; + visibility: visible; + position: absolute; + left: 0; + top: 0; +} + +/* Search */ + +/* Search box on the panel gray with the cyan accent on focus, in place of the black field and blue edge */ +#MSearchBox { + background-color: var(--b3-panel); + border: 1px solid var(--b3-edge); + border-radius: 6px; + padding: 2px 6px 2px 2px; + transition: border-color 0.15s, box-shadow 0.15s; +} + +#MSearchBox:hover { + border-color: var(--b3-edge-hover); +} + +#MSearchBox.MSearchBoxActive, +#MSearchBox:focus-within { + border-color: var(--b3-accent); + box-shadow: 0 0 0 2px rgba(103, 216, 239, 0.2); +} + +#MSearchField { + width: 12em; + background-color: transparent; + color: var(--b3-text); + font-family: inherit; + font-size: 14px; +} + +#MSearchField::placeholder { + color: var(--b3-muted); +} + +/* The lens circle is filled to hide the handle behind it, so it must match the box */ +.search-icon::before { + background: var(--b3-panel); + border-color: var(--b3-muted); +} + +.search-icon::after { + border-color: var(--b3-muted); +} + +.search-icon-dropdown { + border-top-color: var(--b3-muted); +} + +#MSearchSelectWindow, +#MSearchResultsWindow { + background-color: var(--b3-page); + border: 1px solid var(--b3-edge); + border-radius: 6px; + box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); +} + +a.SelectItem { + color: var(--b3-text); +} + +a.SelectItem:hover { + color: var(--b3-text); + background-color: var(--b3-panel); +} + +/* Tree */ + +/* Plain text so the tree doesn't compete with the page's links, cyan only on hover. +Doxygen sets its own small font here */ +#nav-tree .label { + font: 13px system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif; + line-height: 22px; +} + +#nav-tree a { + color: var(--b3-text); +} + +#nav-tree a:hover { + color: var(--b3-accent); +} + +/* Doxygen dims the current page, mark it bright with an accent edge instead */ +#nav-tree .selected { + box-shadow: inset 3px 0 var(--b3-accent); +} + +#nav-tree .selected a { + color: white; +} + +span.arrowhead { + border-right-color: var(--b3-muted); + border-bottom-color: var(--b3-muted); +} + +.selected span.arrowhead { + border-right-color: var(--b3-text); + border-bottom-color: var(--b3-text); +} + +/* Tree sync toggle in the panel grays with the cyan accent on hover */ +div.nav-sync-icon { + background-color: var(--b3-panel); + border: 1px solid var(--b3-edge); + border-radius: 3px; +} + +div.nav-sync-icon:hover { + background-color: var(--b3-edge); +} + +div.nav-sync-icon.active:after { + background-color: var(--b3-panel); + border-top-color: var(--b3-muted); +} + +div.nav-sync-icon.active:hover:after { + border-top-color: var(--b3-accent); +} + +span.sync-icon-left { + border-left-color: var(--b3-muted); + border-top-color: var(--b3-muted); +} + +span.sync-icon-right { + border-right-color: var(--b3-muted); + border-bottom-color: var(--b3-muted); +} + +div.nav-sync-icon:hover span.sync-icon-left { + border-left-color: var(--b3-accent); + border-top-color: var(--b3-accent); +} + +div.nav-sync-icon:hover span.sync-icon-right { + border-right-color: var(--b3-accent); + border-bottom-color: var(--b3-accent); +} + +/* Tree resize handle, shown on hover */ +.ui-resizable-e { + background-color: var(--b3-edge); +} + +.ui-resizable-e:after { + border-left-color: var(--b3-muted); + border-right-color: var(--b3-muted); +} + +/* Footer */ + +/* Footer bar on the page gray, doxygen fills it black. The directory pages put a breadcrumb in it */ +#nav-path ul { + background: var(--b3-page); + border-top: 1px solid var(--b3-edge); + border-bottom: none; + color: var(--b3-muted); +} + +.navpath li, +.navpath li.footer { + color: var(--b3-muted); +} + +.navpath li.navelem a { + color: var(--b3-accent); +} + +#nav-path li.navelem:after { + background: var(--b3-page); + box-shadow: 2px -2px 0 2px var(--b3-edge); +} + +#nav-path li.navelem:hover, +#nav-path li.navelem:hover:after { + background-color: var(--b3-panel); } diff --git a/docs/instant_scroll.cmake b/docs/instant_scroll.cmake new file mode 100644 index 0000000..c82b9b4 --- /dev/null +++ b/docs/instant_scroll.cmake @@ -0,0 +1,19 @@ +# Doxygen's navtree.js slides to an anchor for up to 500 ms and has no option to turn it off. +# Rewrite the call to jump, keeping the callback that runs the highlight glow. +# Run with -DNAVTREE= + +file(READ "${NAVTREE}" text) + +set(animated "animateScrolling(docContent, pos+dcScrTop-dcOffset, Math.max(50,Math.min(500,dist)), function() {") +set(instant "docContent.scrollTop = pos+dcScrTop-dcOffset; requestAnimationFrame(function() {") + +string(FIND "${text}" "${animated}" found) +if(found GREATER_EQUAL 0) + string(REPLACE "${animated}" "${instant}" text "${text}") + file(WRITE "${NAVTREE}" "${text}") +else() + string(FIND "${text}" "${instant}" patched) + if(patched LESS 0) + message(FATAL_ERROR "instant_scroll.cmake: anchor scroll code not found in ${NAVTREE}, doxygen changed it") + endif() +endif() diff --git a/docs/layout.xml b/docs/layout.xml index e93b6cf..331a4ac 100644 --- a/docs/layout.xml +++ b/docs/layout.xml @@ -1,11 +1,11 @@ - - + + - + @@ -51,51 +51,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - + + + + + + + + + + + @@ -113,25 +113,25 @@ - - - - - - - + + + + + + + - + - - - - - - - - + + + + + + + + @@ -141,7 +141,7 @@ - + @@ -160,27 +160,27 @@ - - - - - - - - + + + + + + + + - + - - - - - - - - - + + + + + + + + + @@ -197,42 +197,42 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -244,13 +244,13 @@ - - - - - + + + + + - + @@ -264,6 +264,6 @@ - + diff --git a/include/box3d/collision.h b/include/box3d/collision.h index 51391f1..36e4b3f 100644 --- a/include/box3d/collision.h +++ b/include/box3d/collision.h @@ -232,7 +232,7 @@ B3_API b3HullData* b3CreateCone( float height, float radius1, float radius2, int /// Create a rock shaped hull. B3_API b3HullData* b3CreateRock( float radius ); -// Hull of 32 pseudo random points on a sphere. From the convex pile hull in PEEL. +/// Hull of 32 pseudo random points on a sphere. From the convex pile hull in PEEL. B3_API b3HullData* b3CreateComplexHull( float radius ); /// Create a generic convex hull. This can fail if B3_MAX_HULL_VERTICES, B3_MAX_HULL_FACES, @@ -468,7 +468,7 @@ B3_API b3CompoundData* b3CreateCompound( const b3CompoundDef* def ); /// Destroy a compound shape. B3_API void b3DestroyCompound( b3CompoundData* compound ); -// Cast serialized bytes into a compound and validate. Returns null if invalid. +/// Cast serialized bytes into a compound and validate. Returns null if invalid. B3_API const b3CompoundData* b3ValidateCompound( const uint8_t* bytes, int byteCount ); /**@}*/ // compound diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 3a663ee..ff640b4 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -21,6 +21,10 @@ set_target_properties(shared PROPERTIES C_STANDARD 17 ) +if (BOX3D_COMPILE_WARNING_AS_ERROR) + set_target_properties(shared PROPERTIES COMPILE_WARNING_AS_ERROR ON) +endif() + target_include_directories(shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(shared PRIVATE box3d) @@ -29,6 +33,8 @@ if (NOT BUILD_SHARED_LIBS) target_sources(shared PRIVATE sat_benchmark.c sat_benchmark.h) target_include_directories(shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src) target_compile_definitions(shared PUBLIC BOX3D_INTERNAL_BENCHMARKS) + target_compile_definitions(shared PRIVATE ${BOX3D_SIMD_DEFINITIONS}) + target_compile_options(shared PRIVATE ${BOX3D_SIMD_OPTIONS}) endif() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${BOX3D_SHARED_FILES}) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f324add..aa65d79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -121,8 +121,6 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) add_library(box3d ${BOX3D_SOURCE_FILES} ${BOX3D_INCLUDE_FILES}) -# target_link_libraries(box3d PRIVATE eastl) - target_include_directories(box3d PUBLIC $ @@ -150,13 +148,13 @@ endif() if (BOX3D_PROFILE) target_compile_definitions(box3d PRIVATE BOX3D_PROFILE) - set(TRACY_DELAYED_INIT ON CACHE BOOL "Enable delayed init for Tracy" FORCE) - set(TRACY_MANUAL_LIFETIME ON CACHE BOOL "Enable manual lifetime for Tracy" FORCE) + set(TRACY_ENABLE ON CACHE BOOL "Enable profiling" FORCE) + set(TRACY_MANUAL_LIFETIME ON CACHE BOOL "Enable manual lifetime for Tracy" FORCE) FetchContent_Declare( tracy GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.13.1 + GIT_TAG v0.14.1 GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) @@ -171,15 +169,8 @@ if(BOX3D_VALIDATE) target_compile_definitions(box3d PRIVATE BOX3D_VALIDATE) endif() -if (BOX3D_DISABLE_SIMD) - message(STATUS "Box3D SIMD disabled") - target_compile_definitions(box3d PRIVATE BOX3D_DISABLE_SIMD) -endif() - -if (NOT BOX3D_AVX2) - message(STATUS "Box3D AVX2 disabled") - target_compile_definitions(box3d PRIVATE BOX3D_DISABLE_AVX2) -endif() +target_compile_definitions(box3d PRIVATE ${BOX3D_SIMD_DEFINITIONS}) +target_compile_options(box3d PRIVATE ${BOX3D_SIMD_OPTIONS}) if (BOX3D_DOUBLE_PRECISION) message(STATUS "Box3D double precision ON") @@ -200,39 +191,38 @@ if (MSVC) # Visual Studio won't load the natvis unless it is in the project target_sources(box3d PRIVATE box3d.natvis) - # Warnings Wall is problematic in mixed C/C++, so using W4 - target_compile_options(box3d PRIVATE /W4) - # target_compile_options(box3d PRIVATE /wd4820 /wd5045 /wd4061 /wd4711 /wd4514 /wd4365 /wd5219 /wd5039) - target_compile_options(box3d PRIVATE /wd4820 /wd5045 /wd4061 /wd4711) - # 4710 - warn about inline functions that are not inlined - target_compile_options(box3d PRIVATE /wd4710 ) - - if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") - target_compile_options(box3d PRIVATE -Wmissing-prototypes) + if (CMAKE_GENERATOR MATCHES "Visual Studio") + target_compile_options(box3d PRIVATE /MP) endif() - if (BOX3D_AVX2 AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "^(x64|X86)$") + if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + # clang-cl: /Wall maps to -Weverything which is far too aggressive + target_compile_options(box3d PRIVATE /W4 -Wmissing-prototypes) + else() + # All Warnings with some disabled + # 4820 - padding between members + # 5045 - Spectre mitigation + # 4061 - not handling all cases for an enum in a switch block + # 4711 - function inlined without being marked for inline + # 4710 - inline functions that are not inlined + target_compile_options(box3d PRIVATE /Wall /wd4820 /wd5045 /wd4061 /wd4711 /wd4710) + endif() + + if (NOT BOX3D_DISABLE_SIMD AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "^(x64|X86)$") set_source_files_properties(wide8.c PROPERTIES COMPILE_OPTIONS "/arch:AVX2") endif() elseif (MINGW) message(STATUS "Box3D on MinGW") + target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value) elseif (APPLE) message(STATUS "Box3D on Apple") - target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic) + target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value) elseif (EMSCRIPTEN) message(STATUS "Box3D on Emscripten") - # SSE2/wasm SIMD flags are set directory-wide in the top-level CMakeLists so the - # tests, which include simd.h, get them too. elseif (UNIX) message(STATUS "Box3D using Unix") target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value) - if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64") - # raspberry pi - # -mfpu=neon - # target_compile_options(box3d PRIVATE) - else() - endif() endif() source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "src" FILES ${BOX3D_SOURCE_FILES}) @@ -264,15 +254,69 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/box3d ) +export( + EXPORT box3dConfig + NAMESPACE box3d:: + FILE "${PROJECT_BINARY_DIR}/box3dConfig.cmake" +) + include(CMakePackageConfigHelpers) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/box3dConfigVersion.cmake" + "${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/box3dConfigVersion.cmake" + FILES "${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/box3d" ) + +# Anchor every path to the .pc file itself so the install tree can be relocated, +# by cmake --install --prefix or by moving it afterwards +file(RELATIVE_PATH PKGCONFIG_PREFIX_REL "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}") +string(REGEX REPLACE "/$" "" PKGCONFIG_PREFIX_REL "${PKGCONFIG_PREFIX_REL}") +file(RELATIVE_PATH PKGCONFIG_LIBDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_LIBDIR}") +file(RELATIVE_PATH PKGCONFIG_INCLUDEDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}") + +# The file has to carry every PUBLIC define the exported target carries, or consumers +# compile against different headers than the library was built with. Keep in sync +# with the defines above. +set(PKGCONFIG_CFLAGS "") +if (BOX3D_DOUBLE_PRECISION) + string(APPEND PKGCONFIG_CFLAGS " -DBOX3D_DOUBLE_PRECISION") +endif() +if (WIN32 AND BUILD_SHARED_LIBS) + # base.h keys the dllimport off _WIN32, so MinGW needs this as much as MSVC + string(APPEND PKGCONFIG_CFLAGS " -DBOX3D_DLL") +endif() +string(APPEND PKGCONFIG_CFLAGS "$<$: -DB3_ENABLE_ASSERT>") + +set(PKGCONFIG_LIBNAME "box3d$<$:${CMAKE_DEBUG_POSTFIX}>") + +# Plain pkg-config --libs skips Libs.private, and Box3D builds static by default, so +# public link deps belong on the main line unless we are actually building a shared lib +set(PKGCONFIG_LIBS "") +set(PKGCONFIG_LIBS_PRIVATE "") +if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN) + if(BUILD_SHARED_LIBS) + set(PKGCONFIG_LIBS_PRIVATE "-lm") + else() + set(PKGCONFIG_LIBS " -lm") + endif() +endif() + +configure_file(box3d.pc.in box3d.pc.gen @ONLY) + +# The library name and the assert define vary by config, so finish the substitution +# per config instead of once at configure time +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$/box3d.pc" + INPUT "${CMAKE_CURRENT_BINARY_DIR}/box3d.pc.gen" +) + +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$/box3d.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" +) diff --git a/src/box3d.pc.in b/src/box3d.pc.in new file mode 100644 index 0000000..01a507b --- /dev/null +++ b/src/box3d.pc.in @@ -0,0 +1,11 @@ +prefix=${pcfiledir}/@PKGCONFIG_PREFIX_REL@ +exec_prefix=${prefix} +libdir=${prefix}/@PKGCONFIG_LIBDIR_REL@ +includedir=${prefix}/@PKGCONFIG_INCLUDEDIR_REL@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -l@PKGCONFIG_LIBNAME@@PKGCONFIG_LIBS@ +Libs.private: @PKGCONFIG_LIBS_PRIVATE@ +Cflags: -I${includedir}@PKGCONFIG_CFLAGS@ diff --git a/src/replay.c b/src/replay.c index 7a46d73..38bda1a 100644 --- a/src/replay.c +++ b/src/replay.c @@ -1868,7 +1868,7 @@ static void b3RecComputeQueryBounds( b3RecDrawQuery* q ) // Sweep each point across the translation. A non-cast query has zero translation, so both ends // coincide and the duplicates fold away. b3Pos end = b3OffsetPos( q->origin, q->translation ); - b3Vec3 world[2 * B3_MAX_SHAPE_CAST_POINTS]; + b3Vec3 world[2 * B3_MAX_SHAPE_CAST_POINTS] = { 0 }; int n = 0; for ( int i = 0; i < count; ++i ) { diff --git a/src/simd.h b/src/simd.h index b4da76a..e10b9ed 100644 --- a/src/simd.h +++ b/src/simd.h @@ -395,7 +395,7 @@ float b3IntersectRayTriangle( b3V32 rayStart, b3V32 rayDelta, b3V32 vertex1, b3V B3_FORCE_INLINE b3AABB b3UnionV( b3AABB a, b3AABB b ) { - b3AABB result; + b3AABB result = { 0 }; b3StoreAABBV( &result, b3UnionAABBV( b3LoadAABBV( &a ), b3LoadAABBV( &b ) ), true ); return result; } diff --git a/src/timer.c b/src/timer.c index f779e3b..3fb46f7 100644 --- a/src/timer.c +++ b/src/timer.c @@ -169,12 +169,27 @@ static void b3SetCurrentThreadName( const char* name ) HMODULE kernel = GetModuleHandleW( L"kernel32.dll" ); if ( kernel != NULL ) { - // MSVC /Wall warns C4191 on every FARPROC function-pointer cast. - // This is the intended use of GetProcAddress, so suppress locally. + // MSVC /Wall warns C4191 and GCC/Clang -Wcast-function-type + // warns on every FARPROC function-pointer cast. This is the + // intended use of GetProcAddress, so suppress locally. +#if defined( __clang__ ) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-function-type" +#elif defined( _MSC_VER ) #pragma warning( push ) #pragma warning( disable : 4191 ) +#elif defined( __GNUC__ ) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif pfn = (b3SetThreadDescriptionFn)GetProcAddress( kernel, "SetThreadDescription" ); +#if defined( __clang__ ) +#pragma clang diagnostic pop +#elif defined( _MSC_VER ) #pragma warning( pop ) +#elif defined( __GNUC__ ) +#pragma GCC diagnostic pop +#endif } resolved = 1; } diff --git a/src/world_snapshot.c b/src/world_snapshot.c index e763fde..0f47969 100644 --- a/src/world_snapshot.c +++ b/src/world_snapshot.c @@ -323,7 +323,7 @@ static void b3SerTree( b3RecBuffer* buf, const b3DynamicTree* tree ) static void b3DesTree( b3SnapReader* r, b3DynamicTree* tree ) { - uint64_t version; + uint64_t version = 0; b3SnapR_Bytes( r, &version, sizeof( uint64_t ) ); int nodeEnd = b3SnapR_I32( r ); int pairFreeList = b3SnapR_I32( r ); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b3e192..ee6fceb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,21 +41,20 @@ set_target_properties(test PROPERTIES C_EXTENSIONS NO ) -# Special access to Box3D internals for testing +if(BOX3D_COMPILE_WARNING_AS_ERROR) + set_target_properties(test PROPERTIES COMPILE_WARNING_AS_ERROR ON) +endif() + +# Special access to Box3D internals for testing. The internal headers select the SIMD path +# from the build configuration, so the tests must see the same selection as the library. target_include_directories(test PRIVATE ${CMAKE_SOURCE_DIR}/src) +target_compile_definitions(test PRIVATE ${BOX3D_SIMD_DEFINITIONS}) +target_compile_options(test PRIVATE ${BOX3D_SIMD_OPTIONS}) if(BOX3D_VALIDATE) target_compile_definitions(test PRIVATE BOX3D_VALIDATE) endif() -if(BOX3D_DISABLE_SIMD) - target_compile_definitions(test PRIVATE BOX3D_DISABLE_SIMD) -endif() - -if(NOT BOX3D_AVX2) - target_compile_definitions(test PRIVATE BOX3D_DISABLE_AVX2) -endif() - target_link_libraries(test PRIVATE box3d shared) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "" FILES ${BOX3D_TEST_FILES})